1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-24 08:09:08 -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 Bartek Iwańczuk
parent 13612e7112
commit e1ddb7a473
No known key found for this signature in database
GPG key ID: 0C6BCDDC3B3AD750
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 lsp_types::ClientCapabilities;
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::collections::HashMap;
use std::ops::Deref;
use std::ops::DerefMut;
@ -1190,6 +1191,7 @@ pub struct ConfigData {
pub resolver: Arc<WorkspaceResolver>,
pub sloppy_imports_resolver: Option<Arc<CliSloppyImportsResolver>>,
pub import_map_from_settings: Option<ModuleSpecifier>,
pub unstable: BTreeSet<String>,
watched_files: HashMap<ModuleSpecifier, ConfigWatchedFileType>,
}
@ -1587,9 +1589,16 @@ impl ConfigData {
.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")
.is_ok()
|| member_dir.workspace.has_unstable("sloppy-imports");
|| unstable.contains("sloppy-imports");
let sloppy_imports_resolver = unstable_sloppy_imports.then(|| {
Arc::new(CliSloppyImportsResolver::new(
SloppyImportsCachedFs::new_without_stat_cache(Arc::new(
@ -1630,6 +1639,7 @@ impl ConfigData {
lockfile,
npmrc,
import_map_from_settings,
unstable,
watched_files,
}
}

View file

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

View file

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

View file

@ -15484,25 +15484,23 @@ fn lsp_sloppy_imports() {
fn lsp_sloppy_imports_prefers_dts() {
let context = TestContextBuilder::new().use_temp_cwd().build();
let temp_dir = context.temp_dir();
let temp_dir = temp_dir.path();
temp_dir
.join("deno.json")
.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;");
temp_dir.write("deno.json", json!({}).to_string());
temp_dir.write("a.js", "export const foo: number;");
let a_dts =
source_file(temp_dir.path().join("a.d.ts"), "export const foo = 3;");
let file = source_file(
temp_dir.join("file.ts"),
temp_dir.path().join("file.ts"),
"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);
// no other warnings because "a.js" exists
assert_eq!(