-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(lsp): regression - formatting was broken on windows #21972
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
use base64::Engine; | ||
use deno_ast::MediaType; | ||
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 +28,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 +237,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 +528,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,6 +542,7 @@ impl Inner { | |
diagnostics_server, | ||
documents, | ||
http_client, | ||
initial_cwd, | ||
maybe_global_cache_path: None, | ||
maybe_import_map: None, | ||
maybe_import_map_uri: None, | ||
|
@@ -874,6 +879,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(), | ||
|
@@ -1046,20 +1052,18 @@ impl Inner { | |
self.fmt_options = Default::default(); | ||
self.lint_options = Default::default(); | ||
if let Some(config_file) = self.get_config_file()? { | ||
// this doesn't need to be an actual directory because flags is specified as `None` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lies I wrote. |
||
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) | ||
})?; | ||
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 +1152,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 +1166,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 { | ||
|
@@ -3692,7 +3695,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(), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reverts this change I made. It shouldn't have been done from what I can tell atm
Edit: Tests failed on CI, so maybe not. Edit 2: Oh, it was used to get the base path. Edit 3: denoland/deno_config#31