mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
feat(lsp): respect editor indentation options (#24181)
This commit is contained in:
parent
284ba71362
commit
7dcbc3b674
2 changed files with 72 additions and 9 deletions
|
@ -1331,12 +1331,14 @@ impl Inner {
|
|||
|
||||
// spawn a blocking task to allow doing other work while this is occurring
|
||||
let text_edits = deno_core::unsync::spawn_blocking({
|
||||
let fmt_options = self
|
||||
let mut fmt_options = self
|
||||
.config
|
||||
.tree
|
||||
.fmt_options_for_specifier(&specifier)
|
||||
.options
|
||||
.clone();
|
||||
fmt_options.use_tabs = Some(!params.options.insert_spaces);
|
||||
fmt_options.indent_width = Some(params.options.tab_size as u8);
|
||||
let document = document.clone();
|
||||
move || {
|
||||
let format_result = match document.maybe_parsed_source() {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue