codemirror-languageserver 1.15.0 → 1.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -2
- package/demo/demo.js +27 -18
- package/demo/dist/demo.js +127 -87
- package/dist/completion.d.ts +2 -0
- package/dist/definition.d.ts +4 -0
- package/dist/hover.d.ts +2 -0
- package/dist/index.d.ts +14 -1
- package/dist/index.js +121 -71
- package/dist/initialization.d.ts +279 -0
- package/dist/mouse.d.ts +2 -0
- package/dist/plugin.d.ts +52 -299
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,6 +6,15 @@ This plugin enables code completion, hover tooltips, and linter functionality by
|
|
|
6
6
|
|
|
7
7
|
[How It Works](https://hjr265.me/blog/codemirror-lsp/)
|
|
8
8
|
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
https://user-images.githubusercontent.com/348107/120141150-c6bb9180-c1fd-11eb-8ada-9b7b7a1e4ade.mp4
|
|
12
|
+
|
|
13
|
+
- ⌨️ Code Completion
|
|
14
|
+
- 📚 Hover Documentation
|
|
15
|
+
- 🩺 Diagnostics
|
|
16
|
+
- 🔍 Go to Definition, Declaration, and Type Definition
|
|
17
|
+
|
|
9
18
|
## Usage
|
|
10
19
|
|
|
11
20
|
```
|
|
@@ -60,8 +69,6 @@ Contributions are welcome.
|
|
|
60
69
|
|
|
61
70
|
## Real World Uses
|
|
62
71
|
|
|
63
|
-
https://user-images.githubusercontent.com/348107/120141150-c6bb9180-c1fd-11eb-8ada-9b7b7a1e4ade.mp4
|
|
64
|
-
|
|
65
72
|
- [Toph](https://toph.co): Competitive programming platform. Toph uses Language Server Plugin for CodeMirror 6 with its integrated code editor.
|
|
66
73
|
|
|
67
74
|
## License
|
package/demo/demo.js
CHANGED
|
@@ -32,16 +32,37 @@ import {
|
|
|
32
32
|
} from '@codemirror/autocomplete';
|
|
33
33
|
import { lintKeymap } from '@codemirror/lint';
|
|
34
34
|
import { cpp } from '@codemirror/lang-cpp';
|
|
35
|
-
import {
|
|
36
|
-
languageServer,
|
|
37
|
-
jumpToDefinitionKeymap,
|
|
38
|
-
jumpToDefinitionPos,
|
|
39
|
-
} from '../src';
|
|
35
|
+
import { languageServer } from '../src';
|
|
40
36
|
|
|
41
37
|
const tabSizeCompartment = new Compartment();
|
|
42
38
|
|
|
39
|
+
const doc = `#include <iostream>
|
|
40
|
+
|
|
41
|
+
using namespace std;
|
|
42
|
+
|
|
43
|
+
class Animal {
|
|
44
|
+
public:
|
|
45
|
+
void say(string call) {
|
|
46
|
+
cout << call << endl;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
class Cat : Animal {
|
|
51
|
+
public:
|
|
52
|
+
void meow() {
|
|
53
|
+
this->say("meow");
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
int main() {
|
|
58
|
+
Cat cat;
|
|
59
|
+
cat.meow();
|
|
60
|
+
return 0;
|
|
61
|
+
}
|
|
62
|
+
`
|
|
63
|
+
|
|
43
64
|
const view = new EditorView({
|
|
44
|
-
doc
|
|
65
|
+
doc,
|
|
45
66
|
parent: document.getElementById('editor'),
|
|
46
67
|
extensions: [
|
|
47
68
|
lineNumbers(),
|
|
@@ -84,17 +105,5 @@ const view = new EditorView({
|
|
|
84
105
|
documentUri: `file:///demo/main.cpp`,
|
|
85
106
|
languageId: 'cpp',
|
|
86
107
|
}),
|
|
87
|
-
keymap.of([...jumpToDefinitionKeymap]),
|
|
88
|
-
EditorView.domEventHandlers({
|
|
89
|
-
click: (event, view) => {
|
|
90
|
-
if (!event.ctrlKey && !event.metaKey) return;
|
|
91
|
-
const pos = view.posAtCoords({
|
|
92
|
-
x: event.clientX,
|
|
93
|
-
y: event.clientY,
|
|
94
|
-
});
|
|
95
|
-
const ok = jumpToDefinitionPos(pos)(view);
|
|
96
|
-
if (ok) event.preventDefault();
|
|
97
|
-
},
|
|
98
|
-
}),
|
|
99
108
|
],
|
|
100
109
|
});
|
package/demo/dist/demo.js
CHANGED
|
@@ -4873,7 +4873,7 @@ let nav = typeof navigator != "undefined" ? navigator : {
|
|
|
4873
4873
|
vendor: "",
|
|
4874
4874
|
platform: ""
|
|
4875
4875
|
};
|
|
4876
|
-
let doc = typeof document != "undefined" ? document : {
|
|
4876
|
+
let doc$1 = typeof document != "undefined" ? document : {
|
|
4877
4877
|
documentElement: {
|
|
4878
4878
|
style: {}
|
|
4879
4879
|
}
|
|
@@ -4884,7 +4884,7 @@ const ie_11up = /*@__PURE__*//Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(nav.us
|
|
|
4884
4884
|
const ie$1 = !!(ie_upto10 || ie_11up || ie_edge);
|
|
4885
4885
|
const gecko = !ie$1 && /*@__PURE__*//gecko\/(\d+)/i.test(nav.userAgent);
|
|
4886
4886
|
const chrome = !ie$1 && /*@__PURE__*//Chrome\/(\d+)/.exec(nav.userAgent);
|
|
4887
|
-
const webkit = "webkitFontSmoothing" in doc.documentElement.style;
|
|
4887
|
+
const webkit = "webkitFontSmoothing" in doc$1.documentElement.style;
|
|
4888
4888
|
const safari = !ie$1 && /*@__PURE__*//Apple Computer/.test(nav.vendor);
|
|
4889
4889
|
const ios = safari && (/*@__PURE__*//Mobile\/\w+/.test(nav.userAgent) || nav.maxTouchPoints > 2);
|
|
4890
4890
|
var browser$2 = {
|
|
@@ -4892,7 +4892,7 @@ var browser$2 = {
|
|
|
4892
4892
|
windows: /*@__PURE__*//Win/.test(nav.platform),
|
|
4893
4893
|
linux: /*@__PURE__*//Linux|X11/.test(nav.platform),
|
|
4894
4894
|
ie: ie$1,
|
|
4895
|
-
ie_version: ie_upto10 ? doc.documentMode || 6 : ie_11up ? +ie_11up[1] : ie_edge ? +ie_edge[1] : 0,
|
|
4895
|
+
ie_version: ie_upto10 ? doc$1.documentMode || 6 : ie_11up ? +ie_11up[1] : ie_edge ? +ie_edge[1] : 0,
|
|
4896
4896
|
gecko,
|
|
4897
4897
|
gecko_version: gecko ? +(/*@__PURE__*//Firefox\/(\d+)/.exec(nav.userAgent) || [0, 0])[1] : 0,
|
|
4898
4898
|
chrome: !!chrome,
|
|
@@ -4901,7 +4901,7 @@ var browser$2 = {
|
|
|
4901
4901
|
android: /*@__PURE__*//Android\b/.test(nav.userAgent),
|
|
4902
4902
|
safari,
|
|
4903
4903
|
webkit_version: webkit ? +(/*@__PURE__*//\bAppleWebKit\/(\d+)/.exec(nav.userAgent) || [0, 0])[1] : 0,
|
|
4904
|
-
tabSize: doc.documentElement.style.tabSize != null ? "tab-size" : "-moz-tab-size"
|
|
4904
|
+
tabSize: doc$1.documentElement.style.tabSize != null ? "tab-size" : "-moz-tab-size"
|
|
4905
4905
|
};
|
|
4906
4906
|
const MaxJoinLen = 256;
|
|
4907
4907
|
class TextView extends ContentView {
|
|
@@ -14325,7 +14325,7 @@ but also provides an `active` property holding a state field that
|
|
|
14325
14325
|
can be used to read the currently active tooltips produced by this
|
|
14326
14326
|
extension.
|
|
14327
14327
|
*/
|
|
14328
|
-
function hoverTooltip(source, options = {}) {
|
|
14328
|
+
function hoverTooltip$1(source, options = {}) {
|
|
14329
14329
|
let setHover = StateEffect.define();
|
|
14330
14330
|
let hoverState = StateField.define({
|
|
14331
14331
|
create() {
|
|
@@ -24101,7 +24101,7 @@ function canStartStringAt(state, pos, prefixes) {
|
|
|
24101
24101
|
/**
|
|
24102
24102
|
Returns an extension that enables autocompletion.
|
|
24103
24103
|
*/
|
|
24104
|
-
function autocompletion(config = {}) {
|
|
24104
|
+
function autocompletion$1(config = {}) {
|
|
24105
24105
|
return [commitCharacters, completionState, completionConfig.of(config), completionPlugin, completionKeymapExt, baseTheme$1];
|
|
24106
24106
|
}
|
|
24107
24107
|
/**
|
|
@@ -24784,7 +24784,7 @@ const lintExtensions = [lintState, /*@__PURE__*/EditorView.decorations.compute([
|
|
|
24784
24784
|
panel
|
|
24785
24785
|
} = state.field(lintState);
|
|
24786
24786
|
return !selected || !panel || selected.from == selected.to ? Decoration.none : Decoration.set([activeMark.range(selected.from, selected.to)]);
|
|
24787
|
-
}), /*@__PURE__*/hoverTooltip(lintTooltip, {
|
|
24787
|
+
}), /*@__PURE__*/hoverTooltip$1(lintTooltip, {
|
|
24788
24788
|
hideOn: hideTooltip
|
|
24789
24789
|
}), baseTheme];
|
|
24790
24790
|
|
|
@@ -39846,11 +39846,11 @@ const timeout = 10000;
|
|
|
39846
39846
|
const changesDelay = 500;
|
|
39847
39847
|
const CompletionItemKindMap = Object.fromEntries(Object.entries(mainExports.CompletionItemKind).map(([key, value]) => [value, key]));
|
|
39848
39848
|
const useLast = (values) => values.reduce((_, v) => v, '');
|
|
39849
|
-
|
|
39849
|
+
Facet.define({
|
|
39850
39850
|
combine: useLast,
|
|
39851
39851
|
});
|
|
39852
|
-
|
|
39853
|
-
|
|
39852
|
+
Facet.define({ combine: useLast });
|
|
39853
|
+
Facet.define({ combine: useLast });
|
|
39854
39854
|
class LanguageServerClient {
|
|
39855
39855
|
constructor(options) {
|
|
39856
39856
|
this.options = options;
|
|
@@ -39888,7 +39888,7 @@ class LanguageServerClient {
|
|
|
39888
39888
|
textDocument: {
|
|
39889
39889
|
hover: {
|
|
39890
39890
|
dynamicRegistration: true,
|
|
39891
|
-
contentFormat: ['
|
|
39891
|
+
contentFormat: ['markdown', 'plaintext'],
|
|
39892
39892
|
},
|
|
39893
39893
|
moniker: {},
|
|
39894
39894
|
synchronization: {
|
|
@@ -39902,7 +39902,7 @@ class LanguageServerClient {
|
|
|
39902
39902
|
completionItem: {
|
|
39903
39903
|
snippetSupport: false,
|
|
39904
39904
|
commitCharactersSupport: true,
|
|
39905
|
-
documentationFormat: ['
|
|
39905
|
+
documentationFormat: ['markdown', 'plaintext'],
|
|
39906
39906
|
deprecatedSupport: false,
|
|
39907
39907
|
preselectSupport: false,
|
|
39908
39908
|
},
|
|
@@ -39911,7 +39911,7 @@ class LanguageServerClient {
|
|
|
39911
39911
|
signatureHelp: {
|
|
39912
39912
|
dynamicRegistration: true,
|
|
39913
39913
|
signatureInformation: {
|
|
39914
|
-
documentationFormat: ['
|
|
39914
|
+
documentationFormat: ['markdown', 'plaintext'],
|
|
39915
39915
|
},
|
|
39916
39916
|
},
|
|
39917
39917
|
declaration: {
|
|
@@ -39967,6 +39967,12 @@ class LanguageServerClient {
|
|
|
39967
39967
|
async textDocumentDefinition(params) {
|
|
39968
39968
|
return await this.request('textDocument/definition', params, timeout);
|
|
39969
39969
|
}
|
|
39970
|
+
async textDocumentDeclaration(params) {
|
|
39971
|
+
return await this.request('textDocument/declaration', params, timeout);
|
|
39972
|
+
}
|
|
39973
|
+
async textDocumentTypeDefinition(params) {
|
|
39974
|
+
return await this.request('textDocument/typeDefinition', params, timeout);
|
|
39975
|
+
}
|
|
39970
39976
|
attachPlugin(plugin) {
|
|
39971
39977
|
this.plugins.push(plugin);
|
|
39972
39978
|
}
|
|
@@ -39993,12 +39999,12 @@ class LanguageServerClient {
|
|
|
39993
39999
|
}
|
|
39994
40000
|
}
|
|
39995
40001
|
class LanguageServerPlugin {
|
|
39996
|
-
constructor(view, allowHTMLContent) {
|
|
40002
|
+
constructor(view, { client, documentUri, languageId, allowHTMLContent, }) {
|
|
39997
40003
|
this.view = view;
|
|
40004
|
+
this.client = client;
|
|
40005
|
+
this.documentUri = documentUri;
|
|
40006
|
+
this.languageId = languageId;
|
|
39998
40007
|
this.allowHTMLContent = allowHTMLContent;
|
|
39999
|
-
this.client = this.view.state.facet(client);
|
|
40000
|
-
this.documentUri = this.view.state.facet(documentUri);
|
|
40001
|
-
this.languageId = this.view.state.facet(languageId);
|
|
40002
40008
|
this.documentVersion = 0;
|
|
40003
40009
|
this.changesTimeout = 0;
|
|
40004
40010
|
this.client.attachPlugin(this);
|
|
@@ -40200,12 +40206,11 @@ class LanguageServerPlugin {
|
|
|
40200
40206
|
filter: false,
|
|
40201
40207
|
};
|
|
40202
40208
|
}
|
|
40203
|
-
async
|
|
40204
|
-
if (!this.client.ready ||
|
|
40205
|
-
!this.client.capabilities.definitionProvider) {
|
|
40209
|
+
async requestLocation(view, { line, character }, capability, method) {
|
|
40210
|
+
if (!this.client.ready || !this.client.capabilities[capability]) {
|
|
40206
40211
|
return null;
|
|
40207
40212
|
}
|
|
40208
|
-
const result = await this.client
|
|
40213
|
+
const result = await this.client[method]({
|
|
40209
40214
|
textDocument: { uri: this.documentUri },
|
|
40210
40215
|
position: { line, character },
|
|
40211
40216
|
});
|
|
@@ -40229,6 +40234,15 @@ class LanguageServerPlugin {
|
|
|
40229
40234
|
range,
|
|
40230
40235
|
};
|
|
40231
40236
|
}
|
|
40237
|
+
async requestDefinition(view, { line, character }) {
|
|
40238
|
+
return this.requestLocation(view, { line, character }, 'definitionProvider', 'textDocumentDefinition');
|
|
40239
|
+
}
|
|
40240
|
+
async requestDeclaration(view, { line, character }) {
|
|
40241
|
+
return this.requestLocation(view, { line, character }, 'declarationProvider', 'textDocumentDeclaration');
|
|
40242
|
+
}
|
|
40243
|
+
async requestTypeDefinition(view, { line, character }) {
|
|
40244
|
+
return this.requestLocation(view, { line, character }, 'typeDefinitionProvider', 'textDocumentTypeDefinition');
|
|
40245
|
+
}
|
|
40232
40246
|
processNotification(notification) {
|
|
40233
40247
|
try {
|
|
40234
40248
|
switch (notification.method) {
|
|
@@ -40273,58 +40287,6 @@ class LanguageServerPlugin {
|
|
|
40273
40287
|
}
|
|
40274
40288
|
}
|
|
40275
40289
|
const languageServerPlugin = ViewPlugin.fromClass(LanguageServerPlugin);
|
|
40276
|
-
function languageServer(options) {
|
|
40277
|
-
const serverUri = options.serverUri;
|
|
40278
|
-
const { serverUri: _, ...optionsWithoutServerUri } = options;
|
|
40279
|
-
return languageServerWithTransport({
|
|
40280
|
-
...optionsWithoutServerUri,
|
|
40281
|
-
transport: new buildExports.WebSocketTransport(serverUri),
|
|
40282
|
-
});
|
|
40283
|
-
}
|
|
40284
|
-
function languageServerWithTransport(options) {
|
|
40285
|
-
return [
|
|
40286
|
-
client.of(options.client ||
|
|
40287
|
-
new LanguageServerClient({
|
|
40288
|
-
...options,
|
|
40289
|
-
autoClose: true,
|
|
40290
|
-
})),
|
|
40291
|
-
documentUri.of(options.documentUri),
|
|
40292
|
-
languageId.of(options.languageId),
|
|
40293
|
-
languageServerPlugin.of(options.allowHTMLContent),
|
|
40294
|
-
hoverTooltip((view, pos) => {
|
|
40295
|
-
var _a;
|
|
40296
|
-
const plugin = view.plugin(languageServerPlugin);
|
|
40297
|
-
return ((_a = plugin === null || plugin === void 0 ? void 0 : plugin.requestHoverTooltip(view, offsetToPos(view.state.doc, pos))) !== null && _a !== void 0 ? _a : null);
|
|
40298
|
-
}),
|
|
40299
|
-
autocompletion({
|
|
40300
|
-
override: [
|
|
40301
|
-
async (context) => {
|
|
40302
|
-
var _a, _b, _c;
|
|
40303
|
-
const { state, pos, explicit, view } = context;
|
|
40304
|
-
const plugin = view.plugin(languageServerPlugin);
|
|
40305
|
-
if (plugin == null)
|
|
40306
|
-
return null;
|
|
40307
|
-
const line = state.doc.lineAt(pos);
|
|
40308
|
-
let trigKind = mainExports.CompletionTriggerKind.Invoked;
|
|
40309
|
-
let trigChar;
|
|
40310
|
-
if (!explicit &&
|
|
40311
|
-
((_c = (_b = (_a = plugin.client.capabilities) === null || _a === void 0 ? void 0 : _a.completionProvider) === null || _b === void 0 ? void 0 : _b.triggerCharacters) === null || _c === void 0 ? void 0 : _c.includes(line.text[pos - line.from - 1]))) {
|
|
40312
|
-
trigKind = mainExports.CompletionTriggerKind.TriggerCharacter;
|
|
40313
|
-
trigChar = line.text[pos - line.from - 1];
|
|
40314
|
-
}
|
|
40315
|
-
if (trigKind === mainExports.CompletionTriggerKind.Invoked &&
|
|
40316
|
-
!context.matchBefore(/\w+$/)) {
|
|
40317
|
-
return null;
|
|
40318
|
-
}
|
|
40319
|
-
return await plugin.requestCompletion(context, offsetToPos(state.doc, pos), {
|
|
40320
|
-
triggerCharacter: trigChar,
|
|
40321
|
-
triggerKind: trigKind,
|
|
40322
|
-
});
|
|
40323
|
-
},
|
|
40324
|
-
],
|
|
40325
|
-
}),
|
|
40326
|
-
];
|
|
40327
|
-
}
|
|
40328
40290
|
async function formatContents(contents) {
|
|
40329
40291
|
if (isLSPMarkupContent(contents)) {
|
|
40330
40292
|
let value = contents.value;
|
|
@@ -40372,22 +40334,110 @@ function isLSPMarkupContent(contents) {
|
|
|
40372
40334
|
return contents.kind !== undefined;
|
|
40373
40335
|
}
|
|
40374
40336
|
|
|
40375
|
-
function
|
|
40337
|
+
function requestDefinition(view, pos) {
|
|
40376
40338
|
const plugin = view.plugin(languageServerPlugin);
|
|
40377
40339
|
if (!plugin)
|
|
40378
40340
|
return false;
|
|
40379
40341
|
plugin.requestDefinition(view, offsetToPos(view.state.doc, pos));
|
|
40380
40342
|
return true;
|
|
40381
40343
|
}
|
|
40382
|
-
|
|
40383
|
-
const
|
|
40344
|
+
function requestTypeDefinition(view, pos) {
|
|
40345
|
+
const plugin = view.plugin(languageServerPlugin);
|
|
40346
|
+
if (!plugin)
|
|
40347
|
+
return false;
|
|
40348
|
+
plugin.requestTypeDefinition(view, offsetToPos(view.state.doc, pos));
|
|
40349
|
+
return true;
|
|
40350
|
+
}
|
|
40351
|
+
const jumpToDefinition = (view) => requestDefinition(view, view.state.selection.main.head);
|
|
40352
|
+
const jumpToDefinitionPos = (pos) => (view) => requestDefinition(view, pos);
|
|
40353
|
+
const jumpToTypeDefinition = (view) => requestTypeDefinition(view, view.state.selection.main.head);
|
|
40354
|
+
const jumpToTypeDefinitionPos = (pos) => (view) => requestTypeDefinition(view, pos);
|
|
40384
40355
|
const jumpToDefinitionKeymap = [
|
|
40385
40356
|
{ key: 'F12', run: jumpToDefinition, preventDefault: true },
|
|
40357
|
+
{ key: 'Mod-F12', run: jumpToTypeDefinition, preventDefault: true },
|
|
40386
40358
|
];
|
|
40387
40359
|
|
|
40360
|
+
const hoverTooltip = () => hoverTooltip$1((view, pos) => {
|
|
40361
|
+
var _a;
|
|
40362
|
+
const plugin = view.plugin(languageServerPlugin);
|
|
40363
|
+
return ((_a = plugin === null || plugin === void 0 ? void 0 : plugin.requestHoverTooltip(view, offsetToPos(view.state.doc, pos))) !== null && _a !== void 0 ? _a : null);
|
|
40364
|
+
});
|
|
40365
|
+
|
|
40366
|
+
const autocompletion = () => autocompletion$1({
|
|
40367
|
+
override: [
|
|
40368
|
+
async (context) => {
|
|
40369
|
+
var _a, _b, _c;
|
|
40370
|
+
const { state, pos, explicit, view } = context;
|
|
40371
|
+
const plugin = view.plugin(languageServerPlugin);
|
|
40372
|
+
if (plugin == null)
|
|
40373
|
+
return null;
|
|
40374
|
+
const line = state.doc.lineAt(pos);
|
|
40375
|
+
let trigKind = mainExports.CompletionTriggerKind.Invoked;
|
|
40376
|
+
let trigChar;
|
|
40377
|
+
if (!explicit &&
|
|
40378
|
+
((_c = (_b = (_a = plugin.client.capabilities) === null || _a === void 0 ? void 0 : _a.completionProvider) === null || _b === void 0 ? void 0 : _b.triggerCharacters) === null || _c === void 0 ? void 0 : _c.includes(line.text[pos - line.from - 1]))) {
|
|
40379
|
+
trigKind = mainExports.CompletionTriggerKind.TriggerCharacter;
|
|
40380
|
+
trigChar = line.text[pos - line.from - 1];
|
|
40381
|
+
}
|
|
40382
|
+
if (trigKind === mainExports.CompletionTriggerKind.Invoked &&
|
|
40383
|
+
!context.matchBefore(/\w+$/)) {
|
|
40384
|
+
return null;
|
|
40385
|
+
}
|
|
40386
|
+
return await plugin.requestCompletion(context, offsetToPos(state.doc, pos), {
|
|
40387
|
+
triggerCharacter: trigChar,
|
|
40388
|
+
triggerKind: trigKind,
|
|
40389
|
+
});
|
|
40390
|
+
},
|
|
40391
|
+
],
|
|
40392
|
+
});
|
|
40393
|
+
|
|
40394
|
+
const mouseHandler = () => EditorView.domEventHandlers({
|
|
40395
|
+
mousedown: (event, view) => {
|
|
40396
|
+
if (!event.ctrlKey && !event.metaKey)
|
|
40397
|
+
return;
|
|
40398
|
+
const pos = view.posAtCoords({
|
|
40399
|
+
x: event.clientX,
|
|
40400
|
+
y: event.clientY,
|
|
40401
|
+
});
|
|
40402
|
+
const ok = (event.shiftKey
|
|
40403
|
+
? jumpToTypeDefinitionPos(pos)
|
|
40404
|
+
: jumpToDefinitionPos(pos))(view);
|
|
40405
|
+
if (ok)
|
|
40406
|
+
event.preventDefault();
|
|
40407
|
+
},
|
|
40408
|
+
});
|
|
40409
|
+
|
|
40410
|
+
function languageServer(options) {
|
|
40411
|
+
const serverUri = options.serverUri;
|
|
40412
|
+
const { serverUri: _, ...optionsWithoutServerUri } = options;
|
|
40413
|
+
return languageServerWithTransport({
|
|
40414
|
+
...optionsWithoutServerUri,
|
|
40415
|
+
transport: new buildExports.WebSocketTransport(serverUri),
|
|
40416
|
+
});
|
|
40417
|
+
}
|
|
40418
|
+
function languageServerWithTransport(options) {
|
|
40419
|
+
return [
|
|
40420
|
+
languageServerPlugin.of({
|
|
40421
|
+
client: options.client ||
|
|
40422
|
+
new LanguageServerClient({
|
|
40423
|
+
...options,
|
|
40424
|
+
autoClose: true,
|
|
40425
|
+
}),
|
|
40426
|
+
documentUri: options.documentUri,
|
|
40427
|
+
languageId: options.languageId,
|
|
40428
|
+
allowHTMLContent: options.allowHTMLContent,
|
|
40429
|
+
}),
|
|
40430
|
+
hoverTooltip(),
|
|
40431
|
+
autocompletion(),
|
|
40432
|
+
keymap.of([...jumpToDefinitionKeymap]),
|
|
40433
|
+
mouseHandler(),
|
|
40434
|
+
];
|
|
40435
|
+
}
|
|
40436
|
+
|
|
40388
40437
|
var tabSizeCompartment = new Compartment();
|
|
40438
|
+
var doc = "#include <iostream>\n\nusing namespace std;\n\nclass Animal {\n\tpublic:\n\t\tvoid say(string call) {\n\t\t\tcout << call << endl;\n\t\t}\n};\n\nclass Cat : Animal {\n\tpublic:\n\t\tvoid meow() {\n\t\t\tthis->say(\"meow\");\n\t\t}\n};\n\nint main() {\n\tCat cat;\n\tcat.meow();\n\treturn 0;\n}\n";
|
|
40389
40439
|
new EditorView({
|
|
40390
|
-
doc:
|
|
40440
|
+
doc: doc,
|
|
40391
40441
|
parent: document.getElementById('editor'),
|
|
40392
40442
|
extensions: [lineNumbers(), highlightSpecialChars(), history(), foldGutter(), drawSelection(), EditorState.allowMultipleSelections.of(true), indentOnInput(), indentUnit.of('\t'), syntaxHighlighting(defaultHighlightStyle, {
|
|
40393
40443
|
fallback: true
|
|
@@ -40401,15 +40451,5 @@ new EditorView({
|
|
|
40401
40451
|
}],
|
|
40402
40452
|
documentUri: "file:///demo/main.cpp",
|
|
40403
40453
|
languageId: 'cpp'
|
|
40404
|
-
}), keymap.of(_toConsumableArray(jumpToDefinitionKeymap)), EditorView.domEventHandlers({
|
|
40405
|
-
click: function click(event, view) {
|
|
40406
|
-
if (!event.ctrlKey && !event.metaKey) return;
|
|
40407
|
-
var pos = view.posAtCoords({
|
|
40408
|
-
x: event.clientX,
|
|
40409
|
-
y: event.clientY
|
|
40410
|
-
});
|
|
40411
|
-
var ok = jumpToDefinitionPos(pos)(view);
|
|
40412
|
-
if (ok) event.preventDefault();
|
|
40413
|
-
}
|
|
40414
40454
|
})]
|
|
40415
40455
|
});
|
package/dist/definition.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { Command, KeyBinding } from '@codemirror/view';
|
|
2
2
|
export declare const jumpToDefinition: Command;
|
|
3
3
|
export declare const jumpToDefinitionPos: (pos: number) => Command;
|
|
4
|
+
export declare const jumpToDeclaration: Command;
|
|
5
|
+
export declare const jumpToDeclarationPos: (pos: number) => Command;
|
|
6
|
+
export declare const jumpToTypeDefinition: Command;
|
|
7
|
+
export declare const jumpToTypeDefinitionPos: (pos: number) => Command;
|
|
4
8
|
export declare const jumpToDefinitionKeymap: readonly KeyBinding[];
|
package/dist/hover.d.ts
ADDED
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,15 @@
|
|
|
1
|
-
export { LanguageServerClient, languageServerPlugin
|
|
1
|
+
export { LanguageServerClient, languageServerPlugin } from './plugin';
|
|
2
2
|
export { jumpToDefinition, jumpToDefinitionPos, jumpToDefinitionKeymap, } from './definition';
|
|
3
|
+
export { PyrightInitializationOptions, RustAnalyzerInitializationOptions, TypeScriptInitializationOptions, ESLintInitializationOptions, ClangdInitializationOptions, GoplsInitializationOptions, } from './initialization';
|
|
4
|
+
import { LanguageServerClient } from './plugin';
|
|
5
|
+
import type { LanguageServerClientOptions, LanguageServerBaseOptions } from './plugin';
|
|
6
|
+
interface LanguageServerOptions<InitializationOptions = unknown> extends LanguageServerClientOptions<InitializationOptions> {
|
|
7
|
+
client?: LanguageServerClient<InitializationOptions>;
|
|
8
|
+
allowHTMLContent?: boolean;
|
|
9
|
+
}
|
|
10
|
+
interface LanguageServerWebsocketOptions<InitializationOptions = unknown> extends LanguageServerBaseOptions {
|
|
11
|
+
serverUri: `ws://${string}` | `wss://${string}`;
|
|
12
|
+
initializationOptions?: InitializationOptions;
|
|
13
|
+
}
|
|
14
|
+
export declare function languageServer<InitializationOptions = unknown>(options: LanguageServerWebsocketOptions<InitializationOptions>): import("@codemirror/state").Extension[];
|
|
15
|
+
export declare function languageServerWithTransport<InitializationOptions = unknown>(options: LanguageServerOptions<InitializationOptions>): import("@codemirror/state").Extension[];
|