diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 55bc205..8d1083b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,7 +9,7 @@ jobs: wait: runs-on: ubuntu-latest steps: - - name: Wait for build check to succeed + - name: Wait for checks to succeed uses: poseidon/wait-for-status-checks@v0.3.0 with: token: ${{ secrets.GITHUB_TOKEN }} diff --git a/crates/typos-lsp/src/lsp.rs b/crates/typos-lsp/src/lsp.rs index bcfccb1..1097af4 100644 --- a/crates/typos-lsp/src/lsp.rs +++ b/crates/typos-lsp/src/lsp.rs @@ -22,6 +22,7 @@ pub struct Backend<'s, 'p> { #[derive(Default)] struct BackendState<'s> { + severity: Option, workspace_folders: Vec, router: Router>, } @@ -138,11 +139,37 @@ impl LanguageServer for Backend<'static, 'static> { tracing::debug!("Client supports diagnostics data") } else { tracing::warn!( - "Client does not support diagnostics data.. code actions will not be available" + "Client does not support diagnostics data. Code actions will not be available" ) } let mut state = self.state.lock().unwrap(); + + if let Some(ops) = params.initialization_options { + if let Some(value) = ops + .as_object() + .and_then(|o| o.get("diagnosticSeverity").cloned()) + { + match value.as_str().unwrap_or("").to_lowercase().as_str() { + "error" => { + state.severity = Some(DiagnosticSeverity::ERROR); + } + "warning" => { + state.severity = Some(DiagnosticSeverity::WARNING); + } + "information" => { + state.severity = Some(DiagnosticSeverity::INFORMATION); + } + "hint" => { + state.severity = Some(DiagnosticSeverity::HINT); + } + _ => { + tracing::warn!("Unknown diagnostic severity: {}", value); + } + } + } + } + if let Err(e) = state.set_workspace_folders(params.workspace_folders.unwrap_or_default()) { tracing::warn!("Cannot set workspace folders: {}", e); } @@ -362,7 +389,7 @@ impl<'s, 'p> Backend<'s, 'p> { Position::new(line_num as u32, line_pos as u32), Position::new(line_num as u32, (line_pos + typo.typo.len()) as u32), ), - severity: Some(DiagnosticSeverity::WARNING), + severity: state.severity, source: Some("typos".to_string()), message: match &typo.corrections { typos::Status::Invalid => format!("`{}` is disallowed", typo.typo), diff --git a/crates/typos-lsp/tests/integration_test.rs b/crates/typos-lsp/tests/integration_test.rs index d8dd5ff..43a0539 100644 --- a/crates/typos-lsp/tests/integration_test.rs +++ b/crates/typos-lsp/tests/integration_test.rs @@ -30,6 +30,9 @@ async fn test_e2e() { "jsonrpc": "2.0", "method": "initialize", "params": { + "initializationOptions": { + "diagnosticSeverity": "Warning" + }, "capabilities": { "textDocument": { "publishDiagnostics": { "dataSupport": true } } } @@ -202,6 +205,9 @@ async fn test_config_file_e2e() { "jsonrpc": "2.0", "method": "initialize", "params": {{ + "initializationOptions": {{ + "diagnosticSeverity": "Warning" + }}, "capabilities": {{ "textDocument": {{ "publishDiagnostics": {{ "dataSupport": true }} }} }}, diff --git a/package.json b/package.json index cf7a842..cdc0da9 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,24 @@ "type": "string", "description": "Path to the `typos-lsp` binary. If empty the bundled binary will be used." }, + "typos.diagnosticSeverity": { + "scope": "window", + "type": "string", + "enum": [ + "Error", + "Warning", + "Information", + "Hint" + ], + "enumDescriptions": [ + "Red squiggle", + "Yellow squiggle", + "Blue squiggle", + "Dots" + ], + "default": "Warning", + "description": "How typos are rendered in the editor." + }, "typos.logLevel": { "scope": "window", "type": "string", diff --git a/src/extension.ts b/src/extension.ts index e41c81b..d36d05d 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -24,7 +24,7 @@ export async function activate( context.subscriptions.push( vscode.workspace.onDidChangeConfiguration( async (e: vscode.ConfigurationChangeEvent) => { - const restartTriggeredBy = ["typos.path", "typos.logLevel"].find((s) => + const restartTriggeredBy = ["typos.path", "typos.logLevel", "typos.diagnosticSeverity"].find((s) => e.affectsConfiguration(s) ); @@ -96,6 +96,9 @@ async function createClient( ], outputChannel: outputChannel, traceOutputChannel: outputChannel, + initializationOptions: { + diagnosticSeverity: config.get("diagnosticSeverity"), + } }; return new LanguageClient(