mirror of
https://github.com/denoland/deno.git
synced 2024-10-29 08:58:01 -04:00
feat(lsp): support clients which do not support disabled code actions (#11612)
Closes: #11610
This commit is contained in:
parent
2db381eba9
commit
f7e416bc7f
15 changed files with 265 additions and 82 deletions
|
@ -24,10 +24,11 @@ pub const SETTINGS_SECTION: &str = "deno";
|
|||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct ClientCapabilities {
|
||||
pub code_action_disabled_support: bool,
|
||||
pub line_folding_only: bool,
|
||||
pub status_notification: bool,
|
||||
pub workspace_configuration: bool,
|
||||
pub workspace_did_change_watched_files: bool,
|
||||
pub line_folding_only: bool,
|
||||
}
|
||||
|
||||
fn is_true() -> bool {
|
||||
|
@ -395,6 +396,11 @@ impl Config {
|
|||
.as_ref()
|
||||
.and_then(|it| it.line_folding_only)
|
||||
.unwrap_or(false);
|
||||
self.client_capabilities.code_action_disabled_support = text_document
|
||||
.code_action
|
||||
.as_ref()
|
||||
.and_then(|it| it.disabled_support)
|
||||
.unwrap_or(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1298,11 +1298,18 @@ impl Inner {
|
|||
.map(CodeActionOrCommand::CodeAction),
|
||||
);
|
||||
|
||||
let response = if !all_actions.is_empty() {
|
||||
Some(all_actions)
|
||||
} else {
|
||||
let code_action_disabled_support =
|
||||
self.config.client_capabilities.code_action_disabled_support;
|
||||
let actions: Vec<CodeActionOrCommand> = all_actions.into_iter().filter(|ca| {
|
||||
code_action_disabled_support
|
||||
|| matches!(ca, CodeActionOrCommand::CodeAction(ca) if ca.disabled.is_none())
|
||||
}).collect();
|
||||
let response = if actions.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(actions)
|
||||
};
|
||||
|
||||
self.performance.measure(mark);
|
||||
Ok(response)
|
||||
}
|
||||
|
|
|
@ -2154,6 +2154,54 @@ fn lsp_code_actions_refactor() {
|
|||
shutdown(&mut client);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lsp_code_actions_refactor_no_disabled_support() {
|
||||
let mut client = init("initialize_params_ca_no_disabled.json");
|
||||
did_open(
|
||||
&mut client,
|
||||
json!({
|
||||
"textDocument": {
|
||||
"uri": "file:///a/file.ts",
|
||||
"languageId": "typescript",
|
||||
"version": 1,
|
||||
"text": "interface A {\n a: string;\n}\n\ninterface B {\n b: string;\n}\n\nclass AB implements A, B {\n a = \"a\";\n b = \"b\";\n}\n\nnew AB().a;\n"
|
||||
}
|
||||
}),
|
||||
);
|
||||
let (maybe_res, maybe_err) = client
|
||||
.write_request(
|
||||
"textDocument/codeAction",
|
||||
json!({
|
||||
"textDocument": {
|
||||
"uri": "file:///a/file.ts"
|
||||
},
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 0,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 14,
|
||||
"character": 0
|
||||
}
|
||||
},
|
||||
"context": {
|
||||
"diagnostics": [],
|
||||
"only": [
|
||||
"refactor"
|
||||
]
|
||||
}
|
||||
}),
|
||||
)
|
||||
.unwrap();
|
||||
assert!(maybe_err.is_none());
|
||||
assert_eq!(
|
||||
maybe_res,
|
||||
Some(load_fixture("code_action_response_no_disabled.json"))
|
||||
);
|
||||
shutdown(&mut client);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lsp_code_actions_deadlock() {
|
||||
let mut client = init("initialize_params.json");
|
||||
|
|
|
@ -5,11 +5,11 @@
|
|||
"range": {
|
||||
"start": {
|
||||
"line": 0,
|
||||
"character": 7
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 0,
|
||||
"character": 33
|
||||
"line": 1,
|
||||
"character": 0
|
||||
}
|
||||
},
|
||||
"context": {
|
||||
|
|
22
cli/tests/lsp/code_action_response_no_disabled.json
Normal file
22
cli/tests/lsp/code_action_response_no_disabled.json
Normal file
|
@ -0,0 +1,22 @@
|
|||
[
|
||||
{
|
||||
"title": "Move to a new file",
|
||||
"kind": "refactor.move.newFile",
|
||||
"isPreferred": false,
|
||||
"data": {
|
||||
"specifier": "file:///a/file.ts",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 0,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 14,
|
||||
"character": 0
|
||||
}
|
||||
},
|
||||
"refactorName": "Move to a new file",
|
||||
"actionName": "Move to a new file"
|
||||
}
|
||||
}
|
||||
]
|
|
@ -1,88 +1,62 @@
|
|||
[
|
||||
{
|
||||
"title": "Extract to type alias",
|
||||
"kind": "refactor.extract.type",
|
||||
"isPreferred": true,
|
||||
"data": {
|
||||
"specifier": "file:///a/file.ts",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 0,
|
||||
"character": 7
|
||||
},
|
||||
"end": {
|
||||
"line": 0,
|
||||
"character": 33
|
||||
}
|
||||
},
|
||||
"refactorName": "Extract type",
|
||||
"actionName": "Extract to type alias"
|
||||
}
|
||||
},
|
||||
{
|
||||
"title": "Extract to interface",
|
||||
"kind": "refactor.extract.interface",
|
||||
"isPreferred": true,
|
||||
"data": {
|
||||
"specifier": "file:///a/file.ts",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 0,
|
||||
"character": 7
|
||||
},
|
||||
"end": {
|
||||
"line": 0,
|
||||
"character": 33
|
||||
}
|
||||
},
|
||||
"refactorName": "Extract type",
|
||||
"actionName": "Extract to interface"
|
||||
}
|
||||
},
|
||||
{
|
||||
"title": "Extract function",
|
||||
"title": "Extract to function in global scope",
|
||||
"kind": "refactor.extract.function",
|
||||
"isPreferred": false,
|
||||
"disabled": {
|
||||
"reason": "Statement or expression expected."
|
||||
},
|
||||
"data": {
|
||||
"specifier": "file:///a/file.ts",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 0,
|
||||
"character": 7
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 0,
|
||||
"character": 33
|
||||
"line": 1,
|
||||
"character": 0
|
||||
}
|
||||
},
|
||||
"refactorName": "Extract Symbol",
|
||||
"actionName": "Extract Function"
|
||||
"actionName": "function_scope_0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"title": "Extract constant",
|
||||
"title": "Extract to constant in enclosing scope",
|
||||
"kind": "refactor.extract.constant",
|
||||
"isPreferred": false,
|
||||
"disabled": {
|
||||
"reason": "Statement or expression expected."
|
||||
},
|
||||
"data": {
|
||||
"specifier": "file:///a/file.ts",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 0,
|
||||
"character": 7
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 0,
|
||||
"character": 33
|
||||
"line": 1,
|
||||
"character": 0
|
||||
}
|
||||
},
|
||||
"refactorName": "Extract Symbol",
|
||||
"actionName": "Extract Constant"
|
||||
"actionName": "constant_scope_0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"title": "Move to a new file",
|
||||
"kind": "refactor.move.newFile",
|
||||
"isPreferred": false,
|
||||
"data": {
|
||||
"specifier": "file:///a/file.ts",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 0,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"character": 0
|
||||
}
|
||||
},
|
||||
"refactorName": "Move to a new file",
|
||||
"actionName": "Move to a new file"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -90,18 +64,18 @@
|
|||
"kind": "refactor.rewrite.export.named",
|
||||
"isPreferred": false,
|
||||
"disabled": {
|
||||
"reason": "Could not find export statement"
|
||||
"reason": "This file already has a default export"
|
||||
},
|
||||
"data": {
|
||||
"specifier": "file:///a/file.ts",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 0,
|
||||
"character": 7
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 0,
|
||||
"character": 33
|
||||
"line": 1,
|
||||
"character": 0
|
||||
}
|
||||
},
|
||||
"refactorName": "Convert export",
|
||||
|
@ -113,18 +87,18 @@
|
|||
"kind": "refactor.rewrite.export.default",
|
||||
"isPreferred": false,
|
||||
"disabled": {
|
||||
"reason": "Could not find export statement"
|
||||
"reason": "This file already has a default export"
|
||||
},
|
||||
"data": {
|
||||
"specifier": "file:///a/file.ts",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 0,
|
||||
"character": 7
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 0,
|
||||
"character": 33
|
||||
"line": 1,
|
||||
"character": 0
|
||||
}
|
||||
},
|
||||
"refactorName": "Convert export",
|
||||
|
@ -143,15 +117,61 @@
|
|||
"range": {
|
||||
"start": {
|
||||
"line": 0,
|
||||
"character": 7
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 0,
|
||||
"character": 33
|
||||
"line": 1,
|
||||
"character": 0
|
||||
}
|
||||
},
|
||||
"refactorName": "Convert import",
|
||||
"actionName": "Convert namespace import to named imports"
|
||||
}
|
||||
},
|
||||
{
|
||||
"title": "Convert named imports to namespace import",
|
||||
"kind": "refactor.rewrite.import.namespace",
|
||||
"isPreferred": false,
|
||||
"disabled": {
|
||||
"reason": "Selection is not an import declaration."
|
||||
},
|
||||
"data": {
|
||||
"specifier": "file:///a/file.ts",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 0,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"character": 0
|
||||
}
|
||||
},
|
||||
"refactorName": "Convert import",
|
||||
"actionName": "Convert named imports to namespace import"
|
||||
}
|
||||
},
|
||||
{
|
||||
"title": "Convert to optional chain expression",
|
||||
"kind": "refactor.rewrite.expression.optionalChain",
|
||||
"isPreferred": false,
|
||||
"disabled": {
|
||||
"reason": "Could not find convertible access expression"
|
||||
},
|
||||
"data": {
|
||||
"specifier": "file:///a/file.ts",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 0,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"character": 0
|
||||
}
|
||||
},
|
||||
"refactorName": "Convert to optional chain expression",
|
||||
"actionName": "Convert to optional chain expression"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
|
@ -33,12 +33,14 @@
|
|||
"codeActionLiteralSupport": {
|
||||
"codeActionKind": {
|
||||
"valueSet": [
|
||||
"quickfix"
|
||||
"quickfix",
|
||||
"refactor"
|
||||
]
|
||||
}
|
||||
},
|
||||
"isPreferredSupport": true,
|
||||
"dataSupport": true,
|
||||
"disabledSupport": true,
|
||||
"resolveSupport": {
|
||||
"properties": [
|
||||
"edit"
|
||||
|
|
|
@ -33,12 +33,14 @@
|
|||
"codeActionLiteralSupport": {
|
||||
"codeActionKind": {
|
||||
"valueSet": [
|
||||
"quickfix"
|
||||
"quickfix",
|
||||
"refactor"
|
||||
]
|
||||
}
|
||||
},
|
||||
"isPreferredSupport": true,
|
||||
"dataSupport": true,
|
||||
"disabledSupport": true,
|
||||
"resolveSupport": {
|
||||
"properties": [
|
||||
"edit"
|
||||
|
|
64
cli/tests/lsp/initialize_params_ca_no_disabled.json
Normal file
64
cli/tests/lsp/initialize_params_ca_no_disabled.json
Normal file
|
@ -0,0 +1,64 @@
|
|||
{
|
||||
"processId": 0,
|
||||
"clientInfo": {
|
||||
"name": "test-harness",
|
||||
"version": "1.0.0"
|
||||
},
|
||||
"rootUri": null,
|
||||
"initializationOptions": {
|
||||
"enable": true,
|
||||
"cache": null,
|
||||
"codeLens": {
|
||||
"implementations": true,
|
||||
"references": true,
|
||||
"test": true
|
||||
},
|
||||
"config": "",
|
||||
"importMap": null,
|
||||
"lint": true,
|
||||
"suggest": {
|
||||
"autoImports": true,
|
||||
"completeFunctionCalls": false,
|
||||
"names": true,
|
||||
"paths": true,
|
||||
"imports": {
|
||||
"hosts": {}
|
||||
}
|
||||
},
|
||||
"unstable": false
|
||||
},
|
||||
"capabilities": {
|
||||
"textDocument": {
|
||||
"codeAction": {
|
||||
"codeActionLiteralSupport": {
|
||||
"codeActionKind": {
|
||||
"valueSet": [
|
||||
"quickfix",
|
||||
"refactor"
|
||||
]
|
||||
}
|
||||
},
|
||||
"isPreferredSupport": true,
|
||||
"dataSupport": true,
|
||||
"resolveSupport": {
|
||||
"properties": [
|
||||
"edit"
|
||||
]
|
||||
}
|
||||
},
|
||||
"foldingRange": {
|
||||
"lineFoldingOnly": true
|
||||
},
|
||||
"synchronization": {
|
||||
"dynamicRegistration": true,
|
||||
"willSave": true,
|
||||
"willSaveWaitUntil": true,
|
||||
"didSave": true
|
||||
}
|
||||
},
|
||||
"workspace": {
|
||||
"configuration": true,
|
||||
"workspaceFolders": true
|
||||
}
|
||||
}
|
||||
}
|
|
@ -27,12 +27,14 @@
|
|||
"codeActionLiteralSupport": {
|
||||
"codeActionKind": {
|
||||
"valueSet": [
|
||||
"quickfix"
|
||||
"quickfix",
|
||||
"refactor"
|
||||
]
|
||||
}
|
||||
},
|
||||
"isPreferredSupport": true,
|
||||
"dataSupport": true,
|
||||
"disabledSupport": true,
|
||||
"resolveSupport": {
|
||||
"properties": [
|
||||
"edit"
|
||||
|
|
|
@ -32,12 +32,14 @@
|
|||
"codeActionLiteralSupport": {
|
||||
"codeActionKind": {
|
||||
"valueSet": [
|
||||
"quickfix"
|
||||
"quickfix",
|
||||
"refactor"
|
||||
]
|
||||
}
|
||||
},
|
||||
"isPreferredSupport": true,
|
||||
"dataSupport": true,
|
||||
"disabledSupport": true,
|
||||
"resolveSupport": {
|
||||
"properties": [
|
||||
"edit"
|
||||
|
|
|
@ -33,12 +33,14 @@
|
|||
"codeActionLiteralSupport": {
|
||||
"codeActionKind": {
|
||||
"valueSet": [
|
||||
"quickfix"
|
||||
"quickfix",
|
||||
"refactor"
|
||||
]
|
||||
}
|
||||
},
|
||||
"isPreferredSupport": true,
|
||||
"dataSupport": true,
|
||||
"disabledSupport": true,
|
||||
"resolveSupport": {
|
||||
"properties": [
|
||||
"edit"
|
||||
|
|
|
@ -31,12 +31,14 @@
|
|||
"codeActionLiteralSupport": {
|
||||
"codeActionKind": {
|
||||
"valueSet": [
|
||||
"quickfix"
|
||||
"quickfix",
|
||||
"refactor"
|
||||
]
|
||||
}
|
||||
},
|
||||
"isPreferredSupport": true,
|
||||
"dataSupport": true,
|
||||
"disabledSupport": true,
|
||||
"resolveSupport": {
|
||||
"properties": [
|
||||
"edit"
|
||||
|
|
|
@ -33,12 +33,14 @@
|
|||
"codeActionLiteralSupport": {
|
||||
"codeActionKind": {
|
||||
"valueSet": [
|
||||
"quickfix"
|
||||
"quickfix",
|
||||
"refactor"
|
||||
]
|
||||
}
|
||||
},
|
||||
"isPreferredSupport": true,
|
||||
"dataSupport": true,
|
||||
"disabledSupport": true,
|
||||
"resolveSupport": {
|
||||
"properties": [
|
||||
"edit"
|
||||
|
|
|
@ -31,12 +31,14 @@
|
|||
"codeActionLiteralSupport": {
|
||||
"codeActionKind": {
|
||||
"valueSet": [
|
||||
"quickfix"
|
||||
"quickfix",
|
||||
"refactor"
|
||||
]
|
||||
}
|
||||
},
|
||||
"isPreferredSupport": true,
|
||||
"dataSupport": true,
|
||||
"disabledSupport": true,
|
||||
"resolveSupport": {
|
||||
"properties": [
|
||||
"edit"
|
||||
|
|
Loading…
Reference in a new issue