@kerebron/extension-codemirror 0.3.2 → 0.4.2
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 +3 -3
- package/esm/_dnt.polyfills.d.ts +101 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -0
- package/esm/_dnt.polyfills.js +127 -0
- package/esm/_dnt.shims.d.ts +6 -0
- package/esm/_dnt.shims.d.ts.map +1 -0
- package/esm/_dnt.shims.js +61 -0
- package/esm/editor/src/CoreEditor.d.ts +13 -4
- package/esm/editor/src/CoreEditor.d.ts.map +1 -1
- package/esm/editor/src/CoreEditor.js +64 -12
- package/esm/editor/src/Extension.d.ts +6 -1
- package/esm/editor/src/Extension.d.ts.map +1 -1
- package/esm/editor/src/Extension.js +21 -1
- package/esm/editor/src/ExtensionManager.d.ts +5 -6
- package/esm/editor/src/ExtensionManager.d.ts.map +1 -1
- package/esm/editor/src/ExtensionManager.js +43 -55
- package/esm/editor/src/Mark.d.ts +3 -0
- package/esm/editor/src/Mark.d.ts.map +1 -1
- package/esm/editor/src/Mark.js +11 -0
- package/esm/editor/src/Node.d.ts +5 -2
- package/esm/editor/src/Node.d.ts.map +1 -1
- package/esm/editor/src/Node.js +13 -2
- package/esm/editor/src/commands/CommandManager.d.ts +13 -6
- package/esm/editor/src/commands/CommandManager.d.ts.map +1 -1
- package/esm/editor/src/commands/CommandManager.js +59 -2
- package/esm/editor/src/commands/baseCommandFactories.d.ts +3 -0
- package/esm/editor/src/commands/baseCommandFactories.d.ts.map +1 -0
- package/esm/editor/src/commands/baseCommandFactories.js +836 -0
- package/esm/editor/src/commands/keyCommandFactories.d.ts +3 -0
- package/esm/editor/src/commands/keyCommandFactories.d.ts.map +1 -0
- package/esm/editor/src/commands/keyCommandFactories.js +10 -0
- package/esm/editor/src/commands/mod.d.ts +5 -53
- package/esm/editor/src/commands/mod.d.ts.map +1 -1
- package/esm/editor/src/commands/mod.js +14 -821
- package/esm/editor/src/commands/replaceCommandFactories.d.ts +3 -0
- package/esm/editor/src/commands/replaceCommandFactories.d.ts.map +1 -0
- package/esm/editor/src/commands/replaceCommandFactories.js +94 -0
- package/esm/editor/src/commands/types.d.ts +18 -0
- package/esm/editor/src/commands/types.d.ts.map +1 -0
- package/esm/editor/src/commands/types.js +1 -0
- package/esm/editor/src/mod.d.ts +2 -0
- package/esm/editor/src/mod.d.ts.map +1 -1
- package/esm/editor/src/mod.js +2 -0
- package/esm/editor/src/plugins/TrackSelecionPlugin.d.ts +6 -0
- package/esm/editor/src/plugins/TrackSelecionPlugin.d.ts.map +1 -0
- package/esm/editor/src/plugins/TrackSelecionPlugin.js +24 -0
- package/esm/editor/src/types.d.ts +19 -1
- package/esm/editor/src/types.d.ts.map +1 -1
- package/esm/editor/src/ui.d.ts +15 -0
- package/esm/editor/src/ui.d.ts.map +1 -0
- package/esm/editor/src/ui.js +16 -0
- package/esm/editor/src/utilities/SmartOutput.d.ts +9 -7
- package/esm/editor/src/utilities/SmartOutput.d.ts.map +1 -1
- package/esm/editor/src/utilities/SmartOutput.js +35 -20
- package/esm/editor/src/utilities/getShadowRoot.d.ts +2 -0
- package/esm/editor/src/utilities/getShadowRoot.d.ts.map +1 -0
- package/esm/editor/src/utilities/getShadowRoot.js +16 -0
- package/esm/editor/src/utilities/mod.d.ts +2 -0
- package/esm/editor/src/utilities/mod.d.ts.map +1 -1
- package/esm/editor/src/utilities/mod.js +2 -0
- package/esm/editor/src/utilities/toRawTextResult.d.ts +3 -0
- package/esm/editor/src/utilities/toRawTextResult.d.ts.map +1 -0
- package/esm/editor/src/utilities/toRawTextResult.js +21 -0
- package/esm/extension-autocomplete/src/AutocompletePlugin.d.ts +8 -0
- package/esm/extension-autocomplete/src/AutocompletePlugin.d.ts.map +1 -0
- package/esm/extension-autocomplete/src/AutocompletePlugin.js +232 -0
- package/esm/extension-autocomplete/src/DefaultRenderer.d.ts +17 -0
- package/esm/extension-autocomplete/src/DefaultRenderer.d.ts.map +1 -0
- package/esm/extension-autocomplete/src/DefaultRenderer.js +137 -0
- package/esm/extension-autocomplete/src/ExtensionAutocomplete.d.ts +26 -0
- package/esm/extension-autocomplete/src/ExtensionAutocomplete.d.ts.map +1 -0
- package/esm/extension-autocomplete/src/ExtensionAutocomplete.js +30 -0
- package/esm/extension-autocomplete/src/createDefaultMatcher.d.ts +11 -0
- package/esm/extension-autocomplete/src/createDefaultMatcher.d.ts.map +1 -0
- package/esm/extension-autocomplete/src/createDefaultMatcher.js +58 -0
- package/esm/extension-autocomplete/src/createRegexMatcher.d.ts +4 -0
- package/esm/extension-autocomplete/src/createRegexMatcher.d.ts.map +1 -0
- package/esm/extension-autocomplete/src/createRegexMatcher.js +50 -0
- package/esm/extension-autocomplete/src/mod.d.ts +3 -0
- package/esm/extension-autocomplete/src/mod.d.ts.map +1 -0
- package/esm/extension-autocomplete/src/mod.js +2 -0
- package/esm/extension-autocomplete/src/types.d.ts +60 -0
- package/esm/extension-autocomplete/src/types.d.ts.map +1 -0
- package/esm/extension-autocomplete/src/types.js +1 -0
- package/esm/extension-basic-editor/src/ExtensionHtml.d.ts +15 -0
- package/esm/extension-basic-editor/src/ExtensionHtml.d.ts.map +1 -0
- package/esm/extension-basic-editor/src/ExtensionHtml.js +108 -0
- package/esm/extension-basic-editor/src/NodeCodeBlock.d.ts +9 -0
- package/esm/extension-basic-editor/src/NodeCodeBlock.d.ts.map +1 -0
- package/esm/extension-basic-editor/src/NodeCodeBlock.js +58 -0
- package/esm/extension-basic-editor/src/remote-selection/ExtensionRemoteSelection.d.ts +24 -0
- package/esm/extension-basic-editor/src/remote-selection/ExtensionRemoteSelection.d.ts.map +1 -0
- package/esm/extension-basic-editor/src/remote-selection/ExtensionRemoteSelection.js +35 -0
- package/esm/extension-basic-editor/src/remote-selection/remoteSelectionPlugin.d.ts +25 -0
- package/esm/extension-basic-editor/src/remote-selection/remoteSelectionPlugin.d.ts.map +1 -0
- package/esm/extension-basic-editor/src/remote-selection/remoteSelectionPlugin.js +96 -0
- package/esm/extension-codemirror/src/ExtensionCodeMirror.d.ts +15 -2
- package/esm/extension-codemirror/src/ExtensionCodeMirror.d.ts.map +1 -1
- package/esm/extension-codemirror/src/ExtensionCodeMirror.js +74 -2
- package/esm/extension-codemirror/src/NodeCodeMirror.d.ts +13 -9
- package/esm/extension-codemirror/src/NodeCodeMirror.d.ts.map +1 -1
- package/esm/extension-codemirror/src/NodeCodeMirror.js +34 -122
- package/esm/extension-codemirror/src/codeMirrorBlockNodeView.d.ts +3 -3
- package/esm/extension-codemirror/src/codeMirrorBlockNodeView.d.ts.map +1 -1
- package/esm/extension-codemirror/src/codeMirrorBlockNodeView.js +155 -107
- package/esm/extension-codemirror/src/defaults.d.ts +1 -1
- package/esm/extension-codemirror/src/defaults.d.ts.map +1 -1
- package/esm/extension-codemirror/src/defaults.js +4 -3
- package/esm/extension-codemirror/src/languageLoaders.d.ts.map +1 -1
- package/esm/extension-codemirror/src/languageLoaders.js +1 -2
- package/esm/extension-codemirror/src/lsp/LSPExtension.d.ts +14 -0
- package/esm/extension-codemirror/src/lsp/LSPExtension.d.ts.map +1 -0
- package/esm/extension-codemirror/src/lsp/LSPExtension.js +38 -0
- package/esm/extension-codemirror/src/lsp/completion.d.ts +8 -0
- package/esm/extension-codemirror/src/lsp/completion.d.ts.map +1 -0
- package/esm/extension-codemirror/src/lsp/completion.js +179 -0
- package/esm/extension-codemirror/src/lsp/hover.d.ts +5 -0
- package/esm/extension-codemirror/src/lsp/hover.d.ts.map +1 -0
- package/esm/extension-codemirror/src/lsp/hover.js +81 -0
- package/esm/extension-codemirror/src/lsp/index.d.ts +7 -0
- package/esm/extension-codemirror/src/lsp/index.d.ts.map +1 -0
- package/esm/extension-codemirror/src/lsp/index.js +49 -0
- package/esm/extension-codemirror/src/lsp/plugin.d.ts +37 -0
- package/esm/extension-codemirror/src/lsp/plugin.d.ts.map +1 -0
- package/esm/extension-codemirror/src/lsp/plugin.js +125 -0
- package/esm/extension-codemirror/src/lsp/pos.d.ts +5 -0
- package/esm/extension-codemirror/src/lsp/pos.d.ts.map +1 -0
- package/esm/extension-codemirror/src/lsp/pos.js +8 -0
- package/esm/extension-codemirror/src/lsp/text.d.ts +2 -0
- package/esm/extension-codemirror/src/lsp/text.d.ts.map +1 -0
- package/esm/extension-codemirror/src/lsp/text.js +47 -0
- package/esm/extension-codemirror/src/lsp/theme.d.ts +2 -0
- package/esm/extension-codemirror/src/lsp/theme.d.ts.map +1 -0
- package/esm/extension-codemirror/src/lsp/theme.js +76 -0
- package/esm/extension-codemirror/src/{y-remote-selections.d.ts → remote-selections.d.ts} +5 -5
- package/esm/extension-codemirror/src/remote-selections.d.ts.map +1 -0
- package/esm/extension-codemirror/src/{y-remote-selections.js → remote-selections.js} +49 -69
- package/esm/extension-codemirror/src/remote-sync.d.ts +11 -0
- package/esm/extension-codemirror/src/remote-sync.d.ts.map +1 -0
- package/esm/extension-codemirror/src/{y-sync.js → remote-sync.js} +6 -6
- package/esm/extension-codemirror/src/types.d.ts +10 -10
- package/esm/extension-codemirror/src/types.d.ts.map +1 -1
- package/esm/extension-codemirror/src/utils.d.ts +7 -6
- package/esm/extension-codemirror/src/utils.d.ts.map +1 -1
- package/esm/extension-codemirror/src/utils.js +21 -10
- package/esm/extension-lsp/src/DiagnosticPlugin.d.ts +32 -0
- package/esm/extension-lsp/src/DiagnosticPlugin.d.ts.map +1 -0
- package/esm/extension-lsp/src/DiagnosticPlugin.js +131 -0
- package/esm/extension-lsp/src/ExtensionLsp.d.ts +25 -0
- package/esm/extension-lsp/src/ExtensionLsp.d.ts.map +1 -0
- package/esm/extension-lsp/src/ExtensionLsp.js +126 -0
- package/esm/extension-lsp/src/LSPClient.d.ts +56 -0
- package/esm/extension-lsp/src/LSPClient.d.ts.map +1 -0
- package/esm/extension-lsp/src/LSPClient.js +449 -0
- package/esm/extension-lsp/src/computeIncrementalChanges.d.ts +8 -0
- package/esm/extension-lsp/src/computeIncrementalChanges.d.ts.map +1 -0
- package/esm/extension-lsp/src/computeIncrementalChanges.js +82 -0
- package/esm/extension-lsp/src/createLspAutocomplete.d.ts +23 -0
- package/esm/extension-lsp/src/createLspAutocomplete.d.ts.map +1 -0
- package/esm/extension-lsp/src/createLspAutocomplete.js +68 -0
- package/esm/extension-lsp/src/mod.d.ts +4 -0
- package/esm/extension-lsp/src/mod.d.ts.map +1 -0
- package/esm/extension-lsp/src/mod.js +3 -0
- package/esm/extension-lsp/src/workspace.d.ts +62 -0
- package/esm/extension-lsp/src/workspace.d.ts.map +1 -0
- package/esm/extension-lsp/src/workspace.js +168 -0
- package/esm/extension-markdown/src/DocumentMarkdownInlineTokenizer.d.ts +36 -0
- package/esm/extension-markdown/src/DocumentMarkdownInlineTokenizer.d.ts.map +1 -0
- package/esm/extension-markdown/src/DocumentMarkdownInlineTokenizer.js +240 -0
- package/esm/extension-markdown/src/DocumentMarkdownTokenizer.d.ts +26 -0
- package/esm/extension-markdown/src/DocumentMarkdownTokenizer.d.ts.map +1 -0
- package/esm/extension-markdown/src/DocumentMarkdownTokenizer.js +115 -0
- package/esm/extension-markdown/src/ExtensionMarkdown.d.ts +22 -0
- package/esm/extension-markdown/src/ExtensionMarkdown.d.ts.map +1 -0
- package/esm/extension-markdown/src/ExtensionMarkdown.js +48 -0
- package/esm/extension-markdown/src/MarkdownParser.d.ts +61 -0
- package/esm/extension-markdown/src/MarkdownParser.d.ts.map +1 -0
- package/esm/extension-markdown/src/MarkdownParser.js +249 -0
- package/esm/extension-markdown/src/MarkdownSerializer.d.ts +42 -0
- package/esm/extension-markdown/src/MarkdownSerializer.d.ts.map +1 -0
- package/esm/extension-markdown/src/MarkdownSerializer.js +325 -0
- package/esm/extension-markdown/src/PositionMapper.d.ts +15 -0
- package/esm/extension-markdown/src/PositionMapper.d.ts.map +1 -0
- package/esm/extension-markdown/src/PositionMapper.js +100 -0
- package/esm/extension-markdown/src/TokenSource.d.ts +11 -0
- package/esm/extension-markdown/src/TokenSource.d.ts.map +1 -0
- package/esm/extension-markdown/src/TokenSource.js +39 -0
- package/esm/extension-markdown/src/mdToPmConverter.d.ts +5 -0
- package/esm/extension-markdown/src/mdToPmConverter.d.ts.map +1 -0
- package/esm/extension-markdown/src/mdToPmConverter.js +111 -0
- package/esm/extension-markdown/src/pmToMdConverter.d.ts +16 -0
- package/esm/extension-markdown/src/pmToMdConverter.d.ts.map +1 -0
- package/esm/extension-markdown/src/pmToMdConverter.js +433 -0
- package/esm/extension-markdown/src/token_handlers/basic_token_handlers.d.ts +4 -0
- package/esm/extension-markdown/src/token_handlers/basic_token_handlers.d.ts.map +1 -0
- package/esm/extension-markdown/src/token_handlers/basic_token_handlers.js +151 -0
- package/esm/extension-markdown/src/token_handlers/footnote_token_handlers.d.ts +3 -0
- package/esm/extension-markdown/src/token_handlers/footnote_token_handlers.d.ts.map +1 -0
- package/esm/extension-markdown/src/token_handlers/footnote_token_handlers.js +34 -0
- package/esm/extension-markdown/src/token_handlers/inline_token_handlers.d.ts +6 -0
- package/esm/extension-markdown/src/token_handlers/inline_token_handlers.d.ts.map +1 -0
- package/esm/extension-markdown/src/token_handlers/inline_token_handlers.js +380 -0
- package/esm/extension-markdown/src/token_handlers/lists_token_handlers.d.ts +3 -0
- package/esm/extension-markdown/src/token_handlers/lists_token_handlers.d.ts.map +1 -0
- package/esm/extension-markdown/src/token_handlers/lists_token_handlers.js +323 -0
- package/esm/extension-markdown/src/token_handlers/table_token_handlers.d.ts +9 -0
- package/esm/extension-markdown/src/token_handlers/table_token_handlers.d.ts.map +1 -0
- package/esm/extension-markdown/src/token_handlers/table_token_handlers.js +308 -0
- package/esm/extension-markdown/src/treeSitterTokenizer.d.ts +5 -0
- package/esm/extension-markdown/src/treeSitterTokenizer.d.ts.map +1 -0
- package/esm/extension-markdown/src/treeSitterTokenizer.js +769 -0
- package/esm/extension-markdown/src/types.d.ts +28 -0
- package/esm/extension-markdown/src/types.d.ts.map +1 -0
- package/esm/extension-markdown/src/types.js +131 -0
- package/esm/extension-markdown/src/utils.d.ts +8 -0
- package/esm/extension-markdown/src/utils.d.ts.map +1 -0
- package/esm/extension-markdown/src/utils.js +86 -0
- package/esm/tree-sitter-shim/src/main.d.ts +15 -0
- package/esm/tree-sitter-shim/src/main.d.ts.map +1 -0
- package/esm/tree-sitter-shim/src/main.js +25 -0
- package/esm/tree-sitter-shim/src/tree_sitter/node.d.ts +6 -0
- package/esm/tree-sitter-shim/src/tree_sitter/node.d.ts.map +1 -0
- package/esm/tree-sitter-shim/src/tree_sitter/node.js +1 -0
- package/esm/tree-sitter-shim/src/tree_sitter/parser.d.ts +7 -0
- package/esm/tree-sitter-shim/src/tree_sitter/parser.d.ts.map +1 -0
- package/esm/tree-sitter-shim/src/tree_sitter/parser.js +5 -0
- package/esm/tree-sitter-shim/src/tree_sitter/tree.d.ts +6 -0
- package/esm/tree-sitter-shim/src/tree_sitter/tree.d.ts.map +1 -0
- package/esm/tree-sitter-shim/src/tree_sitter/tree.js +1 -0
- package/esm/wasm/src/mod.d.ts +12 -0
- package/esm/wasm/src/mod.d.ts.map +1 -0
- package/esm/wasm/src/mod.js +48 -0
- package/esm/wasm/wasm.d.ts +138 -0
- package/esm/wasm/wasm.d.ts.map +1 -0
- package/esm/wasm/wasm.js +120 -0
- package/package.json +5 -25
- package/esm/extension-codemirror/src/NodeDocumentCode.d.ts +0 -7
- package/esm/extension-codemirror/src/NodeDocumentCode.d.ts.map +0 -1
- package/esm/extension-codemirror/src/NodeDocumentCode.js +0 -37
- package/esm/extension-codemirror/src/y-remote-selections.d.ts.map +0 -1
- package/esm/extension-codemirror/src/y-sync.d.ts +0 -11
- package/esm/extension-codemirror/src/y-sync.d.ts.map +0 -1
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { Extension } from '../../editor/src/mod.js';
|
|
2
|
+
import { PositionMapper } from '../../extension-markdown/src/PositionMapper.js';
|
|
3
|
+
import { LSPClient } from './LSPClient.js';
|
|
4
|
+
import { AutocompletePlugin } from '../../extension-autocomplete/src/AutocompletePlugin.js';
|
|
5
|
+
import { DiagnosticPlugin } from './DiagnosticPlugin.js';
|
|
6
|
+
import { createLspAutocomplete } from './createLspAutocomplete.js';
|
|
7
|
+
export class ExtensionLsp extends Extension {
|
|
8
|
+
constructor(config) {
|
|
9
|
+
super(config);
|
|
10
|
+
Object.defineProperty(this, "config", {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
writable: true,
|
|
14
|
+
value: config
|
|
15
|
+
});
|
|
16
|
+
Object.defineProperty(this, "name", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
configurable: true,
|
|
19
|
+
writable: true,
|
|
20
|
+
value: 'lsp'
|
|
21
|
+
});
|
|
22
|
+
Object.defineProperty(this, "clients", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
writable: true,
|
|
26
|
+
value: {}
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(this, "uri", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
configurable: true,
|
|
31
|
+
writable: true,
|
|
32
|
+
value: void 0
|
|
33
|
+
});
|
|
34
|
+
Object.defineProperty(this, "extensionMarkdown", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
configurable: true,
|
|
37
|
+
writable: true,
|
|
38
|
+
value: void 0
|
|
39
|
+
});
|
|
40
|
+
Object.defineProperty(this, "extensionAutocomplete", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
configurable: true,
|
|
43
|
+
writable: true,
|
|
44
|
+
value: void 0
|
|
45
|
+
});
|
|
46
|
+
Object.defineProperty(this, "mainLang", {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
configurable: true,
|
|
49
|
+
writable: true,
|
|
50
|
+
value: 'markdown'
|
|
51
|
+
});
|
|
52
|
+
Object.defineProperty(this, "source", {
|
|
53
|
+
enumerable: true,
|
|
54
|
+
configurable: true,
|
|
55
|
+
writable: true,
|
|
56
|
+
value: void 0
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
getProseMirrorPlugins() {
|
|
60
|
+
const plugins = [];
|
|
61
|
+
const { autocompleteConfig } = createLspAutocomplete(this);
|
|
62
|
+
plugins.push(new AutocompletePlugin(autocompleteConfig, this.editor));
|
|
63
|
+
plugins.push(new DiagnosticPlugin({}, this));
|
|
64
|
+
return plugins;
|
|
65
|
+
}
|
|
66
|
+
created() {
|
|
67
|
+
this.mainLang = this.editor.config.languageID || 'markdown';
|
|
68
|
+
this.source = {
|
|
69
|
+
ui: this.editor.ui,
|
|
70
|
+
getMappedContent: () => {
|
|
71
|
+
const editor = this.editor;
|
|
72
|
+
const result = this.extensionMarkdown.toMarkdown(editor.state.doc);
|
|
73
|
+
const mapper = new PositionMapper(editor, result.rawTextMap);
|
|
74
|
+
return {
|
|
75
|
+
...result,
|
|
76
|
+
mapper,
|
|
77
|
+
};
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
const extensionMarkdown = this.editor
|
|
81
|
+
.getExtension('markdown');
|
|
82
|
+
if (!extensionMarkdown) {
|
|
83
|
+
throw new Error('No markdown extension');
|
|
84
|
+
}
|
|
85
|
+
this.extensionMarkdown = extensionMarkdown;
|
|
86
|
+
this.editor.addEventListener('doc:loaded', async () => {
|
|
87
|
+
const languageID = this.mainLang;
|
|
88
|
+
this.uri = this.editor.config.uri;
|
|
89
|
+
if (this.uri) {
|
|
90
|
+
const client = this.getClient(this.mainLang);
|
|
91
|
+
if (client) {
|
|
92
|
+
client.connect(this.uri, this.source);
|
|
93
|
+
await client.restart();
|
|
94
|
+
client.workspace.openFile(this.uri, languageID, this.source);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
this.editor.addEventListener('changed', () => {
|
|
99
|
+
if (this.editor.config.uri) {
|
|
100
|
+
const client = this.getClient(this.mainLang);
|
|
101
|
+
if (client) {
|
|
102
|
+
client.workspace.changedFile(this.editor.config.uri);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
this.editor.addEventListener('beforeDestroy', () => {
|
|
107
|
+
if (this.uri) {
|
|
108
|
+
const client = this.getClient(this.mainLang);
|
|
109
|
+
if (client) {
|
|
110
|
+
client.disconnect(this.uri);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
getClient(lang) {
|
|
116
|
+
if (!this.clients[lang]) {
|
|
117
|
+
const transport = this.config.getLspTransport(lang);
|
|
118
|
+
if (!transport) {
|
|
119
|
+
console.warn(`No lsp transport for ${lang}`);
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
this.clients[lang] = new LSPClient(transport, { rootUri: 'file:///' });
|
|
123
|
+
}
|
|
124
|
+
return this.clients[lang];
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type * as lsp from 'vscode-languageserver-protocol';
|
|
2
|
+
import { TextDocumentSyncKind } from 'vscode-languageserver-protocol';
|
|
3
|
+
import { LspSource, Workspace, WorkspaceFile } from './workspace.js';
|
|
4
|
+
export type Transport = {
|
|
5
|
+
connect(): void;
|
|
6
|
+
disconnect(): void;
|
|
7
|
+
send(message: string): void;
|
|
8
|
+
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
|
|
9
|
+
removeEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean): void;
|
|
10
|
+
isConnected(): boolean;
|
|
11
|
+
isInitialized(): boolean;
|
|
12
|
+
};
|
|
13
|
+
export type LSPClientConfig = {
|
|
14
|
+
rootUri?: string;
|
|
15
|
+
workspace?: (client: LSPClient) => Workspace;
|
|
16
|
+
timeout?: number;
|
|
17
|
+
sanitizeHTML?: (html: string) => string;
|
|
18
|
+
unhandledNotification?: (client: LSPClient, method: string, params: any) => void;
|
|
19
|
+
};
|
|
20
|
+
export declare class LSPError extends Error {
|
|
21
|
+
isTimeout: boolean;
|
|
22
|
+
readonly isLSP = true;
|
|
23
|
+
static createTimeout(): LSPError;
|
|
24
|
+
}
|
|
25
|
+
export declare class LSPClient extends EventTarget {
|
|
26
|
+
private readonly transport;
|
|
27
|
+
readonly config: LSPClientConfig;
|
|
28
|
+
sources: Record<string, LspSource>;
|
|
29
|
+
workspace: Workspace;
|
|
30
|
+
private nextReqID;
|
|
31
|
+
private requests;
|
|
32
|
+
serverCapabilities: lsp.ServerCapabilities | null;
|
|
33
|
+
supportSync: TextDocumentSyncKind;
|
|
34
|
+
private readonly timeout;
|
|
35
|
+
private initializing;
|
|
36
|
+
private readonly receiveListener;
|
|
37
|
+
active: boolean;
|
|
38
|
+
constructor(transport: Transport, config?: LSPClientConfig);
|
|
39
|
+
startInitializing(): void;
|
|
40
|
+
stopInitializing(): void;
|
|
41
|
+
restart(): Promise<void>;
|
|
42
|
+
onInitialized(): void;
|
|
43
|
+
connect(uri: string, source: LspSource): void;
|
|
44
|
+
disconnect(uri: string): void;
|
|
45
|
+
didOpen(file: WorkspaceFile): Promise<boolean>;
|
|
46
|
+
didClose(uri: string): void;
|
|
47
|
+
private receiveMessage;
|
|
48
|
+
request<Params, Result>(method: string, params: Params): Promise<Result>;
|
|
49
|
+
private requestInner;
|
|
50
|
+
notification<Params>(method: string, params: Params): Promise<boolean>;
|
|
51
|
+
cancelRequest(params: any): void;
|
|
52
|
+
hasCapability(name: keyof lsp.ServerCapabilities): boolean | null;
|
|
53
|
+
sync(): void;
|
|
54
|
+
private timeoutRequest;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=LSPClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LSPClient.d.ts","sourceRoot":"","sources":["../../../src/extension-lsp/src/LSPClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,gCAAgC,CAAC;AAC3D,OAAO,EAEL,oBAAoB,EACrB,MAAM,gCAAgC,CAAC;AAExC,OAAO,EAEL,SAAS,EACT,SAAS,EACT,aAAa,EACd,MAAM,gBAAgB,CAAC;AA0BxB,MAAM,MAAM,SAAS,GAAG;IACtB,OAAO,IAAI,IAAI,CAAC;IAChB,UAAU,IAAI,IAAI,CAAC;IACnB,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,gBAAgB,CACd,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,kCAAkC,EAC5C,OAAO,CAAC,EAAE,OAAO,GAAG,uBAAuB,GAC1C,IAAI,CAAC;IACR,mBAAmB,CACjB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,kCAAkC,GAAG,IAAI,EACnD,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,GACvC,IAAI,CAAC;IACR,WAAW,IAAI,OAAO,CAAC;IACvB,aAAa,IAAI,OAAO,CAAC;CAC1B,CAAC;AAiEF,MAAM,MAAM,eAAe,GAAG;IAE5B,OAAO,CAAC,EAAE,MAAM,CAAC;IAMjB,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,KAAK,SAAS,CAAC;IAG7C,OAAO,CAAC,EAAE,MAAM,CAAC;IAOjB,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IAGxC,qBAAqB,CAAC,EAAE,CACtB,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,GAAG,KACR,IAAI,CAAC;CACX,CAAC;AAEF,qBAAa,QAAS,SAAQ,KAAK;IACjC,SAAS,UAAS;IAClB,QAAQ,CAAC,KAAK,QAAQ;IAEtB,MAAM,CAAC,aAAa;CAKrB;AAED,qBAAa,SAAU,SAAQ,WAAW;IAiBtC,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,QAAQ,CAAC,MAAM,EAAE,eAAe;IAjBlC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAM;IAExC,SAAS,EAAE,SAAS,CAAC;IACrB,OAAO,CAAC,SAAS,CAAK;IACtB,OAAO,CAAC,QAAQ,CAAsB;IAEtC,kBAAkB,EAAE,GAAG,CAAC,kBAAkB,GAAG,IAAI,CAAQ;IAClD,WAAW,EAAE,oBAAoB,CAA6B;IAErE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,YAAY,CAA6C;IAEjE,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAqC;IACrE,MAAM,EAAE,OAAO,CAAS;gBAGL,SAAS,EAAE,SAAS,EAC5B,MAAM,GAAE,eAAoB;IAuCvC,iBAAiB;IAoCjB,gBAAgB;IAOV,OAAO;IASb,aAAa;IAQb,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS;IAWtC,UAAU,CAAC,GAAG,EAAE,MAAM;IAahB,OAAO,CAAC,IAAI,EAAE,aAAa;IAmBjC,QAAQ,CAAC,GAAG,EAAE,MAAM;IASpB,OAAO,CAAC,cAAc;IA+ChB,OAAO,CAAC,MAAM,EAAE,MAAM,EAC1B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,CAAC;IAalB,OAAO,CAAC,YAAY;IA8Cd,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAoB5E,aAAa,CAAC,MAAM,EAAE,GAAG;IAOzB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC,kBAAkB;IAIhD,IAAI;IAIJ,OAAO,CAAC,cAAc;CAcvB"}
|
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
import { MessageType, TextDocumentSyncKind, } from 'vscode-languageserver-protocol';
|
|
2
|
+
import { DefaultWorkspace, } from './workspace.js';
|
|
3
|
+
const defaultNotificationHandlers = {
|
|
4
|
+
'window/logMessage': (client, params) => {
|
|
5
|
+
if (params.type == MessageType.Error) {
|
|
6
|
+
console.error('[lsp] ' + params.message);
|
|
7
|
+
}
|
|
8
|
+
else if (params.type == MessageType.Warning) {
|
|
9
|
+
console.warn('[lsp] ' + params.message);
|
|
10
|
+
}
|
|
11
|
+
else if (params.type == MessageType.Info) {
|
|
12
|
+
console.info('[lsp] ' + params.message);
|
|
13
|
+
}
|
|
14
|
+
else if (params.type == MessageType.Log) {
|
|
15
|
+
console.log('[lsp] ' + params.message);
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
'window/showMessage': (client, params) => {
|
|
19
|
+
if (params.type > MessageType.Info)
|
|
20
|
+
return;
|
|
21
|
+
for (const f of client.workspace.files) {
|
|
22
|
+
const ui = f.getUi();
|
|
23
|
+
if (!ui)
|
|
24
|
+
continue;
|
|
25
|
+
ui.showMessage(params.message);
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
class Request {
|
|
30
|
+
constructor(id, params, timeout) {
|
|
31
|
+
Object.defineProperty(this, "id", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
configurable: true,
|
|
34
|
+
writable: true,
|
|
35
|
+
value: id
|
|
36
|
+
});
|
|
37
|
+
Object.defineProperty(this, "params", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
configurable: true,
|
|
40
|
+
writable: true,
|
|
41
|
+
value: params
|
|
42
|
+
});
|
|
43
|
+
Object.defineProperty(this, "timeout", {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
configurable: true,
|
|
46
|
+
writable: true,
|
|
47
|
+
value: timeout
|
|
48
|
+
});
|
|
49
|
+
Object.defineProperty(this, "promise", {
|
|
50
|
+
enumerable: true,
|
|
51
|
+
configurable: true,
|
|
52
|
+
writable: true,
|
|
53
|
+
value: void 0
|
|
54
|
+
});
|
|
55
|
+
this.promise = new Promise((resolve, reject) => {
|
|
56
|
+
this.resolve = resolve;
|
|
57
|
+
this.reject = reject;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const clientCapabilities = {
|
|
62
|
+
general: {
|
|
63
|
+
markdown: {
|
|
64
|
+
parser: 'marked',
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
textDocument: {
|
|
68
|
+
publishDiagnostics: { versionSupport: true },
|
|
69
|
+
completion: {
|
|
70
|
+
completionItem: {
|
|
71
|
+
snippetSupport: true,
|
|
72
|
+
documentationFormat: ['plaintext', 'markdown'],
|
|
73
|
+
insertReplaceSupport: false,
|
|
74
|
+
},
|
|
75
|
+
completionList: {
|
|
76
|
+
itemDefaults: ['commitCharacters', 'editRange', 'insertTextFormat'],
|
|
77
|
+
},
|
|
78
|
+
completionItemKind: { valueSet: [] },
|
|
79
|
+
contextSupport: true,
|
|
80
|
+
},
|
|
81
|
+
hover: {
|
|
82
|
+
contentFormat: ['markdown', 'plaintext'],
|
|
83
|
+
},
|
|
84
|
+
// formatting: {},
|
|
85
|
+
// rename: {},
|
|
86
|
+
signatureHelp: {
|
|
87
|
+
contextSupport: true,
|
|
88
|
+
signatureInformation: {
|
|
89
|
+
documentationFormat: ['markdown', 'plaintext'],
|
|
90
|
+
parameterInformation: { labelOffsetSupport: true },
|
|
91
|
+
activeParameterSupport: true,
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
definition: {},
|
|
95
|
+
declaration: {},
|
|
96
|
+
implementation: {},
|
|
97
|
+
typeDefinition: {},
|
|
98
|
+
references: {},
|
|
99
|
+
diagnostic: {},
|
|
100
|
+
},
|
|
101
|
+
window: {
|
|
102
|
+
showMessage: {},
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
export class LSPError extends Error {
|
|
106
|
+
constructor() {
|
|
107
|
+
super(...arguments);
|
|
108
|
+
Object.defineProperty(this, "isTimeout", {
|
|
109
|
+
enumerable: true,
|
|
110
|
+
configurable: true,
|
|
111
|
+
writable: true,
|
|
112
|
+
value: false
|
|
113
|
+
});
|
|
114
|
+
Object.defineProperty(this, "isLSP", {
|
|
115
|
+
enumerable: true,
|
|
116
|
+
configurable: true,
|
|
117
|
+
writable: true,
|
|
118
|
+
value: true
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
static createTimeout() {
|
|
122
|
+
const err = new LSPError('Request timed out');
|
|
123
|
+
err.isTimeout = true;
|
|
124
|
+
return err;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
export class LSPClient extends EventTarget {
|
|
128
|
+
constructor(transport, config = {}) {
|
|
129
|
+
super();
|
|
130
|
+
Object.defineProperty(this, "transport", {
|
|
131
|
+
enumerable: true,
|
|
132
|
+
configurable: true,
|
|
133
|
+
writable: true,
|
|
134
|
+
value: transport
|
|
135
|
+
});
|
|
136
|
+
Object.defineProperty(this, "config", {
|
|
137
|
+
enumerable: true,
|
|
138
|
+
configurable: true,
|
|
139
|
+
writable: true,
|
|
140
|
+
value: config
|
|
141
|
+
});
|
|
142
|
+
Object.defineProperty(this, "sources", {
|
|
143
|
+
enumerable: true,
|
|
144
|
+
configurable: true,
|
|
145
|
+
writable: true,
|
|
146
|
+
value: {}
|
|
147
|
+
});
|
|
148
|
+
Object.defineProperty(this, "workspace", {
|
|
149
|
+
enumerable: true,
|
|
150
|
+
configurable: true,
|
|
151
|
+
writable: true,
|
|
152
|
+
value: void 0
|
|
153
|
+
});
|
|
154
|
+
Object.defineProperty(this, "nextReqID", {
|
|
155
|
+
enumerable: true,
|
|
156
|
+
configurable: true,
|
|
157
|
+
writable: true,
|
|
158
|
+
value: 0
|
|
159
|
+
});
|
|
160
|
+
Object.defineProperty(this, "requests", {
|
|
161
|
+
enumerable: true,
|
|
162
|
+
configurable: true,
|
|
163
|
+
writable: true,
|
|
164
|
+
value: []
|
|
165
|
+
});
|
|
166
|
+
Object.defineProperty(this, "serverCapabilities", {
|
|
167
|
+
enumerable: true,
|
|
168
|
+
configurable: true,
|
|
169
|
+
writable: true,
|
|
170
|
+
value: null
|
|
171
|
+
});
|
|
172
|
+
Object.defineProperty(this, "supportSync", {
|
|
173
|
+
enumerable: true,
|
|
174
|
+
configurable: true,
|
|
175
|
+
writable: true,
|
|
176
|
+
value: TextDocumentSyncKind.None
|
|
177
|
+
});
|
|
178
|
+
Object.defineProperty(this, "timeout", {
|
|
179
|
+
enumerable: true,
|
|
180
|
+
configurable: true,
|
|
181
|
+
writable: true,
|
|
182
|
+
value: void 0
|
|
183
|
+
});
|
|
184
|
+
Object.defineProperty(this, "initializing", {
|
|
185
|
+
enumerable: true,
|
|
186
|
+
configurable: true,
|
|
187
|
+
writable: true,
|
|
188
|
+
value: void 0
|
|
189
|
+
});
|
|
190
|
+
Object.defineProperty(this, "receiveListener", {
|
|
191
|
+
enumerable: true,
|
|
192
|
+
configurable: true,
|
|
193
|
+
writable: true,
|
|
194
|
+
value: void 0
|
|
195
|
+
});
|
|
196
|
+
Object.defineProperty(this, "active", {
|
|
197
|
+
enumerable: true,
|
|
198
|
+
configurable: true,
|
|
199
|
+
writable: true,
|
|
200
|
+
value: false
|
|
201
|
+
});
|
|
202
|
+
this.timeout = config.timeout ?? 3000;
|
|
203
|
+
this.receiveListener = (event) => this.receiveMessage(event);
|
|
204
|
+
transport.addEventListener('message', this.receiveListener);
|
|
205
|
+
transport.addEventListener('initialized', () => {
|
|
206
|
+
try {
|
|
207
|
+
console.info('LSP initialized');
|
|
208
|
+
this.onInitialized();
|
|
209
|
+
}
|
|
210
|
+
catch (err) {
|
|
211
|
+
if (err.isLSP) {
|
|
212
|
+
console.error('Timeout as client.onConnected()', err.message, this.onInitialized);
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
throw err;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
transport.addEventListener('open', () => {
|
|
220
|
+
this.startInitializing();
|
|
221
|
+
});
|
|
222
|
+
transport.addEventListener('close', (event) => {
|
|
223
|
+
this.active = false;
|
|
224
|
+
this.serverCapabilities = null;
|
|
225
|
+
this.dispatchEvent(new CloseEvent('close'));
|
|
226
|
+
});
|
|
227
|
+
this.workspace = config.workspace
|
|
228
|
+
? config.workspace(this)
|
|
229
|
+
: new DefaultWorkspace(this);
|
|
230
|
+
}
|
|
231
|
+
startInitializing() {
|
|
232
|
+
if (this.initializing) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
this.initializing = setInterval(async () => {
|
|
236
|
+
const capabilities = clientCapabilities;
|
|
237
|
+
try {
|
|
238
|
+
const resp = await this.requestInner('initialize', {
|
|
239
|
+
processId: null,
|
|
240
|
+
clientInfo: { name: '@kerebron/lsp-client' },
|
|
241
|
+
rootUri: this.config.rootUri || null,
|
|
242
|
+
capabilities,
|
|
243
|
+
}).promise;
|
|
244
|
+
this.stopInitializing();
|
|
245
|
+
this.serverCapabilities = resp.capabilities;
|
|
246
|
+
const sync = this.serverCapabilities.textDocumentSync;
|
|
247
|
+
this.supportSync = TextDocumentSyncKind.None;
|
|
248
|
+
if (sync) {
|
|
249
|
+
this.supportSync = typeof sync == 'number'
|
|
250
|
+
? sync
|
|
251
|
+
: sync.change ?? TextDocumentSyncKind.None;
|
|
252
|
+
}
|
|
253
|
+
// deno-lint-ignore no-empty
|
|
254
|
+
}
|
|
255
|
+
catch (ignoreConnectErrors) { }
|
|
256
|
+
}, this.timeout);
|
|
257
|
+
}
|
|
258
|
+
stopInitializing() {
|
|
259
|
+
if (this.initializing) {
|
|
260
|
+
clearInterval(this.initializing);
|
|
261
|
+
this.initializing = undefined;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
async restart() {
|
|
265
|
+
this.active = true;
|
|
266
|
+
if (!this.transport.isConnected()) {
|
|
267
|
+
this.transport.connect();
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
this.startInitializing();
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
onInitialized() {
|
|
274
|
+
this.transport.send(JSON.stringify({ jsonrpc: '2.0', method: 'initialized', params: {} }));
|
|
275
|
+
this.workspace.connected();
|
|
276
|
+
}
|
|
277
|
+
connect(uri, source) {
|
|
278
|
+
if (this.sources[uri] && this.sources[uri] !== source) {
|
|
279
|
+
throw new Error(`Source for ${uri} already connected`);
|
|
280
|
+
}
|
|
281
|
+
this.sources[uri] = source;
|
|
282
|
+
this.active = true;
|
|
283
|
+
if (!this.transport.isConnected()) {
|
|
284
|
+
this.transport.connect();
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
disconnect(uri) {
|
|
288
|
+
delete this.sources[uri];
|
|
289
|
+
this.workspace.closeFile(uri);
|
|
290
|
+
if (Object.keys(this.sources).length === 0) {
|
|
291
|
+
this.active = false;
|
|
292
|
+
this.serverCapabilities = null;
|
|
293
|
+
this.transport.removeEventListener('data', this.receiveListener);
|
|
294
|
+
this.workspace.disconnected();
|
|
295
|
+
this.dispatchEvent(new CloseEvent('close'));
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
/// Send a `textDocument/didOpen` notification to the server.
|
|
299
|
+
async didOpen(file) {
|
|
300
|
+
if (!this.transport.isInitialized()) {
|
|
301
|
+
return false;
|
|
302
|
+
}
|
|
303
|
+
await this.notification('textDocument/didOpen', {
|
|
304
|
+
textDocument: {
|
|
305
|
+
uri: file.uri,
|
|
306
|
+
languageId: file.languageId,
|
|
307
|
+
text: file.content,
|
|
308
|
+
version: file.version,
|
|
309
|
+
},
|
|
310
|
+
});
|
|
311
|
+
return true;
|
|
312
|
+
}
|
|
313
|
+
/// Send a `textDocument/didClose` notification to the server.
|
|
314
|
+
didClose(uri) {
|
|
315
|
+
if (!this.transport.isInitialized()) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
this.notification('textDocument/didClose', {
|
|
319
|
+
textDocument: { uri },
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
receiveMessage(event) {
|
|
323
|
+
const msg = event.data;
|
|
324
|
+
const value = JSON.parse(msg);
|
|
325
|
+
if ('id' in value && !('method' in value)) {
|
|
326
|
+
const index = this.requests.findIndex((r) => r.id == value.id);
|
|
327
|
+
if (index < 0) {
|
|
328
|
+
console.warn(`[lsp] Received a response for non-existent request ${value.id}`);
|
|
329
|
+
}
|
|
330
|
+
else {
|
|
331
|
+
const req = this.requests[index];
|
|
332
|
+
clearTimeout(req.timeout);
|
|
333
|
+
this.requests.splice(index, 1);
|
|
334
|
+
if (value.error)
|
|
335
|
+
req.reject(value.error);
|
|
336
|
+
else
|
|
337
|
+
req.resolve(value.result);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
else if (!('id' in value)) {
|
|
341
|
+
const event = new CustomEvent(value.method, {
|
|
342
|
+
detail: { params: value.params },
|
|
343
|
+
});
|
|
344
|
+
if (this.dispatchEvent(event)) {
|
|
345
|
+
if (this.config.unhandledNotification) {
|
|
346
|
+
this.config.unhandledNotification(this, value.method, value.params);
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
if (defaultNotificationHandlers[value.method]) {
|
|
350
|
+
defaultNotificationHandlers[value.method](this, value.params);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
const resp = {
|
|
357
|
+
jsonrpc: '2.0',
|
|
358
|
+
id: value.id,
|
|
359
|
+
error: {
|
|
360
|
+
code: -32601, /* MethodNotFound */
|
|
361
|
+
message: 'Method not implemented',
|
|
362
|
+
},
|
|
363
|
+
};
|
|
364
|
+
this.transport.send(JSON.stringify(resp));
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
async request(method, params) {
|
|
368
|
+
if (!this.transport.isConnected()) {
|
|
369
|
+
if (this.active) {
|
|
370
|
+
this.transport.connect();
|
|
371
|
+
}
|
|
372
|
+
throw new LSPError('Not connected');
|
|
373
|
+
}
|
|
374
|
+
const retVal = await this.requestInner(method, params)
|
|
375
|
+
.promise;
|
|
376
|
+
return retVal;
|
|
377
|
+
}
|
|
378
|
+
requestInner(method, params, mapped = false) {
|
|
379
|
+
if (!this.transport) {
|
|
380
|
+
throw new Error('No transport');
|
|
381
|
+
}
|
|
382
|
+
if (!this.transport.isConnected()) {
|
|
383
|
+
if (this.active) {
|
|
384
|
+
this.transport.connect();
|
|
385
|
+
}
|
|
386
|
+
throw new Error('Transport not connected');
|
|
387
|
+
}
|
|
388
|
+
const id = ++this.nextReqID, data = {
|
|
389
|
+
jsonrpc: '2.0',
|
|
390
|
+
id,
|
|
391
|
+
method,
|
|
392
|
+
params: params,
|
|
393
|
+
};
|
|
394
|
+
const req = new Request(id, params, setTimeout(() => this.timeoutRequest(req, method, id, params), this.timeout));
|
|
395
|
+
try {
|
|
396
|
+
if (!this.transport) {
|
|
397
|
+
throw new LSPError('No transport');
|
|
398
|
+
}
|
|
399
|
+
this.transport.send(JSON.stringify(data));
|
|
400
|
+
this.requests.push(req);
|
|
401
|
+
}
|
|
402
|
+
catch (e) {
|
|
403
|
+
console.error(e);
|
|
404
|
+
clearTimeout(req.timeout);
|
|
405
|
+
req.reject(e);
|
|
406
|
+
}
|
|
407
|
+
return req;
|
|
408
|
+
}
|
|
409
|
+
async notification(method, params) {
|
|
410
|
+
if (!this.transport)
|
|
411
|
+
return false;
|
|
412
|
+
if (!this.transport.isConnected()) {
|
|
413
|
+
if (this.active) {
|
|
414
|
+
this.transport.connect();
|
|
415
|
+
}
|
|
416
|
+
return false;
|
|
417
|
+
}
|
|
418
|
+
if (!this.transport.isInitialized()) {
|
|
419
|
+
return false;
|
|
420
|
+
}
|
|
421
|
+
const data = {
|
|
422
|
+
jsonrpc: '2.0',
|
|
423
|
+
method,
|
|
424
|
+
params: params,
|
|
425
|
+
};
|
|
426
|
+
this.transport.send(JSON.stringify(data));
|
|
427
|
+
return true;
|
|
428
|
+
}
|
|
429
|
+
cancelRequest(params) {
|
|
430
|
+
const found = this.requests.find((r) => r.params === params);
|
|
431
|
+
if (found) {
|
|
432
|
+
this.notification('$/cancelRequest', found.id);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
hasCapability(name) {
|
|
436
|
+
return this.serverCapabilities ? !!this.serverCapabilities[name] : null;
|
|
437
|
+
}
|
|
438
|
+
sync() {
|
|
439
|
+
this.workspace.syncFiles();
|
|
440
|
+
}
|
|
441
|
+
timeoutRequest(req, method, id, params) {
|
|
442
|
+
console.error('this.timeoutRequest', this.timeout, method, id, params);
|
|
443
|
+
const index = this.requests.indexOf(req);
|
|
444
|
+
if (index > -1) {
|
|
445
|
+
req.reject(LSPError.createTimeout());
|
|
446
|
+
this.requests.splice(index, 1);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as lsp from 'vscode-languageserver-protocol';
|
|
2
|
+
/**
|
|
3
|
+
* Compares two strings and computes the minimal set of text changes
|
|
4
|
+
* using a diff-based approach (simple line-by-line + character diff for simplicity).
|
|
5
|
+
* Returns an array of TextEdit-like changes that transform `previous` into `current`.
|
|
6
|
+
*/
|
|
7
|
+
export declare function computeIncrementalChanges(previous: string, current: string): lsp.TextDocumentContentChangeEvent[];
|
|
8
|
+
//# sourceMappingURL=computeIncrementalChanges.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"computeIncrementalChanges.d.ts","sourceRoot":"","sources":["../../../src/extension-lsp/src/computeIncrementalChanges.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,gCAAgC,CAAC;AAEtD;;;;GAIG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GACd,GAAG,CAAC,8BAA8B,EAAE,CA0FtC"}
|