@platformos/codemirror-language-client 0.0.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/CHANGELOG.md +7 -0
- package/README.md +91 -0
- package/dist/esm/CodeMirrorLanguageClient.d.ts +60 -0
- package/dist/esm/CodeMirrorLanguageClient.js +80 -0
- package/dist/esm/CodeMirrorLanguageClient.js.map +1 -0
- package/dist/esm/LanguageClient.d.ts +112 -0
- package/dist/esm/LanguageClient.js +187 -0
- package/dist/esm/LanguageClient.js.map +1 -0
- package/dist/esm/extensions/client.d.ts +6 -0
- package/dist/esm/extensions/client.js +12 -0
- package/dist/esm/extensions/client.js.map +1 -0
- package/dist/esm/extensions/complete.d.ts +17 -0
- package/dist/esm/extensions/complete.js +202 -0
- package/dist/esm/extensions/complete.js.map +1 -0
- package/dist/esm/extensions/complete.spec.d.ts +1 -0
- package/dist/esm/extensions/complete.spec.js +189 -0
- package/dist/esm/extensions/complete.spec.js.map +1 -0
- package/dist/esm/extensions/documentHighlights.d.ts +14 -0
- package/dist/esm/extensions/documentHighlights.js +78 -0
- package/dist/esm/extensions/documentHighlights.js.map +1 -0
- package/dist/esm/extensions/documentHighlights.spec.d.ts +1 -0
- package/dist/esm/extensions/documentHighlights.spec.js +99 -0
- package/dist/esm/extensions/documentHighlights.spec.js.map +1 -0
- package/dist/esm/extensions/hover.d.ts +16 -0
- package/dist/esm/extensions/hover.js +49 -0
- package/dist/esm/extensions/hover.js.map +1 -0
- package/dist/esm/extensions/hover.spec.d.ts +1 -0
- package/dist/esm/extensions/hover.spec.js +59 -0
- package/dist/esm/extensions/hover.spec.js.map +1 -0
- package/dist/esm/extensions/index.d.ts +6 -0
- package/dist/esm/extensions/index.js +7 -0
- package/dist/esm/extensions/index.js.map +1 -0
- package/dist/esm/extensions/lspLinter.d.ts +23 -0
- package/dist/esm/extensions/lspLinter.js +104 -0
- package/dist/esm/extensions/lspLinter.js.map +1 -0
- package/dist/esm/extensions/lspLinter.spec.d.ts +1 -0
- package/dist/esm/extensions/lspLinter.spec.js +141 -0
- package/dist/esm/extensions/lspLinter.spec.js.map +1 -0
- package/dist/esm/extensions/snippet.d.ts +19 -0
- package/dist/esm/extensions/snippet.js +25 -0
- package/dist/esm/extensions/snippet.js.map +1 -0
- package/dist/esm/extensions/snippet.spec.d.ts +1 -0
- package/dist/esm/extensions/snippet.spec.js +23 -0
- package/dist/esm/extensions/snippet.spec.js.map +1 -0
- package/dist/esm/extensions/textDocumentSync.d.ts +4 -0
- package/dist/esm/extensions/textDocumentSync.js +109 -0
- package/dist/esm/extensions/textDocumentSync.js.map +1 -0
- package/dist/esm/extensions/textDocumentSync.spec.d.ts +1 -0
- package/dist/esm/extensions/textDocumentSync.spec.js +163 -0
- package/dist/esm/extensions/textDocumentSync.spec.js.map +1 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/test/MockClient.d.ts +18 -0
- package/dist/esm/test/MockClient.js +63 -0
- package/dist/esm/test/MockClient.js.map +1 -0
- package/dist/esm/tsconfig.tsbuildInfo +1 -0
- package/dist/esm/utils/simpleStateField.d.ts +3 -0
- package/dist/esm/utils/simpleStateField.js +17 -0
- package/dist/esm/utils/simpleStateField.js.map +1 -0
- package/dist/umd/CodeMirrorLanguageClient.d.ts +60 -0
- package/dist/umd/CodeMirrorLanguageClient.js +94 -0
- package/dist/umd/CodeMirrorLanguageClient.js.map +1 -0
- package/dist/umd/LanguageClient.d.ts +112 -0
- package/dist/umd/LanguageClient.js +202 -0
- package/dist/umd/LanguageClient.js.map +1 -0
- package/dist/umd/extensions/client.d.ts +6 -0
- package/dist/umd/extensions/client.js +25 -0
- package/dist/umd/extensions/client.js.map +1 -0
- package/dist/umd/extensions/complete.d.ts +17 -0
- package/dist/umd/extensions/complete.js +217 -0
- package/dist/umd/extensions/complete.js.map +1 -0
- package/dist/umd/extensions/documentHighlights.d.ts +14 -0
- package/dist/umd/extensions/documentHighlights.js +93 -0
- package/dist/umd/extensions/documentHighlights.js.map +1 -0
- package/dist/umd/extensions/hover.d.ts +16 -0
- package/dist/umd/extensions/hover.js +64 -0
- package/dist/umd/extensions/hover.js.map +1 -0
- package/dist/umd/extensions/index.d.ts +6 -0
- package/dist/umd/extensions/index.js +36 -0
- package/dist/umd/extensions/index.js.map +1 -0
- package/dist/umd/extensions/lspLinter.d.ts +23 -0
- package/dist/umd/extensions/lspLinter.js +119 -0
- package/dist/umd/extensions/lspLinter.js.map +1 -0
- package/dist/umd/extensions/snippet.d.ts +19 -0
- package/dist/umd/extensions/snippet.js +38 -0
- package/dist/umd/extensions/snippet.js.map +1 -0
- package/dist/umd/extensions/textDocumentSync.d.ts +4 -0
- package/dist/umd/extensions/textDocumentSync.js +122 -0
- package/dist/umd/extensions/textDocumentSync.js.map +1 -0
- package/dist/umd/index.d.ts +2 -0
- package/dist/umd/index.js +29 -0
- package/dist/umd/index.js.map +1 -0
- package/dist/umd/test/MockClient.d.ts +18 -0
- package/dist/umd/test/MockClient.js +77 -0
- package/dist/umd/test/MockClient.js.map +1 -0
- package/dist/umd/tsconfig.tsbuildInfo +1 -0
- package/dist/umd/utils/simpleStateField.d.ts +3 -0
- package/dist/umd/utils/simpleStateField.js +30 -0
- package/dist/umd/utils/simpleStateField.js.map +1 -0
- package/package.json +67 -0
- package/playground/src/index.html +10 -0
- package/playground/src/language-server-worker.ts +82 -0
- package/playground/src/playground.ts +251 -0
- package/playground/tsconfig.json +26 -0
- package/playground/webpack.config.js +85 -0
- package/src/CodeMirrorLanguageClient.ts +179 -0
- package/src/LanguageClient.ts +329 -0
- package/src/extensions/client.ts +17 -0
- package/src/extensions/complete.spec.ts +200 -0
- package/src/extensions/complete.ts +274 -0
- package/src/extensions/documentHighlights.spec.ts +111 -0
- package/src/extensions/documentHighlights.ts +91 -0
- package/src/extensions/hover.spec.ts +68 -0
- package/src/extensions/hover.ts +66 -0
- package/src/extensions/index.ts +19 -0
- package/src/extensions/lspLinter.spec.ts +156 -0
- package/src/extensions/lspLinter.ts +154 -0
- package/src/extensions/snippet.spec.ts +31 -0
- package/src/extensions/snippet.ts +42 -0
- package/src/extensions/textDocumentSync.spec.ts +188 -0
- package/src/extensions/textDocumentSync.ts +138 -0
- package/src/index.ts +2 -0
- package/src/test/MockClient.ts +96 -0
- package/src/utils/simpleStateField.ts +22 -0
- package/tsconfig.json +18 -0
- package/tsconfig.umd.json +9 -0
package/CHANGELOG.md
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
> **Warning**
|
|
2
|
+
>
|
|
3
|
+
> This package is open source but not open to contributions. It comes with little documentation but can serve as an example implementation of LSP features on the web.
|
|
4
|
+
|
|
5
|
+
# CodeMirror Language Client
|
|
6
|
+
|
|
7
|
+
[CodeMirror](https://codemirror.net/) is an open source code editor library.
|
|
8
|
+
|
|
9
|
+
The [Language Server Protocol](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/) empowers developers to write one language server that can run in all language clients. Write a client, and you gain access to all servers; write one server, and all clients can use it.
|
|
10
|
+
|
|
11
|
+
This repo serves as a CodeMirror Language Client. Feed it a Language Server and receive the following code editing features:
|
|
12
|
+
|
|
13
|
+
- [x] Diagnostics (aka Linting)
|
|
14
|
+
- [x] Completions
|
|
15
|
+
- [x] Hover
|
|
16
|
+
- [x] Document Highlights
|
|
17
|
+
- [ ] Document Links
|
|
18
|
+
- [ ] Workspace Edits (aka Refactorings, Quickfix, etc.)
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { CodeMirrorLanguageClient } from '@platformos/codemirror-language-client';
|
|
24
|
+
|
|
25
|
+
async function main() {
|
|
26
|
+
// This doesn't have to be liquid-language-server, it
|
|
27
|
+
// theoretically could be tsserver.
|
|
28
|
+
const worker = new Worker(
|
|
29
|
+
new URL('./language-server-worker.ts', import.meta.url),
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
// This is how you instantiate it
|
|
33
|
+
const client = new CodeMirrorLanguageClient(worker);
|
|
34
|
+
await client.start();
|
|
35
|
+
|
|
36
|
+
// Demo junk to be replaced
|
|
37
|
+
const filePath = 'browser///input.liquid';
|
|
38
|
+
|
|
39
|
+
// Here we add the client.extension for the file path.
|
|
40
|
+
new EditorView({
|
|
41
|
+
state: EditorState.create({
|
|
42
|
+
doc: exampleTemplate,
|
|
43
|
+
extensions: [
|
|
44
|
+
/* ... */
|
|
45
|
+
client.extension(filePath),
|
|
46
|
+
],
|
|
47
|
+
}),
|
|
48
|
+
parent: document.getElementById('editor')!,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
main();
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Learn more
|
|
56
|
+
|
|
57
|
+
- Read the [CodeMirror System Guide](https://codemirror.net/docs/guide/) a couple of times.
|
|
58
|
+
|
|
59
|
+
The concepts are hard to grok but the time is well spent.
|
|
60
|
+
|
|
61
|
+
- Read the [Language Server Protocol Spec](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/)
|
|
62
|
+
|
|
63
|
+
It's important to understand the following concepts:
|
|
64
|
+
|
|
65
|
+
- Language Client
|
|
66
|
+
- Language Server
|
|
67
|
+
- Messages
|
|
68
|
+
- Requests / Response
|
|
69
|
+
- Notifications
|
|
70
|
+
- Message direction
|
|
71
|
+
- Client Capabilities
|
|
72
|
+
- Server Capabilities
|
|
73
|
+
- TextDocument synchronization
|
|
74
|
+
- Lifecycle methods
|
|
75
|
+
|
|
76
|
+
- Take a look at the `vscode-languageserver-*` libraries offered by VS Code.
|
|
77
|
+
|
|
78
|
+
They have `vscode` in their name, but only `vscode-languageclient` is VS Code specific, the other libraries can be used in non-VS Code contexts (we do this here).
|
|
79
|
+
|
|
80
|
+
- [`vscode-languageserver-protocol`](https://github.com/microsoft/vscode-languageserver-node/tree/main/protocol)
|
|
81
|
+
|
|
82
|
+
This library is useful to reuse and type check message parameter types.
|
|
83
|
+
|
|
84
|
+
Examples: `PublishDiagnosticsNotification`, `DiagnosticClientCapabilities`, `DiagnosticServerCapabilities`, etc.
|
|
85
|
+
|
|
86
|
+
- [`vscode-languageserver-types`](https://github.com/microsoft/vscode-languageserver-node/tree/main/types)
|
|
87
|
+
|
|
88
|
+
This library is useful to get the types of specific parts of the Protocol.
|
|
89
|
+
|
|
90
|
+
Examples: `Diagnostic`, `URI`, `TextDocument`, `Position`, `Range`, `LocationLink`, etc.
|
|
91
|
+
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Extension } from '@codemirror/state';
|
|
2
|
+
import { Dependencies, LanguageClient } from './LanguageClient';
|
|
3
|
+
import { AutocompleteOptions, DiagnosticRenderer, HoverOptions, HoverRenderer, InfoRenderer, LinterOptions } from './extensions';
|
|
4
|
+
export { Dependencies };
|
|
5
|
+
export interface FeatureFlags {
|
|
6
|
+
shouldComplete: boolean;
|
|
7
|
+
shouldLint: boolean;
|
|
8
|
+
shouldHover: boolean;
|
|
9
|
+
}
|
|
10
|
+
export type ClientDependencies = Partial<Dependencies>;
|
|
11
|
+
export interface CodeMirrorDependencies {
|
|
12
|
+
/**
|
|
13
|
+
* The infoRenderer is a function that returns a DOM node that contains the documentation
|
|
14
|
+
* for a completion item. Presumably does markdown conversions to DOM nodes.
|
|
15
|
+
*
|
|
16
|
+
* A function that takes a completion object and returns a DOM node.
|
|
17
|
+
*/
|
|
18
|
+
infoRenderer?: InfoRenderer;
|
|
19
|
+
/**
|
|
20
|
+
* Say you wanted to change the settings of the `autocomplete` extension,
|
|
21
|
+
* you'd do it with that.
|
|
22
|
+
*/
|
|
23
|
+
autocompleteOptions?: AutocompleteOptions;
|
|
24
|
+
/**
|
|
25
|
+
* Say you wanted to change the settings of the `linter` extension,
|
|
26
|
+
* you'd do it with that.
|
|
27
|
+
*/
|
|
28
|
+
linterOptions?: LinterOptions;
|
|
29
|
+
/**
|
|
30
|
+
* The diagnosticRenderer is a function that returns a DOM node that
|
|
31
|
+
* contains the content of a diagnostic. It overrides the default
|
|
32
|
+
* rendering logic for diagnostics.
|
|
33
|
+
*/
|
|
34
|
+
diagnosticRenderer?: DiagnosticRenderer;
|
|
35
|
+
/**
|
|
36
|
+
* The hoverRenderer is a function that returns a DOM node that contains the documentation
|
|
37
|
+
* for the item under the cursor. The documentation is provided by the Language Server.
|
|
38
|
+
*/
|
|
39
|
+
hoverRenderer?: HoverRenderer;
|
|
40
|
+
/**
|
|
41
|
+
* Say you wanted to change the settings of the `hoverTooltip` extension,
|
|
42
|
+
* you'd do it with that.
|
|
43
|
+
*/
|
|
44
|
+
hoverOptions?: HoverOptions;
|
|
45
|
+
}
|
|
46
|
+
export declare class CodeMirrorLanguageClient {
|
|
47
|
+
private readonly worker;
|
|
48
|
+
readonly client: LanguageClient;
|
|
49
|
+
private readonly infoRenderer;
|
|
50
|
+
private readonly autocompleteExtension;
|
|
51
|
+
private readonly diagnosticRenderer;
|
|
52
|
+
private readonly linterExtension;
|
|
53
|
+
private readonly hoverRenderer;
|
|
54
|
+
private readonly hoverExtension;
|
|
55
|
+
private readonly documentHighlightsExtension;
|
|
56
|
+
constructor(worker: Worker, { log, initializationOptions }?: ClientDependencies, { infoRenderer, autocompleteOptions, diagnosticRenderer, linterOptions, hoverRenderer, hoverOptions, }?: CodeMirrorDependencies);
|
|
57
|
+
start(): Promise<void>;
|
|
58
|
+
stop(): Promise<void>;
|
|
59
|
+
extension(fileUri: string, { shouldLint, shouldComplete, shouldHover }?: FeatureFlags): Extension[];
|
|
60
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { MarkupKind } from 'vscode-languageserver-protocol';
|
|
2
|
+
import { LanguageClient } from './LanguageClient';
|
|
3
|
+
import { clientFacet, diagnosticRendererFacet, fileUriFacet, infoRendererFacet, lspComplete, lspDocumentHighlights, lspHover, lspLinter, serverCapabilitiesFacet, textDocumentSync, } from './extensions';
|
|
4
|
+
import { hoverRendererFacet } from './extensions/hover';
|
|
5
|
+
/**
|
|
6
|
+
* The client capabilities are how we tell the language server what
|
|
7
|
+
* features we support so that they have the opportunity to skip doing
|
|
8
|
+
* things that the client does not support. Everything is false by default,
|
|
9
|
+
* but we migth need to change that and this is where we'll do it.
|
|
10
|
+
*/
|
|
11
|
+
const clientCapabilities = {
|
|
12
|
+
textDocument: {
|
|
13
|
+
documentHighlight: {
|
|
14
|
+
dynamicRegistration: false,
|
|
15
|
+
},
|
|
16
|
+
completion: {
|
|
17
|
+
// We send the completion context to the server
|
|
18
|
+
contextSupport: true,
|
|
19
|
+
completionItem: {
|
|
20
|
+
snippetSupport: true,
|
|
21
|
+
insertReplaceSupport: true,
|
|
22
|
+
documentationFormat: [MarkupKind.PlainText, MarkupKind.Markdown],
|
|
23
|
+
commitCharactersSupport: false,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
const defaultLogger = console.log.bind(console);
|
|
29
|
+
// There is one LanguageClient
|
|
30
|
+
// There is one LanguageServer
|
|
31
|
+
// There are many CodeMirror instances
|
|
32
|
+
export class CodeMirrorLanguageClient {
|
|
33
|
+
constructor(worker, { log = defaultLogger, initializationOptions } = {}, { infoRenderer, autocompleteOptions, diagnosticRenderer, linterOptions, hoverRenderer, hoverOptions, } = {}) {
|
|
34
|
+
this.worker = worker;
|
|
35
|
+
this.client = new LanguageClient(worker, {
|
|
36
|
+
clientCapabilities,
|
|
37
|
+
initializationOptions,
|
|
38
|
+
log,
|
|
39
|
+
});
|
|
40
|
+
this.worker = worker;
|
|
41
|
+
this.infoRenderer = infoRenderer;
|
|
42
|
+
this.autocompleteExtension = lspComplete(autocompleteOptions);
|
|
43
|
+
this.diagnosticRenderer = diagnosticRenderer;
|
|
44
|
+
this.linterExtension = lspLinter(linterOptions);
|
|
45
|
+
this.hoverRenderer = hoverRenderer;
|
|
46
|
+
this.hoverExtension = lspHover(hoverOptions);
|
|
47
|
+
this.documentHighlightsExtension = lspDocumentHighlights();
|
|
48
|
+
}
|
|
49
|
+
async start() {
|
|
50
|
+
await this.client.start();
|
|
51
|
+
}
|
|
52
|
+
async stop() {
|
|
53
|
+
try {
|
|
54
|
+
await this.client.stop();
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
this.worker.terminate();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
extension(fileUri, { shouldLint, shouldComplete, shouldHover } = {
|
|
61
|
+
shouldLint: true,
|
|
62
|
+
shouldComplete: true,
|
|
63
|
+
shouldHover: true,
|
|
64
|
+
}) {
|
|
65
|
+
return [
|
|
66
|
+
clientFacet.of(this.client),
|
|
67
|
+
serverCapabilitiesFacet.of(this.client.serverCapabilities),
|
|
68
|
+
fileUriFacet.of(fileUri),
|
|
69
|
+
textDocumentSync,
|
|
70
|
+
infoRendererFacet.of(this.infoRenderer),
|
|
71
|
+
diagnosticRendererFacet.of(this.diagnosticRenderer),
|
|
72
|
+
hoverRendererFacet.of(this.hoverRenderer),
|
|
73
|
+
this.documentHighlightsExtension,
|
|
74
|
+
]
|
|
75
|
+
.concat(shouldLint ? this.linterExtension : [])
|
|
76
|
+
.concat(shouldComplete ? this.autocompleteExtension : [])
|
|
77
|
+
.concat(shouldHover ? this.hoverExtension : []);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=CodeMirrorLanguageClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CodeMirrorLanguageClient.js","sourceRoot":"","sources":["../../src/CodeMirrorLanguageClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAEhF,OAAO,EAAgB,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAOL,WAAW,EACX,uBAAuB,EACvB,YAAY,EACZ,iBAAiB,EACjB,WAAW,EACX,qBAAqB,EACrB,QAAQ,EACR,SAAS,EACT,uBAAuB,EACvB,gBAAgB,GACjB,MAAM,cAAc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}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { Disposable, NotificationHandler, ProtocolNotificationType, ProtocolRequestType, ProtocolRequestType0, RequestHandler, ProtocolNotificationType0, ServerCapabilities, ClientCapabilities } from 'vscode-languageserver-protocol';
|
|
2
|
+
export interface PromiseCompletion {
|
|
3
|
+
resolve(value: unknown): void;
|
|
4
|
+
reject(error: unknown): void;
|
|
5
|
+
}
|
|
6
|
+
export interface Dependencies {
|
|
7
|
+
clientCapabilities: ClientCapabilities;
|
|
8
|
+
initializationOptions?: any;
|
|
9
|
+
log(...args: any[]): void;
|
|
10
|
+
}
|
|
11
|
+
export interface AbstractLanguageClient {
|
|
12
|
+
clientCapabilities: ClientCapabilities;
|
|
13
|
+
serverCapabilities: ServerCapabilities | null;
|
|
14
|
+
serverInfo: any;
|
|
15
|
+
onRequest: LanguageClient['onRequest'];
|
|
16
|
+
onNotification: LanguageClient['onNotification'];
|
|
17
|
+
sendRequest: LanguageClient['sendRequest'];
|
|
18
|
+
sendNotification: LanguageClient['sendNotification'];
|
|
19
|
+
}
|
|
20
|
+
export declare class LanguageClient extends EventTarget implements AbstractLanguageClient {
|
|
21
|
+
readonly worker: Worker;
|
|
22
|
+
readonly clientCapabilities: ClientCapabilities;
|
|
23
|
+
readonly initializationOptions: any;
|
|
24
|
+
serverCapabilities: ServerCapabilities | null;
|
|
25
|
+
serverInfo: any;
|
|
26
|
+
private requestId;
|
|
27
|
+
private requests;
|
|
28
|
+
private dispose;
|
|
29
|
+
private disposables;
|
|
30
|
+
private log;
|
|
31
|
+
constructor(worker: Worker, dependencies: Dependencies);
|
|
32
|
+
/**
|
|
33
|
+
* Lifecycle method to start the server
|
|
34
|
+
*/
|
|
35
|
+
start(): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Lifecycle method to stop the server
|
|
38
|
+
*/
|
|
39
|
+
stop(): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* For when you want to handle requests sent from the language server.
|
|
42
|
+
*
|
|
43
|
+
* @param {MessageSignature} type this is an export from vscode-languageserver-protocol
|
|
44
|
+
* @param {RequestHandler} handler a type-inferred event handler whose return value matches the MessageSignature
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* import {ApplyWorkspaceEditRequest, ApplyWorkspaceEditResponse} from 'vscode-languageserver-protocol';
|
|
48
|
+
* client.onRequest(ApplyWorkspaceEditRequest.type, (params, cancellationToken) => {
|
|
49
|
+
* // `params` and `cancellationToken` are typed inferred
|
|
50
|
+
* // The return value must match the MessageSignature (ApplyWorkspaceEditResponse)
|
|
51
|
+
* return result as ApplyWorkspaceEditResponse;
|
|
52
|
+
* })
|
|
53
|
+
*/
|
|
54
|
+
onRequest<P, R, PR, E, RO>(type: ProtocolRequestType<P, R, PR, E, RO>, handler: RequestHandler<P, R, E>): Disposable;
|
|
55
|
+
/**
|
|
56
|
+
* For when you want to handle notifications sent from the language server.
|
|
57
|
+
*
|
|
58
|
+
* @param {MessageSignature} type this is an export from vscode-languageserver-protocol
|
|
59
|
+
* @param {NotificationHandler} handler this is a type-inferred event handler
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* import {PublishDiagnosticsNotification} from 'vscode-languageserver-protocol';
|
|
63
|
+
* client.onNotification(PublishDiagnosticsNotification.type, (params) => {
|
|
64
|
+
* // the type of `params` is inferred from the first argument
|
|
65
|
+
* });
|
|
66
|
+
*/
|
|
67
|
+
onNotification<P, RO>(type: ProtocolNotificationType<P, RO>, handler: NotificationHandler<P>): Disposable;
|
|
68
|
+
/**
|
|
69
|
+
* Send a request to the language server and await a response.
|
|
70
|
+
*
|
|
71
|
+
* @param {MessageSignature} type this is an export from vscode-languageserver-protocol
|
|
72
|
+
* @param [params] its type is inferred from the first argument
|
|
73
|
+
* @returns {any} response, its type is inferred from the first argument
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
*
|
|
77
|
+
* import {CompletionRequest} from 'vscode-languageserver-protocol';
|
|
78
|
+
* const completions = await client.sendRequest(
|
|
79
|
+
* CompletionRequest.type,
|
|
80
|
+
* params
|
|
81
|
+
* );
|
|
82
|
+
*/
|
|
83
|
+
sendRequest<R, PR, E, RO>(type: ProtocolRequestType0<R, PR, E, RO>): Promise<R>;
|
|
84
|
+
sendRequest<P, R, PR, E, RO>(type: ProtocolRequestType<P, R, PR, E, RO>, params?: P): Promise<R>;
|
|
85
|
+
/**
|
|
86
|
+
* Send a notification to the language server. Notifications are fire and forget.
|
|
87
|
+
*
|
|
88
|
+
* @param {MessageSignature} type this is an export from vscode-languageserver-protocol
|
|
89
|
+
* @param [params] its type is inferred from the first argument
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
*
|
|
93
|
+
* import {DidChangeTextDocumentNotification} from 'vscode-languageserver-protocol';
|
|
94
|
+
* client.sendNotification(
|
|
95
|
+
* DidChangeTextDocumentNotification.type,
|
|
96
|
+
* params
|
|
97
|
+
* );
|
|
98
|
+
*/
|
|
99
|
+
sendNotification<RO>(type: ProtocolNotificationType0<RO>): void;
|
|
100
|
+
sendNotification<P, RO>(type: ProtocolNotificationType<P, RO>, params?: P): void;
|
|
101
|
+
private sendResponse;
|
|
102
|
+
private sendMessage;
|
|
103
|
+
/**
|
|
104
|
+
* Map messages to their correct destition.
|
|
105
|
+
* - Responses -> resolve or reject the corresponding Request
|
|
106
|
+
* - Notification -> emit(message.method, message)
|
|
107
|
+
* - Request -> emit(message.method, message)
|
|
108
|
+
*/
|
|
109
|
+
private handleMessage;
|
|
110
|
+
private disposable;
|
|
111
|
+
}
|
|
112
|
+
export declare function disposable(dispose: () => void): Disposable;
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/* eslint-disable lines-between-class-members */
|
|
2
|
+
import { CancellationTokenSource, ExitNotification, InitializeRequest, InitializedNotification, ResponseError, ShutdownRequest, } from 'vscode-languageserver-protocol';
|
|
3
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
4
|
+
export class LanguageClient extends EventTarget {
|
|
5
|
+
constructor(worker, dependencies) {
|
|
6
|
+
super();
|
|
7
|
+
this.worker = worker;
|
|
8
|
+
this.requests = new Map();
|
|
9
|
+
this.requestId = 0;
|
|
10
|
+
this.dispose = () => { };
|
|
11
|
+
this.disposables = [];
|
|
12
|
+
this.clientCapabilities = dependencies.clientCapabilities;
|
|
13
|
+
this.initializationOptions = dependencies.initializationOptions;
|
|
14
|
+
this.log = dependencies.log;
|
|
15
|
+
this.serverCapabilities = null;
|
|
16
|
+
this.serverInfo = null;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Lifecycle method to start the server
|
|
20
|
+
*/
|
|
21
|
+
async start() {
|
|
22
|
+
/**
|
|
23
|
+
* Here we setup the web worker event handler.
|
|
24
|
+
* We route the message sent via the worker's postMessage to our event handler.
|
|
25
|
+
*/
|
|
26
|
+
const handler = (ev) => this.handleMessage(ev.data);
|
|
27
|
+
this.worker.addEventListener('message', handler);
|
|
28
|
+
this.dispose = () => {
|
|
29
|
+
this.worker.removeEventListener('message', handler);
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* We send the `initialize` request and obtain the capabilities supported by
|
|
33
|
+
* the language server.
|
|
34
|
+
*
|
|
35
|
+
* https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#initialize
|
|
36
|
+
*/
|
|
37
|
+
const response = await this.sendRequest(InitializeRequest.type, {
|
|
38
|
+
capabilities: this.clientCapabilities,
|
|
39
|
+
initializationOptions: this.initializationOptions,
|
|
40
|
+
processId: 0,
|
|
41
|
+
rootUri: 'browser:///',
|
|
42
|
+
});
|
|
43
|
+
/**
|
|
44
|
+
* We unpack the response from the server and remember the capabilities.
|
|
45
|
+
* Those will be useful.
|
|
46
|
+
*/
|
|
47
|
+
this.serverCapabilities = response.capabilities;
|
|
48
|
+
this.serverInfo = response.serverInfo;
|
|
49
|
+
/**
|
|
50
|
+
* Once we're ready, we send the `initialized` notification to tell the
|
|
51
|
+
* server that we're ready to roll!
|
|
52
|
+
*
|
|
53
|
+
* https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#initialized
|
|
54
|
+
*/
|
|
55
|
+
this.sendNotification(InitializedNotification.type, {});
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Lifecycle method to stop the server
|
|
59
|
+
*/
|
|
60
|
+
async stop() {
|
|
61
|
+
await Promise.race([this.sendRequest(ShutdownRequest.type), sleep(1000)]);
|
|
62
|
+
this.disposables.forEach((disposable) => disposable.dispose());
|
|
63
|
+
this.disposables = [];
|
|
64
|
+
this.dispose();
|
|
65
|
+
this.sendNotification(ExitNotification.type);
|
|
66
|
+
}
|
|
67
|
+
onRequest(type, handler) {
|
|
68
|
+
const method = typeof type === 'string' ? type : type.method;
|
|
69
|
+
const callback = async (event) => {
|
|
70
|
+
const { params, id } = event.detail;
|
|
71
|
+
const cancellationToken = new CancellationTokenSource().token;
|
|
72
|
+
try {
|
|
73
|
+
const response = await handler(params, cancellationToken);
|
|
74
|
+
if (response && typeof response === 'object' && 'code' in response) {
|
|
75
|
+
this.sendResponse(id, undefined, response);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
this.sendResponse(id, response, undefined);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
this.sendResponse(id, undefined, new ResponseError(1, error instanceof Error ? error.message : error));
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
this.addEventListener(method, callback);
|
|
86
|
+
return this.disposable(() => this.removeEventListener(method, callback));
|
|
87
|
+
}
|
|
88
|
+
onNotification(type, handler) {
|
|
89
|
+
const method = typeof type === 'string' ? type : type.method;
|
|
90
|
+
const callback = (event) => {
|
|
91
|
+
const { params } = event.detail;
|
|
92
|
+
handler(params);
|
|
93
|
+
};
|
|
94
|
+
this.addEventListener(method, callback);
|
|
95
|
+
return this.disposable(() => this.removeEventListener(method, callback));
|
|
96
|
+
}
|
|
97
|
+
async sendRequest(type, params) {
|
|
98
|
+
this.requestId += 1;
|
|
99
|
+
const requestId = this.requestId;
|
|
100
|
+
const method = typeof type === 'string' ? type : type.method;
|
|
101
|
+
const request = {
|
|
102
|
+
jsonrpc: '2.0',
|
|
103
|
+
id: requestId,
|
|
104
|
+
method,
|
|
105
|
+
};
|
|
106
|
+
if (params)
|
|
107
|
+
request.params = params;
|
|
108
|
+
this.log(`Client->Server ${request.method} request [${request.id}]`, request);
|
|
109
|
+
this.sendMessage(request);
|
|
110
|
+
return new Promise((resolve, reject) => {
|
|
111
|
+
this.requests.set(requestId.toString(), { resolve, reject });
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
sendNotification(type, params) {
|
|
115
|
+
const method = typeof type === 'string' ? type : type.method;
|
|
116
|
+
const notification = {
|
|
117
|
+
jsonrpc: '2.0',
|
|
118
|
+
method,
|
|
119
|
+
};
|
|
120
|
+
if (params)
|
|
121
|
+
notification.params = params;
|
|
122
|
+
this.log(`Client->Server ${method} notification`, notification);
|
|
123
|
+
this.sendMessage(notification);
|
|
124
|
+
}
|
|
125
|
+
sendResponse(id, result, error) {
|
|
126
|
+
const response = { jsonrpc: '2.0', id };
|
|
127
|
+
if (result !== undefined)
|
|
128
|
+
response.result = result;
|
|
129
|
+
if (error !== undefined)
|
|
130
|
+
response.error = error.toJson();
|
|
131
|
+
this.log(`Client->Server response [${id}]`, response);
|
|
132
|
+
this.sendMessage(response);
|
|
133
|
+
}
|
|
134
|
+
sendMessage(message) {
|
|
135
|
+
this.worker.postMessage(message);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Map messages to their correct destition.
|
|
139
|
+
* - Responses -> resolve or reject the corresponding Request
|
|
140
|
+
* - Notification -> emit(message.method, message)
|
|
141
|
+
* - Request -> emit(message.method, message)
|
|
142
|
+
*/
|
|
143
|
+
handleMessage(message) {
|
|
144
|
+
if (isResponse(message)) {
|
|
145
|
+
this.log(`Server->Client response [${message.id}]`, message);
|
|
146
|
+
const id = message.id.toString();
|
|
147
|
+
if ('result' in message) {
|
|
148
|
+
this.requests.get(id).resolve(message.result);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
this.requests.get(id).reject(message.error);
|
|
152
|
+
}
|
|
153
|
+
this.requests.delete(id);
|
|
154
|
+
}
|
|
155
|
+
else if (isRequest(message)) {
|
|
156
|
+
this.log(`Server->Client ${message.method} request [${message.id}]`, message);
|
|
157
|
+
this.dispatchEvent(new CustomEvent(message.method, { detail: message }));
|
|
158
|
+
}
|
|
159
|
+
else if (isNotification(message)) {
|
|
160
|
+
this.log(`Server->Client ${message.method} notification`, message);
|
|
161
|
+
this.dispatchEvent(new CustomEvent(message.method, {
|
|
162
|
+
detail: message,
|
|
163
|
+
}));
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
this.log('what?', message);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
disposable(dispose) {
|
|
170
|
+
const disp = disposable(dispose);
|
|
171
|
+
this.disposables.push(disp);
|
|
172
|
+
return disp;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
export function disposable(dispose) {
|
|
176
|
+
return { dispose };
|
|
177
|
+
}
|
|
178
|
+
function isResponse(message) {
|
|
179
|
+
return 'id' in message && ('error' in message || 'result' in message);
|
|
180
|
+
}
|
|
181
|
+
function isRequest(message) {
|
|
182
|
+
return 'id' in message && 'method' in message;
|
|
183
|
+
}
|
|
184
|
+
function isNotification(message) {
|
|
185
|
+
return !('id' in message) && 'method' in message;
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=LanguageClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LanguageClient.js","sourceRoot":"","sources":["../../src/LanguageClient.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,OAAO,EAEL,uBAAuB,EAEvB,gBAAgB,EAChB,iBAAiB,EACjB,uBAAuB,EASvB,aAAa,EAEb,eAAe,GAKhB,MAAM,gCAAgC,CAAC;AAaxC,MAA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facet } from '@codemirror/state';
|
|
2
|
+
import { AbstractLanguageClient } from '../LanguageClient';
|
|
3
|
+
import { ServerCapabilities } from 'vscode-languageserver-protocol';
|
|
4
|
+
export declare const clientFacet: Facet<AbstractLanguageClient, AbstractLanguageClient>;
|
|
5
|
+
export declare const fileUriFacet: Facet<string, string>;
|
|
6
|
+
export declare const serverCapabilitiesFacet: Facet<ServerCapabilities<any> | null, ServerCapabilities<any>>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Facet } from '@codemirror/state';
|
|
2
|
+
export const clientFacet = Facet.define({
|
|
3
|
+
combine: (values) => values[0],
|
|
4
|
+
static: true,
|
|
5
|
+
});
|
|
6
|
+
export const fileUriFacet = Facet.define({
|
|
7
|
+
combine: (values) => values[0],
|
|
8
|
+
});
|
|
9
|
+
export const serverCapabilitiesFacet = Facet.define({
|
|
10
|
+
combine: (values) => values[0] ?? {},
|
|
11
|
+
});
|
|
12
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/extensions/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAK1C,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAiD;IACtF,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9B,MAAM,EAAE,IAAI;CACb,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,CAAiB;IACvD,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;CAC/B,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,uBAAuB,GAAG,KAAK,CAAC,MAAM,CAAgD;IACjG,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE;CACrC,CAAC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { autocompletion, CompletionContext, CompletionResult, CompletionInfo } from '@codemirror/autocomplete';
|
|
2
|
+
import { CompletionItem } from 'vscode-languageserver-protocol';
|
|
3
|
+
import { Facet } from '@codemirror/state';
|
|
4
|
+
type FirstArgType<F> = F extends (arg: infer A) => any ? A : never;
|
|
5
|
+
export type AutocompleteOptions = Partial<FirstArgType<typeof autocompletion>>;
|
|
6
|
+
export declare const lspComplete: (overrides?: AutocompleteOptions) => import("@codemirror/state").Extension;
|
|
7
|
+
/**
|
|
8
|
+
* An InfoRenderer would be equivalent to the Quick Info window in VS Code. It's the part of the completion
|
|
9
|
+
* window that shows you the docs about the thing that is currently selected.
|
|
10
|
+
*
|
|
11
|
+
* Takes a LSP CompletionItem as argument and returns a DOM node, optional and injected so that we can control
|
|
12
|
+
* how we render the info window from the rendering context.
|
|
13
|
+
*/
|
|
14
|
+
export type InfoRenderer = (completion: CompletionItem) => CompletionInfo;
|
|
15
|
+
export declare const infoRendererFacet: Facet<InfoRenderer | undefined, InfoRenderer | undefined>;
|
|
16
|
+
export declare function complete(context: CompletionContext): Promise<CompletionResult | null>;
|
|
17
|
+
export {};
|