Skip to content

Commit 09ed409

Browse files
committed
Restart server on changes that requires it.
1 parent 6285d0e commit 09ed409

File tree

2 files changed

+28
-23
lines changed

2 files changed

+28
-23
lines changed

src/extension.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as vscode from 'vscode';
55
import { createLanguageClient, getServerPlatform, ServerPlatform } from './validator';
66
import { dumpAstRequest, dumpDependencyRequest } from './request';
77
import { ShaderVariantTreeDataProvider } from './shaderVariant';
8+
import { DidChangeConfigurationNotification, LanguageClient } from 'vscode-languageclient';
89

910
export let sidebar: ShaderVariantTreeDataProvider;
1011

@@ -40,11 +41,12 @@ export async function activate(context: vscode.ExtensionContext)
4041
}
4142

4243
// Create language client
43-
const client = await createLanguageClient(context);
44-
if (client === null) {
44+
const possiblyNullClient = await createLanguageClient(context);
45+
if (possiblyNullClient === null) {
4546
vscode.window.showErrorMessage("Failed to launch shader-validator language server.");
4647
return;
4748
}
49+
let client = possiblyNullClient;
4850

4951
// Create sidebar
5052
sidebar = new ShaderVariantTreeDataProvider(context, client);
@@ -87,6 +89,24 @@ export async function activate(context: vscode.ExtensionContext)
8789
client.outputChannel.appendLine("No active file for dumping deps tree");
8890
}
8991
}));
92+
context.subscriptions.push(
93+
vscode.workspace.onDidChangeConfiguration(async (event : vscode.ConfigurationChangeEvent) => {
94+
if (event.affectsConfiguration("shader-validator")) {
95+
if (event.affectsConfiguration("shader-validator.trace.server") ||
96+
event.affectsConfiguration("shader-validator.serverPath")) {
97+
let newClient = await createLanguageClient(context);
98+
if (newClient !== null) {
99+
client.dispose();
100+
client = newClient;
101+
}
102+
} else {
103+
await client.sendNotification(DidChangeConfigurationNotification.type, {
104+
settings: "",
105+
});
106+
}
107+
}
108+
})
109+
);
90110
}
91111

92112

src/validator.ts

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -116,22 +116,6 @@ export function getServerPlatform() : ServerPlatform {
116116
}
117117
}
118118

119-
function notifyConfigurationChange(context: vscode.ExtensionContext, client: LanguageClient) {
120-
context.subscriptions.push(
121-
vscode.workspace.onDidChangeConfiguration(async (event : vscode.ConfigurationChangeEvent) => {
122-
if (event.affectsConfiguration("shader-validator")) {
123-
if (event.affectsConfiguration("shader-validator.trace.server") ||
124-
event.affectsConfiguration("shader-validator.serverPath")) {
125-
//restartServer();
126-
}
127-
await client.sendNotification(DidChangeConfigurationNotification.type, {
128-
settings: "",
129-
});
130-
}
131-
})
132-
);
133-
}
134-
135119
function getMiddleware() : Middleware {
136120
return {
137121
async provideDocumentSymbols(document: vscode.TextDocument, token: vscode.CancellationToken, next: ProvideDocumentSymbolsSignature) {
@@ -194,6 +178,10 @@ export async function createLanguageClient(context: vscode.ExtensionContext): Pr
194178
}
195179
}
196180
async function createLanguageClientStandard(context: vscode.ExtensionContext, platform : ServerPlatform) : Promise<LanguageClient | null> {
181+
const channelName = 'Shader language Server'; // For trace option, need same name
182+
const channel = vscode.window.createOutputChannel(channelName);
183+
context.subscriptions.push(channel);
184+
197185
const executable = getPlatformBinaryUri(context.extensionUri, platform);
198186
const cwd = getPlatformBinaryDirectoryPath(context.extensionUri, platform);
199187
console.info(`Executing server ${executable} with working directory ${cwd}`);
@@ -223,13 +211,14 @@ async function createLanguageClientStandard(context: vscode.ExtensionContext, pl
223211
{ scheme: 'file', language: 'glsl' },
224212
{ scheme: 'file', language: 'wgsl' },
225213
],
214+
outputChannel: channel,
226215
middleware: getMiddleware(),
227216
errorHandler: new ShaderErrorHandler()
228217
};
229218

230219
let client = new LanguageClient(
231220
'shader-validator',
232-
'Shader language server',
221+
channelName,
233222
serverOptions,
234223
clientOptions,
235224
context.extensionMode === vscode.ExtensionMode.Development
@@ -238,9 +227,6 @@ async function createLanguageClientStandard(context: vscode.ExtensionContext, pl
238227
// Start the client. This will also launch the server
239228
await client.start();
240229

241-
// Ensure configuration is sent
242-
notifyConfigurationChange(context, client);
243-
244230
return client;
245231
}
246232
async function createLanguageClientWASI(context: vscode.ExtensionContext) : Promise<LanguageClient> {
@@ -340,7 +326,6 @@ async function createLanguageClientWASI(context: vscode.ExtensionContext) : Prom
340326
} catch (error) {
341327
client.error(`Start failed`, error, 'force');
342328
}
343-
notifyConfigurationChange(context, client);
344329

345330
return client;
346331
}

0 commit comments

Comments
 (0)