Skip to content

Commit

Permalink
fix(lsp): regression - formatting was broken on windows (denoland#21972)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Jan 18, 2024
1 parent 4e3aff8 commit 35c1652
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 117 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ winres.workspace = true
[dependencies]
deno_ast = { workspace = true, features = ["bundler", "cjs", "codegen", "dep_graph", "module_specifier", "proposal", "react", "sourcemap", "transforms", "typescript", "view", "visit"] }
deno_cache_dir = "=0.6.1"
deno_config = "=0.7.1"
deno_config = "=0.8.0"
deno_core = { workspace = true, features = ["include_js_files_for_snapshotting"] }
deno_doc = { version = "=0.93.0", features = ["html"] }
deno_emit = "=0.33.0"
Expand Down
38 changes: 22 additions & 16 deletions cli/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pub mod package_json;
pub use self::import_map::resolve_import_map_from_specifier;
use self::package_json::PackageJsonDeps;
use ::import_map::ImportMap;
use deno_config::glob::PathOrPattern;
use deno_core::resolve_url_or_path;
use deno_npm::resolution::ValidSerializedNpmResolutionSnapshot;
use deno_npm::NpmSystemInfo;
Expand Down Expand Up @@ -244,14 +243,22 @@ impl BenchOptions {
}
}

#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug)]
pub struct FmtOptions {
pub check: bool,
pub options: FmtOptionsConfig,
pub files: FilePatterns,
}

impl FmtOptions {
pub fn new_with_base(base: PathBuf) -> Self {
Self {
check: false,
options: FmtOptionsConfig::default(),
files: FilePatterns::new_with_base(base),
}
}

pub fn resolve(
maybe_fmt_config: Option<FmtConfig>,
maybe_fmt_flags: Option<FmtFlags>,
Expand Down Expand Up @@ -369,14 +376,22 @@ pub enum LintReporterKind {
Compact,
}

#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug)]
pub struct LintOptions {
pub rules: LintRulesConfig,
pub files: FilePatterns,
pub reporter_kind: LintReporterKind,
}

impl LintOptions {
pub fn new_with_base(base: PathBuf) -> Self {
Self {
rules: Default::default(),
files: FilePatterns::new_with_base(base),
reporter_kind: Default::default(),
}
}

pub fn resolve(
maybe_lint_config: Option<LintConfig>,
maybe_lint_flags: Option<LintFlags>,
Expand Down Expand Up @@ -1648,7 +1663,8 @@ fn resolve_files(
maybe_file_flags: Option<FileFlags>,
initial_cwd: &Path,
) -> Result<FilePatterns, AnyError> {
let mut maybe_files_config = maybe_files_config.unwrap_or_default();
let mut maybe_files_config = maybe_files_config
.unwrap_or_else(|| FilePatterns::new_with_base(initial_cwd.to_path_buf()));
if let Some(file_flags) = maybe_file_flags {
if !file_flags.include.is_empty() {
maybe_files_config.include =
Expand All @@ -1665,18 +1681,7 @@ fn resolve_files(
)?;
}
}
Ok(FilePatterns {
include: {
let files = match maybe_files_config.include {
Some(include) => include,
None => PathOrPatternSet::new(vec![PathOrPattern::Path(
initial_cwd.to_path_buf(),
)]),
};
Some(files)
},
exclude: maybe_files_config.exclude,
})
Ok(maybe_files_config)
}

/// Resolves the no_prompt value based on the cli flags and environment.
Expand Down Expand Up @@ -1896,6 +1901,7 @@ mod test {

let resolved_files = resolve_files(
Some(FilePatterns {
base: temp_dir_path.to_path_buf(),
include: Some(
PathOrPatternSet::from_relative_path_or_patterns(
temp_dir_path,
Expand Down
10 changes: 8 additions & 2 deletions cli/lsp/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1540,6 +1540,7 @@ mod tests {
use crate::lsp::documents::Documents;
use crate::lsp::documents::LanguageId;
use crate::lsp::language_server::StateSnapshot;
use deno_config::glob::FilePatterns;
use pretty_assertions::assert_eq;
use std::path::Path;
use std::path::PathBuf;
Expand Down Expand Up @@ -1640,14 +1641,19 @@ let c: number = "a";
Arc::new(GlobalHttpCache::new(cache_location, RealDenoCacheEnv));
let ts_server = TsServer::new(Default::default(), cache);
ts_server.start(None);
let lint_options = LintOptions {
rules: Default::default(),
files: FilePatterns::new_with_base(temp_dir.path().to_path_buf()),
reporter_kind: Default::default(),
};

// test enabled
{
let enabled_config = mock_config();
let diagnostics = generate_lint_diagnostics(
&snapshot,
&enabled_config,
&Default::default(),
&lint_options,
Default::default(),
);
assert_eq!(get_diagnostics_for_single(diagnostics).len(), 6);
Expand Down Expand Up @@ -1679,7 +1685,7 @@ let c: number = "a";
let diagnostics = generate_lint_diagnostics(
&snapshot,
&disabled_config,
&Default::default(),
&lint_options,
Default::default(),
);
assert_eq!(get_diagnostics_for_single(diagnostics).len(), 0);
Expand Down
Loading

0 comments on commit 35c1652

Please sign in to comment.