diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2023-09-18 20:48:32 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-18 20:48:32 +0100 |
commit | 86c04f43e0eda139a262c4f2e106e9b11e8d7da8 (patch) | |
tree | 71e8661fdaf7ac0e677707d76d6c82d2e0d1dade /cli/tests | |
parent | f7ba7013045fc0629092ea4e07ce5c768a7ee95f (diff) |
fix(lsp): pass quote preference to tsc (#20547)
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/integration/lsp_tests.rs | 168 |
1 files changed, 168 insertions, 0 deletions
diff --git a/cli/tests/integration/lsp_tests.rs b/cli/tests/integration/lsp_tests.rs index de9626620..8b265f911 100644 --- a/cli/tests/integration/lsp_tests.rs +++ b/cli/tests/integration/lsp_tests.rs @@ -4907,6 +4907,174 @@ fn lsp_code_actions_refactor() { } #[test] +fn lsp_code_actions_imports_respects_fmt_config() { + let context = TestContextBuilder::new().use_temp_cwd().build(); + let temp_dir = context.temp_dir(); + temp_dir.write( + "./deno.jsonc", + json!({ + "fmt": { + "semiColons": false, + "singleQuote": true, + } + }) + .to_string(), + ); + temp_dir.write( + "file00.ts", + r#" + export interface MallardDuckConfigOptions extends DuckConfigOptions { + kind: "mallard"; + } + "#, + ); + temp_dir.write( + "file01.ts", + r#" + export interface DuckConfigOptions { + kind: string; + quacks: boolean; + } + "#, + ); + let mut client = context.new_lsp_command().build(); + client.initialize_default(); + client.did_open(json!({ + "textDocument": { + "uri": temp_dir.uri().join("file00.ts").unwrap(), + "languageId": "typescript", + "version": 1, + "text": temp_dir.read_to_string("file00.ts"), + } + })); + client.did_open(json!({ + "textDocument": { + "uri": temp_dir.uri().join("file01.ts").unwrap(), + "languageId": "typescript", + "version": 1, + "text": temp_dir.read_to_string("file01.ts"), + } + })); + + let res = client.write_request( + "textDocument/codeAction", + json!({ + "textDocument": { + "uri": temp_dir.uri().join("file00.ts").unwrap() + }, + "range": { + "start": { "line": 0, "character": 0 }, + "end": { "line": 4, "character": 0 } + }, + "context": { + "diagnostics": [{ + "range": { + "start": { "line": 1, "character": 55 }, + "end": { "line": 1, "character": 64 } + }, + "severity": 1, + "code": 2304, + "source": "deno-ts", + "message": "Cannot find name 'DuckConfigOptions'." + }], + "only": ["quickfix"] + } + }), + ); + assert_eq!( + res, + json!([{ + "title": "Add import from \"./file01.ts\"", + "kind": "quickfix", + "diagnostics": [{ + "range": { + "start": { "line": 1, "character": 55 }, + "end": { "line": 1, "character": 64 } + }, + "severity": 1, + "code": 2304, + "source": "deno-ts", + "message": "Cannot find name 'DuckConfigOptions'." + }], + "edit": { + "documentChanges": [{ + "textDocument": { + "uri": temp_dir.uri().join("file00.ts").unwrap(), + "version": 1 + }, + "edits": [{ + "range": { + "start": { "line": 0, "character": 0 }, + "end": { "line": 0, "character": 0 } + }, + "newText": "import { DuckConfigOptions } from './file01.ts'\n" + }] + }] + } + }]) + ); + let res = client.write_request( + "codeAction/resolve", + json!({ + "title": "Add all missing imports", + "kind": "quickfix", + "diagnostics": [{ + "range": { + "start": { "line": 1, "character": 55 }, + "end": { "line": 1, "character": 64 } + }, + "severity": 1, + "code": 2304, + "source": "deno-ts", + "message": "Cannot find name 'DuckConfigOptions'." + }], + "data": { + "specifier": temp_dir.uri().join("file00.ts").unwrap(), + "fixId": "fixMissingImport" + } + }), + ); + assert_eq!( + res, + json!({ + "title": "Add all missing imports", + "kind": "quickfix", + "diagnostics": [{ + "range": { + "start": { "line": 1, "character": 55 }, + "end": { "line": 1, "character": 64 } + }, + "severity": 1, + "code": 2304, + "source": "deno-ts", + "message": "Cannot find name 'DuckConfigOptions'." + }], + "edit": { + "documentChanges": [{ + "textDocument": { + "uri": temp_dir.uri().join("file00.ts").unwrap(), + "version": 1 + }, + "edits": [{ + "range": { + "start": { "line": 0, "character": 0 }, + "end": { "line": 0, "character": 0 } + }, + "newText": "import { DuckConfigOptions } from './file01.ts'\n" + }] + }] + }, + "data": { + "specifier": temp_dir.uri().join("file00.ts").unwrap(), + "fixId": "fixMissingImport" + } + }) + ); + + client.shutdown(); +} + +#[test] fn lsp_code_actions_refactor_no_disabled_support() { let context = TestContextBuilder::new().use_temp_cwd().build(); let mut client = context.new_lsp_command().build(); |