From 50dc49ee83cdb4a8d77be7bf8b3108e2895d0953 Mon Sep 17 00:00:00 2001 From: Sysix Date: Sat, 23 Nov 2024 22:28:33 +0100 Subject: [PATCH 1/6] feat(language_server)!: add capability `diagnosticProvider` --- crates/oxc_language_server/src/main.rs | 119 ++++++++++++------------- editors/vscode/client/extension.ts | 14 +++ 2 files changed, 72 insertions(+), 61 deletions(-) diff --git a/crates/oxc_language_server/src/main.rs b/crates/oxc_language_server/src/main.rs index bcbaa8f128c21..cd72de7e0aac3 100644 --- a/crates/oxc_language_server/src/main.rs +++ b/crates/oxc_language_server/src/main.rs @@ -13,14 +13,7 @@ use tokio::sync::{Mutex, OnceCell, RwLock, SetError}; use tower_lsp::{ jsonrpc::{Error, ErrorCode, Result}, lsp_types::{ - CodeAction, CodeActionKind, CodeActionOptions, CodeActionOrCommand, CodeActionParams, - CodeActionProviderCapability, CodeActionResponse, ConfigurationItem, Diagnostic, - DidChangeConfigurationParams, DidChangeTextDocumentParams, DidChangeWatchedFilesParams, - DidCloseTextDocumentParams, DidOpenTextDocumentParams, DidSaveTextDocumentParams, - InitializeParams, InitializeResult, InitializedParams, OneOf, ServerCapabilities, - ServerInfo, TextDocumentSyncCapability, TextDocumentSyncKind, TextEdit, Url, - WorkDoneProgressOptions, WorkspaceEdit, WorkspaceFoldersServerCapabilities, - WorkspaceServerCapabilities, + CodeAction, CodeActionKind, CodeActionOptions, CodeActionOrCommand, CodeActionParams, CodeActionProviderCapability, CodeActionResponse, ConfigurationItem, Diagnostic, DiagnosticOptions, DiagnosticServerCapabilities, DidChangeConfigurationParams, DidChangeTextDocumentParams, DidChangeWatchedFilesParams, DidCloseTextDocumentParams, DidOpenTextDocumentParams, DidSaveTextDocumentParams, DocumentDiagnosticParams, DocumentDiagnosticReport, DocumentDiagnosticReportResult, FullDocumentDiagnosticReport, InitializeParams, InitializeResult, InitializedParams, OneOf, RelatedFullDocumentDiagnosticReport, ServerCapabilities, ServerInfo, TextDocumentSyncCapability, TextDocumentSyncKind, TextEdit, Url, WorkDoneProgressOptions, WorkspaceEdit, WorkspaceFoldersServerCapabilities, WorkspaceServerCapabilities }, Client, LanguageServer, LspService, Server, }; @@ -31,6 +24,7 @@ struct Backend { client: Client, root_uri: OnceCell>, server_linter: RwLock, + document_content_cache: DashMap, diagnostics_report_map: DashMap>, options: Mutex, gitignore_glob: Mutex>, @@ -114,6 +108,12 @@ impl LanguageServer for Backend { }), file_operations: None, }), + diagnostic_provider: Some(DiagnosticServerCapabilities::Options(DiagnosticOptions { + identifier: Some("oxc".into()), + inter_file_dependencies: false, + workspace_diagnostics: false, + work_done_progress_options: WorkDoneProgressOptions::default(), + })), code_action_provider: Some(CodeActionProviderCapability::Options( CodeActionOptions { code_action_kinds: Some(vec![CodeActionKind::QUICKFIX]), @@ -187,58 +187,48 @@ impl LanguageServer for Backend { Ok(()) } - async fn did_save(&self, params: DidSaveTextDocumentParams) { - debug!("oxc server did save"); - // drop as fast as possible - let run_level = { self.options.lock().await.get_lint_level() }; - if run_level < SyntheticRunLevel::OnSave { - return; - } - let uri = params.text_document.uri; - if self.is_ignored(&uri).await { - return; - } - self.handle_file_update(uri, None, None).await; + async fn did_open(&self, params: DidOpenTextDocumentParams) { + self.document_content_cache.insert(params.text_document.uri, params.text_document.text); } - /// When the document changed, it may not be written to disk, so we should - /// get the file context from the language client - async fn did_change(&self, params: DidChangeTextDocumentParams) { - let run_level = { self.options.lock().await.get_lint_level() }; - if run_level < SyntheticRunLevel::OnType { - return; - } + async fn did_close(&self, params: DidCloseTextDocumentParams) { + self.document_content_cache.remove(¶ms.text_document.uri); + } - let uri = ¶ms.text_document.uri; - if self.is_ignored(uri).await { - return; - } + async fn did_change(&self, params: DidChangeTextDocumentParams) { let content = params.content_changes.first().map(|c| c.text.clone()); - self.handle_file_update( - params.text_document.uri, - content, - Some(params.text_document.version), - ) - .await; - } - async fn did_open(&self, params: DidOpenTextDocumentParams) { - let run_level = { self.options.lock().await.get_lint_level() }; - if run_level <= SyntheticRunLevel::Disable { - return; - } - if self.is_ignored(¶ms.text_document.uri).await { - return; + if let Some(content) = content { + self.document_content_cache.insert(params.text_document.uri, content); } - self.handle_file_update(params.text_document.uri, None, Some(params.text_document.version)) - .await; } - async fn did_close(&self, params: DidCloseTextDocumentParams) { - let uri = params.text_document.uri.to_string(); - self.diagnostics_report_map.remove(&uri); + async fn diagnostic(&self, params: DocumentDiagnosticParams) -> Result { + let content = self.document_content_cache.get(¶ms.text_document.uri).map(|entry| entry.value().to_owned()); + + let Some(entry) = self.document_content_cache.get(¶ms.text_document.uri) else { + return Err(Error::new(ErrorCode::InvalidParams)); + }; + + let Some(result) = self.lint_uri(entry.key(), content).await else { + return Ok(DocumentDiagnosticReportResult::Report(DocumentDiagnosticReport::Full(RelatedFullDocumentDiagnosticReport { + related_documents: None, + full_document_diagnostic_report: FullDocumentDiagnosticReport::default() + }))) + }; + + self.diagnostics_report_map.insert(entry.key().to_string(), result.clone()); + + Ok(DocumentDiagnosticReportResult::Report(DocumentDiagnosticReport::Full(RelatedFullDocumentDiagnosticReport { + related_documents: None, + full_document_diagnostic_report: FullDocumentDiagnosticReport { + items: result.into_iter().map(|report| report.diagnostic).collect(), + ..FullDocumentDiagnosticReport::default() + }, + }))) } + async fn code_action(&self, params: CodeActionParams) -> Result> { let uri = params.text_document.uri; @@ -381,19 +371,24 @@ impl Backend { } } + async fn lint_uri(&self, uri: &Url, content: Option) -> Option> { + let Some(Some(_root_uri)) = self.root_uri.get() else { + return None; + }; + + self.server_linter.read().await.run_single(&uri, content) + } async fn handle_file_update(&self, uri: Url, content: Option, version: Option) { - if let Some(Some(_root_uri)) = self.root_uri.get() { - if let Some(diagnostics) = self.server_linter.read().await.run_single(&uri, content) { - self.client - .publish_diagnostics( - uri.clone(), - diagnostics.clone().into_iter().map(|d| d.diagnostic).collect(), - version, - ) - .await; + if let Some(diagnostics) = self.lint_uri(&uri, content).await { + self.client + .publish_diagnostics( + uri.clone(), + diagnostics.clone().into_iter().map(|d| d.diagnostic).collect(), + version, + ) + .await; - self.diagnostics_report_map.insert(uri.to_string(), diagnostics); - } + self.diagnostics_report_map.insert(uri.to_string(), diagnostics); } } @@ -435,11 +430,13 @@ async fn main() { let server_linter = ServerLinter::new(); let diagnostics_report_map = DashMap::new(); + let document_content_cache = DashMap::new(); let (service, socket) = LspService::build(|client| Backend { client, root_uri: OnceCell::new(), server_linter: RwLock::new(server_linter), + document_content_cache, diagnostics_report_map, options: Mutex::new(Options::default()), gitignore_glob: Mutex::new(vec![]), diff --git a/editors/vscode/client/extension.ts b/editors/vscode/client/extension.ts index d8417b081f740..1d6dda0f91ea9 100644 --- a/editors/vscode/client/extension.ts +++ b/editors/vscode/client/extension.ts @@ -152,6 +152,20 @@ export async function activate(context: ExtensionContext) { }, outputChannel, traceOutputChannel: outputChannel, + diagnosticPullOptions: { + onChange: true, + onSave: true, + onTabs: false, + filter: (_, mode) => { + if (mode === 'onType' && configService.config.runTrigger !== 'onType') { + return true; + } else if (mode === 'onSave' && configService.config.runTrigger !== 'onSave') { + return true; + } + + return !configService.config.enable + } + } }; // Create the language client and start the client. From ee530a39b582ae6936902e76cde3948526b28087 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Sat, 23 Nov 2024 21:31:21 +0000 Subject: [PATCH 2/6] [autofix.ci] apply automated fixes --- crates/oxc_language_server/src/main.rs | 64 +++++++++++++++++--------- editors/vscode/client/extension.ts | 6 +-- 2 files changed, 45 insertions(+), 25 deletions(-) diff --git a/crates/oxc_language_server/src/main.rs b/crates/oxc_language_server/src/main.rs index cd72de7e0aac3..dd8b5be25d9be 100644 --- a/crates/oxc_language_server/src/main.rs +++ b/crates/oxc_language_server/src/main.rs @@ -13,7 +13,16 @@ use tokio::sync::{Mutex, OnceCell, RwLock, SetError}; use tower_lsp::{ jsonrpc::{Error, ErrorCode, Result}, lsp_types::{ - CodeAction, CodeActionKind, CodeActionOptions, CodeActionOrCommand, CodeActionParams, CodeActionProviderCapability, CodeActionResponse, ConfigurationItem, Diagnostic, DiagnosticOptions, DiagnosticServerCapabilities, DidChangeConfigurationParams, DidChangeTextDocumentParams, DidChangeWatchedFilesParams, DidCloseTextDocumentParams, DidOpenTextDocumentParams, DidSaveTextDocumentParams, DocumentDiagnosticParams, DocumentDiagnosticReport, DocumentDiagnosticReportResult, FullDocumentDiagnosticReport, InitializeParams, InitializeResult, InitializedParams, OneOf, RelatedFullDocumentDiagnosticReport, ServerCapabilities, ServerInfo, TextDocumentSyncCapability, TextDocumentSyncKind, TextEdit, Url, WorkDoneProgressOptions, WorkspaceEdit, WorkspaceFoldersServerCapabilities, WorkspaceServerCapabilities + CodeAction, CodeActionKind, CodeActionOptions, CodeActionOrCommand, CodeActionParams, + CodeActionProviderCapability, CodeActionResponse, ConfigurationItem, Diagnostic, + DiagnosticOptions, DiagnosticServerCapabilities, DidChangeConfigurationParams, + DidChangeTextDocumentParams, DidChangeWatchedFilesParams, DidCloseTextDocumentParams, + DidOpenTextDocumentParams, DidSaveTextDocumentParams, DocumentDiagnosticParams, + DocumentDiagnosticReport, DocumentDiagnosticReportResult, FullDocumentDiagnosticReport, + InitializeParams, InitializeResult, InitializedParams, OneOf, + RelatedFullDocumentDiagnosticReport, ServerCapabilities, ServerInfo, + TextDocumentSyncCapability, TextDocumentSyncKind, TextEdit, Url, WorkDoneProgressOptions, + WorkspaceEdit, WorkspaceFoldersServerCapabilities, WorkspaceServerCapabilities, }, Client, LanguageServer, LspService, Server, }; @@ -108,12 +117,14 @@ impl LanguageServer for Backend { }), file_operations: None, }), - diagnostic_provider: Some(DiagnosticServerCapabilities::Options(DiagnosticOptions { - identifier: Some("oxc".into()), - inter_file_dependencies: false, - workspace_diagnostics: false, - work_done_progress_options: WorkDoneProgressOptions::default(), - })), + diagnostic_provider: Some(DiagnosticServerCapabilities::Options( + DiagnosticOptions { + identifier: Some("oxc".into()), + inter_file_dependencies: false, + workspace_diagnostics: false, + work_done_progress_options: WorkDoneProgressOptions::default(), + }, + )), code_action_provider: Some(CodeActionProviderCapability::Options( CodeActionOptions { code_action_kinds: Some(vec![CodeActionKind::QUICKFIX]), @@ -203,32 +214,41 @@ impl LanguageServer for Backend { } } - async fn diagnostic(&self, params: DocumentDiagnosticParams) -> Result { - let content = self.document_content_cache.get(¶ms.text_document.uri).map(|entry| entry.value().to_owned()); + async fn diagnostic( + &self, + params: DocumentDiagnosticParams, + ) -> Result { + let content = self + .document_content_cache + .get(¶ms.text_document.uri) + .map(|entry| entry.value().to_owned()); let Some(entry) = self.document_content_cache.get(¶ms.text_document.uri) else { return Err(Error::new(ErrorCode::InvalidParams)); }; - + let Some(result) = self.lint_uri(entry.key(), content).await else { - return Ok(DocumentDiagnosticReportResult::Report(DocumentDiagnosticReport::Full(RelatedFullDocumentDiagnosticReport { - related_documents: None, - full_document_diagnostic_report: FullDocumentDiagnosticReport::default() - }))) + return Ok(DocumentDiagnosticReportResult::Report(DocumentDiagnosticReport::Full( + RelatedFullDocumentDiagnosticReport { + related_documents: None, + full_document_diagnostic_report: FullDocumentDiagnosticReport::default(), + }, + ))); }; self.diagnostics_report_map.insert(entry.key().to_string(), result.clone()); - Ok(DocumentDiagnosticReportResult::Report(DocumentDiagnosticReport::Full(RelatedFullDocumentDiagnosticReport { - related_documents: None, - full_document_diagnostic_report: FullDocumentDiagnosticReport { - items: result.into_iter().map(|report| report.diagnostic).collect(), - ..FullDocumentDiagnosticReport::default() + Ok(DocumentDiagnosticReportResult::Report(DocumentDiagnosticReport::Full( + RelatedFullDocumentDiagnosticReport { + related_documents: None, + full_document_diagnostic_report: FullDocumentDiagnosticReport { + items: result.into_iter().map(|report| report.diagnostic).collect(), + ..FullDocumentDiagnosticReport::default() + }, }, - }))) + ))) } - async fn code_action(&self, params: CodeActionParams) -> Result> { let uri = params.text_document.uri; @@ -376,7 +396,7 @@ impl Backend { return None; }; - self.server_linter.read().await.run_single(&uri, content) + self.server_linter.read().await.run_single(&uri, content) } async fn handle_file_update(&self, uri: Url, content: Option, version: Option) { if let Some(diagnostics) = self.lint_uri(&uri, content).await { diff --git a/editors/vscode/client/extension.ts b/editors/vscode/client/extension.ts index 1d6dda0f91ea9..e12030456f6a7 100644 --- a/editors/vscode/client/extension.ts +++ b/editors/vscode/client/extension.ts @@ -163,9 +163,9 @@ export async function activate(context: ExtensionContext) { return true; } - return !configService.config.enable - } - } + return !configService.config.enable; + }, + }, }; // Create the language client and start the client. From 733bb53b5207fa49b231b6ee4bcf3987057344a6 Mon Sep 17 00:00:00 2001 From: Sysix Date: Sun, 24 Nov 2024 18:52:52 +0100 Subject: [PATCH 3/6] feat(language_server)!: add capability diagnosticProvider --- crates/oxc_language_server/src/main.rs | 71 ++++++++++++++++---------- 1 file changed, 44 insertions(+), 27 deletions(-) diff --git a/crates/oxc_language_server/src/main.rs b/crates/oxc_language_server/src/main.rs index dd8b5be25d9be..da717572e0b6c 100644 --- a/crates/oxc_language_server/src/main.rs +++ b/crates/oxc_language_server/src/main.rs @@ -17,12 +17,12 @@ use tower_lsp::{ CodeActionProviderCapability, CodeActionResponse, ConfigurationItem, Diagnostic, DiagnosticOptions, DiagnosticServerCapabilities, DidChangeConfigurationParams, DidChangeTextDocumentParams, DidChangeWatchedFilesParams, DidCloseTextDocumentParams, - DidOpenTextDocumentParams, DidSaveTextDocumentParams, DocumentDiagnosticParams, - DocumentDiagnosticReport, DocumentDiagnosticReportResult, FullDocumentDiagnosticReport, - InitializeParams, InitializeResult, InitializedParams, OneOf, - RelatedFullDocumentDiagnosticReport, ServerCapabilities, ServerInfo, - TextDocumentSyncCapability, TextDocumentSyncKind, TextEdit, Url, WorkDoneProgressOptions, - WorkspaceEdit, WorkspaceFoldersServerCapabilities, WorkspaceServerCapabilities, + DidOpenTextDocumentParams, DocumentDiagnosticParams, DocumentDiagnosticReport, + DocumentDiagnosticReportResult, FullDocumentDiagnosticReport, InitializeParams, + InitializeResult, InitializedParams, OneOf, RelatedFullDocumentDiagnosticReport, + ServerCapabilities, ServerInfo, TextDocumentSyncCapability, TextDocumentSyncKind, TextEdit, + Url, WorkDoneProgressOptions, WorkspaceEdit, WorkspaceFoldersServerCapabilities, + WorkspaceServerCapabilities, }, Client, LanguageServer, LspService, Server, }; @@ -33,7 +33,7 @@ struct Backend { client: Client, root_uri: OnceCell>, server_linter: RwLock, - document_content_cache: DashMap, + document_content_cache: DashMap, diagnostics_report_map: DashMap>, options: Mutex, gitignore_glob: Mutex>, @@ -165,7 +165,7 @@ impl LanguageServer for Backend { debug!("{:?}", &changed_options.get_lint_level()); if changed_options.get_lint_level() == SyntheticRunLevel::Disable { // clear all exists diagnostics when linter is disabled - let opened_files = self.diagnostics_report_map.iter().map(|k| k.key().to_string()); + let opened_files = self.document_content_cache.iter().map(|k| k.key().to_string()); let cleared_diagnostics = opened_files .into_iter() .map(|uri| { @@ -180,6 +180,7 @@ impl LanguageServer for Backend { }) .collect::>(); self.publish_all_diagnostics(&cleared_diagnostics).await; + self.diagnostics_report_map.clear(); } *self.options.lock().await = changed_options; } @@ -199,18 +200,19 @@ impl LanguageServer for Backend { } async fn did_open(&self, params: DidOpenTextDocumentParams) { - self.document_content_cache.insert(params.text_document.uri, params.text_document.text); + self.document_content_cache + .insert(params.text_document.uri.to_string(), params.text_document.text); } async fn did_close(&self, params: DidCloseTextDocumentParams) { - self.document_content_cache.remove(¶ms.text_document.uri); + self.document_content_cache.remove(¶ms.text_document.uri.to_string()); } async fn did_change(&self, params: DidChangeTextDocumentParams) { let content = params.content_changes.first().map(|c| c.text.clone()); if let Some(content) = content { - self.document_content_cache.insert(params.text_document.uri, content); + self.document_content_cache.insert(params.text_document.uri.to_string(), content); } } @@ -218,16 +220,22 @@ impl LanguageServer for Backend { &self, params: DocumentDiagnosticParams, ) -> Result { + // the file is ignored, return empty result + if self.is_ignored(¶ms.text_document.uri).await { + return Ok(DocumentDiagnosticReportResult::Report(DocumentDiagnosticReport::Full( + RelatedFullDocumentDiagnosticReport { + related_documents: None, + full_document_diagnostic_report: FullDocumentDiagnosticReport::default(), + }, + ))); + } + let content = self .document_content_cache - .get(¶ms.text_document.uri) + .get(¶ms.text_document.uri.to_string()) .map(|entry| entry.value().to_owned()); - let Some(entry) = self.document_content_cache.get(¶ms.text_document.uri) else { - return Err(Error::new(ErrorCode::InvalidParams)); - }; - - let Some(result) = self.lint_uri(entry.key(), content).await else { + let Some(result) = self.lint_uri(¶ms.text_document.uri, content).await else { return Ok(DocumentDiagnosticReportResult::Report(DocumentDiagnosticReport::Full( RelatedFullDocumentDiagnosticReport { related_documents: None, @@ -236,8 +244,6 @@ impl LanguageServer for Backend { ))); }; - self.diagnostics_report_map.insert(entry.key().to_string(), result.clone()); - Ok(DocumentDiagnosticReportResult::Report(DocumentDiagnosticReport::Full( RelatedFullDocumentDiagnosticReport { related_documents: None, @@ -357,10 +363,12 @@ impl Backend { } 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) + join_all(self.document_content_cache.iter().map(|map| { + self.lint_file_and_publish_diagnostic( + Url::from_str(map.key()).unwrap(), + Some(map.value().clone()), + None, + ) })) .await; } @@ -396,9 +404,20 @@ impl Backend { return None; }; - self.server_linter.read().await.run_single(&uri, content) + let result = self.server_linter.read().await.run_single(&uri, content); + + if result.is_some() { + self.diagnostics_report_map.insert(uri.to_string(), result.clone().unwrap()); + } + + result } - async fn handle_file_update(&self, uri: Url, content: Option, version: Option) { + async fn lint_file_and_publish_diagnostic( + &self, + uri: Url, + content: Option, + version: Option, + ) { if let Some(diagnostics) = self.lint_uri(&uri, content).await { self.client .publish_diagnostics( @@ -407,8 +426,6 @@ impl Backend { version, ) .await; - - self.diagnostics_report_map.insert(uri.to_string(), diagnostics); } } From 6f5a7374d26a52c39773b9f6aa76e75eac48a672 Mon Sep 17 00:00:00 2001 From: Sysix Date: Sun, 24 Nov 2024 18:57:31 +0100 Subject: [PATCH 4/6] feat(language_server)!: add capability diagnosticProvider --- crates/oxc_language_server/README.md | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/crates/oxc_language_server/README.md b/crates/oxc_language_server/README.md index 8e03c90d0cd6b..4ae786c959be1 100644 --- a/crates/oxc_language_server/README.md +++ b/crates/oxc_language_server/README.md @@ -8,6 +8,9 @@ This crate provides an [LSP](https://microsoft.github.io/language-server-protoco - Workspace - [Workspace Folders](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspaceFoldersServerCapabilities): `true` - File Operations: `false` +- [Diagnostic Provider](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_pullDiagnostics) + - `interFileDependencies`: `false` + - `workspaceDiagnostics`: `false` - [Code Actions Provider](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#codeActionKind): - `quickfix` @@ -34,20 +37,20 @@ The server will revalidate the diagnostics for all open files and send one or mo #### [textDocument/didOpen](https://microsoft.github.io/language-server-protocol/specification#textDocument_didOpen) -The server will validate the file content and send a [textDocument/publishDiagnostics](#textdocumentpublishdiagnostics) request to the client. - -#### [textDocument/didSave](https://microsoft.github.io/language-server-protocol/specification#textDocument_didSave) - -When the configuration `run` is set to `onSave`, the server will validate the file content and send a [textDocument/publishDiagnostics](#textdocumentpublishdiagnostics) request to the client. +It will save the reference internal. #### [textDocument/didChange](https://microsoft.github.io/language-server-protocol/specification#textDocument_didChange) -When the configuration `run` is set to `onType`, the server will validate the file content and send a [textDocument/publishDiagnostics](#textdocumentpublishdiagnostics) request to the client. +It will update the reference internal. #### [textDocument/didClose](https://microsoft.github.io/language-server-protocol/specification#textDocument_didClose) It will remove the reference internal. +#### [textDocument/diagnostic](https://microsoft.github.io/language-server-protocol/specification#textDocument_diagnostic) + +Returns all Diagnostics for the requested file + #### [textDocument/codeAction](https://microsoft.github.io/language-server-protocol/specification#textDocument_codeAction) Returns a list of [CodeAction](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_codeAction) From e6e6e5c02a51fa28ab8b0fce5d6a46214dbbd34c Mon Sep 17 00:00:00 2001 From: Sysix Date: Sun, 24 Nov 2024 19:05:11 +0100 Subject: [PATCH 5/6] feat(language_server)!: add capability diagnosticProvider --- crates/oxc_language_server/src/main.rs | 27 ++++---------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/crates/oxc_language_server/src/main.rs b/crates/oxc_language_server/src/main.rs index da717572e0b6c..754c5c98cbca4 100644 --- a/crates/oxc_language_server/src/main.rs +++ b/crates/oxc_language_server/src/main.rs @@ -48,29 +48,17 @@ enum Run { #[derive(Debug, Serialize, Deserialize, Clone)] #[serde(rename_all = "camelCase")] struct Options { - run: Run, enable: bool, config_path: String, } impl Default for Options { fn default() -> Self { - Self { enable: true, run: Run::default(), config_path: ".eslintrc".into() } + Self { enable: true, config_path: ".eslintrc".into() } } } impl Options { - fn get_lint_level(&self) -> SyntheticRunLevel { - if self.enable { - match self.run { - Run::OnSave => SyntheticRunLevel::OnSave, - Run::OnType => SyntheticRunLevel::OnType, - } - } else { - SyntheticRunLevel::Disable - } - } - fn get_config_path(&self) -> Option { if self.config_path.is_empty() { None @@ -80,13 +68,6 @@ impl Options { } } -#[derive(Debug, PartialEq, PartialOrd, Clone, Copy)] -enum SyntheticRunLevel { - Disable, - OnSave, - OnType, -} - #[tower_lsp::async_trait] impl LanguageServer for Backend { async fn initialize(&self, params: InitializeParams) -> Result { @@ -162,8 +143,8 @@ impl LanguageServer for Backend { options }; - debug!("{:?}", &changed_options.get_lint_level()); - if changed_options.get_lint_level() == SyntheticRunLevel::Disable { + debug!("{:?}", &changed_options.enable); + if !changed_options.enable { // clear all exists diagnostics when linter is disabled let opened_files = self.document_content_cache.iter().map(|k| k.key().to_string()); let cleared_diagnostics = opened_files @@ -404,7 +385,7 @@ impl Backend { return None; }; - let result = self.server_linter.read().await.run_single(&uri, content); + let result = self.server_linter.read().await.run_single(uri, content); if result.is_some() { self.diagnostics_report_map.insert(uri.to_string(), result.clone().unwrap()); From 0b4c93f4d423f6a3378cd7dfc52bdca73e17aaf0 Mon Sep 17 00:00:00 2001 From: Sysix Date: Sun, 24 Nov 2024 19:26:44 +0100 Subject: [PATCH 6/6] feat(language_server)!: add capability diagnosticProvider --- crates/oxc_language_server/src/main.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/crates/oxc_language_server/src/main.rs b/crates/oxc_language_server/src/main.rs index 754c5c98cbca4..d584dae4749a9 100644 --- a/crates/oxc_language_server/src/main.rs +++ b/crates/oxc_language_server/src/main.rs @@ -38,13 +38,7 @@ struct Backend { options: Mutex, gitignore_glob: Mutex>, } -#[derive(Debug, Serialize, Deserialize, Default, PartialEq, PartialOrd, Clone, Copy)] -#[serde(rename_all = "camelCase")] -enum Run { - OnSave, - #[default] - OnType, -} + #[derive(Debug, Serialize, Deserialize, Clone)] #[serde(rename_all = "camelCase")] struct Options {