From d814937dc4d86707fbdc38c00670d20a056ac1c8 Mon Sep 17 00:00:00 2001 From: Matthew Espino <65783406+mcecode@users.noreply.github.com> Date: Thu, 28 Nov 2024 05:24:57 +0800 Subject: [PATCH 1/3] feat(harper-ls): update linters and diagnostics on config change --- harper-ls/src/backend.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/harper-ls/src/backend.rs b/harper-ls/src/backend.rs index 1cb4c670..73ceedeb 100644 --- a/harper-ls/src/backend.rs +++ b/harper-ls/src/backend.rs @@ -477,6 +477,22 @@ impl LanguageServer for Backend { async fn did_change_configuration(&self, params: DidChangeConfigurationParams) { self.update_config_from_obj(params.settings).await; + + let urls: Vec = { + let mut doc_lock = self.doc_state.lock().await; + let config_lock = self.config.read().await; + + for doc in doc_lock.values_mut() { + doc.linter = LintGroup::new(config_lock.lint_config, doc.dict.clone()); + } + + doc_lock.keys().cloned().collect() + }; + + for url in urls { + let _ = self.update_document_from_file(&url, None).await; + self.publish_diagnostics(&url).await; + } } async fn code_action(&self, params: CodeActionParams) -> Result> { From 1e6dfbc615a0b29a72a33a16ee446a9f77267b51 Mon Sep 17 00:00:00 2001 From: Matthew Espino <65783406+mcecode@users.noreply.github.com> Date: Thu, 28 Nov 2024 05:27:53 +0800 Subject: [PATCH 2/3] feat(vscode-plugin): notify harper-ls of config change instead of restarting it --- packages/vscode-plugin/src/extension.ts | 5 +++-- packages/vscode-plugin/src/tests/suite/integration.test.ts | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/vscode-plugin/src/extension.ts b/packages/vscode-plugin/src/extension.ts index 7396aacd..3fe4a5a7 100644 --- a/packages/vscode-plugin/src/extension.ts +++ b/packages/vscode-plugin/src/extension.ts @@ -44,8 +44,9 @@ export async function activate(context: ExtensionContext): Promise { context.subscriptions.push( workspace.onDidChangeConfiguration(async (event) => { if (configs.find((c) => event.affectsConfiguration(c))) { - clientOptions.outputChannel?.appendLine('Configuration changed, restarting server'); - await startLanguageServer(); + await client?.sendNotification('workspace/didChangeConfiguration', { + settings: { 'harper-ls': workspace.getConfiguration('harper-ls') } + }); } }) ); diff --git a/packages/vscode-plugin/src/tests/suite/integration.test.ts b/packages/vscode-plugin/src/tests/suite/integration.test.ts index 59475230..2ae9b3de 100644 --- a/packages/vscode-plugin/src/tests/suite/integration.test.ts +++ b/packages/vscode-plugin/src/tests/suite/integration.test.ts @@ -47,8 +47,8 @@ describe('Integration >', () => { it('updates diagnostics on configuration change', async () => { const config = workspace.getConfiguration('harper-ls.linters'); await config.update('repeated_words', false, ConfigurationTarget.Workspace); - // Wait for `harper-ls` to restart and send new diagnostics - await sleep(1000); + // Wait for `harper-ls` to update diagnostics + await sleep(200); compareActualVsExpectedDiagnostics( getActualDiagnostics(markdownUri), From 1a89d7e3bf4a1c239e572e416578b458342830d4 Mon Sep 17 00:00:00 2001 From: Matthew Espino <65783406+mcecode@users.noreply.github.com> Date: Thu, 28 Nov 2024 07:19:46 +0800 Subject: [PATCH 3/3] fix(vscode-plugin): fix precommit failing by increasing sleep time --- packages/vscode-plugin/src/tests/suite/integration.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vscode-plugin/src/tests/suite/integration.test.ts b/packages/vscode-plugin/src/tests/suite/integration.test.ts index 2ae9b3de..98d31b3c 100644 --- a/packages/vscode-plugin/src/tests/suite/integration.test.ts +++ b/packages/vscode-plugin/src/tests/suite/integration.test.ts @@ -48,7 +48,7 @@ describe('Integration >', () => { const config = workspace.getConfiguration('harper-ls.linters'); await config.update('repeated_words', false, ConfigurationTarget.Workspace); // Wait for `harper-ls` to update diagnostics - await sleep(200); + await sleep(250); compareActualVsExpectedDiagnostics( getActualDiagnostics(markdownUri),