@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,179 @@
|
|
|
1
|
+
import { EditorState, Facet } from '@codemirror/state';
|
|
2
|
+
import { autocompletion, snippet, } from '@codemirror/autocomplete';
|
|
3
|
+
import { LSPPlugin } from './plugin.js';
|
|
4
|
+
import { CompletionTriggerKind } from 'vscode-languageserver-protocol';
|
|
5
|
+
export function serverCompletion(config = {}) {
|
|
6
|
+
let result;
|
|
7
|
+
if (config.override) {
|
|
8
|
+
result = [autocompletion({ override: [serverCompletionSource] })];
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
const data = [{ autocomplete: serverCompletionSource }];
|
|
12
|
+
result = [autocompletion(), EditorState.languageData.of(() => data)];
|
|
13
|
+
}
|
|
14
|
+
if (config.validFor) {
|
|
15
|
+
result.push(completionConfig.of({ validFor: config.validFor }));
|
|
16
|
+
}
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
const completionConfig = Facet.define({
|
|
20
|
+
combine: (results) => results.length ? results[0] : { validFor: null },
|
|
21
|
+
});
|
|
22
|
+
async function getCompletions(plugin, pos, context, abort) {
|
|
23
|
+
const client = plugin.extensionLsp.getClient(plugin.lang);
|
|
24
|
+
if (!client) {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
if (client.hasCapability('completionProvider') === false) {
|
|
28
|
+
null;
|
|
29
|
+
}
|
|
30
|
+
client.sync();
|
|
31
|
+
const params = {
|
|
32
|
+
position: plugin.toPosition(pos),
|
|
33
|
+
textDocument: { uri: plugin.uri },
|
|
34
|
+
context,
|
|
35
|
+
};
|
|
36
|
+
if (abort) {
|
|
37
|
+
abort.addEventListener('abort', () => client.cancelRequest(params));
|
|
38
|
+
}
|
|
39
|
+
const result = await client.request('textDocument/completion', params);
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
// Look for non-alphanumeric prefixes in the completions, and return a
|
|
43
|
+
// regexp that matches them, to use in validFor
|
|
44
|
+
function prefixRegexp(items) {
|
|
45
|
+
let step = Math.ceil(items.length / 50), prefixes = [];
|
|
46
|
+
for (let i = 0; i < items.length; i += step) {
|
|
47
|
+
let item = items[i], text = item.textEdit?.newText || item.textEditText || item.insertText ||
|
|
48
|
+
item.label;
|
|
49
|
+
if (!/^\w/.test(text)) {
|
|
50
|
+
let prefix = /^[^\w]*/.exec(text)[0];
|
|
51
|
+
if (prefixes.indexOf(prefix) < 0)
|
|
52
|
+
prefixes.push(prefix);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (!prefixes.length)
|
|
56
|
+
return /^\w*$/;
|
|
57
|
+
return new RegExp('^(?:' + prefixes.map(RegExp.escape || ((s) => s.replace(/[^\w\s]/g, '\\$&'))).join('|') + ')?\\w*$');
|
|
58
|
+
}
|
|
59
|
+
/// A completion source that requests completions from a language
|
|
60
|
+
/// server.
|
|
61
|
+
export const serverCompletionSource = async (context) => {
|
|
62
|
+
const plugin = context.view && LSPPlugin.get(context.view);
|
|
63
|
+
if (!plugin)
|
|
64
|
+
return null;
|
|
65
|
+
let triggerChar = '';
|
|
66
|
+
if (!context.explicit) {
|
|
67
|
+
triggerChar = context.view.state.sliceDoc(context.pos - 1, context.pos);
|
|
68
|
+
const client = plugin.extensionLsp.getClient(plugin.lang);
|
|
69
|
+
if (!client) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
const triggers = client.serverCapabilities?.completionProvider
|
|
73
|
+
?.triggerCharacters;
|
|
74
|
+
if (!/[a-zA-Z_]/.test(triggerChar) &&
|
|
75
|
+
!(triggers && triggers.indexOf(triggerChar) > -1))
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
let result = await getCompletions(plugin, context.pos, {
|
|
80
|
+
triggerCharacter: triggerChar,
|
|
81
|
+
triggerKind: context.explicit
|
|
82
|
+
? CompletionTriggerKind.Invoked
|
|
83
|
+
: CompletionTriggerKind.TriggerCharacter,
|
|
84
|
+
}, context);
|
|
85
|
+
if (!result)
|
|
86
|
+
return null;
|
|
87
|
+
if (Array.isArray(result)) {
|
|
88
|
+
result = { items: result };
|
|
89
|
+
}
|
|
90
|
+
const { from, to } = completionResultRange(context, result);
|
|
91
|
+
const defaultCommitChars = result.itemDefaults?.commitCharacters;
|
|
92
|
+
const config = context.state.facet(completionConfig);
|
|
93
|
+
const options = result.items.map((item) => {
|
|
94
|
+
let text = item.textEdit?.newText || item.textEditText ||
|
|
95
|
+
item.insertText || item.label;
|
|
96
|
+
let option = {
|
|
97
|
+
label: text,
|
|
98
|
+
type: item.kind && kindToType[item.kind],
|
|
99
|
+
};
|
|
100
|
+
if (item.commitCharacters && item.commitCharacters != defaultCommitChars) {
|
|
101
|
+
option.commitCharacters = item.commitCharacters;
|
|
102
|
+
}
|
|
103
|
+
if (item.detail)
|
|
104
|
+
option.detail = item.detail;
|
|
105
|
+
if (item.insertTextFormat == 2 /* Snippet */) {
|
|
106
|
+
option.apply = (view, c, from, to) => snippet(text)(view, c, from, to);
|
|
107
|
+
option.label = item.label;
|
|
108
|
+
}
|
|
109
|
+
if (item.documentation) {
|
|
110
|
+
option.info = () => renderDocInfo(plugin, item.documentation);
|
|
111
|
+
}
|
|
112
|
+
return option;
|
|
113
|
+
});
|
|
114
|
+
return {
|
|
115
|
+
from,
|
|
116
|
+
to,
|
|
117
|
+
options,
|
|
118
|
+
commitCharacters: defaultCommitChars,
|
|
119
|
+
validFor: config.validFor ?? prefixRegexp(result.items),
|
|
120
|
+
map: (result, changes) => ({
|
|
121
|
+
...result,
|
|
122
|
+
from: changes.mapPos(result.from),
|
|
123
|
+
}),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
catch (err) {
|
|
127
|
+
if ('code' in err &&
|
|
128
|
+
err.code == -32800 /* RequestCancelled */) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
throw err;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
function completionResultRange(cx, result) {
|
|
135
|
+
if (!result.items.length) {
|
|
136
|
+
return { from: cx.pos, to: cx.pos };
|
|
137
|
+
}
|
|
138
|
+
const defaultRange = result.itemDefaults?.editRange;
|
|
139
|
+
const item0 = result.items[0];
|
|
140
|
+
const range = defaultRange
|
|
141
|
+
? ('insert' in defaultRange ? defaultRange.insert : defaultRange)
|
|
142
|
+
: item0.textEdit
|
|
143
|
+
? ('range' in item0.textEdit ? item0.textEdit.range : item0.textEdit.insert)
|
|
144
|
+
: null;
|
|
145
|
+
if (!range)
|
|
146
|
+
return cx.state.wordAt(cx.pos) || { from: cx.pos, to: cx.pos };
|
|
147
|
+
const line = cx.state.doc.lineAt(cx.pos);
|
|
148
|
+
return {
|
|
149
|
+
from: line.from + range.start.character,
|
|
150
|
+
to: line.from + range.end.character,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function renderDocInfo(plugin, doc) {
|
|
154
|
+
let elt = document.createElement('div');
|
|
155
|
+
elt.className = 'cm-lsp-documentation cm-lsp-completion-documentation';
|
|
156
|
+
elt.innerHTML = plugin.docToHTML(doc);
|
|
157
|
+
return elt;
|
|
158
|
+
}
|
|
159
|
+
const kindToType = {
|
|
160
|
+
1: 'text', // Text
|
|
161
|
+
2: 'method', // Method
|
|
162
|
+
3: 'function', // Function
|
|
163
|
+
4: 'class', // Constructor
|
|
164
|
+
5: 'property', // Field
|
|
165
|
+
6: 'variable', // Variable
|
|
166
|
+
7: 'class', // Class
|
|
167
|
+
8: 'interface', // Interface
|
|
168
|
+
9: 'namespace', // Module
|
|
169
|
+
10: 'property', // Property
|
|
170
|
+
11: 'keyword', // Unit
|
|
171
|
+
12: 'constant', // Value
|
|
172
|
+
13: 'constant', // Enum
|
|
173
|
+
14: 'keyword', // Keyword
|
|
174
|
+
16: 'constant', // Color
|
|
175
|
+
20: 'constant', // EnumMember
|
|
176
|
+
21: 'constant', // Constant
|
|
177
|
+
22: 'class', // Struct
|
|
178
|
+
25: 'type', // TypeParameter
|
|
179
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hover.d.ts","sourceRoot":"","sources":["../../../../src/extension-codemirror/src/lsp/hover.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAa9C,wBAAgB,aAAa,CAAC,MAAM,GAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,SAAS,CAK5E"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { hoverTooltip } from '@codemirror/view';
|
|
2
|
+
import { fromPosition } from './pos.js';
|
|
3
|
+
import { LSPPlugin } from './plugin.js';
|
|
4
|
+
// import {highlightCode} from "@lezer/highlight"
|
|
5
|
+
// import {escHTML} from "./text.ts"
|
|
6
|
+
/// Create an extension that queries the language server for hover
|
|
7
|
+
/// tooltips when the user hovers over the code with their pointer,
|
|
8
|
+
/// and displays a tooltip when the server provides one.
|
|
9
|
+
export function hoverTooltips(config = {}) {
|
|
10
|
+
return hoverTooltip(lspTooltipSource, {
|
|
11
|
+
hideOn: (tr) => tr.docChanged,
|
|
12
|
+
hoverTime: config.hoverTime,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function hoverRequest(plugin, pos) {
|
|
16
|
+
const client = plugin.getClient();
|
|
17
|
+
if (client?.hasCapability('hoverProvider') === false) {
|
|
18
|
+
return Promise.resolve(null);
|
|
19
|
+
}
|
|
20
|
+
client?.sync();
|
|
21
|
+
return client?.request('textDocument/hover', {
|
|
22
|
+
position: plugin.toPosition(pos),
|
|
23
|
+
textDocument: { uri: plugin.uri },
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function lspTooltipSource(view, pos) {
|
|
27
|
+
const plugin = LSPPlugin.get(view);
|
|
28
|
+
if (!plugin)
|
|
29
|
+
return Promise.resolve(null);
|
|
30
|
+
return hoverRequest(plugin, pos).then((result) => {
|
|
31
|
+
if (!result)
|
|
32
|
+
return null;
|
|
33
|
+
return {
|
|
34
|
+
pos: result.range
|
|
35
|
+
? fromPosition(view.state.doc, result.range.start)
|
|
36
|
+
: pos,
|
|
37
|
+
end: result.range ? fromPosition(view.state.doc, result.range.end) : pos,
|
|
38
|
+
create() {
|
|
39
|
+
let elt = document.createElement('div');
|
|
40
|
+
elt.className = 'cm-lsp-hover-tooltip cm-lsp-documentation';
|
|
41
|
+
elt.innerHTML = renderTooltipContent(plugin, result.contents);
|
|
42
|
+
return { dom: elt };
|
|
43
|
+
},
|
|
44
|
+
above: true,
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function renderTooltipContent(plugin, value) {
|
|
49
|
+
if (Array.isArray(value)) {
|
|
50
|
+
return value.map((m) => renderCode(plugin, m)).join('<br>');
|
|
51
|
+
}
|
|
52
|
+
if (typeof value == 'string' || typeof value == 'object' && 'language' in value)
|
|
53
|
+
return renderCode(plugin, value);
|
|
54
|
+
return plugin.docToHTML(value);
|
|
55
|
+
}
|
|
56
|
+
function renderCode(plugin, code) {
|
|
57
|
+
if (typeof code == 'string')
|
|
58
|
+
return plugin.docToHTML(code, 'markdown');
|
|
59
|
+
let { language, value } = code;
|
|
60
|
+
// return plugin.docToHTML(value, language); // TODO highlight language
|
|
61
|
+
return plugin.docToHTML(value, 'plaintext');
|
|
62
|
+
}
|
|
63
|
+
/*
|
|
64
|
+
function renderCode(plugin: LSPPlugin, code: lsp.MarkedString) {
|
|
65
|
+
if (typeof code == "string") return plugin.docToHTML(code, "markdown")
|
|
66
|
+
let {language, value} = code
|
|
67
|
+
let lang = plugin.client.config.highlightLanguage && plugin.client.config.highlightLanguage(language || "")
|
|
68
|
+
if (!lang) {
|
|
69
|
+
let viewLang = plugin.view.state.facet(languageFacet)
|
|
70
|
+
if (viewLang && (!language || viewLang.name == language)) lang = viewLang
|
|
71
|
+
}
|
|
72
|
+
if (!lang) return escHTML(value)
|
|
73
|
+
let result = ""
|
|
74
|
+
highlightCode(value, lang.parser.parse(value), {style: tags => highlightingFor(plugin.view.state, tags)}, (text, cls) => {
|
|
75
|
+
result += cls ? `<span class="${cls}">${escHTML(text)}</span>` : escHTML(text)
|
|
76
|
+
}, () => {
|
|
77
|
+
result += "<br>"
|
|
78
|
+
})
|
|
79
|
+
return result
|
|
80
|
+
}
|
|
81
|
+
*/
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Extension } from '@codemirror/state';
|
|
2
|
+
export { LSPExtension, type LSPExtensionConfig } from './LSPExtension.js';
|
|
3
|
+
export { LSPPlugin } from './plugin.js';
|
|
4
|
+
export { serverCompletion, serverCompletionSource } from './completion.js';
|
|
5
|
+
export { hoverTooltips } from './hover.js';
|
|
6
|
+
export declare function languageServerExtensions(): readonly (Extension)[];
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/extension-codemirror/src/lsp/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAG9C,OAAO,EAAE,YAAY,EAAE,KAAK,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAiC3C,wBAAgB,wBAAwB,IAAI,SAAS,CACnD,SAAS,CACV,EAAE,CAaF"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { keymap } from '@codemirror/view';
|
|
2
|
+
export { LSPExtension } from './LSPExtension.js';
|
|
3
|
+
export { LSPPlugin } from './plugin.js';
|
|
4
|
+
export { serverCompletion, serverCompletionSource } from './completion.js';
|
|
5
|
+
export { hoverTooltips } from './hover.js';
|
|
6
|
+
// export { formatDocument, formatKeymap } from './formatting.ts';
|
|
7
|
+
// export { renameKeymap, renameSymbol } from './rename.ts';
|
|
8
|
+
// export {
|
|
9
|
+
// nextSignature,
|
|
10
|
+
// prevSignature,
|
|
11
|
+
// showSignatureHelp,
|
|
12
|
+
// signatureHelp,
|
|
13
|
+
// signatureKeymap,
|
|
14
|
+
// } from './signature.ts';
|
|
15
|
+
// export {
|
|
16
|
+
// jumpToDeclaration,
|
|
17
|
+
// jumpToDefinition,
|
|
18
|
+
// jumpToDefinitionKeymap,
|
|
19
|
+
// jumpToImplementation,
|
|
20
|
+
// jumpToTypeDefinition,
|
|
21
|
+
// } from './definition.ts';
|
|
22
|
+
// export {
|
|
23
|
+
// closeReferencePanel,
|
|
24
|
+
// findReferences,
|
|
25
|
+
// findReferencesKeymap,
|
|
26
|
+
// } from './references.ts';
|
|
27
|
+
// export { serverDiagnostics } from './diagnostics.ts';
|
|
28
|
+
import { serverCompletion } from './completion.js';
|
|
29
|
+
import { hoverTooltips } from './hover.js';
|
|
30
|
+
// import { formatKeymap } from './formatting.ts';
|
|
31
|
+
// import { renameKeymap } from './rename.ts';
|
|
32
|
+
// import { signatureHelp } from './signature.ts';
|
|
33
|
+
// import { jumpToDefinitionKeymap } from './definition.ts';
|
|
34
|
+
// import { findReferencesKeymap } from './references.ts';
|
|
35
|
+
// import { serverDiagnostics } from './diagnostics.ts';
|
|
36
|
+
export function languageServerExtensions() {
|
|
37
|
+
return [
|
|
38
|
+
serverCompletion(),
|
|
39
|
+
hoverTooltips(),
|
|
40
|
+
keymap.of([
|
|
41
|
+
// ...formatKeymap,
|
|
42
|
+
// ...renameKeymap,
|
|
43
|
+
// ...jumpToDefinitionKeymap,
|
|
44
|
+
// ...findReferencesKeymap,
|
|
45
|
+
]),
|
|
46
|
+
// signatureHelp(),
|
|
47
|
+
// serverDiagnostics(),
|
|
48
|
+
];
|
|
49
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type * as lsp from 'vscode-languageserver-protocol';
|
|
2
|
+
import { EditorView, ViewPlugin } from '@codemirror/view';
|
|
3
|
+
import { Text } from '@codemirror/state';
|
|
4
|
+
import { type CoreEditor } from '../../../editor/src/mod.js';
|
|
5
|
+
import type { ExtensionLsp, LSPClient, LspSource } from '../../../extension-lsp/src/mod.js';
|
|
6
|
+
import { LSPExtension } from './index.js';
|
|
7
|
+
export declare class LSPPlugin {
|
|
8
|
+
readonly view: EditorView;
|
|
9
|
+
readonly extensionLsp: ExtensionLsp;
|
|
10
|
+
readonly uri: string;
|
|
11
|
+
readonly editor: CoreEditor;
|
|
12
|
+
readonly extension: LSPExtension;
|
|
13
|
+
lang: string;
|
|
14
|
+
client?: LSPClient;
|
|
15
|
+
source: LspSource;
|
|
16
|
+
constructor(view: EditorView, { extension, extensionLsp, uri, editor }: {
|
|
17
|
+
extension: LSPExtension;
|
|
18
|
+
extensionLsp: ExtensionLsp;
|
|
19
|
+
uri: string;
|
|
20
|
+
editor: CoreEditor;
|
|
21
|
+
});
|
|
22
|
+
getClient(): LSPClient | undefined;
|
|
23
|
+
setLang(lang: string): void;
|
|
24
|
+
update(): void;
|
|
25
|
+
docToHTML(value: string | lsp.MarkupContent, defaultKind?: lsp.MarkupKind): string;
|
|
26
|
+
toPosition(pos: number, doc?: Text): lsp.Position;
|
|
27
|
+
fromPosition(pos: lsp.Position, doc?: Text): number;
|
|
28
|
+
reportError(message: string, err: any): void;
|
|
29
|
+
static get(view: EditorView): LSPPlugin | null;
|
|
30
|
+
}
|
|
31
|
+
export declare const lspPlugin: ViewPlugin<LSPPlugin, {
|
|
32
|
+
extension: LSPExtension;
|
|
33
|
+
extensionLsp: ExtensionLsp;
|
|
34
|
+
uri: string;
|
|
35
|
+
editor: CoreEditor;
|
|
36
|
+
}>;
|
|
37
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../../src/extension-codemirror/src/lsp/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,gCAAgC,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,OAAO,EAAE,KAAK,UAAU,EAAiB,MAAM,4BAA4B,CAAC;AAC5E,OAAO,KAAK,EACV,YAAY,EACZ,SAAS,EACT,SAAS,EACV,MAAM,mCAAmC,CAAC;AAI3C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAI1C,qBAAa,SAAS;IAYlB,QAAQ,CAAC,IAAI,EAAE,UAAU;IAX3B,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;IACpC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,YAAY,CAAC;IACjC,IAAI,SAAe;IACnB,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,MAAM,EAAE,SAAS,CAAC;gBAKP,IAAI,EAAE,UAAU,EACzB,EAAE,SAAS,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE;QACxC,SAAS,EAAE,YAAY,CAAC;QACxB,YAAY,EAAE,YAAY,CAAC;QAC3B,GAAG,EAAE,MAAM,CAAC;QACZ,MAAM,EAAE,UAAU,CAAC;KACpB;IAwBH,SAAS;IAIT,OAAO,CAAC,IAAI,EAAE,MAAM;IAgBpB,MAAM;IAcN,SAAS,CACP,KAAK,EAAE,MAAM,GAAG,GAAG,CAAC,aAAa,EACjC,WAAW,GAAE,GAAG,CAAC,UAAwB;IAW3C,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,GAAE,IAA0B,GAAG,GAAG,CAAC,QAAQ;IAMtE,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,QAAQ,EAAE,GAAG,GAAE,IAA0B,GAAG,MAAM;IAKxE,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG;IAKrC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,UAAU;CAG5B;AAED,eAAO,MAAM,SAAS;eAhGL,YAAY;kBACT,YAAY;SACrB,MAAM;YACH,UAAU;EA6FgC,CAAC"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { ViewPlugin } from '@codemirror/view';
|
|
2
|
+
import { fromPosition, toPosition } from './pos.js';
|
|
3
|
+
import { escHTML } from './text.js';
|
|
4
|
+
import { PositionMapper } from '../../../extension-markdown/src/PositionMapper.js';
|
|
5
|
+
import { toRawTextResult } from '../../../editor/src/utilities/mod.js';
|
|
6
|
+
export class LSPPlugin {
|
|
7
|
+
/// @internal
|
|
8
|
+
constructor(
|
|
9
|
+
/// The editor view that this plugin belongs to.
|
|
10
|
+
view, { extension, extensionLsp, uri, editor }) {
|
|
11
|
+
Object.defineProperty(this, "view", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: true,
|
|
15
|
+
value: view
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(this, "extensionLsp", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true,
|
|
21
|
+
value: void 0
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(this, "uri", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true,
|
|
27
|
+
value: void 0
|
|
28
|
+
});
|
|
29
|
+
Object.defineProperty(this, "editor", {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
configurable: true,
|
|
32
|
+
writable: true,
|
|
33
|
+
value: void 0
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(this, "extension", {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
configurable: true,
|
|
38
|
+
writable: true,
|
|
39
|
+
value: void 0
|
|
40
|
+
});
|
|
41
|
+
Object.defineProperty(this, "lang", {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
configurable: true,
|
|
44
|
+
writable: true,
|
|
45
|
+
value: 'plaintext'
|
|
46
|
+
});
|
|
47
|
+
Object.defineProperty(this, "client", {
|
|
48
|
+
enumerable: true,
|
|
49
|
+
configurable: true,
|
|
50
|
+
writable: true,
|
|
51
|
+
value: void 0
|
|
52
|
+
});
|
|
53
|
+
Object.defineProperty(this, "source", {
|
|
54
|
+
enumerable: true,
|
|
55
|
+
configurable: true,
|
|
56
|
+
writable: true,
|
|
57
|
+
value: void 0
|
|
58
|
+
});
|
|
59
|
+
this.extension = extension;
|
|
60
|
+
this.extensionLsp = extensionLsp;
|
|
61
|
+
this.uri = uri;
|
|
62
|
+
this.editor = editor;
|
|
63
|
+
this.source = {
|
|
64
|
+
ui: this.editor.ui,
|
|
65
|
+
getMappedContent: () => {
|
|
66
|
+
const editor = this.editor;
|
|
67
|
+
const result = toRawTextResult(this.view.state.doc.toString().toString(), 0);
|
|
68
|
+
const mapper = new PositionMapper(editor, result.rawTextMap);
|
|
69
|
+
return {
|
|
70
|
+
...result,
|
|
71
|
+
mapper,
|
|
72
|
+
};
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
getClient() {
|
|
77
|
+
return this.client;
|
|
78
|
+
}
|
|
79
|
+
setLang(lang) {
|
|
80
|
+
this.lang = lang;
|
|
81
|
+
const client = this.extensionLsp.getClient(lang);
|
|
82
|
+
this.client = client;
|
|
83
|
+
if (client) {
|
|
84
|
+
client.disconnect(this.uri);
|
|
85
|
+
client.connect(this.uri, this.source);
|
|
86
|
+
client.workspace.openFile(this.uri, lang, this.source);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
update() {
|
|
90
|
+
if (this.client) {
|
|
91
|
+
this.client.workspace.changedFile(this.uri);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// /// Render a doc string from the server to HTML.
|
|
95
|
+
// docToHTML(value: string | lsp.MarkupContent, defaultKind: lsp.MarkupKind = "plaintext") {
|
|
96
|
+
// let html = withContext(this.view, this.client.config.highlightLanguage, () => docToHTML(value, defaultKind))
|
|
97
|
+
// return this.client.config.sanitizeHTML ? this.client.config.sanitizeHTML(html) : html
|
|
98
|
+
// }
|
|
99
|
+
docToHTML(value, defaultKind = 'plaintext') {
|
|
100
|
+
if ('string' === typeof value) {
|
|
101
|
+
return escHTML(value);
|
|
102
|
+
}
|
|
103
|
+
return `docToHTML ${value.kind} ${JSON.stringify(value.value, null, 2)}`;
|
|
104
|
+
}
|
|
105
|
+
/// Convert a CodeMirror document offset into an LSP `{line,
|
|
106
|
+
/// character}` object. Defaults to using the view's current
|
|
107
|
+
/// document, but can be given another one.
|
|
108
|
+
toPosition(pos, doc = this.view.state.doc) {
|
|
109
|
+
return toPosition(doc, pos);
|
|
110
|
+
}
|
|
111
|
+
/// Convert an LSP `{line, character}` object to a CodeMirror
|
|
112
|
+
/// document offset.
|
|
113
|
+
fromPosition(pos, doc = this.view.state.doc) {
|
|
114
|
+
return fromPosition(doc, pos);
|
|
115
|
+
}
|
|
116
|
+
/// Display an error in this plugin's editor.
|
|
117
|
+
reportError(message, err) {
|
|
118
|
+
this.editor.ui.showError(err);
|
|
119
|
+
}
|
|
120
|
+
/// Get the LSP plugin associated with an editor, if any.
|
|
121
|
+
static get(view) {
|
|
122
|
+
return view.plugin(lspPlugin);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
export const lspPlugin = ViewPlugin.fromClass(LSPPlugin);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type * as lsp from 'vscode-languageserver-protocol';
|
|
2
|
+
import { Text } from '@codemirror/state';
|
|
3
|
+
export declare function toPosition(doc: Text, pos: number): lsp.Position;
|
|
4
|
+
export declare function fromPosition(doc: Text, pos: lsp.Position): number;
|
|
5
|
+
//# sourceMappingURL=pos.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pos.d.ts","sourceRoot":"","sources":["../../../../src/extension-codemirror/src/lsp/pos.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,gCAAgC,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,wBAAgB,UAAU,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC,QAAQ,CAG/D;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,QAAQ,GAAG,MAAM,CAGjE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../../../src/extension-codemirror/src/lsp/text.ts"],"names":[],"mappings":"AAsBA,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,UAKnC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// import {Marked} from "marked"
|
|
2
|
+
// import {highlightCode, Highlighter} from "@lezer/highlight"
|
|
3
|
+
// let context: {view: EditorView, language: ((name: string) => Language | null) | undefined} | null = null
|
|
4
|
+
// export function withContext<T>(view: EditorView, language: ((name: string) => Language | null) | undefined, f: () => T): T {
|
|
5
|
+
// let prev = context
|
|
6
|
+
// try {
|
|
7
|
+
// context = {view, language}
|
|
8
|
+
// return f()
|
|
9
|
+
// } finally {
|
|
10
|
+
// context = prev
|
|
11
|
+
// }
|
|
12
|
+
// }
|
|
13
|
+
export function escHTML(text) {
|
|
14
|
+
return text.replace(/[\n<&]/g, (ch) => ch == '\n' ? '<br>' : ch == '<' ? '<' : '&');
|
|
15
|
+
}
|
|
16
|
+
// const marked = new Marked({
|
|
17
|
+
// walkTokens(token) {
|
|
18
|
+
// if (!context || token.type != "code") return
|
|
19
|
+
// let lang = context.language && context.language(token.lang)
|
|
20
|
+
// if (!lang) {
|
|
21
|
+
// let viewLang = context.view.state.facet(languageFacet)
|
|
22
|
+
// if (viewLang && viewLang.name == token.lang) lang = viewLang
|
|
23
|
+
// }
|
|
24
|
+
// if (!lang) return
|
|
25
|
+
// let highlighter: Highlighter = {style: tags => highlightingFor(context!.view.state, tags)}
|
|
26
|
+
// let result = ""
|
|
27
|
+
// highlightCode(token.text, lang.parser.parse(token.text), highlighter, (text, cls) => {
|
|
28
|
+
// result += cls ? `<span class="${cls}">${escHTML(text)}</span>` : escHTML(text)
|
|
29
|
+
// }, () => {
|
|
30
|
+
// result += "<br>"
|
|
31
|
+
// })
|
|
32
|
+
// token.escaped = true
|
|
33
|
+
// token.text = result
|
|
34
|
+
// }
|
|
35
|
+
// })
|
|
36
|
+
// export function docToHTML(value: string | lsp.MarkupContent, defaultKind: lsp.MarkupKind) {
|
|
37
|
+
// let kind = defaultKind, text = value
|
|
38
|
+
// if (typeof text != "string") {
|
|
39
|
+
// kind = text.kind
|
|
40
|
+
// text = text.value
|
|
41
|
+
// }
|
|
42
|
+
// if (kind == "plaintext") {
|
|
43
|
+
// return escHTML(text)
|
|
44
|
+
// } else {
|
|
45
|
+
// return marked.parse(text, {async: false, })
|
|
46
|
+
// }
|
|
47
|
+
// }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../../../src/extension-codemirror/src/lsp/theme.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ,uCA8EnB,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { EditorView } from '@codemirror/view';
|
|
2
|
+
export const lspTheme = EditorView.baseTheme({
|
|
3
|
+
'.cm-lsp-documentation': {
|
|
4
|
+
padding: '0 7px',
|
|
5
|
+
'& p, & pre': {
|
|
6
|
+
margin: '2px 0',
|
|
7
|
+
},
|
|
8
|
+
},
|
|
9
|
+
'.cm-lsp-signature-tooltip': {
|
|
10
|
+
padding: '2px 6px',
|
|
11
|
+
borderRadius: '2.5px',
|
|
12
|
+
position: 'relative',
|
|
13
|
+
maxWidth: '30em',
|
|
14
|
+
maxHeight: '10em',
|
|
15
|
+
overflowY: 'scroll',
|
|
16
|
+
'& .cm-lsp-documentation': {
|
|
17
|
+
padding: '0',
|
|
18
|
+
fontSize: '80%',
|
|
19
|
+
},
|
|
20
|
+
'& .cm-lsp-signature-num': {
|
|
21
|
+
fontFamily: 'monospace',
|
|
22
|
+
position: 'absolute',
|
|
23
|
+
left: '2px',
|
|
24
|
+
top: '4px',
|
|
25
|
+
fontSize: '70%',
|
|
26
|
+
lineHeight: '1.3',
|
|
27
|
+
},
|
|
28
|
+
'& .cm-lsp-signature': {
|
|
29
|
+
fontFamily: 'monospace',
|
|
30
|
+
textIndent: '1em hanging',
|
|
31
|
+
},
|
|
32
|
+
'& .cm-lsp-active-parameter': {
|
|
33
|
+
fontWeight: 'bold',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
'.cm-lsp-signature-multiple': {
|
|
37
|
+
paddingLeft: '1.5em',
|
|
38
|
+
},
|
|
39
|
+
'.cm-panel.cm-lsp-rename-panel': {
|
|
40
|
+
padding: '2px 6px 4px',
|
|
41
|
+
position: 'relative',
|
|
42
|
+
'& label': { fontSize: '80%' },
|
|
43
|
+
'& [name=close]': {
|
|
44
|
+
position: 'absolute',
|
|
45
|
+
top: '0',
|
|
46
|
+
bottom: '0',
|
|
47
|
+
right: '4px',
|
|
48
|
+
backgroundColor: 'inherit',
|
|
49
|
+
border: 'none',
|
|
50
|
+
font: 'inherit',
|
|
51
|
+
padding: '0',
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
'.cm-lsp-message button[type=submit]': {
|
|
55
|
+
display: 'block',
|
|
56
|
+
},
|
|
57
|
+
'.cm-lsp-reference-panel': {
|
|
58
|
+
fontFamily: 'monospace',
|
|
59
|
+
whiteSpace: 'pre',
|
|
60
|
+
padding: '3px 6px',
|
|
61
|
+
maxHeight: '120px',
|
|
62
|
+
overflow: 'auto',
|
|
63
|
+
'& .cm-lsp-reference-file': {
|
|
64
|
+
fontWeight: 'bold',
|
|
65
|
+
},
|
|
66
|
+
'& .cm-lsp-reference': {
|
|
67
|
+
cursor: 'pointer',
|
|
68
|
+
'&[aria-selected]': {
|
|
69
|
+
backgroundColor: '#0077ee44',
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
'& .cm-lsp-reference-line': {
|
|
73
|
+
opacity: '0.7',
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
});
|