Skip to content

Commit bd3fb8a

Browse files
authored
(feat) restart language server when tsconfig/jsconfig changed
1 parent 696c181 commit bd3fb8a

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

packages/svelte-vscode/src/extension.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,29 @@ export function activate(context: ExtensionContext) {
122122
context.subscriptions.push(disposable);
123123
});
124124

125+
workspace.onDidSaveTextDocument(async (doc) => {
126+
const parts = doc.uri.toString().split(/\/|\\/);
127+
if (['tsconfig.json', 'jsconfig.json'].includes(parts[parts.length - 1])) {
128+
await restartLS(false);
129+
}
130+
});
131+
125132
context.subscriptions.push(
126133
commands.registerCommand('svelte.restartLanguageServer', async () => {
127-
await ls.stop();
128-
ls = createLanguageServer(serverOptions, clientOptions);
129-
context.subscriptions.push(ls.start());
130-
await ls.onReady();
131-
window.showInformationMessage('Svelte language server restarted.');
134+
await restartLS(true);
132135
})
133136
);
134137

138+
async function restartLS(showNotification: boolean) {
139+
await ls.stop();
140+
ls = createLanguageServer(serverOptions, clientOptions);
141+
context.subscriptions.push(ls.start());
142+
await ls.onReady();
143+
if (showNotification) {
144+
window.showInformationMessage('Svelte language server restarted.');
145+
}
146+
}
147+
135148
function getLS() {
136149
return ls;
137150
}

0 commit comments

Comments
 (0)