Skip to content

Commit

Permalink
fix(language_server): do not tell clients about codeActionProvider
Browse files Browse the repository at this point in the history
…when they do not support `codeActionLiteralSupport` (#7445)

VSCode output:

```
                "codeActionLiteralSupport": {
                    "codeActionKind": {
                        "valueSet": [
                            "",
                            "quickfix",
                            "refactor",
                            "refactor.extract",
                            "refactor.inline",
                            "refactor.rewrite",
                            "source",
                            "source.organizeImports"
                        ]
                    }
                },
```

See also eslint implementation
https://github.com/microsoft/vscode-eslint/blob/b33437b5ad9ca6c8829f373a92679660c177991b/server/src/eslintServer.ts#L221-L225
  • Loading branch information
Sysix authored Nov 25, 2024
1 parent 25d9ed9 commit a3ecbde
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions crates/oxc_language_server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,24 @@ impl LanguageServer for Backend {
info!("language server version: {:?}", env!("CARGO_PKG_VERSION"));
*self.options.lock().await = value;
}

// check if the client support some code action literal support
let code_action_provider = if params.capabilities.text_document.is_some_and(|capability| {
capability.code_action.is_some_and(|code_action| {
code_action.code_action_literal_support.is_some_and(|literal_support| {
!literal_support.code_action_kind.value_set.is_empty()
})
})
}) {
Some(CodeActionProviderCapability::Options(CodeActionOptions {
code_action_kinds: Some(vec![CodeActionKind::QUICKFIX]),
work_done_progress_options: WorkDoneProgressOptions { work_done_progress: None },
resolve_provider: None,
}))
} else {
None
};

self.init_linter_config().await;
Ok(InitializeResult {
server_info: Some(ServerInfo { name: "oxc".into(), version: None }),
Expand All @@ -114,15 +132,7 @@ impl LanguageServer for Backend {
}),
file_operations: None,
}),
code_action_provider: Some(CodeActionProviderCapability::Options(
CodeActionOptions {
code_action_kinds: Some(vec![CodeActionKind::QUICKFIX]),
work_done_progress_options: WorkDoneProgressOptions {
work_done_progress: None,
},
resolve_provider: None,
},
)),
code_action_provider,
..ServerCapabilities::default()
},
})
Expand Down

0 comments on commit a3ecbde

Please sign in to comment.