1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 15:24:46 -05:00

Revert "feat(lsp): enable via config file detection (#20334)" (#20347)

This reverts commit c0dcf6a357.

CC @nayeemrmn
This commit is contained in:
Bartek Iwańczuk 2023-09-01 14:01:20 +02:00 committed by GitHub
parent 3436f65e20
commit a74554987a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 47 deletions

View file

@ -359,7 +359,7 @@ impl ClientTrait for ReplClient {
.into_iter() .into_iter()
.map(|_| { .map(|_| {
Ok(SpecifierSettings { Ok(SpecifierSettings {
enable: Some(true), enable: true,
..Default::default() ..Default::default()
}) })
}) })

View file

@ -236,7 +236,7 @@ impl Default for ImportCompletionSettings {
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct SpecifierSettings { pub struct SpecifierSettings {
/// A flag that indicates if Deno is enabled for this specifier or not. /// A flag that indicates if Deno is enabled for this specifier or not.
pub enable: Option<bool>, pub enable: bool,
/// A list of paths, using the workspace folder as a base that should be Deno /// A list of paths, using the workspace folder as a base that should be Deno
/// enabled. /// enabled.
#[serde(default)] #[serde(default)]
@ -288,7 +288,8 @@ fn empty_string_none<'de, D: serde::Deserializer<'de>>(
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct WorkspaceSettings { pub struct WorkspaceSettings {
/// A flag that indicates if Deno is enabled for the workspace. /// A flag that indicates if Deno is enabled for the workspace.
pub enable: Option<bool>, #[serde(default)]
pub enable: bool,
/// A list of paths, using the root_uri as a base that should be Deno enabled. /// A list of paths, using the root_uri as a base that should be Deno enabled.
#[serde(default)] #[serde(default)]
@ -358,7 +359,7 @@ pub struct WorkspaceSettings {
impl Default for WorkspaceSettings { impl Default for WorkspaceSettings {
fn default() -> Self { fn default() -> Self {
WorkspaceSettings { WorkspaceSettings {
enable: None, enable: false,
enable_paths: vec![], enable_paths: vec![],
cache: None, cache: None,
certificate_stores: None, certificate_stores: None,
@ -404,7 +405,6 @@ pub struct ConfigSnapshot {
pub client_capabilities: ClientCapabilities, pub client_capabilities: ClientCapabilities,
pub enabled_paths: HashMap<Url, Vec<Url>>, pub enabled_paths: HashMap<Url, Vec<Url>>,
pub excluded_paths: Option<Vec<Url>>, pub excluded_paths: Option<Vec<Url>>,
pub has_config_file: bool,
pub settings: Settings, pub settings: Settings,
} }
@ -415,7 +415,6 @@ impl ConfigSnapshot {
&self.enabled_paths, &self.enabled_paths,
self.excluded_paths.as_ref(), self.excluded_paths.as_ref(),
&self.settings, &self.settings,
self.has_config_file,
specifier, specifier,
) )
} }
@ -524,10 +523,6 @@ impl Config {
self.maybe_config_file_info = None; self.maybe_config_file_info = None;
} }
pub fn has_config_file(&self) -> bool {
self.maybe_config_file_info.is_some()
}
pub fn set_config_file(&mut self, config_file: ConfigFile) { pub fn set_config_file(&mut self, config_file: ConfigFile) {
self.maybe_config_file_info = Some(LspConfigFileInfo { self.maybe_config_file_info = Some(LspConfigFileInfo {
maybe_lockfile: resolve_lockfile_from_config(&config_file).map( maybe_lockfile: resolve_lockfile_from_config(&config_file).map(
@ -587,7 +582,6 @@ impl Config {
.maybe_config_file_info .maybe_config_file_info
.as_ref() .as_ref()
.map(|i| i.excluded_paths.clone()), .map(|i| i.excluded_paths.clone()),
has_config_file: self.has_config_file(),
settings: self.settings.clone(), settings: self.settings.clone(),
}) })
} }
@ -596,14 +590,6 @@ impl Config {
self.settings.specifiers.contains_key(specifier) self.settings.specifiers.contains_key(specifier)
} }
pub fn enabled(&self) -> bool {
self
.settings
.workspace
.enable
.unwrap_or_else(|| self.has_config_file())
}
pub fn specifier_enabled(&self, specifier: &ModuleSpecifier) -> bool { pub fn specifier_enabled(&self, specifier: &ModuleSpecifier) -> bool {
specifier_enabled( specifier_enabled(
&self.enabled_paths, &self.enabled_paths,
@ -612,7 +598,6 @@ impl Config {
.as_ref() .as_ref()
.map(|i| &i.excluded_paths), .map(|i| &i.excluded_paths),
&self.settings, &self.settings,
self.has_config_file(),
specifier, specifier,
) )
} }
@ -625,7 +610,7 @@ impl Config {
pub fn enabled_urls(&self) -> Vec<Url> { pub fn enabled_urls(&self) -> Vec<Url> {
let mut urls: Vec<Url> = Vec::new(); let mut urls: Vec<Url> = Vec::new();
if !self.enabled() && self.enabled_paths.is_empty() { if !self.settings.workspace.enable && self.enabled_paths.is_empty() {
// do not return any urls when disabled // do not return any urls when disabled
return urls; return urls;
} }
@ -795,7 +780,6 @@ fn specifier_enabled(
enabled_paths: &HashMap<Url, Vec<Url>>, enabled_paths: &HashMap<Url, Vec<Url>>,
excluded_paths: Option<&Vec<Url>>, excluded_paths: Option<&Vec<Url>>,
settings: &Settings, settings: &Settings,
workspace_has_config_file: bool,
specifier: &Url, specifier: &Url,
) -> bool { ) -> bool {
let specifier_str = specifier.as_str(); let specifier_str = specifier.as_str();
@ -816,9 +800,8 @@ fn specifier_enabled(
settings settings
.specifiers .specifiers
.get(specifier) .get(specifier)
.and_then(|settings| settings.enable) .map(|settings| settings.enable)
.or(settings.workspace.enable) .unwrap_or_else(|| settings.workspace.enable)
.unwrap_or(workspace_has_config_file)
} }
fn resolve_lockfile_from_config(config_file: &ConfigFile) -> Option<Lockfile> { fn resolve_lockfile_from_config(config_file: &ConfigFile) -> Option<Lockfile> {
@ -933,7 +916,7 @@ mod tests {
assert_eq!( assert_eq!(
config.workspace_settings().clone(), config.workspace_settings().clone(),
WorkspaceSettings { WorkspaceSettings {
enable: None, enable: false,
enable_paths: Vec::new(), enable_paths: Vec::new(),
cache: None, cache: None,
certificate_stores: None, certificate_stores: None,
@ -1042,14 +1025,14 @@ mod tests {
let mut config = Config::new(); let mut config = Config::new();
let root_dir = Url::parse("file:///example/").unwrap(); let root_dir = Url::parse("file:///example/").unwrap();
config.root_uri = Some(root_dir.clone()); config.root_uri = Some(root_dir.clone());
config.settings.workspace.enable = Some(false); config.settings.workspace.enable = false;
config.settings.workspace.enable_paths = Vec::new(); config.settings.workspace.enable_paths = Vec::new();
assert_eq!(config.enabled_urls(), vec![]); assert_eq!(config.enabled_urls(), vec![]);
config.settings.workspace.enable = Some(true); config.settings.workspace.enable = true;
assert_eq!(config.enabled_urls(), vec![root_dir]); assert_eq!(config.enabled_urls(), vec![root_dir]);
config.settings.workspace.enable = Some(false); config.settings.workspace.enable = false;
let root_dir1 = Url::parse("file:///root1/").unwrap(); let root_dir1 = Url::parse("file:///root1/").unwrap();
let root_dir2 = Url::parse("file:///root2/").unwrap(); let root_dir2 = Url::parse("file:///root2/").unwrap();
let root_dir3 = Url::parse("file:///root3/").unwrap(); let root_dir3 = Url::parse("file:///root3/").unwrap();
@ -1077,18 +1060,4 @@ mod tests {
] ]
); );
} }
#[test]
fn config_enable_via_config_file_detection() {
let mut config = Config::new();
let root_uri = Url::parse("file:///root/").unwrap();
config.root_uri = Some(root_uri.clone());
config.settings.workspace.enable = None;
assert_eq!(config.enabled_urls(), vec![]);
config.set_config_file(
ConfigFile::new("{}", root_uri.join("deno.json").unwrap()).unwrap(),
);
assert_eq!(config.enabled_urls(), vec![root_uri]);
}
} }

View file

@ -1390,7 +1390,7 @@ mod tests {
ConfigSnapshot { ConfigSnapshot {
settings: Settings { settings: Settings {
workspace: WorkspaceSettings { workspace: WorkspaceSettings {
enable: Some(true), enable: true,
lint: true, lint: true,
..Default::default() ..Default::default()
}, },
@ -1466,7 +1466,7 @@ let c: number = "a";
disabled_config.settings.specifiers.insert( disabled_config.settings.specifiers.insert(
specifier.clone(), specifier.clone(),
SpecifierSettings { SpecifierSettings {
enable: Some(false), enable: false,
enable_paths: Vec::new(), enable_paths: Vec::new(),
code_lens: Default::default(), code_lens: Default::default(),
}, },

View file

@ -3053,7 +3053,7 @@ impl tower_lsp::LanguageServer for LanguageServer {
let options = DidChangeWatchedFilesRegistrationOptions { let options = DidChangeWatchedFilesRegistrationOptions {
watchers: vec![FileSystemWatcher { watchers: vec![FileSystemWatcher {
glob_pattern: "**/*.{json,jsonc,lock}".to_string(), glob_pattern: "**/*.{json,jsonc,lock}".to_string(),
kind: None, kind: Some(WatchKind::Change),
}], }],
}; };
registrations.push(Registration { registrations.push(Registration {

View file

@ -284,7 +284,7 @@ fn get_cwd_uri() -> Result<ModuleSpecifier, AnyError> {
pub fn get_repl_workspace_settings() -> WorkspaceSettings { pub fn get_repl_workspace_settings() -> WorkspaceSettings {
WorkspaceSettings { WorkspaceSettings {
enable: Some(true), enable: true,
enable_paths: Vec::new(), enable_paths: Vec::new(),
config: None, config: None,
certificate_stores: None, certificate_stores: None,