summaryrefslogtreecommitdiff
path: root/cli/tests/integration/lsp_tests.rs
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2023-10-17 02:51:42 +0100
committerGitHub <noreply@github.com>2023-10-17 02:51:42 +0100
commit659cd90758c7fbfc7dd5896e35c20f3a79ec65cb (patch)
treeaebec825ffa1995b804abc87bfc45de87d549eed /cli/tests/integration/lsp_tests.rs
parentebb7fe412e97e851a9373be71931f13930e7a02e (diff)
feat(lsp): respect "typescript.preferences.quoteStyle" when deno.json is absent (#20891)
Diffstat (limited to 'cli/tests/integration/lsp_tests.rs')
-rw-r--r--cli/tests/integration/lsp_tests.rs145
1 files changed, 145 insertions, 0 deletions
diff --git a/cli/tests/integration/lsp_tests.rs b/cli/tests/integration/lsp_tests.rs
index 50b01b2ea..39b9b16b8 100644
--- a/cli/tests/integration/lsp_tests.rs
+++ b/cli/tests/integration/lsp_tests.rs
@@ -5570,6 +5570,151 @@ fn lsp_code_actions_imports_respects_fmt_config() {
}
#[test]
+fn lsp_quote_style_from_workspace_settings() {
+ let context = TestContextBuilder::new().use_temp_cwd().build();
+ let temp_dir = context.temp_dir();
+ 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.write_notification(
+ "workspace/didChangeConfiguration",
+ json!({
+ "settings": {}
+ }),
+ );
+ let settings = json!({
+ "typescript": {
+ "preferences": {
+ "quoteStyle": "single",
+ },
+ },
+ });
+ // one for the workspace
+ client.handle_configuration_request(&settings);
+ // one for the specifier
+ client.handle_configuration_request(&settings);
+
+ let code_action_params = 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": 56 },
+ "end": { "line": 1, "character": 73 },
+ },
+ "severity": 1,
+ "code": 2304,
+ "source": "deno-ts",
+ "message": "Cannot find name 'DuckConfigOptions'.",
+ }],
+ "only": ["quickfix"],
+ },
+ });
+
+ let res =
+ client.write_request("textDocument/codeAction", code_action_params.clone());
+ // Expect single quotes in the auto-import.
+ assert_eq!(
+ res,
+ json!([{
+ "title": "Add import from \"./file01.ts\"",
+ "kind": "quickfix",
+ "diagnostics": [{
+ "range": {
+ "start": { "line": 1, "character": 56 },
+ "end": { "line": 1, "character": 73 },
+ },
+ "severity": 1,
+ "code": 2304,
+ "source": "deno-ts",
+ "message": "Cannot find name 'DuckConfigOptions'.",
+ }],
+ "edit": {
+ "documentChanges": [{
+ "textDocument": {
+ "uri": temp_dir.uri().join("file00.ts").unwrap(),
+ "version": null,
+ },
+ "edits": [{
+ "range": {
+ "start": { "line": 0, "character": 0 },
+ "end": { "line": 0, "character": 0 },
+ },
+ "newText": "import { DuckConfigOptions } from './file01.ts';\n",
+ }],
+ }],
+ },
+ }]),
+ );
+
+ // It should ignore the workspace setting if a `deno.json` is present.
+ temp_dir.write("./deno.json", json!({}).to_string());
+ client.did_change_watched_files(json!({
+ "changes": [{
+ "uri": temp_dir.uri().join("deno.json").unwrap(),
+ "type": 1,
+ }],
+ }));
+
+ let res = client.write_request("textDocument/codeAction", code_action_params);
+ // Expect double quotes in the auto-import.
+ assert_eq!(
+ res,
+ json!([{
+ "title": "Add import from \"./file01.ts\"",
+ "kind": "quickfix",
+ "diagnostics": [{
+ "range": {
+ "start": { "line": 1, "character": 56 },
+ "end": { "line": 1, "character": 73 },
+ },
+ "severity": 1,
+ "code": 2304,
+ "source": "deno-ts",
+ "message": "Cannot find name 'DuckConfigOptions'.",
+ }],
+ "edit": {
+ "documentChanges": [{
+ "textDocument": {
+ "uri": temp_dir.uri().join("file00.ts").unwrap(),
+ "version": null,
+ },
+ "edits": [{
+ "range": {
+ "start": { "line": 0, "character": 0 },
+ "end": { "line": 0, "character": 0 },
+ },
+ "newText": "import { DuckConfigOptions } from \"./file01.ts\";\n",
+ }],
+ }],
+ },
+ }]),
+ );
+}
+
+#[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();