@codingame/monaco-languageclient-wrapper 5.0.0-update-monaco.3 → 5.0.0-update-monaco.5
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/createLanguageClient.js +130 -0
- package/dist/{src/customRequests.js → customRequests.js} +11 -11
- package/dist/{src/extensionConfiguration.js → extensionConfiguration.js} +1 -1
- package/dist/extensions/cobol.js +27 -0
- package/dist/extensions/csharp.js +27 -0
- package/dist/extensions/java/commands.js +70 -70
- package/dist/extensions/java/extension.js +9 -8
- package/dist/extensions/java/inlayHintsProvider.js +43 -42
- package/dist/extensions/java/protocol.js +19 -19
- package/dist/extensions/java/sourceAction.js +328 -328
- package/dist/extensions/java.js +34 -0
- package/dist/extensions/tools.js +66 -0
- package/dist/extensions.js +171 -0
- package/dist/index.js +5 -5
- package/dist/infrastructure.js +89 -0
- package/dist/languageClient.js +314 -0
- package/dist/languageClientOptions.js +16 -0
- package/dist/node_modules/tslib/tslib.es6.js +9 -9
- package/dist/services.js +8 -0
- package/dist/staticOptions.js +421 -0
- package/package.json +9 -10
- package/stats.html +1 -1
- package/dist/_virtual/_commonjsHelpers.js +0 -5
- package/dist/_virtual/_rollupPluginBabelHelpers.js +0 -50
- package/dist/_virtual/api.js +0 -2
- package/dist/_virtual/cancellation.js +0 -2
- package/dist/_virtual/connection.js +0 -2
- package/dist/_virtual/disposable.js +0 -2
- package/dist/_virtual/events.js +0 -2
- package/dist/_virtual/is.js +0 -2
- package/dist/_virtual/linkedMap.js +0 -2
- package/dist/_virtual/main.js +0 -2
- package/dist/_virtual/messageBuffer.js +0 -2
- package/dist/_virtual/messageReader.js +0 -2
- package/dist/_virtual/messageWriter.js +0 -2
- package/dist/_virtual/messages.js +0 -2
- package/dist/_virtual/once.js +0 -2
- package/dist/_virtual/ral.js +0 -2
- package/dist/_virtual/ril.js +0 -2
- package/dist/_virtual/semaphore.js +0 -2
- package/dist/_virtual/sharedArrayCancellation.js +0 -2
- package/dist/node_modules/delay/index.js +0 -45
- package/dist/node_modules/once/once.js +0 -44
- package/dist/node_modules/vscode-jsonrpc/lib/browser/main.js +0 -77
- package/dist/node_modules/vscode-jsonrpc/lib/browser/ril.js +0 -153
- package/dist/node_modules/vscode-jsonrpc/lib/common/api.js +0 -96
- package/dist/node_modules/vscode-jsonrpc/lib/common/cancellation.js +0 -95
- package/dist/node_modules/vscode-jsonrpc/lib/common/connection.js +0 -1182
- package/dist/node_modules/vscode-jsonrpc/lib/common/disposable.js +0 -19
- package/dist/node_modules/vscode-jsonrpc/lib/common/events.js +0 -121
- package/dist/node_modules/vscode-jsonrpc/lib/common/is.js +0 -38
- package/dist/node_modules/vscode-jsonrpc/lib/common/linkedMap.js +0 -386
- package/dist/node_modules/vscode-jsonrpc/lib/common/messageBuffer.js +0 -149
- package/dist/node_modules/vscode-jsonrpc/lib/common/messageReader.js +0 -198
- package/dist/node_modules/vscode-jsonrpc/lib/common/messageWriter.js +0 -122
- package/dist/node_modules/vscode-jsonrpc/lib/common/messages.js +0 -240
- package/dist/node_modules/vscode-jsonrpc/lib/common/ral.js +0 -26
- package/dist/node_modules/vscode-jsonrpc/lib/common/semaphore.js +0 -72
- package/dist/node_modules/vscode-jsonrpc/lib/common/sharedArrayCancellation.js +0 -80
- package/dist/node_modules/wrappy/wrappy.js +0 -25
- package/dist/src/createLanguageClient.js +0 -131
- package/dist/src/extensions/cobol.js +0 -24
- package/dist/src/extensions/csharp.js +0 -29
- package/dist/src/extensions/java.js +0 -36
- package/dist/src/extensions/tools.js +0 -91
- package/dist/src/extensions.js +0 -166
- package/dist/src/infrastructure.js +0 -87
- package/dist/src/languageClient.js +0 -305
- package/dist/src/languageClientOptions.js +0 -16
- package/dist/src/services.js +0 -8
- package/dist/src/staticOptions.js +0 -441
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { commands, Uri, languages, workspace } from 'vscode';
|
|
2
|
+
import { JavaInlayHintsProvider } from './java/inlayHintsProvider.js';
|
|
3
|
+
import { registerCommands } from './java/sourceAction.js';
|
|
4
|
+
import { Commands } from './java/commands.js';
|
|
5
|
+
import { applyWorkspaceEdit } from './java/extension.js';
|
|
6
|
+
import { ClassFileContentsRequest } from './java/protocol.js';
|
|
7
|
+
import { ExtensionFeature } from './tools.js';
|
|
8
|
+
class JavaExtensionFeature extends ExtensionFeature {
|
|
9
|
+
constructor(languageClient) {
|
|
10
|
+
super();
|
|
11
|
+
this.languageClient = languageClient;
|
|
12
|
+
}
|
|
13
|
+
activate(context) {
|
|
14
|
+
context.subscriptions.push(commands.registerCommand(Commands.SHOW_JAVA_REFERENCES, (uri, position, locations) => {
|
|
15
|
+
void commands.executeCommand(Commands.SHOW_REFERENCES, Uri.parse(uri), this.languageClient.protocol2CodeConverter.asPosition(position), locations.map(this.languageClient.protocol2CodeConverter.asLocation));
|
|
16
|
+
}));
|
|
17
|
+
context.subscriptions.push(commands.registerCommand(Commands.SHOW_JAVA_IMPLEMENTATIONS, (uri, position, locations) => {
|
|
18
|
+
void commands.executeCommand(Commands.SHOW_REFERENCES, Uri.parse(uri), this.languageClient.protocol2CodeConverter.asPosition(position), locations.map(this.languageClient.protocol2CodeConverter.asLocation));
|
|
19
|
+
}));
|
|
20
|
+
context.subscriptions.push(commands.registerCommand(Commands.APPLY_WORKSPACE_EDIT, (obj) => {
|
|
21
|
+
void applyWorkspaceEdit(obj, this.languageClient);
|
|
22
|
+
}));
|
|
23
|
+
context.subscriptions.push(languages.registerInlayHintsProvider(this.languageClient.clientOptions.documentSelector, new JavaInlayHintsProvider(this.languageClient)));
|
|
24
|
+
registerCommands(this.languageClient, context);
|
|
25
|
+
context.subscriptions.push(workspace.registerTextDocumentContentProvider('jdt', {
|
|
26
|
+
provideTextDocumentContent: async (uri, token) => {
|
|
27
|
+
return this.languageClient.sendRequest(ClassFileContentsRequest.type, { uri: uri.toString() }, token).then((v) => {
|
|
28
|
+
return v !== null && v !== void 0 ? v : '';
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export { JavaExtensionFeature };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
function unsupported() {
|
|
2
|
+
throw new Error('unsupported');
|
|
3
|
+
}
|
|
4
|
+
class MultiDisposeError extends Error {
|
|
5
|
+
constructor(errors) {
|
|
6
|
+
super(`Encountered errors while disposing of store. Errors: [${errors.join(', ')}]`);
|
|
7
|
+
this.errors = errors;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
class SimpleExtensionContext {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.subscriptions = [];
|
|
13
|
+
this.asAbsolutePath = unsupported;
|
|
14
|
+
this.storageUri = undefined;
|
|
15
|
+
this.storagePath = undefined;
|
|
16
|
+
this.messagePassingProtocol = undefined;
|
|
17
|
+
}
|
|
18
|
+
dispose() {
|
|
19
|
+
const errors = [];
|
|
20
|
+
for (const d of this.subscriptions) {
|
|
21
|
+
try {
|
|
22
|
+
d.dispose();
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
errors.push(e);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (errors.length === 1) {
|
|
29
|
+
throw errors[0];
|
|
30
|
+
}
|
|
31
|
+
else if (errors.length > 1) {
|
|
32
|
+
throw new MultiDisposeError(errors);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
get workspaceState() { return unsupported(); }
|
|
36
|
+
get globalState() { return unsupported(); }
|
|
37
|
+
get secrets() { return unsupported(); }
|
|
38
|
+
get extensionUri() { return unsupported(); }
|
|
39
|
+
get extensionPath() { return unsupported(); }
|
|
40
|
+
get environmentVariableCollection() { return unsupported(); }
|
|
41
|
+
get globalStorageUri() { return unsupported(); }
|
|
42
|
+
get globalStoragePath() { return unsupported(); }
|
|
43
|
+
get logUri() { return unsupported(); }
|
|
44
|
+
get logPath() { return unsupported(); }
|
|
45
|
+
get extensionMode() { return unsupported(); }
|
|
46
|
+
get extension() { return unsupported(); }
|
|
47
|
+
get extensionRuntime() { return unsupported(); }
|
|
48
|
+
}
|
|
49
|
+
class ExtensionFeature {
|
|
50
|
+
constructor() {
|
|
51
|
+
this.context = new SimpleExtensionContext();
|
|
52
|
+
}
|
|
53
|
+
fillClientCapabilities() { }
|
|
54
|
+
initialize(capabilities, documentSelector) {
|
|
55
|
+
this.activate(this.context, capabilities, documentSelector);
|
|
56
|
+
}
|
|
57
|
+
getState() {
|
|
58
|
+
return {
|
|
59
|
+
kind: 'static'
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
clear() {
|
|
63
|
+
this.context.dispose();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export { ExtensionFeature, unsupported };
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { monaco } from '@codingame/monaco-editor-wrapper';
|
|
2
|
+
import { registerFileSystemOverlay, FileSystemProviderError, FileSystemProviderErrorCode, FileType } from '@codingame/monaco-vscode-files-service-override';
|
|
3
|
+
import { DidSaveTextDocumentNotification } from 'vscode-languageserver-protocol';
|
|
4
|
+
import * as vscode from 'vscode';
|
|
5
|
+
import { DisposableStore } from 'vscode/monaco';
|
|
6
|
+
import { willShutdownNotificationType } from './customRequests.js';
|
|
7
|
+
class InitializeTextDocumentFeature {
|
|
8
|
+
constructor(languageClient, infrastructure) {
|
|
9
|
+
this.languageClient = languageClient;
|
|
10
|
+
this.infrastructure = infrastructure;
|
|
11
|
+
}
|
|
12
|
+
fillClientCapabilities() { }
|
|
13
|
+
initialize(capabilities, documentSelector) {
|
|
14
|
+
var _a;
|
|
15
|
+
const textDocumentSyncOptions = capabilities.resolvedTextDocumentSync;
|
|
16
|
+
if (documentSelector == null || ((_a = textDocumentSyncOptions === null || textDocumentSyncOptions === void 0 ? void 0 : textDocumentSyncOptions.openClose) !== null && _a !== void 0 ? _a : false)) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const infrastructure = this.infrastructure;
|
|
20
|
+
const languageClient = this.languageClient;
|
|
21
|
+
async function saveFile(textDocument) {
|
|
22
|
+
var _a;
|
|
23
|
+
if (documentSelector != null && vscode.languages.match(documentSelector, textDocument) > 0 && textDocument.uri.scheme === 'file') {
|
|
24
|
+
await ((_a = infrastructure.saveFileContent) === null || _a === void 0 ? void 0 : _a.call(infrastructure, textDocument.uri, textDocument.getText(), languageClient));
|
|
25
|
+
await languageClient.sendNotification(DidSaveTextDocumentNotification.type, {
|
|
26
|
+
textDocument: {
|
|
27
|
+
uri: textDocument.uri.toString()
|
|
28
|
+
},
|
|
29
|
+
text: textDocument.getText()
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
this.didOpenTextDocumentDisposable = vscode.workspace.onDidOpenTextDocument(saveFile);
|
|
34
|
+
vscode.workspace.textDocuments.forEach(saveFile);
|
|
35
|
+
}
|
|
36
|
+
getState() {
|
|
37
|
+
return {
|
|
38
|
+
kind: 'static'
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
clear() {
|
|
42
|
+
var _a;
|
|
43
|
+
(_a = this.didOpenTextDocumentDisposable) === null || _a === void 0 ? void 0 : _a.dispose();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
class WillDisposeFeature {
|
|
47
|
+
constructor(languageClient, onWillShutdownEmitter) {
|
|
48
|
+
this.languageClient = languageClient;
|
|
49
|
+
this.onWillShutdownEmitter = onWillShutdownEmitter;
|
|
50
|
+
}
|
|
51
|
+
fillClientCapabilities() { }
|
|
52
|
+
initialize() {
|
|
53
|
+
this.languageClient.onNotification(willShutdownNotificationType, (params) => {
|
|
54
|
+
this.onWillShutdownEmitter.fire(params);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
getState() {
|
|
58
|
+
return {
|
|
59
|
+
kind: 'static'
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
clear() { }
|
|
63
|
+
}
|
|
64
|
+
const encoder = new TextEncoder();
|
|
65
|
+
const decoder = new TextDecoder();
|
|
66
|
+
class InfrastructureTextFileSystemProvider {
|
|
67
|
+
constructor(infrastructure, languageClientManager) {
|
|
68
|
+
this.infrastructure = infrastructure;
|
|
69
|
+
this.languageClientManager = languageClientManager;
|
|
70
|
+
this.capabilities = 2 | 1024 | 2048 ;
|
|
71
|
+
this.cachedContent = new Map();
|
|
72
|
+
this.onDidChangeCapabilities = new vscode.EventEmitter().event;
|
|
73
|
+
this.onDidChangeFile = new vscode.EventEmitter().event;
|
|
74
|
+
}
|
|
75
|
+
async getFileContent(resource) {
|
|
76
|
+
const REMOTE_FILE_BLACKLIST = ['.git/config', '.vscode', monaco.Uri.parse(this.infrastructure.rootUri).path];
|
|
77
|
+
const blacklisted = REMOTE_FILE_BLACKLIST.some(blacklisted => resource.path.endsWith(blacklisted));
|
|
78
|
+
if (blacklisted) {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
if (!this.cachedContent.has(resource.toString())) {
|
|
82
|
+
this.cachedContent.set(resource.toString(), this.infrastructure.getFileContent(resource, this.languageClientManager));
|
|
83
|
+
}
|
|
84
|
+
return await this.cachedContent.get(resource.toString());
|
|
85
|
+
}
|
|
86
|
+
async readFile(resource) {
|
|
87
|
+
const content = await this.getFileContent(resource);
|
|
88
|
+
return encoder.encode(content);
|
|
89
|
+
}
|
|
90
|
+
async writeFile() {
|
|
91
|
+
throw FileSystemProviderError.create('not allowed', FileSystemProviderErrorCode.NoPermissions);
|
|
92
|
+
}
|
|
93
|
+
watch() {
|
|
94
|
+
return {
|
|
95
|
+
dispose() { }
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
async stat(resource) {
|
|
99
|
+
try {
|
|
100
|
+
const content = await this.getFileContent(resource);
|
|
101
|
+
if (content != null) {
|
|
102
|
+
return {
|
|
103
|
+
type: FileType.File,
|
|
104
|
+
size: encoder.encode(content).length,
|
|
105
|
+
mtime: Date.now(),
|
|
106
|
+
ctime: Date.now()
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
throw FileSystemProviderError.create(err, FileSystemProviderErrorCode.Unknown);
|
|
112
|
+
}
|
|
113
|
+
throw FileSystemProviderError.create('file not found', FileSystemProviderErrorCode.FileNotFound);
|
|
114
|
+
}
|
|
115
|
+
async mkdir() {
|
|
116
|
+
}
|
|
117
|
+
async readdir() {
|
|
118
|
+
return [];
|
|
119
|
+
}
|
|
120
|
+
delete() {
|
|
121
|
+
throw new Error('Method not implemented.');
|
|
122
|
+
}
|
|
123
|
+
rename() {
|
|
124
|
+
throw new Error('Method not implemented.');
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
class FileSystemFeature {
|
|
128
|
+
constructor(infrastructure, languageClientManager) {
|
|
129
|
+
this.infrastructure = infrastructure;
|
|
130
|
+
this.languageClientManager = languageClientManager;
|
|
131
|
+
}
|
|
132
|
+
registerFileHandlers() {
|
|
133
|
+
const disposables = new DisposableStore();
|
|
134
|
+
if (this.infrastructure.getFileContent != null) {
|
|
135
|
+
disposables.add(registerFileSystemOverlay(-1, new InfrastructureTextFileSystemProvider(this.infrastructure, this.languageClientManager)));
|
|
136
|
+
}
|
|
137
|
+
if (this.infrastructure.saveFileContent != null) {
|
|
138
|
+
const watcher = vscode.workspace.createFileSystemWatcher(new vscode.RelativePattern(vscode.Uri.parse(this.infrastructure.rootUri), '**/*'));
|
|
139
|
+
disposables.add(watcher);
|
|
140
|
+
const onFileChange = async (uri) => {
|
|
141
|
+
var _a, _b;
|
|
142
|
+
if ((await vscode.workspace.fs.stat(uri)).type === vscode.FileType.File) {
|
|
143
|
+
const content = await vscode.workspace.fs.readFile(uri);
|
|
144
|
+
await ((_b = (_a = this.infrastructure).saveFileContent) === null || _b === void 0 ? void 0 : _b.call(_a, uri, decoder.decode(content), this.languageClientManager));
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
watcher.onDidChange(onFileChange);
|
|
148
|
+
watcher.onDidCreate(onFileChange);
|
|
149
|
+
}
|
|
150
|
+
return disposables;
|
|
151
|
+
}
|
|
152
|
+
fillClientCapabilities() { }
|
|
153
|
+
initialize() {
|
|
154
|
+
this.dispose();
|
|
155
|
+
this.disposable = this.registerFileHandlers();
|
|
156
|
+
}
|
|
157
|
+
getState() {
|
|
158
|
+
return {
|
|
159
|
+
kind: 'static'
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
dispose() {
|
|
163
|
+
var _a;
|
|
164
|
+
(_a = this.disposable) === null || _a === void 0 ? void 0 : _a.dispose();
|
|
165
|
+
this.disposable = undefined;
|
|
166
|
+
}
|
|
167
|
+
clear() {
|
|
168
|
+
this.dispose();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
export { FileSystemFeature, InitializeTextDocumentFeature, WillDisposeFeature };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { CodinGameInfrastructure } from './
|
|
2
|
-
export { loadExtensionConfigurations } from './
|
|
3
|
-
export { LanguageClientManager, createLanguageClientManager } from './
|
|
4
|
-
export { getLanguageClientOptions, registerLanguageClient } from './
|
|
5
|
-
export { default as defaultLanguageClientOptions } from './
|
|
1
|
+
export { CodinGameInfrastructure } from './infrastructure.js';
|
|
2
|
+
export { loadExtensionConfigurations } from './extensionConfiguration.js';
|
|
3
|
+
export { LanguageClientManager, createLanguageClientManager } from './languageClient.js';
|
|
4
|
+
export { getLanguageClientOptions, registerLanguageClient } from './languageClientOptions.js';
|
|
5
|
+
export { default as defaultLanguageClientOptions } from './staticOptions.js';
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { toSocket, WebSocketMessageWriter, WebSocketMessageReader } from 'vscode-ws-jsonrpc';
|
|
2
|
+
import * as monaco from 'monaco-editor';
|
|
3
|
+
import * as vscode from 'vscode';
|
|
4
|
+
import { updateFile, getFile } from './customRequests.js';
|
|
5
|
+
class CloseOnDisposeWebSocketMessageReader extends WebSocketMessageReader {
|
|
6
|
+
dispose() {
|
|
7
|
+
super.dispose();
|
|
8
|
+
this.socket.dispose();
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
async function openWebsocketConnection(url) {
|
|
12
|
+
const webSocket = new WebSocket(url);
|
|
13
|
+
const socket = toSocket(webSocket);
|
|
14
|
+
const reader = new CloseOnDisposeWebSocketMessageReader(socket);
|
|
15
|
+
const writer = new WebSocketMessageWriter(socket);
|
|
16
|
+
await new Promise((resolve, reject) => {
|
|
17
|
+
webSocket.addEventListener('open', resolve);
|
|
18
|
+
webSocket.addEventListener('error', reject);
|
|
19
|
+
});
|
|
20
|
+
return {
|
|
21
|
+
reader,
|
|
22
|
+
writer
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
class CodinGameInfrastructure {
|
|
26
|
+
constructor(
|
|
27
|
+
serverAddress, _useMutualizedProxy,
|
|
28
|
+
sessionId,
|
|
29
|
+
libraryUrls) {
|
|
30
|
+
this.serverAddress = serverAddress;
|
|
31
|
+
this._useMutualizedProxy = _useMutualizedProxy;
|
|
32
|
+
this.sessionId = sessionId;
|
|
33
|
+
this.libraryUrls = libraryUrls;
|
|
34
|
+
this.automaticTextDocumentUpdate = false;
|
|
35
|
+
this.rootUri = 'file:///tmp/project';
|
|
36
|
+
this.workspaceFolders = [{
|
|
37
|
+
uri: monaco.Uri.file('/tmp/project'),
|
|
38
|
+
index: 0,
|
|
39
|
+
name: 'main'
|
|
40
|
+
}];
|
|
41
|
+
}
|
|
42
|
+
useMutualizedProxy(languageClientId, options) {
|
|
43
|
+
return this._useMutualizedProxy && options.mutualizable;
|
|
44
|
+
}
|
|
45
|
+
async saveFileContent(document, content, languageClient) {
|
|
46
|
+
if (languageClient.isConnected()) {
|
|
47
|
+
await updateFile(document.toString(), content, languageClient);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async getFileContent(resource, languageClient) {
|
|
51
|
+
try {
|
|
52
|
+
return (await getFile(resource.toString(true), languageClient)).text;
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async openConnection(id) {
|
|
59
|
+
var _a;
|
|
60
|
+
try {
|
|
61
|
+
const url = new URL(this.sessionId != null ? `run/${this.sessionId}/${id}` : `run/${id}`, this.serverAddress);
|
|
62
|
+
(_a = this.libraryUrls) === null || _a === void 0 ? void 0 : _a.forEach(libraryUrl => url.searchParams.append('libraryUrl', libraryUrl));
|
|
63
|
+
url.searchParams.append('token', await this.getSecurityToken());
|
|
64
|
+
const connection = await openWebsocketConnection(url);
|
|
65
|
+
return connection;
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
if (error instanceof Error) {
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
throw new Error('Unable to connect to server');
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
getInitializationOptions(documentSelector) {
|
|
75
|
+
let documents = vscode.workspace.textDocuments.filter(doc => doc.uri.scheme === 'file');
|
|
76
|
+
if (documentSelector != null) {
|
|
77
|
+
documents = documents.filter(doc => vscode.languages.match(documentSelector, doc));
|
|
78
|
+
}
|
|
79
|
+
const files = documents
|
|
80
|
+
.reduce((map, doc) => {
|
|
81
|
+
map[doc.uri.toString(true)] = doc.getText();
|
|
82
|
+
return map;
|
|
83
|
+
}, {});
|
|
84
|
+
return {
|
|
85
|
+
files
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
export { CodinGameInfrastructure };
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import { CloseAction, ErrorAction, State } from 'vscode-languageclient';
|
|
2
|
+
import delay from 'delay';
|
|
3
|
+
import { Emitter, LogMessageNotification } from 'vscode-languageserver-protocol';
|
|
4
|
+
import * as vscode from 'vscode';
|
|
5
|
+
import { errorHandler } from 'vscode/monaco';
|
|
6
|
+
import once from 'once';
|
|
7
|
+
import { DisposableCollection } from 'vscode-ws-jsonrpc';
|
|
8
|
+
import { initializePromise } from '@codingame/monaco-editor-wrapper';
|
|
9
|
+
import { updateServices } from './services.js';
|
|
10
|
+
import createLanguageClient from './createLanguageClient.js';
|
|
11
|
+
import { WillDisposeFeature, FileSystemFeature, InitializeTextDocumentFeature } from './extensions.js';
|
|
12
|
+
import { loadExtensionConfigurations } from './extensionConfiguration.js';
|
|
13
|
+
import { getLanguageClientOptions } from './languageClientOptions.js';
|
|
14
|
+
const RETRY_CONNECTION_DELAY = 3000;
|
|
15
|
+
class LanguageClientManager {
|
|
16
|
+
constructor(id, clientOptions, infrastructure, managerOptions) {
|
|
17
|
+
this.id = id;
|
|
18
|
+
this.clientOptions = clientOptions;
|
|
19
|
+
this.infrastructure = infrastructure;
|
|
20
|
+
this.managerOptions = managerOptions;
|
|
21
|
+
this.disposed = false;
|
|
22
|
+
this.onDidChangeStatusEmitter = new Emitter();
|
|
23
|
+
this.onErrorEmitter = new Emitter();
|
|
24
|
+
this.onDidCloseEmitter = new Emitter();
|
|
25
|
+
this.onWillShutdownEmitter = new Emitter();
|
|
26
|
+
this.currentStatus = 'connecting';
|
|
27
|
+
this.handleClose = () => {
|
|
28
|
+
return {
|
|
29
|
+
action: CloseAction.DoNotRestart
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
this.handleError = (error) => {
|
|
33
|
+
errorHandler.onUnexpectedError(new Error('[LSP] Language client error', {
|
|
34
|
+
cause: error
|
|
35
|
+
}));
|
|
36
|
+
this.onErrorEmitter.fire(error);
|
|
37
|
+
this.updateStatus('error');
|
|
38
|
+
return {
|
|
39
|
+
action: ErrorAction.Shutdown
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
this.prepare = once(async () => {
|
|
43
|
+
try {
|
|
44
|
+
await initializePromise;
|
|
45
|
+
await loadExtensionConfigurations([this.clientOptions]);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
errorHandler.onUnexpectedError(new Error('[LSP] Unable to load extension configuration', {
|
|
49
|
+
cause: error
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
this.useMutualizedProxy = this.infrastructure.useMutualizedProxy(this.id, this.clientOptions);
|
|
54
|
+
}
|
|
55
|
+
updateStatus(status) {
|
|
56
|
+
this.currentStatus = status;
|
|
57
|
+
this.notifyStatusChanged();
|
|
58
|
+
}
|
|
59
|
+
notifyStatusChanged() {
|
|
60
|
+
this.onDidChangeStatusEmitter.fire({
|
|
61
|
+
status: this.currentStatus
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
isConnected() {
|
|
65
|
+
return ['connected', 'ready'].includes(this.currentStatus);
|
|
66
|
+
}
|
|
67
|
+
async dispose(timeout) {
|
|
68
|
+
this.disposed = true;
|
|
69
|
+
try {
|
|
70
|
+
if (this.startPromise != null) {
|
|
71
|
+
try {
|
|
72
|
+
await this.startPromise;
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (this.languageClient != null) {
|
|
78
|
+
const languageClient = this.languageClient;
|
|
79
|
+
this.languageClient = undefined;
|
|
80
|
+
await languageClient.dispose(timeout);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
finally {
|
|
84
|
+
this.onDidCloseEmitter.fire();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
get onDidChangeStatus() {
|
|
88
|
+
return this.onDidChangeStatusEmitter.event;
|
|
89
|
+
}
|
|
90
|
+
get onDidClose() {
|
|
91
|
+
return this.onDidCloseEmitter.event;
|
|
92
|
+
}
|
|
93
|
+
get onWillShutdown() {
|
|
94
|
+
return this.onWillShutdownEmitter.event;
|
|
95
|
+
}
|
|
96
|
+
get onError() {
|
|
97
|
+
return this.onErrorEmitter.event;
|
|
98
|
+
}
|
|
99
|
+
isModelManaged(document) {
|
|
100
|
+
if (this.clientOptions.documentSelector == null) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
return vscode.languages.match(this.clientOptions.documentSelector, document) > 0;
|
|
104
|
+
}
|
|
105
|
+
isDisposed() {
|
|
106
|
+
return this.disposed;
|
|
107
|
+
}
|
|
108
|
+
async start() {
|
|
109
|
+
var _a, _b;
|
|
110
|
+
let started = false;
|
|
111
|
+
let attempt = 0;
|
|
112
|
+
const maxStartAttemptCount = this.managerOptions.maxStartAttemptCount;
|
|
113
|
+
while (!this.isDisposed() &&
|
|
114
|
+
!started) {
|
|
115
|
+
if (maxStartAttemptCount != null && attempt >= maxStartAttemptCount) {
|
|
116
|
+
throw new Error(`Max connection attempt count exceeded: ${maxStartAttemptCount}`);
|
|
117
|
+
}
|
|
118
|
+
try {
|
|
119
|
+
this.startPromise = this._start();
|
|
120
|
+
await this.startPromise;
|
|
121
|
+
if (!((_b = (_a = this.languageClient) === null || _a === void 0 ? void 0 : _a.isRunning()) !== null && _b !== void 0 ? _b : false)) {
|
|
122
|
+
throw new Error('Language server not running');
|
|
123
|
+
}
|
|
124
|
+
started = true;
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
this.languageClient = undefined;
|
|
128
|
+
this.startPromise = undefined;
|
|
129
|
+
errorHandler.onUnexpectedError(new Error(`[LSP] Unable to start language client, retrying in ${RETRY_CONNECTION_DELAY} ms`, {
|
|
130
|
+
cause: error
|
|
131
|
+
}));
|
|
132
|
+
await delay(RETRY_CONNECTION_DELAY);
|
|
133
|
+
}
|
|
134
|
+
++attempt;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
async _start() {
|
|
138
|
+
var _a;
|
|
139
|
+
await this.prepare();
|
|
140
|
+
const onServerResponse = new Emitter();
|
|
141
|
+
const languageClient = await createLanguageClient(this.id, this.infrastructure, this.clientOptions, {
|
|
142
|
+
error: this.handleError,
|
|
143
|
+
closed: this.handleClose
|
|
144
|
+
}, {
|
|
145
|
+
...((_a = this.clientOptions.middleware) !== null && _a !== void 0 ? _a : {}),
|
|
146
|
+
handleDiagnostics: (uri, diagnostics, next) => {
|
|
147
|
+
var _a;
|
|
148
|
+
if (((_a = this.clientOptions.middleware) === null || _a === void 0 ? void 0 : _a.handleDiagnostics) != null) {
|
|
149
|
+
this.clientOptions.middleware.handleDiagnostics(uri, diagnostics, next);
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
next(uri, diagnostics);
|
|
153
|
+
}
|
|
154
|
+
onServerResponse.fire();
|
|
155
|
+
},
|
|
156
|
+
provideCodeActions: async (document, range, context, token, next) => {
|
|
157
|
+
var _a;
|
|
158
|
+
try {
|
|
159
|
+
if (((_a = this.clientOptions.middleware) === null || _a === void 0 ? void 0 : _a.provideCodeActions) != null) {
|
|
160
|
+
return await this.clientOptions.middleware.provideCodeActions(document, range, context, token, next);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
return await next(document, range, context, token);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
finally {
|
|
167
|
+
onServerResponse.fire();
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
provideDocumentRangeSemanticTokens: async (document, range, token, next) => {
|
|
171
|
+
var _a;
|
|
172
|
+
try {
|
|
173
|
+
if (((_a = this.clientOptions.middleware) === null || _a === void 0 ? void 0 : _a.provideDocumentRangeSemanticTokens) != null) {
|
|
174
|
+
return await this.clientOptions.middleware.provideDocumentRangeSemanticTokens(document, range, token, next);
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
return await next(document, range, token);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
finally {
|
|
181
|
+
onServerResponse.fire();
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
provideDocumentSemanticTokens: async (document, token, next) => {
|
|
185
|
+
var _a;
|
|
186
|
+
try {
|
|
187
|
+
if (((_a = this.clientOptions.middleware) === null || _a === void 0 ? void 0 : _a.provideDocumentSemanticTokens) != null) {
|
|
188
|
+
return await this.clientOptions.middleware.provideDocumentSemanticTokens(document, token, next);
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
return await next(document, token);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
finally {
|
|
195
|
+
onServerResponse.fire();
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
handleWorkDoneProgress: async (token, params, next) => {
|
|
199
|
+
var _a;
|
|
200
|
+
if (((_a = this.clientOptions.middleware) === null || _a === void 0 ? void 0 : _a.handleWorkDoneProgress) != null) {
|
|
201
|
+
this.clientOptions.middleware.handleWorkDoneProgress(token, params, next);
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
next(token, params);
|
|
205
|
+
}
|
|
206
|
+
if (params.kind === 'end') {
|
|
207
|
+
onServerResponse.fire();
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
provideHover: async (document, position, token, next) => {
|
|
211
|
+
var _a;
|
|
212
|
+
try {
|
|
213
|
+
if (((_a = this.clientOptions.middleware) === null || _a === void 0 ? void 0 : _a.provideHover) != null) {
|
|
214
|
+
return await this.clientOptions.middleware.provideHover(document, position, token, next);
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
return await next(document, position, token);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
finally {
|
|
221
|
+
onServerResponse.fire();
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
this.languageClient = languageClient;
|
|
226
|
+
let readyPromise = null;
|
|
227
|
+
languageClient.onDidChangeState(async (state) => {
|
|
228
|
+
switch (state.newState) {
|
|
229
|
+
case State.Starting: {
|
|
230
|
+
this.updateStatus('connecting');
|
|
231
|
+
readyPromise = Promise.resolve().then(async () => {
|
|
232
|
+
const disposableCollection = new DisposableCollection();
|
|
233
|
+
let readyPromise;
|
|
234
|
+
const { maxInitializeDuration, readinessMessageMatcher } = this.clientOptions;
|
|
235
|
+
if (readinessMessageMatcher != null && !this.useMutualizedProxy) {
|
|
236
|
+
readyPromise = new Promise(resolve => {
|
|
237
|
+
disposableCollection.push(languageClient.onNotification(LogMessageNotification.type, logMessage => {
|
|
238
|
+
if (readinessMessageMatcher.exec(logMessage.message) != null) {
|
|
239
|
+
resolve();
|
|
240
|
+
}
|
|
241
|
+
}));
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
readyPromise = new Promise(resolve => {
|
|
246
|
+
disposableCollection.push(onServerResponse.event(resolve));
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
await Promise.race([
|
|
250
|
+
readyPromise,
|
|
251
|
+
delay(maxInitializeDuration !== null && maxInitializeDuration !== void 0 ? maxInitializeDuration : 15000)
|
|
252
|
+
]);
|
|
253
|
+
disposableCollection.dispose();
|
|
254
|
+
}, (error) => {
|
|
255
|
+
errorHandler.onUnexpectedError(new Error(`[LSP] Error while waiting for the ${this.id} language client to be ready`, {
|
|
256
|
+
cause: error
|
|
257
|
+
}));
|
|
258
|
+
});
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
case State.Running: {
|
|
262
|
+
this.updateStatus('connected');
|
|
263
|
+
await readyPromise;
|
|
264
|
+
this.updateStatus('ready');
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
case State.Stopped: {
|
|
268
|
+
this.updateStatus('closed');
|
|
269
|
+
setTimeout(() => {
|
|
270
|
+
void languageClient.dispose();
|
|
271
|
+
});
|
|
272
|
+
if (state.oldState === State.Running && !this.isDisposed() && this.languageClient === languageClient) {
|
|
273
|
+
this.languageClient = undefined;
|
|
274
|
+
console.info('[LSP] Restarting language client', state);
|
|
275
|
+
this.start().catch(error => {
|
|
276
|
+
errorHandler.onUnexpectedError(new Error('[LSP] Language client stopped', {
|
|
277
|
+
cause: error
|
|
278
|
+
}));
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
this.languageClient.registerFeature(new WillDisposeFeature(this.languageClient, this.onWillShutdownEmitter));
|
|
286
|
+
if (this.infrastructure.getFileContent != null) {
|
|
287
|
+
this.languageClient.registerFeature(new FileSystemFeature(this.infrastructure, this));
|
|
288
|
+
}
|
|
289
|
+
if (!this.infrastructure.automaticTextDocumentUpdate) {
|
|
290
|
+
this.languageClient.registerFeature(new InitializeTextDocumentFeature(this, this.infrastructure));
|
|
291
|
+
}
|
|
292
|
+
await this.languageClient.start();
|
|
293
|
+
}
|
|
294
|
+
async sendNotification(type, params) {
|
|
295
|
+
await this.languageClient.sendNotification(type, params);
|
|
296
|
+
}
|
|
297
|
+
sendRequest(type, params) {
|
|
298
|
+
return this.languageClient.sendRequest(type, params);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
function createLanguageClientManager(id, infrastructure, clientOptions = getLanguageClientOptions(id), managerOptions = {}) {
|
|
302
|
+
if (clientOptions == null) {
|
|
303
|
+
throw new Error(`Unknown ${id} language server`);
|
|
304
|
+
}
|
|
305
|
+
if (infrastructure.useMutualizedProxy(id, clientOptions) && clientOptions.mutualizable) {
|
|
306
|
+
clientOptions = {
|
|
307
|
+
...clientOptions,
|
|
308
|
+
synchronize: undefined
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
updateServices(infrastructure);
|
|
312
|
+
return new LanguageClientManager(id, clientOptions, infrastructure, managerOptions);
|
|
313
|
+
}
|
|
314
|
+
export { LanguageClientManager, createLanguageClientManager };
|