Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve config change handling #292

Merged
merged 3 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
elijah-potter marked this conversation as resolved.
Show resolved Hide resolved

compareActualVsExpectedDiagnostics(
getActualDiagnostics(markdownUri),
Expand Down