Skip to content

Commit

Permalink
fix(language_server): revalidate files when oxlint config is changing (
Browse files Browse the repository at this point in the history
…#7259)

![lsp-refresh-files](https://github.com/user-attachments/assets/e6b64f73-966d-490a-9191-b3ec64d3ac1e)

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
Sysix and autofix-ci[bot] authored Nov 14, 2024
1 parent 10cdce9 commit 216d533
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions crates/oxc_language_server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ use tower_lsp::{
lsp_types::{
CodeAction, CodeActionKind, CodeActionOptions, CodeActionOrCommand, CodeActionParams,
CodeActionProviderCapability, CodeActionResponse, ConfigurationItem, Diagnostic,
DidChangeConfigurationParams, DidChangeTextDocumentParams, DidCloseTextDocumentParams,
DidOpenTextDocumentParams, DidSaveTextDocumentParams, InitializeParams, InitializeResult,
InitializedParams, OneOf, ServerCapabilities, ServerInfo, TextDocumentSyncCapability,
TextDocumentSyncKind, TextEdit, Url, WorkDoneProgressOptions, WorkspaceEdit,
WorkspaceFoldersServerCapabilities, WorkspaceServerCapabilities,
DidChangeConfigurationParams, DidChangeTextDocumentParams, DidChangeWatchedFilesParams,
DidCloseTextDocumentParams, DidOpenTextDocumentParams, DidSaveTextDocumentParams,
InitializeParams, InitializeResult, InitializedParams, OneOf, ServerCapabilities,
ServerInfo, TextDocumentSyncCapability, TextDocumentSyncKind, TextEdit, Url,
WorkDoneProgressOptions, WorkspaceEdit, WorkspaceFoldersServerCapabilities,
WorkspaceServerCapabilities,
},
Client, LanguageServer, LspService, Server,
};
Expand Down Expand Up @@ -172,6 +173,12 @@ impl LanguageServer for Backend {
*self.options.lock().await = changed_options;
}

async fn did_change_watched_files(&self, _params: DidChangeWatchedFilesParams) {
debug!("watched file did change");
self.init_linter_config().await;
self.revalidate_open_files().await;
}

async fn initialized(&self, _params: InitializedParams) {
debug!("oxc initialized.");
}
Expand Down Expand Up @@ -339,6 +346,15 @@ impl Backend {
.await;
}

async fn revalidate_open_files(&self) {
join_all(self.diagnostics_report_map.iter().map(|map| {
let url = Url::from_str(map.key()).expect("should convert to path");

self.handle_file_update(url, None, None)
}))
.await;
}

async fn init_linter_config(&self) {
let Some(Some(uri)) = self.root_uri.get() else {
return;
Expand Down

0 comments on commit 216d533

Please sign in to comment.