summaryrefslogtreecommitdiff
path: root/cli/lsp/language_server.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-01-18 15:57:30 -0500
committerGitHub <noreply@github.com>2024-01-18 15:57:30 -0500
commit35c1652f56f2a83380080b2c9942c595f80bd14d (patch)
tree4867dacfcbcbb01e7e1766d2fd8ce5e0a62ddf2b /cli/lsp/language_server.rs
parent4e3aff8400fe1e6854a27687d14a07dc837c88d9 (diff)
fix(lsp): regression - formatting was broken on windows (#21972)
~~Waiting on: https://github.com/denoland/deno_config/pull/31~~ Closes #21971 Closes https://github.com/denoland/vscode_deno/issues/1029
Diffstat (limited to 'cli/lsp/language_server.rs')
-rw-r--r--cli/lsp/language_server.rs37
1 files changed, 22 insertions, 15 deletions
diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs
index 921e34bcd..8355b4fe2 100644
--- a/cli/lsp/language_server.rs
+++ b/cli/lsp/language_server.rs
@@ -2,8 +2,8 @@
use base64::Engine;
use deno_ast::MediaType;
+use deno_config::glob::FilePatterns;
use deno_core::anyhow::anyhow;
-use deno_core::anyhow::Context;
use deno_core::error::AnyError;
use deno_core::parking_lot::Mutex;
use deno_core::resolve_url;
@@ -29,6 +29,7 @@ use std::collections::HashMap;
use std::collections::HashSet;
use std::env;
use std::fmt::Write as _;
+use std::path::Path;
use std::path::PathBuf;
use std::sync::Arc;
use tokio::sync::mpsc::unbounded_channel;
@@ -237,6 +238,7 @@ pub struct Inner {
/// The collection of documents that the server is currently handling, either
/// on disk or "open" within the client.
pub documents: Documents,
+ initial_cwd: PathBuf,
http_client: Arc<HttpClient>,
task_queue: LanguageServerTaskQueue,
/// Handles module registries, which allow discovery of modules
@@ -527,6 +529,9 @@ impl Inner {
diagnostics_state.clone(),
);
let assets = Assets::new(ts_server.clone());
+ let initial_cwd = std::env::current_dir().unwrap_or_else(|_| {
+ panic!("Could not resolve current working directory")
+ });
Self {
assets,
@@ -538,13 +543,14 @@ impl Inner {
diagnostics_server,
documents,
http_client,
+ initial_cwd: initial_cwd.clone(),
maybe_global_cache_path: None,
maybe_import_map: None,
maybe_import_map_uri: None,
maybe_package_json: None,
- fmt_options: Default::default(),
+ fmt_options: FmtOptions::new_with_base(initial_cwd.clone()),
task_queue: Default::default(),
- lint_options: Default::default(),
+ lint_options: LintOptions::new_with_base(initial_cwd),
maybe_testing_server: None,
module_registries,
module_registries_location,
@@ -874,6 +880,7 @@ impl Inner {
let npm_resolver = create_npm_resolver(
&deno_dir,
+ &self.initial_cwd,
&self.http_client,
self.config.maybe_config_file(),
self.config.maybe_lockfile(),
@@ -1043,15 +1050,13 @@ impl Inner {
async fn update_config_file(&mut self) -> Result<(), AnyError> {
self.config.clear_config_file();
- self.fmt_options = Default::default();
- self.lint_options = Default::default();
+ self.fmt_options = FmtOptions::new_with_base(self.initial_cwd.clone());
+ self.lint_options = LintOptions::new_with_base(self.initial_cwd.clone());
if let Some(config_file) = self.get_config_file()? {
- // this doesn't need to be an actual directory because flags is specified as `None`
- let dummy_args_cwd = PathBuf::from("/");
let lint_options = config_file
.to_lint_config()
.and_then(|maybe_lint_config| {
- LintOptions::resolve(maybe_lint_config, None, &dummy_args_cwd)
+ LintOptions::resolve(maybe_lint_config, None, &self.initial_cwd)
})
.map_err(|err| {
anyhow!("Unable to update lint configuration: {:?}", err)
@@ -1059,7 +1064,7 @@ impl Inner {
let fmt_options = config_file
.to_fmt_config()
.and_then(|maybe_fmt_config| {
- FmtOptions::resolve(maybe_fmt_config, None, &dummy_args_cwd)
+ FmtOptions::resolve(maybe_fmt_config, None, &self.initial_cwd)
})
.map_err(|err| {
anyhow!("Unable to update formatter configuration: {:?}", err)
@@ -1148,6 +1153,7 @@ impl Inner {
async fn create_npm_resolver(
deno_dir: &DenoDir,
+ initial_cwd: &Path,
http_client: &Arc<HttpClient>,
maybe_config_file: Option<&ConfigFile>,
maybe_lockfile: Option<&Arc<Mutex<Lockfile>>>,
@@ -1161,9 +1167,7 @@ async fn create_npm_resolver(
create_cli_npm_resolver_for_lsp(if is_byonm {
CliNpmResolverCreateOptions::Byonm(CliNpmResolverByonmCreateOptions {
fs: Arc::new(deno_fs::RealFs),
- root_node_modules_dir: std::env::current_dir()
- .unwrap()
- .join("node_modules"),
+ root_node_modules_dir: initial_cwd.join("node_modules"),
})
} else {
CliNpmResolverCreateOptions::Managed(CliNpmResolverManagedCreateOptions {
@@ -1348,8 +1352,11 @@ impl Inner {
async fn refresh_documents_config(&mut self) {
self.documents.update_config(UpdateDocumentConfigOptions {
- enabled_paths: self.config.get_enabled_paths(),
- disabled_paths: self.config.get_disabled_paths(),
+ file_patterns: FilePatterns {
+ base: self.initial_cwd.clone(),
+ include: Some(self.config.get_enabled_paths()),
+ exclude: self.config.get_disabled_paths(),
+ },
document_preload_limit: self
.config
.workspace_settings()
@@ -3722,7 +3729,7 @@ impl Inner {
type_check_mode: crate::args::TypeCheckMode::Local,
..Default::default()
},
- std::env::current_dir().with_context(|| "Failed getting cwd.")?,
+ self.initial_cwd.clone(),
self.config.maybe_config_file().cloned(),
self.config.maybe_lockfile().cloned(),
self.maybe_package_json.clone(),