summaryrefslogtreecommitdiff
path: root/cli/lsp/language_server.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2021-11-23 10:38:11 -0500
committerGitHub <noreply@github.com>2021-11-23 10:38:11 -0500
commit51e3db956a5927229e3f46f4eaaf317e935f8f17 (patch)
tree1af79152c7c1edc2c9bc21e8501aad1ba5d7e426 /cli/lsp/language_server.rs
parentd8afd5683857de83f3cc80c33322df3d65377210 (diff)
fix(cli): config file should resolve paths relative to the config file (#12867)
* Add `specifier_to_file_path` to support converting a ModuleSpecifier with a unix-style path to a PathBuf on Windows.
Diffstat (limited to 'cli/lsp/language_server.rs')
-rw-r--r--cli/lsp/language_server.rs40
1 files changed, 14 insertions, 26 deletions
diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs
index a0d0ee0ad..e13215efb 100644
--- a/cli/lsp/language_server.rs
+++ b/cli/lsp/language_server.rs
@@ -60,6 +60,7 @@ use crate::config_file::TsConfig;
use crate::deno_dir;
use crate::file_fetcher::get_source_from_data_url;
use crate::fs_util;
+use crate::fs_util::specifier_to_file_path;
use crate::logger;
use crate::tools::fmt::format_file;
use crate::tools::fmt::format_parsed_source;
@@ -303,9 +304,7 @@ impl Inner {
let config_url = if let Ok(url) = Url::from_file_path(config_str) {
Ok(url)
} else if let Some(root_uri) = maybe_root_uri {
- let root_path = root_uri
- .to_file_path()
- .map_err(|_| anyhow!("Bad root_uri: {}", root_uri))?;
+ let root_path = specifier_to_file_path(&root_uri)?;
let config_path = root_path.join(config_str);
Url::from_file_path(config_path).map_err(|_| {
anyhow!("Bad file path for configuration file: \"{}\"", config_str)
@@ -319,9 +318,7 @@ impl Inner {
info!(" Resolved configuration file: \"{}\"", config_url);
let config_file = {
- let buffer = config_url
- .to_file_path()
- .map_err(|_| anyhow!("Bad uri: \"{}\"", config_url))?;
+ let buffer = specifier_to_file_path(&config_url)?;
let path = buffer
.to_str()
.ok_or_else(|| anyhow!("Bad uri: \"{}\"", config_url))?;
@@ -404,9 +401,7 @@ impl Inner {
let cache_url = if let Ok(url) = Url::from_file_path(cache_str) {
Ok(url)
} else if let Some(root_uri) = &maybe_root_uri {
- let root_path = root_uri
- .to_file_path()
- .map_err(|_| anyhow!("Bad root_uri: {}", root_uri))?;
+ let root_path = specifier_to_file_path(root_uri)?;
let cache_path = root_path.join(cache_str);
Url::from_file_path(cache_path).map_err(|_| {
anyhow!("Bad file path for import path: {:?}", cache_str)
@@ -417,9 +412,7 @@ impl Inner {
cache_str
))
}?;
- let cache_path = cache_url.to_file_path().map_err(|_| {
- anyhow!("Cannot convert \"{}\" into a file path.", cache_url)
- })?;
+ let cache_path = specifier_to_file_path(&cache_url)?;
info!(
" Resolved cache path: \"{}\"",
cache_path.to_string_lossy()
@@ -464,9 +457,7 @@ impl Inner {
anyhow!("Bad data url for import map: {:?}", import_map_str)
})
} else if let Some(root_uri) = &maybe_root_uri {
- let root_path = root_uri
- .to_file_path()
- .map_err(|_| anyhow!("Bad root_uri: {}", root_uri))?;
+ let root_path = specifier_to_file_path(root_uri)?;
let import_map_path = root_path.join(import_map_str);
Url::from_file_path(import_map_path).map_err(|_| {
anyhow!("Bad file path for import map: {:?}", import_map_str)
@@ -481,9 +472,7 @@ impl Inner {
let import_map_json = if import_map_url.scheme() == "data" {
get_source_from_data_url(&import_map_url)?.0
} else {
- let import_map_path = import_map_url.to_file_path().map_err(|_| {
- anyhow!("Cannot convert \"{}\" into a file path.", import_map_url)
- })?;
+ let import_map_path = specifier_to_file_path(&import_map_url)?;
info!(
" Resolved import map: \"{}\"",
import_map_path.to_string_lossy()
@@ -1024,11 +1013,10 @@ impl Inner {
};
let mark = self.performance.mark("formatting", Some(&params));
let file_path =
- if let Ok(file_path) = params.text_document.uri.to_file_path() {
- file_path
- } else {
- PathBuf::from(params.text_document.uri.path())
- };
+ specifier_to_file_path(&params.text_document.uri).map_err(|err| {
+ error!("{}", err);
+ LspError::invalid_request()
+ })?;
let fmt_options = if let Some(fmt_config) = self.maybe_fmt_config.as_ref() {
fmt_config.options.clone()
@@ -1913,7 +1901,7 @@ impl Inner {
.config
.root_uri
.as_ref()
- .and_then(|uri| uri.to_file_path().ok());
+ .and_then(|uri| specifier_to_file_path(uri).ok());
let mut resolved_items = Vec::<CallHierarchyIncomingCall>::new();
for item in incoming_calls.iter() {
if let Some(resolved) = item
@@ -1962,7 +1950,7 @@ impl Inner {
.config
.root_uri
.as_ref()
- .and_then(|uri| uri.to_file_path().ok());
+ .and_then(|uri| specifier_to_file_path(uri).ok());
let mut resolved_items = Vec::<CallHierarchyOutgoingCall>::new();
for item in outgoing_calls.iter() {
if let Some(resolved) = item
@@ -2018,7 +2006,7 @@ impl Inner {
.config
.root_uri
.as_ref()
- .and_then(|uri| uri.to_file_path().ok());
+ .and_then(|uri| specifier_to_file_path(uri).ok());
let mut resolved_items = Vec::<CallHierarchyItem>::new();
match one_or_many {
tsc::OneOrMany::One(item) => {