Skip to content

Commit f831f50

Browse files
committed
Make LanguageClientOptions.synchronize.fileEvents configurable
1 parent 531f35e commit f831f50

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

package.json

+12
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,18 @@
256256
"description": "[DEBUG] If enabled (together with debugAttach.enabled), the language server will not immediately launch but instead listen on the specified attach port and wait for a debugger. This is ONLY useful if you need to debug the language server ITSELF.",
257257
"default": false
258258
},
259+
"kotlin.languageServer.watchFiles": {
260+
"type": "array",
261+
"default": [
262+
"**/*.kt",
263+
"**/*.kts",
264+
"**/*.java",
265+
"**/pom.xml",
266+
"**/build.gradle",
267+
"**/settings.gradle"
268+
],
269+
"description": "Specifies glob patterns of files, which would be watched by LSP client. The LSP client doesn't support watching files outside a workspace folder."
270+
},
259271
"kotlin.trace.server": {
260272
"type": "string",
261273
"enum": [

src/languageSetup.ts

+18-10
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,17 @@ export async function activateLanguageServer({ context, status, config, javaInst
7575
await fs.promises.mkdir(storagePath);
7676
}
7777

78-
const options = { outputChannel, startScriptPath, tcpPort, env, storagePath };
78+
const customFileEventsGlobPatterns: string[] = config.get("languageServer.watchFiles")
79+
const fileEventsGlobPatterns = customFileEventsGlobPatterns || [
80+
"**/*.kt",
81+
"**/*.kts",
82+
"**/*.java",
83+
"**/pom.xml",
84+
"**/build.gradle",
85+
"**/settings.gradle"
86+
];
87+
88+
const options = { outputChannel, startScriptPath, tcpPort, env, storagePath, fileEventsGlobPatterns };
7989
const languageClient = createLanguageClient(options);
8090

8191
// Create the language client and start the client.
@@ -167,7 +177,8 @@ function createLanguageClient(options: {
167177
startScriptPath: string,
168178
tcpPort?: number,
169179
env?: any,
170-
storagePath: string
180+
storagePath: string,
181+
fileEventsGlobPatterns: string[]
171182
}): LanguageClient {
172183
// Options to control the language client
173184
const clientOptions: LanguageClientOptions = {
@@ -182,14 +193,11 @@ function createLanguageClient(options: {
182193
configurationSection: 'kotlin',
183194
// Notify the server about file changes to 'javaconfig.json' files contain in the workspace
184195
// TODO this should be registered from the language server side
185-
fileEvents: [
186-
vscode.workspace.createFileSystemWatcher('**/*.kt'),
187-
vscode.workspace.createFileSystemWatcher('**/*.kts'),
188-
vscode.workspace.createFileSystemWatcher('**/*.java'),
189-
vscode.workspace.createFileSystemWatcher('**/pom.xml'),
190-
vscode.workspace.createFileSystemWatcher('**/build.gradle'),
191-
vscode.workspace.createFileSystemWatcher('**/settings.gradle')
192-
]
196+
fileEvents: options.fileEventsGlobPatterns.map(
197+
function (globPattern: string): vscode.FileSystemWatcher {
198+
return vscode.workspace.createFileSystemWatcher(globPattern)
199+
}
200+
)
193201
},
194202
progressOnInitialization: true,
195203
outputChannel: options.outputChannel,

0 commit comments

Comments
 (0)