Skip to content
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): include unstable features from editor settings #26655

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion cli/lsp/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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>,
}

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -1630,6 +1639,7 @@ impl ConfigData {
lockfile,
npmrc,
import_map_from_settings,
unstable,
watched_files,
}
}
Expand Down
10 changes: 3 additions & 7 deletions cli/lsp/language_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions cli/lsp/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
}))
Expand Down
30 changes: 14 additions & 16 deletions tests/integration/lsp_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down