summaryrefslogtreecommitdiff
path: root/cli/lsp/language_server.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/lsp/language_server.rs')
-rw-r--r--cli/lsp/language_server.rs21
1 files changed, 14 insertions, 7 deletions
diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs
index 08ebfccee..9e553b8b9 100644
--- a/cli/lsp/language_server.rs
+++ b/cli/lsp/language_server.rs
@@ -1632,23 +1632,30 @@ impl Inner {
&self,
params: DocumentFormattingParams,
) -> LspResult<Option<Vec<TextEdit>>> {
- let specifier = self
+ let mut specifier = self
.url_map
.normalize_url(&params.text_document.uri, LspUrlKind::File);
+ // skip formatting any files ignored by the config file
+ if !self.fmt_options.files.matches_specifier(&specifier) {
+ return Ok(None);
+ }
let document = match self.documents.get(&specifier) {
Some(doc) if doc.is_open() => doc,
_ => return Ok(None),
};
- let mark = self.performance.mark("formatting", Some(&params));
+ // Detect vendored paths. Vendor file URLs will normalize to their remote
+ // counterparts, but for formatting we want to favour the file URL.
+ // TODO(nayeemrmn): Implement `Document::file_resource_path()` or similar.
+ if specifier.scheme() != "file"
+ && params.text_document.uri.scheme() == "file"
+ {
+ specifier = params.text_document.uri.clone();
+ }
let file_path = specifier_to_file_path(&specifier).map_err(|err| {
error!("{}", err);
LspError::invalid_request()
})?;
-
- // skip formatting any files ignored by the config file
- if !self.fmt_options.files.matches_specifier(&specifier) {
- return Ok(None);
- }
+ let mark = self.performance.mark("formatting", Some(&params));
// spawn a blocking task to allow doing other work while this is occurring
let text_edits = deno_core::unsync::spawn_blocking({