monaco-languageclient 1.0.1 → 2.0.0-dev.1
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/dist/amd/console-window.d.ts +5 -4
- package/dist/amd/console-window.d.ts.map +1 -1
- package/dist/amd/console-window.js +17 -7
- package/dist/amd/console-window.js.map +1 -1
- package/dist/amd/disposable.d.ts +1 -1
- package/dist/amd/disposable.d.ts.map +1 -1
- package/dist/amd/disposable.js +6 -2
- package/dist/amd/disposable.js.map +1 -1
- package/dist/amd/index.d.ts +2 -4
- package/dist/amd/index.d.ts.map +1 -1
- package/dist/amd/index.js +7 -5
- package/dist/amd/index.js.map +1 -1
- package/dist/amd/monaco-converter.d.ts +14 -5
- package/dist/amd/monaco-converter.d.ts.map +1 -1
- package/dist/amd/monaco-converter.js +150 -122
- package/dist/amd/monaco-converter.js.map +1 -1
- package/dist/amd/monaco-language-client.d.ts +10 -3
- package/dist/amd/monaco-language-client.d.ts.map +1 -1
- package/dist/amd/monaco-language-client.js +69 -8
- package/dist/amd/monaco-language-client.js.map +1 -1
- package/dist/amd/monaco-services.d.ts +6 -10
- package/dist/amd/monaco-services.d.ts.map +1 -1
- package/dist/amd/monaco-services.js +6 -13
- package/dist/amd/monaco-services.js.map +1 -1
- package/dist/amd/monaco-workspace.d.ts +6 -28
- package/dist/amd/monaco-workspace.d.ts.map +1 -1
- package/dist/amd/monaco-workspace.js +4 -121
- package/dist/amd/monaco-workspace.js.map +1 -1
- package/lib/console-window.d.ts +5 -4
- package/lib/console-window.d.ts.map +1 -1
- package/lib/console-window.js +18 -12
- package/lib/console-window.js.map +1 -1
- package/lib/disposable.d.ts +1 -1
- package/lib/disposable.d.ts.map +1 -1
- package/lib/disposable.js +3 -7
- package/lib/disposable.js.map +1 -1
- package/lib/index.d.ts +2 -4
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +8 -13
- package/lib/index.js.map +1 -1
- package/lib/monaco-converter.d.ts +14 -5
- package/lib/monaco-converter.d.ts.map +1 -1
- package/lib/monaco-converter.js +164 -142
- package/lib/monaco-converter.js.map +1 -1
- package/lib/monaco-language-client.d.ts +10 -3
- package/lib/monaco-language-client.d.ts.map +1 -1
- package/lib/monaco-language-client.js +94 -13
- package/lib/monaco-language-client.js.map +1 -1
- package/lib/monaco-services.d.ts +6 -10
- package/lib/monaco-services.d.ts.map +1 -1
- package/lib/monaco-services.js +16 -26
- package/lib/monaco-services.js.map +1 -1
- package/lib/monaco-workspace.d.ts +6 -28
- package/lib/monaco-workspace.d.ts.map +1 -1
- package/lib/monaco-workspace.js +4 -128
- package/lib/monaco-workspace.js.map +1 -1
- package/package.json +25 -14
- package/src/console-window.ts +21 -10
- package/src/disposable.ts +2 -1
- package/src/index.ts +5 -4
- package/src/monaco-converter.ts +60 -29
- package/src/monaco-language-client.ts +102 -13
- package/src/monaco-services.ts +9 -23
- package/src/monaco-workspace.ts +6 -154
- package/dist/amd/connection.d.ts +0 -53
- package/dist/amd/connection.d.ts.map +0 -1
- package/dist/amd/connection.js +0 -41
- package/dist/amd/connection.js.map +0 -1
- package/dist/amd/converters.d.ts +0 -144
- package/dist/amd/converters.d.ts.map +0 -1
- package/dist/amd/converters.js +0 -154
- package/dist/amd/converters.js.map +0 -1
- package/dist/amd/monaco-commands.d.ts +0 -8
- package/dist/amd/monaco-commands.d.ts.map +0 -1
- package/dist/amd/monaco-commands.js +0 -15
- package/dist/amd/monaco-commands.js.map +0 -1
- package/dist/amd/monaco-diagnostic-collection.d.ts +0 -32
- package/dist/amd/monaco-diagnostic-collection.d.ts.map +0 -1
- package/dist/amd/monaco-diagnostic-collection.js +0 -76
- package/dist/amd/monaco-diagnostic-collection.js.map +0 -1
- package/dist/amd/monaco-languages.d.ts +0 -70
- package/dist/amd/monaco-languages.d.ts.map +0 -1
- package/dist/amd/monaco-languages.js +0 -503
- package/dist/amd/monaco-languages.js.map +0 -1
- package/dist/amd/register-vscode.d.ts +0 -2
- package/dist/amd/register-vscode.d.ts.map +0 -1
- package/dist/amd/register-vscode.js +0 -16
- package/dist/amd/register-vscode.js.map +0 -1
- package/dist/amd/services.d.ts +0 -234
- package/dist/amd/services.d.ts.map +0 -1
- package/dist/amd/services.js +0 -69
- package/dist/amd/services.js.map +0 -1
- package/dist/amd/vscode-api.d.ts +0 -4
- package/dist/amd/vscode-api.d.ts.map +0 -1
- package/dist/amd/vscode-api.js +0 -1018
- package/dist/amd/vscode-api.js.map +0 -1
- package/dist/amd/vscode-compatibility.d.ts +0 -4
- package/dist/amd/vscode-compatibility.d.ts.map +0 -1
- package/dist/amd/vscode-compatibility.js +0 -5
- package/dist/amd/vscode-compatibility.js.map +0 -1
- package/lib/connection.d.ts +0 -53
- package/lib/connection.d.ts.map +0 -1
- package/lib/connection.js +0 -41
- package/lib/connection.js.map +0 -1
- package/lib/converters.d.ts +0 -144
- package/lib/converters.d.ts.map +0 -1
- package/lib/converters.js +0 -152
- package/lib/converters.js.map +0 -1
- package/lib/monaco-commands.d.ts +0 -8
- package/lib/monaco-commands.d.ts.map +0 -1
- package/lib/monaco-commands.js +0 -13
- package/lib/monaco-commands.js.map +0 -1
- package/lib/monaco-diagnostic-collection.d.ts +0 -32
- package/lib/monaco-diagnostic-collection.d.ts.map +0 -1
- package/lib/monaco-diagnostic-collection.js +0 -75
- package/lib/monaco-diagnostic-collection.js.map +0 -1
- package/lib/monaco-languages.d.ts +0 -70
- package/lib/monaco-languages.d.ts.map +0 -1
- package/lib/monaco-languages.js +0 -504
- package/lib/monaco-languages.js.map +0 -1
- package/lib/register-vscode.d.ts +0 -2
- package/lib/register-vscode.d.ts.map +0 -1
- package/lib/register-vscode.js +0 -15
- package/lib/register-vscode.js.map +0 -1
- package/lib/services.d.ts +0 -234
- package/lib/services.d.ts.map +0 -1
- package/lib/services.js +0 -70
- package/lib/services.js.map +0 -1
- package/lib/vscode-api.d.ts +0 -4
- package/lib/vscode-api.d.ts.map +0 -1
- package/lib/vscode-api.js +0 -1021
- package/lib/vscode-api.js.map +0 -1
- package/lib/vscode-compatibility.d.ts +0 -4
- package/lib/vscode-compatibility.d.ts.map +0 -1
- package/lib/vscode-compatibility.js +0 -9
- package/lib/vscode-compatibility.js.map +0 -1
- package/src/connection.ts +0 -134
- package/src/converters.ts +0 -155
- package/src/monaco-commands.ts +0 -15
- package/src/monaco-diagnostic-collection.ts +0 -94
- package/src/monaco-languages.ts +0 -571
- package/src/register-vscode.ts +0 -13
- package/src/services.ts +0 -326
- package/src/typings/monaco/index.d.ts +0 -21
- package/src/vscode-api.ts +0 -1047
- package/src/vscode-compatibility.ts +0 -8
package/lib/monaco-workspace.js
CHANGED
|
@@ -1,131 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
|
6
|
-
const disposable_1 = require("./disposable");
|
|
7
|
-
class MonacoWorkspace {
|
|
8
|
-
constructor(_monaco, p2m, m2p, _rootUri = null) {
|
|
9
|
-
this._monaco = _monaco;
|
|
10
|
-
this.p2m = p2m;
|
|
11
|
-
this.m2p = m2p;
|
|
12
|
-
this._rootUri = _rootUri;
|
|
13
|
-
this.disposableCollection = new disposable_1.DisposableCollection();
|
|
14
|
-
this.documents = new Map();
|
|
15
|
-
this.documentDisposables = new Map();
|
|
16
|
-
this.onDidOpenTextDocumentEmitter = new services_1.Emitter();
|
|
17
|
-
this.onDidCloseTextDocumentEmitter = new services_1.Emitter();
|
|
18
|
-
this.onDidChangeTextDocumentEmitter = new services_1.Emitter();
|
|
19
|
-
for (const model of this._monaco.editor.getModels()) {
|
|
20
|
-
this.addModel(model);
|
|
21
|
-
}
|
|
22
|
-
this.disposableCollection.push(this._monaco.editor.onDidCreateModel(model => this.addModel(model)));
|
|
23
|
-
this.disposableCollection.push(this._monaco.editor.onWillDisposeModel(model => this.removeModel(model)));
|
|
24
|
-
this.disposableCollection.push(this._monaco.editor.onDidChangeModelLanguage((event) => {
|
|
25
|
-
this.removeModel(event.model);
|
|
26
|
-
this.addModel(event.model);
|
|
27
|
-
}));
|
|
28
|
-
}
|
|
29
|
-
dispose() {
|
|
30
|
-
this.disposableCollection.dispose();
|
|
31
|
-
for (const model of this._monaco.editor.getModels()) {
|
|
32
|
-
this.removeModel(model);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
get rootUri() {
|
|
36
|
-
return this._rootUri;
|
|
37
|
-
}
|
|
38
|
-
removeModel(model) {
|
|
39
|
-
const uri = model.uri.toString();
|
|
40
|
-
const document = this.documents.get(uri);
|
|
41
|
-
if (document) {
|
|
42
|
-
this.documents.delete(uri);
|
|
43
|
-
this.onDidCloseTextDocumentEmitter.fire(document);
|
|
44
|
-
}
|
|
45
|
-
const disposable = this.documentDisposables.get(uri);
|
|
46
|
-
if (disposable) {
|
|
47
|
-
disposable.dispose();
|
|
48
|
-
this.documentDisposables.delete(uri);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
addModel(model) {
|
|
52
|
-
const uri = model.uri.toString();
|
|
53
|
-
const document = this.setModel(uri, model);
|
|
54
|
-
this.onDidOpenTextDocumentEmitter.fire(document);
|
|
55
|
-
this.documentDisposables.set(uri, model.onDidChangeContent(event => this.onDidChangeContent(uri, model, event)));
|
|
56
|
-
}
|
|
57
|
-
onDidChangeContent(uri, model, event) {
|
|
58
|
-
const textDocument = this.setModel(uri, model);
|
|
59
|
-
const contentChanges = [];
|
|
60
|
-
for (const change of event.changes) {
|
|
61
|
-
const range = this.m2p.asRange(change.range);
|
|
62
|
-
const rangeLength = change.rangeLength;
|
|
63
|
-
const text = change.text;
|
|
64
|
-
contentChanges.push({ range, rangeLength, text });
|
|
65
|
-
}
|
|
66
|
-
this.onDidChangeTextDocumentEmitter.fire({
|
|
67
|
-
textDocument,
|
|
68
|
-
contentChanges,
|
|
69
|
-
isRedoing: event.isRedoing,
|
|
70
|
-
isUndoing: event.isUndoing
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
setModel(uri, model) {
|
|
74
|
-
const document = vscode_languageserver_textdocument_1.TextDocument.create(uri, model.getLanguageId(), model.getVersionId(), model.getValue());
|
|
75
|
-
this.documents.set(uri, document);
|
|
76
|
-
return document;
|
|
77
|
-
}
|
|
78
|
-
get textDocuments() {
|
|
79
|
-
return Array.from(this.documents.values());
|
|
80
|
-
}
|
|
81
|
-
get onDidOpenTextDocument() {
|
|
82
|
-
return this.onDidOpenTextDocumentEmitter.event;
|
|
83
|
-
}
|
|
84
|
-
get onDidCloseTextDocument() {
|
|
85
|
-
return this.onDidCloseTextDocumentEmitter.event;
|
|
86
|
-
}
|
|
87
|
-
get onDidChangeTextDocument() {
|
|
88
|
-
return this.onDidChangeTextDocumentEmitter.event;
|
|
89
|
-
}
|
|
90
|
-
applyEdit(workspaceEdit) {
|
|
91
|
-
const edit = this.p2m.asWorkspaceEdit(workspaceEdit);
|
|
92
|
-
// Collect all referenced models
|
|
93
|
-
const models = edit.edits ? edit.edits.reduce((acc, currentEdit) => {
|
|
94
|
-
const textEdit = currentEdit;
|
|
95
|
-
acc[textEdit.resource.toString()] = this._monaco.editor.getModel(textEdit.resource);
|
|
96
|
-
return acc;
|
|
97
|
-
}, {}) : {};
|
|
98
|
-
// If any of the models do not exist, refuse to apply the edit.
|
|
99
|
-
if (!Object.keys(models).map(uri => models[uri]).every(model => !!model)) {
|
|
100
|
-
return Promise.resolve(false);
|
|
101
|
-
}
|
|
102
|
-
// Group edits by resource so we can batch them when applying
|
|
103
|
-
const editsByResource = edit.edits ? edit.edits.reduce((acc, currentEdit) => {
|
|
104
|
-
const textEdit = currentEdit;
|
|
105
|
-
const uri = textEdit.resource.toString();
|
|
106
|
-
if (!(uri in acc)) {
|
|
107
|
-
acc[uri] = [];
|
|
108
|
-
}
|
|
109
|
-
acc[uri].push({
|
|
110
|
-
range: this._monaco.Range.lift(textEdit.edit.range),
|
|
111
|
-
text: textEdit.edit.text,
|
|
112
|
-
});
|
|
113
|
-
return acc;
|
|
114
|
-
}, {}) : {};
|
|
115
|
-
// Apply edits for each resource
|
|
116
|
-
Object.keys(editsByResource).forEach(uri => {
|
|
117
|
-
models[uri].pushEditOperations([], // Do not try and preserve editor selections.
|
|
118
|
-
editsByResource[uri].map(resourceEdit => {
|
|
119
|
-
return {
|
|
120
|
-
identifier: { major: 1, minor: 0 },
|
|
121
|
-
range: resourceEdit.range,
|
|
122
|
-
text: resourceEdit.text,
|
|
123
|
-
forceMoveMarkers: true,
|
|
124
|
-
};
|
|
125
|
-
}), () => []);
|
|
126
|
-
});
|
|
127
|
-
return Promise.resolve(true);
|
|
1
|
+
export class MonacoWorkspace {
|
|
2
|
+
constructor(workspaceFolders, rootPath) {
|
|
3
|
+
this.workspaceFolders = workspaceFolders;
|
|
4
|
+
this.rootPath = rootPath;
|
|
128
5
|
}
|
|
129
6
|
}
|
|
130
|
-
exports.MonacoWorkspace = MonacoWorkspace;
|
|
131
7
|
//# sourceMappingURL=monaco-workspace.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"monaco-workspace.js","sourceRoot":"","sources":["../src/monaco-workspace.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"monaco-workspace.js","sourceRoot":"","sources":["../src/monaco-workspace.ts"],"names":[],"mappings":"AAOA,MAAM,OAAO,eAAe;IACxB,YACoB,gBAA2C,EAC3C,QAA6B;QAD7B,qBAAgB,GAAhB,gBAAgB,CAA2B;QAC3C,aAAQ,GAAR,QAAQ,CAAqB;IAEjD,CAAC;CACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "monaco-languageclient",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-dev.1",
|
|
4
4
|
"description": "Monaco Language client implementation",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "TypeFox GmbH ",
|
|
@@ -21,17 +21,25 @@
|
|
|
21
21
|
"types": "./lib/index.d.ts",
|
|
22
22
|
"default": "./lib/index.js"
|
|
23
23
|
},
|
|
24
|
+
"./monaco-converter": {
|
|
25
|
+
"types": "./lib/monaco-converter.d.ts",
|
|
26
|
+
"default": "./lib/monaco-converter.js"
|
|
27
|
+
},
|
|
28
|
+
"./cjs/monaco-converter": {
|
|
29
|
+
"types": "./dist/cjs/monaco-converter.d.ts",
|
|
30
|
+
"default": "./dist/cjs/monaco-converter.js"
|
|
31
|
+
},
|
|
32
|
+
"./cjs": {
|
|
33
|
+
"types": "./dist/cjs/index.d.ts",
|
|
34
|
+
"default": "./dist/cjs/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./amd/monaco-converter": {
|
|
37
|
+
"types": "./dist/amd/monaco-converter.d.ts",
|
|
38
|
+
"default": "./dist/amd/monaco-converter.js"
|
|
39
|
+
},
|
|
24
40
|
"./amd": {
|
|
25
41
|
"types": "./dist/amd/index.d.ts",
|
|
26
42
|
"default": "./dist/amd/index.js"
|
|
27
|
-
},
|
|
28
|
-
"./vscode-compatibility": {
|
|
29
|
-
"types": "./lib/vscode-compatibility.d.ts",
|
|
30
|
-
"default": "./lib/vscode-compatibility.js"
|
|
31
|
-
},
|
|
32
|
-
"./amd/vscode-compatibility": {
|
|
33
|
-
"types": "./dist/amd/vscode-compatibility.d.ts",
|
|
34
|
-
"default": "./dist/amd/vscode-compatibility.js"
|
|
35
43
|
}
|
|
36
44
|
},
|
|
37
45
|
"files": [
|
|
@@ -41,22 +49,25 @@
|
|
|
41
49
|
],
|
|
42
50
|
"dependencies": {
|
|
43
51
|
"glob-to-regexp": "^0.4.1",
|
|
52
|
+
"vscode": "npm:@codingame/monaco-vscode-api@^1.68.0",
|
|
44
53
|
"vscode-jsonrpc": "8.0.1",
|
|
45
54
|
"vscode-languageclient": "8.0.1",
|
|
46
|
-
"vscode-languageserver-textdocument": "1.0.
|
|
55
|
+
"vscode-languageserver-textdocument": "1.0.5",
|
|
47
56
|
"vscode-uri": "3.0.3"
|
|
48
57
|
},
|
|
49
58
|
"devDependencies": {
|
|
50
|
-
"@types/
|
|
59
|
+
"@types/glob-to-regexp": "^0.4.1",
|
|
51
60
|
"@types/node": "^16.11.7",
|
|
52
|
-
"@types/
|
|
61
|
+
"@types/vscode": "1.68.0"
|
|
53
62
|
},
|
|
54
63
|
"scripts": {
|
|
55
64
|
"clean": "npx shx rm -fr lib tsconfig.tsbuildinfo",
|
|
56
65
|
"compile": "tsc",
|
|
57
66
|
"watch": "tsc -w",
|
|
58
|
-
"clean:amd": "npx shx rm -fr dist",
|
|
67
|
+
"clean:amd": "npx shx rm -fr dist/amd",
|
|
68
|
+
"clean:cjs": "npx shx rm -fr dist/cjs",
|
|
59
69
|
"build:amd": "npm run clean:amd && tsc --outDir dist/amd --module amd --declarationDir dist/amd --declaration",
|
|
60
|
-
"build": "npm run clean &&
|
|
70
|
+
"build:cjs": "npm run clean:cjs && tsc --outDir dist/cjs --module commonjs --declarationDir dist/cjs --declaration",
|
|
71
|
+
"build": "npm run clean && npm run compile && npm run build:amd && npm run build:cjs"
|
|
61
72
|
}
|
|
62
73
|
}
|
package/src/console-window.ts
CHANGED
|
@@ -2,31 +2,33 @@
|
|
|
2
2
|
* Copyright (c) 2018-2022 TypeFox GmbH (http://www.typefox.io). All rights reserved.
|
|
3
3
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
4
|
* ------------------------------------------------------------------------------------------ */
|
|
5
|
-
import {
|
|
5
|
+
import { Window, Severity } from 'vscode/services'
|
|
6
|
+
import * as vscode from 'vscode'
|
|
6
7
|
|
|
7
8
|
export class ConsoleWindow implements Window {
|
|
8
|
-
protected readonly channels = new Map<string, OutputChannel>();
|
|
9
|
-
showMessage<T extends
|
|
10
|
-
if (
|
|
9
|
+
protected readonly channels = new Map<string, vscode.OutputChannel>();
|
|
10
|
+
showMessage<T extends vscode.MessageOptions | string | vscode.MessageItem>(severity: Severity, message: string, ...actions: T[]): Thenable<T | undefined> {
|
|
11
|
+
if (severity === Severity.Error) {
|
|
11
12
|
console.error(message);
|
|
12
13
|
}
|
|
13
|
-
if (
|
|
14
|
+
if (severity === Severity.Warning) {
|
|
14
15
|
console.warn(message);
|
|
15
16
|
}
|
|
16
|
-
if (
|
|
17
|
+
if (severity === Severity.Info) {
|
|
17
18
|
console.info(message);
|
|
18
19
|
}
|
|
19
|
-
if (
|
|
20
|
-
console.
|
|
20
|
+
if (severity === Severity.Ignore) {
|
|
21
|
+
console.debug(message);
|
|
21
22
|
}
|
|
22
23
|
return Promise.resolve(undefined);
|
|
23
24
|
}
|
|
24
|
-
createOutputChannel(name: string): OutputChannel {
|
|
25
|
+
createOutputChannel(name: string): vscode.OutputChannel {
|
|
25
26
|
const existing = this.channels.get(name);
|
|
26
27
|
if (existing) {
|
|
27
28
|
return existing;
|
|
28
29
|
}
|
|
29
|
-
const channel: OutputChannel = {
|
|
30
|
+
const channel: vscode.OutputChannel = {
|
|
31
|
+
name: 'default',
|
|
30
32
|
append(value: string): void {
|
|
31
33
|
console.log(name + ': ' + value);
|
|
32
34
|
},
|
|
@@ -38,6 +40,15 @@ export class ConsoleWindow implements Window {
|
|
|
38
40
|
},
|
|
39
41
|
dispose(): void {
|
|
40
42
|
// no-op
|
|
43
|
+
},
|
|
44
|
+
replace: function (value: string): void {
|
|
45
|
+
// no-op
|
|
46
|
+
},
|
|
47
|
+
clear: function (): void {
|
|
48
|
+
// no-op
|
|
49
|
+
},
|
|
50
|
+
hide: function (): void {
|
|
51
|
+
// no-op
|
|
41
52
|
}
|
|
42
53
|
}
|
|
43
54
|
this.channels.set(name, channel)
|
package/src/disposable.ts
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* Copyright (c) 2018-2022 TypeFox GmbH (http://www.typefox.io). All rights reserved.
|
|
3
3
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
4
|
* ------------------------------------------------------------------------------------------ */
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
import { Disposable } from "vscode-jsonrpc";
|
|
6
7
|
|
|
7
8
|
export {
|
|
8
9
|
Disposable
|
package/src/index.ts
CHANGED
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
4
|
* ------------------------------------------------------------------------------------------ */
|
|
5
5
|
export * from './disposable';
|
|
6
|
-
export * from './services';
|
|
7
|
-
export * from './connection';
|
|
8
6
|
export * from './monaco-language-client';
|
|
9
|
-
export * from './monaco-commands';
|
|
10
7
|
export * from './console-window';
|
|
11
|
-
export * from './monaco-languages';
|
|
12
8
|
export * from './monaco-workspace';
|
|
13
9
|
export * from './monaco-services';
|
|
14
10
|
export * from './monaco-converter';
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
Disposable, CancellationToken, Event, Emitter
|
|
14
|
+
} from 'vscode-jsonrpc/lib/common/api';
|
|
15
|
+
export * from 'vscode-languageserver-protocol/lib/common/api';
|
package/src/monaco-converter.ts
CHANGED
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
MarkedString, MarkupContent, ColorInformation, ColorPresentation, FoldingRange, FoldingRangeKind,
|
|
21
21
|
DiagnosticRelatedInformation, MarkupKind, SymbolKind, DocumentSymbol, CodeAction, SignatureHelpContext, SignatureHelpTriggerKind,
|
|
22
22
|
SemanticTokens, InsertTextMode, AnnotatedTextEdit, ChangeAnnotation, InlayHint, InlayHintLabelPart
|
|
23
|
-
} from '
|
|
23
|
+
} from 'vscode-languageserver-protocol/lib/common/api';
|
|
24
24
|
|
|
25
25
|
export type RecursivePartial<T> = {
|
|
26
26
|
[P in keyof T]?: RecursivePartial<T[P]>;
|
|
@@ -83,6 +83,9 @@ function isRangeReplace(v: Partial<monaco.IRange> | RangeReplace): v is RangeRep
|
|
|
83
83
|
return (v as RangeReplace).insert !== undefined;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
/**
|
|
87
|
+
* @deprecated use @CodinGame/monaco-vscode-api and vscode-languageclient/lib/common/codeConverter (see browser example)
|
|
88
|
+
*/
|
|
86
89
|
export class MonacoToProtocolConverter {
|
|
87
90
|
public constructor(protected readonly _monaco: typeof monaco) { }
|
|
88
91
|
|
|
@@ -225,7 +228,7 @@ export class MonacoToProtocolConverter {
|
|
|
225
228
|
case this._monaco.languages.SignatureHelpTriggerKind.TriggerCharacter:
|
|
226
229
|
return SignatureHelpTriggerKind.TriggerCharacter;
|
|
227
230
|
default:
|
|
228
|
-
return SignatureHelpTriggerKind.
|
|
231
|
+
return SignatureHelpTriggerKind.Invoked;
|
|
229
232
|
}
|
|
230
233
|
}
|
|
231
234
|
|
|
@@ -553,6 +556,9 @@ export class MonacoToProtocolConverter {
|
|
|
553
556
|
}
|
|
554
557
|
}
|
|
555
558
|
|
|
559
|
+
/**
|
|
560
|
+
* @deprecated use @CodinGame/monaco-vscode-api and vscode-languageclient/lib/common/protocolConverter (see browser example)
|
|
561
|
+
*/
|
|
556
562
|
export class ProtocolToMonacoConverter {
|
|
557
563
|
public constructor(protected readonly _monaco: typeof monaco) { }
|
|
558
564
|
|
|
@@ -1032,7 +1038,7 @@ export class ProtocolToMonacoConverter {
|
|
|
1032
1038
|
}
|
|
1033
1039
|
}
|
|
1034
1040
|
|
|
1035
|
-
asCompletionResult(result: CompletionItem[] | CompletionList | null | undefined,
|
|
1041
|
+
asCompletionResult(result: CompletionItem[] | CompletionList | null | undefined, defaultMonacoRange: monaco.IRange): monaco.languages.CompletionList {
|
|
1036
1042
|
if (!result) {
|
|
1037
1043
|
return {
|
|
1038
1044
|
incomplete: false,
|
|
@@ -1040,29 +1046,30 @@ export class ProtocolToMonacoConverter {
|
|
|
1040
1046
|
}
|
|
1041
1047
|
}
|
|
1042
1048
|
if (Array.isArray(result)) {
|
|
1043
|
-
const suggestions = result.map(item => this.asCompletionItem(item, defaultRange));
|
|
1049
|
+
const suggestions = result.map(item => this.asCompletionItem(item, defaultMonacoRange, defaultRange));
|
|
1044
1050
|
return {
|
|
1045
1051
|
incomplete: false,
|
|
1046
1052
|
suggestions
|
|
1047
1053
|
}
|
|
1048
1054
|
}
|
|
1055
|
+
const defaultRange = this.getCompletionItemDefaultRange(result);
|
|
1049
1056
|
return {
|
|
1050
1057
|
incomplete: result.isIncomplete,
|
|
1051
|
-
suggestions: result.items.map(item => this.asCompletionItem(item, defaultRange))
|
|
1058
|
+
suggestions: result.items.map(item => this.asCompletionItem(item, defaultMonacoRange, defaultRange, result.itemDefaults))
|
|
1052
1059
|
}
|
|
1053
1060
|
}
|
|
1054
1061
|
|
|
1055
|
-
asCompletionItem(item: CompletionItem,
|
|
1056
|
-
const result = <ProtocolCompletionItem>{ label: item
|
|
1062
|
+
asCompletionItem(item: CompletionItem, defaultMonacoRange: monaco.IRange | RangeReplace, defaultRange?: monaco.IRange | RangeReplace, itemDefaults?: CompletionList['itemDefaults']): ProtocolCompletionItem {
|
|
1063
|
+
const result = <ProtocolCompletionItem>{ label: this.asCompletionItemLabel(item) };
|
|
1057
1064
|
if (item.detail) { result.detail = item.detail; }
|
|
1058
1065
|
if (item.documentation) {
|
|
1059
1066
|
result.documentation = this.asDocumentation(item.documentation);
|
|
1060
1067
|
result.documentationFormat = Is.string(item.documentation) ? undefined : item.documentation.kind;
|
|
1061
1068
|
};
|
|
1062
1069
|
if (item.filterText) { result.filterText = item.filterText; }
|
|
1063
|
-
const insertText = this.asCompletionInsertText(item, defaultRange);
|
|
1070
|
+
const insertText = this.asCompletionInsertText(item, defaultRange, itemDefaults?.insertTextFormat);
|
|
1064
1071
|
result.insertText = insertText.insertText;
|
|
1065
|
-
result.range = insertText.range;
|
|
1072
|
+
result.range = insertText.range ?? defaultMonacoRange;
|
|
1066
1073
|
result.fromEdit = insertText.fromEdit;
|
|
1067
1074
|
if (insertText.isSnippet) {
|
|
1068
1075
|
result.insertTextRules = this._monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet;
|
|
@@ -1080,15 +1087,38 @@ export class ProtocolToMonacoConverter {
|
|
|
1080
1087
|
if (item.command) { result.command = this.asCommand(item.command); }
|
|
1081
1088
|
if (item.deprecated === true || item.deprecated === false) { result.deprecated = item.deprecated; }
|
|
1082
1089
|
if (item.preselect === true || item.preselect === false) { result.preselect = item.preselect; }
|
|
1083
|
-
|
|
1090
|
+
const data = item.data ?? itemDefaults?.data;
|
|
1091
|
+
if (data !== undefined) { result.data = data; }
|
|
1084
1092
|
if (item.deprecated === true || item.deprecated === false) {
|
|
1085
1093
|
result.deprecated = item.deprecated;
|
|
1086
1094
|
}
|
|
1087
|
-
|
|
1095
|
+
const insertTextMode = item.insertTextMode ?? itemDefaults?.insertTextMode
|
|
1096
|
+
if (insertTextMode) { result.insertTextMode = insertTextMode; }
|
|
1088
1097
|
if (item.tags) { result.tags = item.tags; }
|
|
1089
1098
|
return result;
|
|
1090
1099
|
}
|
|
1091
1100
|
|
|
1101
|
+
getCompletionItemDefaultRange(list: CompletionList): monaco.Range | RangeReplace | undefined {
|
|
1102
|
+
const rangeDefaults = list.itemDefaults?.editRange;
|
|
1103
|
+
return ls.Range.is(rangeDefaults)
|
|
1104
|
+
? this.asRange(rangeDefaults)
|
|
1105
|
+
: rangeDefaults !== undefined
|
|
1106
|
+
? { insert: this.asRange(rangeDefaults.insert), replace: this.asRange(rangeDefaults.replace) }
|
|
1107
|
+
: undefined;
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
asCompletionItemLabel(item: ls.CompletionItem): monaco.languages.CompletionItemLabel | string {
|
|
1111
|
+
if (ls.CompletionItemLabelDetails.is(item.labelDetails)) {
|
|
1112
|
+
return {
|
|
1113
|
+
label: item.label,
|
|
1114
|
+
detail: item.labelDetails.detail,
|
|
1115
|
+
description: item.labelDetails.description
|
|
1116
|
+
};
|
|
1117
|
+
} else {
|
|
1118
|
+
return item.label;
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1092
1122
|
asCompletionItemKind(value: CompletionItemKind): [monaco.languages.CompletionItemKind, CompletionItemKind | undefined] {
|
|
1093
1123
|
if (CompletionItemKind.Text <= value && value <= CompletionItemKind.TypeParameter) {
|
|
1094
1124
|
switch (value) {
|
|
@@ -1124,29 +1154,30 @@ export class ProtocolToMonacoConverter {
|
|
|
1124
1154
|
return [CompletionItemKind.Text, value];
|
|
1125
1155
|
}
|
|
1126
1156
|
|
|
1127
|
-
asCompletionInsertText(item: CompletionItem, defaultRange: monaco.IRange | RangeReplace
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
replace: this.asRange(item.textEdit.replace)
|
|
1139
|
-
};
|
|
1140
|
-
const value = item.textEdit.newText;
|
|
1141
|
-
return { isSnippet, insertText: value, range, fromEdit: true, };
|
|
1142
|
-
}
|
|
1143
|
-
}
|
|
1144
|
-
if (item.insertText) {
|
|
1157
|
+
asCompletionInsertText(item: CompletionItem, defaultRange?: monaco.IRange | RangeReplace, defaultInsertTextFormat?: InsertTextFormat): { insertText: string, range?: monaco.IRange | RangeReplace, fromEdit: boolean, isSnippet: boolean } {
|
|
1158
|
+
const insertTextFormat = item.insertTextFormat ?? defaultInsertTextFormat;
|
|
1159
|
+
|
|
1160
|
+
const isSnippet = insertTextFormat === InsertTextFormat.Snippet;
|
|
1161
|
+
if (item.textEdit !== undefined || defaultRange !== undefined) {
|
|
1162
|
+
const [range, newText] = item.textEdit !== undefined
|
|
1163
|
+
? this.getCompletionRangeAndText(item.textEdit)
|
|
1164
|
+
: [defaultRange, item.textEditText ?? item.label];
|
|
1165
|
+
|
|
1166
|
+
return { insertText: newText, range: range, fromEdit: true, isSnippet };
|
|
1167
|
+
} else if (item.insertText) {
|
|
1145
1168
|
return { isSnippet, insertText: item.insertText, fromEdit: false, range: defaultRange };
|
|
1146
1169
|
}
|
|
1147
1170
|
return { insertText: item.label, range: defaultRange, fromEdit: false, isSnippet: false };
|
|
1148
1171
|
}
|
|
1149
1172
|
|
|
1173
|
+
getCompletionRangeAndText(value: ls.TextEdit | ls.InsertReplaceEdit): [monaco.Range | RangeReplace, string] {
|
|
1174
|
+
if (ls.InsertReplaceEdit.is(value)) {
|
|
1175
|
+
return [{ insert: this.asRange(value.insert), replace: this.asRange(value.replace) }, value.newText];
|
|
1176
|
+
} else {
|
|
1177
|
+
return [this.asRange(value.range), value.newText];
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1150
1181
|
asDocumentLinks(documentLinks: DocumentLink[]): monaco.languages.ILinksList {
|
|
1151
1182
|
const links = documentLinks.map(link => this.asDocumentLink(link));
|
|
1152
1183
|
return { links };
|
|
@@ -3,16 +3,43 @@
|
|
|
3
3
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
4
|
* ------------------------------------------------------------------------------------------ */
|
|
5
5
|
import {
|
|
6
|
-
BaseLanguageClient, MessageTransports, LanguageClientOptions
|
|
7
|
-
} from "vscode-languageclient";
|
|
8
|
-
import * as p2c from 'vscode-languageclient/lib/common/protocolConverter';
|
|
9
|
-
import * as c2p from 'vscode-languageclient/lib/common/codeConverter';
|
|
10
|
-
import { IConnectionProvider } from './connection';
|
|
6
|
+
BaseLanguageClient, MessageTransports, LanguageClientOptions, CloseAction, ErrorAction
|
|
7
|
+
} from "vscode-languageclient/lib/common/client";
|
|
11
8
|
|
|
12
9
|
export * from 'vscode-languageclient/lib/common/client';
|
|
13
10
|
import type * as vscode from 'vscode'
|
|
14
|
-
import {
|
|
11
|
+
import { ConfigurationFeature, SyncConfigurationFeature } from "vscode-languageclient/lib/common/configuration";
|
|
12
|
+
import { DidChangeTextDocumentFeature, DidCloseTextDocumentFeature, DidOpenTextDocumentFeature, DidSaveTextDocumentFeature, WillSaveFeature, WillSaveWaitUntilFeature } from "vscode-languageclient/lib/common/textSynchronization";
|
|
13
|
+
import { CompletionItemFeature } from "vscode-languageclient/lib/common/completion";
|
|
14
|
+
import { HoverFeature } from "vscode-languageclient/lib/common/hover";
|
|
15
|
+
import { SignatureHelpFeature } from "vscode-languageclient/lib/common/signatureHelp";
|
|
16
|
+
import { DefinitionFeature } from "vscode-languageclient/lib/common/definition";
|
|
17
|
+
import { ReferencesFeature } from "vscode-languageclient/lib/common/reference";
|
|
18
|
+
import { DocumentHighlightFeature } from "vscode-languageclient/lib/common/documentHighlight";
|
|
19
|
+
import { DocumentSymbolFeature } from "vscode-languageclient/lib/common/documentSymbol";
|
|
20
|
+
import { CodeActionFeature } from "vscode-languageclient/lib/common/codeAction";
|
|
21
|
+
import { CodeLensFeature } from "vscode-languageclient/lib/common/codeLens";
|
|
22
|
+
import { DocumentFormattingFeature, DocumentOnTypeFormattingFeature, DocumentRangeFormattingFeature } from "vscode-languageclient/lib/common/formatting";
|
|
23
|
+
import { RenameFeature } from "vscode-languageclient/lib/common/rename";
|
|
24
|
+
import { DocumentLinkFeature } from "vscode-languageclient/lib/common/documentLink";
|
|
25
|
+
import { ExecuteCommandFeature } from "vscode-languageclient/lib/common/executeCommand";
|
|
26
|
+
import { TypeDefinitionFeature } from "vscode-languageclient/lib/common/typeDefinition";
|
|
27
|
+
import { ImplementationFeature } from "vscode-languageclient/lib/common/implementation";
|
|
28
|
+
import { ColorProviderFeature } from "vscode-languageclient/lib/common/colorProvider";
|
|
29
|
+
import { WorkspaceFoldersFeature } from "vscode-languageclient/lib/common/workspaceFolder";
|
|
30
|
+
import { FoldingRangeFeature } from "vscode-languageclient/lib/common/foldingRange";
|
|
31
|
+
import { DeclarationFeature } from "vscode-languageclient/lib/common/declaration";
|
|
32
|
+
import { SelectionRangeFeature } from "vscode-languageclient/lib/common/selectionRange";
|
|
33
|
+
import { SemanticTokensFeature } from "vscode-languageclient/lib/common/semanticTokens";
|
|
34
|
+
import { LinkedEditingFeature } from "vscode-languageclient/lib/common/linkedEditingRange";
|
|
35
|
+
import { InlayHintsFeature } from "vscode-languageclient/lib/common/inlayHint";
|
|
36
|
+
import { DiagnosticFeature } from "vscode-languageclient/lib/common/diagnostic";
|
|
37
|
+
import { ProgressFeature } from "vscode-languageclient/lib/common/progress";
|
|
38
|
+
import { RegistrationParams, UnregistrationParams } from "vscode-languageclient";
|
|
15
39
|
|
|
40
|
+
export interface IConnectionProvider {
|
|
41
|
+
get(encoding: string): Promise<MessageTransports>;
|
|
42
|
+
}
|
|
16
43
|
export class MonacoLanguageClient extends BaseLanguageClient {
|
|
17
44
|
|
|
18
45
|
static bypassConversion = (result: any, token?: vscode.CancellationToken) => token != null ? Promise.resolve(result || undefined) : (result || undefined);
|
|
@@ -23,13 +50,22 @@ export class MonacoLanguageClient extends BaseLanguageClient {
|
|
|
23
50
|
super(id || name.toLowerCase(), name, clientOptions);
|
|
24
51
|
this.connectionProvider = connectionProvider;
|
|
25
52
|
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
53
|
+
// Hack because vscode-language client rejects the whole registration block if one capability registration has no associated client feature registered
|
|
54
|
+
// Some language servers still send the registration even though the client says it doesn't support it
|
|
55
|
+
const originalHandleRegistrationRequest: (params: RegistrationParams) => Promise<void> = this['handleRegistrationRequest'].bind(this)
|
|
56
|
+
this['handleRegistrationRequest'] = (params: RegistrationParams) => {
|
|
57
|
+
originalHandleRegistrationRequest({
|
|
58
|
+
...params,
|
|
59
|
+
registrations: params.registrations.filter(registration => this.getFeature(<any>registration.method) != null)
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
const originalHandleUnregistrationRequest: (params: UnregistrationParams) => Promise<void> = this['handleUnregistrationRequest'].bind(this)
|
|
63
|
+
this['handleUnregistrationRequest'] = (params: UnregistrationParams) => {
|
|
64
|
+
originalHandleUnregistrationRequest({
|
|
65
|
+
...params,
|
|
66
|
+
unregisterations: params.unregisterations.filter(unregistration => this.getFeature(<any>unregistration.method) != null)
|
|
67
|
+
})
|
|
68
|
+
}
|
|
33
69
|
}
|
|
34
70
|
|
|
35
71
|
protected createMessageTransports(encoding: string): Promise<MessageTransports> {
|
|
@@ -39,6 +75,57 @@ export class MonacoLanguageClient extends BaseLanguageClient {
|
|
|
39
75
|
protected getLocale(): string {
|
|
40
76
|
return navigator.language || 'en-US'
|
|
41
77
|
}
|
|
78
|
+
|
|
79
|
+
protected override registerBuiltinFeatures() {
|
|
80
|
+
this.registerFeature(new DidOpenTextDocumentFeature(this, this['_syncedDocuments']));
|
|
81
|
+
this.registerFeature(new DidChangeTextDocumentFeature(this));
|
|
82
|
+
this.registerFeature(new DidCloseTextDocumentFeature(this, this['_syncedDocuments']));
|
|
83
|
+
this.registerFeature(new CompletionItemFeature(this));
|
|
84
|
+
this.registerFeature(new HoverFeature(this));
|
|
85
|
+
this.registerFeature(new SignatureHelpFeature(this));
|
|
86
|
+
this.registerFeature(new DefinitionFeature(this));
|
|
87
|
+
this.registerFeature(new ReferencesFeature(this));
|
|
88
|
+
this.registerFeature(new DocumentHighlightFeature(this));
|
|
89
|
+
this.registerFeature(new DocumentSymbolFeature(this));
|
|
90
|
+
this.registerFeature(new CodeActionFeature(this));
|
|
91
|
+
this.registerFeature(new CodeLensFeature(this));
|
|
92
|
+
this.registerFeature(new DocumentFormattingFeature(this));
|
|
93
|
+
this.registerFeature(new DocumentRangeFormattingFeature(this));
|
|
94
|
+
this.registerFeature(new DocumentOnTypeFormattingFeature(this));
|
|
95
|
+
this.registerFeature(new RenameFeature(this));
|
|
96
|
+
this.registerFeature(new DocumentLinkFeature(this));
|
|
97
|
+
this.registerFeature(new ExecuteCommandFeature(this));
|
|
98
|
+
this.registerFeature(new TypeDefinitionFeature(this));
|
|
99
|
+
this.registerFeature(new ImplementationFeature(this));
|
|
100
|
+
this.registerFeature(new ColorProviderFeature(this));
|
|
101
|
+
// We only register the workspace folder feature if the client is not locked
|
|
102
|
+
// to a specific workspace folder.
|
|
103
|
+
if (this.clientOptions.workspaceFolder === undefined) {
|
|
104
|
+
this.registerFeature(new WorkspaceFoldersFeature(this));
|
|
105
|
+
}
|
|
106
|
+
this.registerFeature(new FoldingRangeFeature(this));
|
|
107
|
+
this.registerFeature(new DeclarationFeature(this));
|
|
108
|
+
this.registerFeature(new SelectionRangeFeature(this));
|
|
109
|
+
this.registerFeature(new SemanticTokensFeature(this));
|
|
110
|
+
this.registerFeature(new LinkedEditingFeature(this));
|
|
111
|
+
this.registerFeature(new InlayHintsFeature(this));
|
|
112
|
+
this.registerFeature(new DiagnosticFeature(this));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
public registerTextDocumentSaveFeatures() {
|
|
116
|
+
this.registerFeature(new WillSaveFeature(this));
|
|
117
|
+
this.registerFeature(new WillSaveWaitUntilFeature(this));
|
|
118
|
+
this.registerFeature(new DidSaveTextDocumentFeature(this));
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
public registerConfigurationFeatures() {
|
|
122
|
+
this.registerFeature(new ConfigurationFeature(this));
|
|
123
|
+
this.registerFeature(new SyncConfigurationFeature(this));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
public registerProgressFeatures() {
|
|
127
|
+
this.registerFeature(new ProgressFeature(this));
|
|
128
|
+
}
|
|
42
129
|
}
|
|
43
130
|
export namespace MonacoLanguageClient {
|
|
44
131
|
export interface Options {
|
|
@@ -48,3 +135,5 @@ export namespace MonacoLanguageClient {
|
|
|
48
135
|
connectionProvider: IConnectionProvider;
|
|
49
136
|
}
|
|
50
137
|
}
|
|
138
|
+
|
|
139
|
+
export { CloseAction, ErrorAction }
|