|
1 | 1 | import { IWebSocket, WebSocketMessageReader, WebSocketMessageWriter, toSocket } from 'vscode-ws-jsonrpc' |
2 | 2 | import { MessageTransports } from 'vscode-languageclient' |
3 | 3 | import * as monaco from 'monaco-editor' |
4 | | -import type * as vscode from 'vscode' |
| 4 | +import * as vscode from 'vscode' |
5 | 5 | import { LSPAny } from 'vscode-languageserver-protocol' |
6 | 6 | import { getFile, updateFile } from './customRequests' |
7 | 7 | import { LanguageClientManager } from './languageClient' |
@@ -48,7 +48,7 @@ export interface Infrastructure { |
48 | 48 | */ |
49 | 49 | openConnection (id: LanguageClientId): Promise<MessageTransports> |
50 | 50 |
|
51 | | - getInitializationOptions? (): LSPAny |
| 51 | + getInitializationOptions? (documentSelector?: vscode.DocumentSelector): LSPAny |
52 | 52 | } |
53 | 53 |
|
54 | 54 | class CloseOnDisposeWebSocketMessageReader extends WebSocketMessageReader { |
@@ -141,18 +141,20 @@ export abstract class CodinGameInfrastructure implements Infrastructure { |
141 | 141 | } |
142 | 142 | } |
143 | 143 |
|
144 | | - public getInitializationOptions (): LSPAny { |
| 144 | + public getInitializationOptions (documentSelector?: vscode.DocumentSelector): LSPAny { |
145 | 145 | // Provide all open model content to the backend so it's able to write them on the disk |
146 | 146 | // BEFORE starting the server or registering the workspace folders |
147 | 147 | // The didOpen notification already contain the file content but some LSP (like gopls) |
148 | 148 | // don't use it and needs the file to be up-to-date on the disk before the workspace folder is added |
149 | | - const files = monaco.editor |
150 | | - .getModels() |
151 | | - .filter((model) => model.uri.scheme === 'file') |
152 | | - .reduce((map, model) => { |
153 | | - map[model.uri.toString(true)] = model.getValue() |
| 149 | + let documents = vscode.workspace.textDocuments.filter(doc => doc.uri.scheme === 'file') |
| 150 | + if (documentSelector != null) { |
| 151 | + documents = documents.filter(doc => vscode.languages.match(documentSelector, doc)) |
| 152 | + } |
| 153 | + const files = documents |
| 154 | + .reduce((map, doc) => { |
| 155 | + map[doc.uri.toString(true)] = doc.getText() |
154 | 156 | return map |
155 | | - }, {} as Record<string, string>) |
| 157 | + }, <Record<string, string>>{}) |
156 | 158 | return { |
157 | 159 | files |
158 | 160 | } |
|
0 commit comments