codemirror-languageserver 1.14.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 CHANGED
@@ -6,52 +6,70 @@ 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
  ```
12
21
  npm i codemirror-languageserver
13
22
  ```
14
23
 
15
- ``` js
24
+ ```js
16
25
  import { languageServer } from 'codemirror-languageserver';
17
26
 
18
- const transport = new WebSocketTransport(serverUri)
27
+ const transport = new WebSocketTransport(serverUri);
19
28
 
20
29
  var ls = languageServer({
21
- // WebSocket server uri and other client options.
22
- serverUri,
23
- rootUri: 'file:///',
24
-
25
- // Alternatively, to share the same client across multiple instances of this plugin.
26
- client: new LanguageServerClient({
27
- serverUri,
28
- rootUri: 'file:///'
29
- }),
30
-
31
- documentUri: `file:///${filename}`,
32
- languageId: 'cpp' // As defined at https://microsoft.github.io/language-server-protocol/specification#textDocumentItem.
30
+ // WebSocket server uri and other client options.
31
+ serverUri,
32
+ rootUri: 'file:///',
33
+
34
+ // Alternatively, to share the same client across multiple instances of this plugin.
35
+ client: new LanguageServerClient({
36
+ serverUri,
37
+ rootUri: 'file:///',
38
+ }),
39
+
40
+ documentUri: `file:///${filename}`,
41
+ languageId: 'cpp', // As defined at https://microsoft.github.io/language-server-protocol/specification#textDocumentItem.
33
42
  });
34
43
 
35
44
  var view = new EditorView({
36
- state: EditorState.create({
37
- extensions: [
38
- // ...
39
- ls,
40
- // ...
41
- ]
42
- })
45
+ state: EditorState.create({
46
+ extensions: [
47
+ // ...
48
+ ls,
49
+ // ...
50
+ ],
51
+ }),
43
52
  });
44
53
  ```
45
54
 
55
+ ### Using with Initialization Options
56
+
57
+ The plugin includes built-in TypeScript definitions for popular language servers:
58
+
59
+ - `PyrightInitializationOptions` - Python (Pyright)
60
+ - `RustAnalyzerInitializationOptions` - Rust (rust-analyzer)
61
+ - `TypeScriptInitializationOptions` - TypeScript/JavaScript
62
+ - `ESLintInitializationOptions` - ESLint
63
+ - `ClangdInitializationOptions` - C/C++ (Clangd)
64
+ - `GoplsInitializationOptions` - Go (Gopls)
65
+
46
66
  ## Contributing
47
67
 
48
68
  Contributions are welcome.
49
69
 
50
70
  ## Real World Uses
51
71
 
52
- https://user-images.githubusercontent.com/348107/120141150-c6bb9180-c1fd-11eb-8ada-9b7b7a1e4ade.mp4
53
-
54
- - [Toph](https://toph.co): Competitive programming platform. Toph uses Language Server Plugin for CodeMirror 6 with its integrated code editor.
72
+ - [Toph](https://toph.co): Competitive programming platform. Toph uses Language Server Plugin for CodeMirror 6 with its integrated code editor.
55
73
 
56
74
  ## License
57
75
 
package/demo/demo.js CHANGED
@@ -36,8 +36,33 @@ import { languageServer } from '../src';
36
36
 
37
37
  const tabSizeCompartment = new Compartment();
38
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
+
39
64
  const view = new EditorView({
40
- doc: '#include <iostream>\n\nusing namespace std;\n\nint main() {\n\treturn 0;\n}\n',
65
+ doc,
41
66
  parent: document.getElementById('editor'),
42
67
  extensions: [
43
68
  lineNumbers(),
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
 
@@ -39824,17 +39824,36 @@ d.options;
39824
39824
  R.parse;
39825
39825
  b.lex;
39826
39826
 
39827
+ function posToOffset(doc, pos) {
39828
+ if (pos.line >= doc.lines) {
39829
+ return;
39830
+ }
39831
+ const offset = doc.line(pos.line + 1).from + pos.character;
39832
+ if (offset > doc.length) {
39833
+ return;
39834
+ }
39835
+ return offset;
39836
+ }
39837
+ function offsetToPos(doc, offset) {
39838
+ const line = doc.lineAt(offset);
39839
+ return {
39840
+ character: offset - line.from,
39841
+ line: line.number - 1,
39842
+ };
39843
+ }
39844
+
39827
39845
  const timeout = 10000;
39828
39846
  const changesDelay = 500;
39829
39847
  const CompletionItemKindMap = Object.fromEntries(Object.entries(mainExports.CompletionItemKind).map(([key, value]) => [value, key]));
39830
39848
  const useLast = (values) => values.reduce((_, v) => v, '');
39831
- const client = Facet.define({
39849
+ Facet.define({
39832
39850
  combine: useLast,
39833
39851
  });
39834
- const documentUri = Facet.define({ combine: useLast });
39835
- const languageId = Facet.define({ combine: useLast });
39852
+ Facet.define({ combine: useLast });
39853
+ Facet.define({ combine: useLast });
39836
39854
  class LanguageServerClient {
39837
39855
  constructor(options) {
39856
+ this.options = options;
39838
39857
  this.rootUri = options.rootUri;
39839
39858
  this.workspaceFolders = options.workspaceFolders;
39840
39859
  this.autoClose = options.autoClose;
@@ -39862,13 +39881,14 @@ class LanguageServerClient {
39862
39881
  }
39863
39882
  this.initializePromise = this.initialize();
39864
39883
  }
39865
- async initialize() {
39866
- const { capabilities } = await this.request('initialize', {
39884
+ getInitializeParams() {
39885
+ var _a;
39886
+ return {
39867
39887
  capabilities: {
39868
39888
  textDocument: {
39869
39889
  hover: {
39870
39890
  dynamicRegistration: true,
39871
- contentFormat: ['plaintext', 'markdown'],
39891
+ contentFormat: ['markdown', 'plaintext'],
39872
39892
  },
39873
39893
  moniker: {},
39874
39894
  synchronization: {
@@ -39882,16 +39902,16 @@ class LanguageServerClient {
39882
39902
  completionItem: {
39883
39903
  snippetSupport: false,
39884
39904
  commitCharactersSupport: true,
39885
- documentationFormat: ['plaintext', 'markdown'],
39905
+ documentationFormat: ['markdown', 'plaintext'],
39886
39906
  deprecatedSupport: false,
39887
39907
  preselectSupport: false,
39888
39908
  },
39889
- contextSupport: false,
39909
+ contextSupport: true,
39890
39910
  },
39891
39911
  signatureHelp: {
39892
39912
  dynamicRegistration: true,
39893
39913
  signatureInformation: {
39894
- documentationFormat: ['plaintext', 'markdown'],
39914
+ documentationFormat: ['markdown', 'plaintext'],
39895
39915
  },
39896
39916
  },
39897
39917
  declaration: {
@@ -39917,11 +39937,14 @@ class LanguageServerClient {
39917
39937
  },
39918
39938
  },
39919
39939
  },
39920
- initializationOptions: null,
39940
+ initializationOptions: (_a = this.options.initializationOptions) !== null && _a !== void 0 ? _a : null,
39921
39941
  processId: null,
39922
39942
  rootUri: this.rootUri,
39923
39943
  workspaceFolders: this.workspaceFolders,
39924
- }, timeout * 3);
39944
+ };
39945
+ }
39946
+ async initialize() {
39947
+ const { capabilities } = await this.request('initialize', this.getInitializeParams(), timeout * 3);
39925
39948
  this.capabilities = capabilities;
39926
39949
  this.notify('initialized', {});
39927
39950
  this.ready = true;
@@ -39941,6 +39964,15 @@ class LanguageServerClient {
39941
39964
  async textDocumentCompletion(params) {
39942
39965
  return await this.request('textDocument/completion', params, timeout);
39943
39966
  }
39967
+ async textDocumentDefinition(params) {
39968
+ return await this.request('textDocument/definition', params, timeout);
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
+ }
39944
39976
  attachPlugin(plugin) {
39945
39977
  this.plugins.push(plugin);
39946
39978
  }
@@ -39967,12 +39999,12 @@ class LanguageServerClient {
39967
39999
  }
39968
40000
  }
39969
40001
  class LanguageServerPlugin {
39970
- constructor(view, allowHTMLContent) {
40002
+ constructor(view, { client, documentUri, languageId, allowHTMLContent, }) {
39971
40003
  this.view = view;
40004
+ this.client = client;
40005
+ this.documentUri = documentUri;
40006
+ this.languageId = languageId;
39972
40007
  this.allowHTMLContent = allowHTMLContent;
39973
- this.client = this.view.state.facet(client);
39974
- this.documentUri = this.view.state.facet(documentUri);
39975
- this.languageId = this.view.state.facet(languageId);
39976
40008
  this.documentVersion = 0;
39977
40009
  this.changesTimeout = 0;
39978
40010
  this.client.attachPlugin(this);
@@ -40174,6 +40206,43 @@ class LanguageServerPlugin {
40174
40206
  filter: false,
40175
40207
  };
40176
40208
  }
40209
+ async requestLocation(view, { line, character }, capability, method) {
40210
+ if (!this.client.ready || !this.client.capabilities[capability]) {
40211
+ return null;
40212
+ }
40213
+ const result = await this.client[method]({
40214
+ textDocument: { uri: this.documentUri },
40215
+ position: { line, character },
40216
+ });
40217
+ if (!result)
40218
+ return;
40219
+ const location = Array.isArray(result) ? result[0] : result;
40220
+ const uri = location.uri ||
40221
+ location.targetUri;
40222
+ const range = location.range ||
40223
+ location.targetRange;
40224
+ if (uri === this.documentUri) {
40225
+ view.dispatch(view.state.update({
40226
+ selection: {
40227
+ anchor: posToOffset(view.state.doc, range.start),
40228
+ head: posToOffset(view.state.doc, range.end),
40229
+ },
40230
+ }));
40231
+ }
40232
+ return {
40233
+ uri,
40234
+ range,
40235
+ };
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
+ }
40177
40246
  processNotification(notification) {
40178
40247
  try {
40179
40248
  switch (notification.method) {
@@ -40217,72 +40286,7 @@ class LanguageServerPlugin {
40217
40286
  this.view.dispatch(setDiagnostics(this.view.state, diagnostics));
40218
40287
  }
40219
40288
  }
40220
- function languageServer(options) {
40221
- const serverUri = options.serverUri;
40222
- delete options.serverUri;
40223
- return languageServerWithTransport({
40224
- ...options,
40225
- transport: new buildExports.WebSocketTransport(serverUri),
40226
- });
40227
- }
40228
- function languageServerWithTransport(options) {
40229
- let plugin = null;
40230
- return [
40231
- client.of(options.client ||
40232
- new LanguageServerClient({ ...options, autoClose: true })),
40233
- documentUri.of(options.documentUri),
40234
- languageId.of(options.languageId),
40235
- ViewPlugin.define((view) => (plugin = new LanguageServerPlugin(view, options.allowHTMLContent))),
40236
- hoverTooltip((view, pos) => {
40237
- var _a;
40238
- return (_a = plugin === null || plugin === void 0 ? void 0 : plugin.requestHoverTooltip(view, offsetToPos(view.state.doc, pos))) !== null && _a !== void 0 ? _a : null;
40239
- }),
40240
- autocompletion({
40241
- override: [
40242
- async (context) => {
40243
- var _a, _b, _c;
40244
- if (plugin == null) {
40245
- return null;
40246
- }
40247
- const { state, pos, explicit } = context;
40248
- const line = state.doc.lineAt(pos);
40249
- let trigKind = mainExports.CompletionTriggerKind.Invoked;
40250
- let trigChar;
40251
- if (!explicit &&
40252
- ((_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]))) {
40253
- trigKind = mainExports.CompletionTriggerKind.TriggerCharacter;
40254
- trigChar = line.text[pos - line.from - 1];
40255
- }
40256
- if (trigKind === mainExports.CompletionTriggerKind.Invoked &&
40257
- !context.matchBefore(/\w+$/)) {
40258
- return null;
40259
- }
40260
- return await plugin.requestCompletion(context, offsetToPos(state.doc, pos), {
40261
- triggerCharacter: trigChar,
40262
- triggerKind: trigKind,
40263
- });
40264
- },
40265
- ],
40266
- }),
40267
- ];
40268
- }
40269
- function posToOffset(doc, pos) {
40270
- if (pos.line >= doc.lines) {
40271
- return;
40272
- }
40273
- const offset = doc.line(pos.line + 1).from + pos.character;
40274
- if (offset > doc.length) {
40275
- return;
40276
- }
40277
- return offset;
40278
- }
40279
- function offsetToPos(doc, offset) {
40280
- const line = doc.lineAt(offset);
40281
- return {
40282
- character: offset - line.from,
40283
- line: line.number - 1,
40284
- };
40285
- }
40289
+ const languageServerPlugin = ViewPlugin.fromClass(LanguageServerPlugin);
40286
40290
  async function formatContents(contents) {
40287
40291
  if (isLSPMarkupContent(contents)) {
40288
40292
  let value = contents.value;
@@ -40313,10 +40317,11 @@ function prefixMatch(items) {
40313
40317
  const first = new Set();
40314
40318
  const rest = new Set();
40315
40319
  for (const item of items) {
40316
- const [initial, ...restStr] = ((_a = item.textEdit) === null || _a === void 0 ? void 0 : _a.newText) || item.label;
40320
+ const text = ((_a = item.textEdit) === null || _a === void 0 ? void 0 : _a.newText) || item.label;
40321
+ const initial = text[0];
40317
40322
  first.add(initial);
40318
- for (const char of restStr) {
40319
- rest.add(char);
40323
+ for (let i = 1; i < text.length; i++) {
40324
+ rest.add(text[i]);
40320
40325
  }
40321
40326
  }
40322
40327
  const source = toSet(first) + toSet(rest) + '*$';
@@ -40329,9 +40334,110 @@ function isLSPMarkupContent(contents) {
40329
40334
  return contents.kind !== undefined;
40330
40335
  }
40331
40336
 
40337
+ function requestDefinition(view, pos) {
40338
+ const plugin = view.plugin(languageServerPlugin);
40339
+ if (!plugin)
40340
+ return false;
40341
+ plugin.requestDefinition(view, offsetToPos(view.state.doc, pos));
40342
+ return true;
40343
+ }
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);
40355
+ const jumpToDefinitionKeymap = [
40356
+ { key: 'F12', run: jumpToDefinition, preventDefault: true },
40357
+ { key: 'Mod-F12', run: jumpToTypeDefinition, preventDefault: true },
40358
+ ];
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
+
40332
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";
40333
40439
  new EditorView({
40334
- doc: '#include <iostream>\n\nusing namespace std;\n\nint main() {\n\treturn 0;\n}\n',
40440
+ doc: doc,
40335
40441
  parent: document.getElementById('editor'),
40336
40442
  extensions: [lineNumbers(), highlightSpecialChars(), history(), foldGutter(), drawSelection(), EditorState.allowMultipleSelections.of(true), indentOnInput(), indentUnit.of('\t'), syntaxHighlighting(defaultHighlightStyle, {
40337
40443
  fallback: true
@@ -0,0 +1,2 @@
1
+ import { Extension } from '@codemirror/state';
2
+ export declare const autocompletion: () => Extension;
@@ -0,0 +1,8 @@
1
+ import { Command, KeyBinding } from '@codemirror/view';
2
+ export declare const jumpToDefinition: Command;
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;
8
+ export declare const jumpToDefinitionKeymap: readonly KeyBinding[];
@@ -0,0 +1,2 @@
1
+ import { Extension } from '@codemirror/state';
2
+ export declare const hoverTooltip: () => Extension;