diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2022-12-20 15:19:35 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-20 15:19:35 -0500 |
commit | 423474caa88f658477ed9f2df1099b7037166c3a (patch) | |
tree | 44d203094c1b9f6857653157a100a98b3a88f33f /cli/lsp/language_server.rs | |
parent | fcca54d3ba2b5c1f9f45b70fde46ba07bde4d07b (diff) |
fix(lsp/format): language formatter used should be based on language id (#17148)
Closes #11897
Diffstat (limited to 'cli/lsp/language_server.rs')
-rw-r--r-- | cli/lsp/language_server.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index a97b3d1f2..e23db159a 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -1212,6 +1212,14 @@ impl Inner { } Some(Err(err)) => Err(anyhow!("{}", err)), None => { + // the file path is only used to determine what formatter should + // be used to format the file, so give the filepath an extension + // that matches what the user selected as the language + let file_path = document + .maybe_language_id() + .and_then(|id| id.as_extension()) + .map(|ext| file_path.with_extension(ext)) + .unwrap_or(file_path); // it's not a js/ts file, so attempt to format its contents format_file(&file_path, &document.content(), &fmt_options) } |