1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

fix(lsp): include unstable features from editor settings (#26655)

This commit is contained in:
Nayeem Rahman 2024-10-31 10:52:43 +00:00 committed by GitHub
parent 8bfd134da6
commit 2f0c25d33f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 30 additions and 26 deletions

View file

@ -41,6 +41,7 @@ use deno_runtime::deno_node::PackageJson;
use indexmap::IndexSet; use indexmap::IndexSet;
use lsp_types::ClientCapabilities; use lsp_types::ClientCapabilities;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::collections::HashMap; use std::collections::HashMap;
use std::ops::Deref; use std::ops::Deref;
use std::ops::DerefMut; use std::ops::DerefMut;
@ -1190,6 +1191,7 @@ pub struct ConfigData {
pub resolver: Arc<WorkspaceResolver>, pub resolver: Arc<WorkspaceResolver>,
pub sloppy_imports_resolver: Option<Arc<CliSloppyImportsResolver>>, pub sloppy_imports_resolver: Option<Arc<CliSloppyImportsResolver>>,
pub import_map_from_settings: Option<ModuleSpecifier>, pub import_map_from_settings: Option<ModuleSpecifier>,
pub unstable: BTreeSet<String>,
watched_files: HashMap<ModuleSpecifier, ConfigWatchedFileType>, watched_files: HashMap<ModuleSpecifier, ConfigWatchedFileType>,
} }
@ -1587,9 +1589,16 @@ impl ConfigData {
.join("\n") .join("\n")
); );
} }
let unstable = member_dir
.workspace
.unstable_features()
.iter()
.chain(settings.unstable.as_deref())
.cloned()
.collect::<BTreeSet<_>>();
let unstable_sloppy_imports = std::env::var("DENO_UNSTABLE_SLOPPY_IMPORTS") let unstable_sloppy_imports = std::env::var("DENO_UNSTABLE_SLOPPY_IMPORTS")
.is_ok() .is_ok()
|| member_dir.workspace.has_unstable("sloppy-imports"); || unstable.contains("sloppy-imports");
let sloppy_imports_resolver = unstable_sloppy_imports.then(|| { let sloppy_imports_resolver = unstable_sloppy_imports.then(|| {
Arc::new(CliSloppyImportsResolver::new( Arc::new(CliSloppyImportsResolver::new(
SloppyImportsCachedFs::new_without_stat_cache(Arc::new( SloppyImportsCachedFs::new_without_stat_cache(Arc::new(
@ -1630,6 +1639,7 @@ impl ConfigData {
lockfile, lockfile,
npmrc, npmrc,
import_map_from_settings, import_map_from_settings,
unstable,
watched_files, watched_files,
} }
} }

View file

@ -1384,14 +1384,10 @@ impl Inner {
.clone(); .clone();
fmt_options.use_tabs = Some(!params.options.insert_spaces); fmt_options.use_tabs = Some(!params.options.insert_spaces);
fmt_options.indent_width = Some(params.options.tab_size as u8); fmt_options.indent_width = Some(params.options.tab_size as u8);
let maybe_workspace = self let config_data = self.config.tree.data_for_specifier(&specifier);
.config
.tree
.data_for_specifier(&specifier)
.map(|d| &d.member_dir.workspace);
let unstable_options = UnstableFmtOptions { let unstable_options = UnstableFmtOptions {
component: maybe_workspace component: config_data
.map(|w| w.has_unstable("fmt-component")) .map(|d| d.unstable.contains("fmt-component"))
.unwrap_or(false), .unwrap_or(false),
}; };
let document = document.clone(); let document = document.clone();

View file

@ -555,8 +555,8 @@ fn create_graph_resolver(
workspace.to_maybe_jsx_import_source_config().ok().flatten() workspace.to_maybe_jsx_import_source_config().ok().flatten()
}), }),
maybe_vendor_dir: config_data.and_then(|d| d.vendor_dir.as_ref()), maybe_vendor_dir: config_data.and_then(|d| d.vendor_dir.as_ref()),
bare_node_builtins_enabled: workspace bare_node_builtins_enabled: config_data
.is_some_and(|workspace| workspace.has_unstable("bare-node-builtins")), .is_some_and(|d| d.unstable.contains("bare-node-builtins")),
sloppy_imports_resolver: config_data sloppy_imports_resolver: config_data
.and_then(|d| d.sloppy_imports_resolver.clone()), .and_then(|d| d.sloppy_imports_resolver.clone()),
})) }))

View file

@ -15484,25 +15484,23 @@ fn lsp_sloppy_imports() {
fn lsp_sloppy_imports_prefers_dts() { fn lsp_sloppy_imports_prefers_dts() {
let context = TestContextBuilder::new().use_temp_cwd().build(); let context = TestContextBuilder::new().use_temp_cwd().build();
let temp_dir = context.temp_dir(); let temp_dir = context.temp_dir();
let temp_dir = temp_dir.path(); temp_dir.write("deno.json", json!({}).to_string());
temp_dir.write("a.js", "export const foo: number;");
temp_dir let a_dts =
.join("deno.json") source_file(temp_dir.path().join("a.d.ts"), "export const foo = 3;");
.write(r#"{ "unstable": ["sloppy-imports"] }"#);
let mut client: LspClient = context
.new_lsp_command()
.set_root_dir(temp_dir.clone())
.build();
client.initialize_default();
temp_dir.join("a.js").write("export const foo: number;");
let a_dts = source_file(temp_dir.join("a.d.ts"), "export const foo = 3;");
let file = source_file( let file = source_file(
temp_dir.join("file.ts"), temp_dir.path().join("file.ts"),
"import { foo } from './a.js';\nconsole.log(foo);", "import { foo } from './a.js';\nconsole.log(foo);",
); );
let mut client: LspClient = context.new_lsp_command().build();
client.initialize_default();
client.change_configuration(json!({
"deno": {
"enable": true,
"unstable": ["sloppy-imports"],
},
}));
let diagnostics = client.did_open_file(&file); let diagnostics = client.did_open_file(&file);
// no other warnings because "a.js" exists // no other warnings because "a.js" exists
assert_eq!( assert_eq!(