From 85e9a790c9873a042d22eb4cea24d195fd27334f Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Wed, 12 Jun 2024 17:41:01 +0100 Subject: feat(lsp): respect editor indentation options (#24181) --- tests/integration/lsp_tests.rs | 77 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 69 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/integration/lsp_tests.rs b/tests/integration/lsp_tests.rs index 62cb84457..944285293 100644 --- a/tests/integration/lsp_tests.rs +++ b/tests/integration/lsp_tests.rs @@ -9765,13 +9765,13 @@ fn lsp_format_json() { let res = client.write_request( "textDocument/formatting", json!({ - "textDocument": { - "uri": json_file.uri(), - }, - "options": { - "tabSize": 2, - "insertSpaces": true - } + "textDocument": { + "uri": json_file.uri(), + }, + "options": { + "tabSize": 2, + "insertSpaces": true + } }), ); @@ -9802,6 +9802,67 @@ fn lsp_format_json() { client.shutdown(); } +#[test] +fn lsp_format_editor_options() { + let context = TestContextBuilder::new().use_temp_cwd().build(); + let temp_dir = context.temp_dir(); + let file = source_file( + temp_dir.path().join("file.ts"), + "if (true) {\n console.log();\n}\n", + ); + let mut client = context.new_lsp_command().build(); + client.initialize_default(); + let res = client.write_request( + "textDocument/formatting", + json!({ + "textDocument": { + "uri": file.uri(), + }, + "options": { + "tabSize": 4, + "insertSpaces": true, + }, + }), + ); + assert_eq!( + res, + json!([ + { + "range": { + "start": { "line": 1, "character": 0 }, + "end": { "line": 1, "character": 0 }, + }, + "newText": " ", + }, + ]) + ); + let res = client.write_request( + "textDocument/formatting", + json!({ + "textDocument": { + "uri": file.uri(), + }, + "options": { + "tabSize": 2, + "insertSpaces": false, + }, + }), + ); + assert_eq!( + res, + json!([ + { + "range": { + "start": { "line": 1, "character": 0 }, + "end": { "line": 1, "character": 2 }, + }, + "newText": "\t", + }, + ]) + ); + client.shutdown(); +} + #[test] fn lsp_json_no_diagnostics() { let context = TestContextBuilder::new().use_temp_cwd().build(); @@ -9964,7 +10025,7 @@ fn lsp_format_with_config() { }, "options": { "tabSize": 2, - "insertSpaces": true + "insertSpaces": false } }), ); -- cgit v1.2.3