Skip to content

Commit

Permalink
Merge pull request #292 from elijah-potter/config-change
Browse files Browse the repository at this point in the history
Improve config change handling
  • Loading branch information
elijah-potter authored Nov 28, 2024
2 parents 672ebc9 + 1a89d7e commit 47069a8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
16 changes: 16 additions & 0 deletions harper-ls/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Url> = {
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<Option<CodeActionResponse>> {
Expand Down
5 changes: 3 additions & 2 deletions packages/vscode-plugin/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ export async function activate(context: ExtensionContext): Promise<void> {
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') }
});
}
})
);
Expand Down
4 changes: 2 additions & 2 deletions packages/vscode-plugin/src/tests/suite/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(250);

compareActualVsExpectedDiagnostics(
getActualDiagnostics(markdownUri),
Expand Down

0 comments on commit 47069a8

Please sign in to comment.