mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 09:31:22 -05:00
chore(lsp): remove ConfigSnapshot (#23579)
This commit is contained in:
parent
8178f758bc
commit
e0f849289f
5 changed files with 18 additions and 118 deletions
|
@ -1,7 +1,7 @@
|
|||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
use super::client::Client;
|
||||
use super::config::ConfigSnapshot;
|
||||
use super::config::Config;
|
||||
use super::config::WorkspaceSettings;
|
||||
use super::documents::Documents;
|
||||
use super::documents::DocumentsFilter;
|
||||
|
@ -148,7 +148,7 @@ fn to_narrow_lsp_range(
|
|||
pub async fn get_import_completions(
|
||||
specifier: &ModuleSpecifier,
|
||||
position: &lsp::Position,
|
||||
config: &ConfigSnapshot,
|
||||
config: &Config,
|
||||
client: &Client,
|
||||
module_registries: &ModuleRegistry,
|
||||
jsr_search_api: &CliJsrSearchApi,
|
||||
|
|
|
@ -726,53 +726,6 @@ impl WorkspaceSettings {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct ConfigSnapshot {
|
||||
pub client_capabilities: ClientCapabilities,
|
||||
pub settings: Settings,
|
||||
pub workspace_folders: Vec<(ModuleSpecifier, lsp::WorkspaceFolder)>,
|
||||
pub tree: ConfigTree,
|
||||
}
|
||||
|
||||
impl ConfigSnapshot {
|
||||
pub fn workspace_settings_for_specifier(
|
||||
&self,
|
||||
specifier: &ModuleSpecifier,
|
||||
) -> &WorkspaceSettings {
|
||||
self.settings.get_for_specifier(specifier).0
|
||||
}
|
||||
|
||||
/// Determine if the provided specifier is enabled or not.
|
||||
pub fn specifier_enabled(&self, specifier: &ModuleSpecifier) -> bool {
|
||||
let config_file = self.tree.config_file_for_specifier(specifier);
|
||||
if let Some(cf) = config_file {
|
||||
if let Ok(files) = cf.to_files_config() {
|
||||
if !files.matches_specifier(specifier) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
self
|
||||
.settings
|
||||
.specifier_enabled(specifier)
|
||||
.unwrap_or_else(|| config_file.is_some())
|
||||
}
|
||||
|
||||
pub fn specifier_enabled_for_test(
|
||||
&self,
|
||||
specifier: &ModuleSpecifier,
|
||||
) -> bool {
|
||||
if let Some(cf) = self.tree.config_file_for_specifier(specifier) {
|
||||
if let Some(options) = cf.to_test_config().ok().flatten() {
|
||||
if !options.files.matches_specifier(specifier) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
self.specifier_enabled(specifier)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct Settings {
|
||||
pub unscoped: WorkspaceSettings,
|
||||
|
@ -982,15 +935,6 @@ impl Config {
|
|||
self.workspace_folders.first().map(|p| &p.0)
|
||||
}
|
||||
|
||||
pub fn snapshot(&self) -> Arc<ConfigSnapshot> {
|
||||
Arc::new(ConfigSnapshot {
|
||||
client_capabilities: self.client_capabilities.clone(),
|
||||
settings: self.settings.clone(),
|
||||
workspace_folders: self.workspace_folders.clone(),
|
||||
tree: self.tree.clone(),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn specifier_enabled(&self, specifier: &ModuleSpecifier) -> bool {
|
||||
let config_file = self.tree.config_file_for_specifier(specifier);
|
||||
if let Some(cf) = config_file {
|
||||
|
@ -1805,8 +1749,7 @@ mod tests {
|
|||
.unwrap(),
|
||||
vec![],
|
||||
);
|
||||
let config_snapshot = config.snapshot();
|
||||
assert!(config_snapshot.specifier_enabled(&specifier));
|
||||
assert!(config.specifier_enabled(&specifier));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1822,9 +1765,6 @@ mod tests {
|
|||
config.set_workspace_settings(workspace_settings, vec![]);
|
||||
assert!(config.specifier_enabled(&specifier_a));
|
||||
assert!(!config.specifier_enabled(&specifier_b));
|
||||
let config_snapshot = config.snapshot();
|
||||
assert!(config_snapshot.specifier_enabled(&specifier_a));
|
||||
assert!(!config_snapshot.specifier_enabled(&specifier_b));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -2146,35 +2086,4 @@ mod tests {
|
|||
!config.specifier_enabled_for_test(&root_uri.join("mod2.ts").unwrap())
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn config_snapshot_specifier_enabled_for_test() {
|
||||
let root_uri = resolve_url("file:///root/").unwrap();
|
||||
let mut config = Config::new_with_roots(vec![root_uri.clone()]);
|
||||
config.settings.unscoped.enable = Some(true);
|
||||
config
|
||||
.tree
|
||||
.inject_config_file(
|
||||
ConfigFile::new(
|
||||
&json!({
|
||||
"exclude": ["mod2.ts"],
|
||||
"test": {
|
||||
"exclude": ["mod3.ts"],
|
||||
},
|
||||
})
|
||||
.to_string(),
|
||||
root_uri.join("deno.json").unwrap(),
|
||||
&deno_config::ParseOptions::default(),
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
.await;
|
||||
let config_snapshot = config.snapshot();
|
||||
assert!(config_snapshot
|
||||
.specifier_enabled_for_test(&root_uri.join("mod1.ts").unwrap()));
|
||||
assert!(!config_snapshot
|
||||
.specifier_enabled_for_test(&root_uri.join("mod2.ts").unwrap()));
|
||||
assert!(!config_snapshot
|
||||
.specifier_enabled_for_test(&root_uri.join("mod3.ts").unwrap()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
use super::analysis;
|
||||
use super::cache;
|
||||
use super::client::Client;
|
||||
use super::config::ConfigSnapshot;
|
||||
use super::config::Config;
|
||||
use super::documents;
|
||||
use super::documents::Document;
|
||||
use super::documents::DocumentsFilter;
|
||||
|
@ -62,7 +62,6 @@ use tower_lsp::lsp_types as lsp;
|
|||
#[derive(Debug)]
|
||||
pub struct DiagnosticServerUpdateMessage {
|
||||
pub snapshot: Arc<StateSnapshot>,
|
||||
pub config: Arc<ConfigSnapshot>,
|
||||
pub url_map: LspUrlMap,
|
||||
}
|
||||
|
||||
|
@ -458,12 +457,7 @@ impl DiagnosticsServer {
|
|||
}
|
||||
};
|
||||
let ChannelUpdateMessage {
|
||||
message:
|
||||
DiagnosticServerUpdateMessage {
|
||||
snapshot,
|
||||
config,
|
||||
url_map,
|
||||
},
|
||||
message: DiagnosticServerUpdateMessage { snapshot, url_map },
|
||||
batch_index,
|
||||
} = message;
|
||||
let url_map = Arc::new(url_map);
|
||||
|
@ -480,7 +474,7 @@ impl DiagnosticsServer {
|
|||
let token = token.clone();
|
||||
let ts_diagnostics_store = ts_diagnostics_store.clone();
|
||||
let snapshot = snapshot.clone();
|
||||
let config = config.clone();
|
||||
let config = snapshot.config.clone();
|
||||
let url_map = url_map.clone();
|
||||
async move {
|
||||
if let Some(previous_handle) = previous_ts_handle {
|
||||
|
@ -555,7 +549,7 @@ impl DiagnosticsServer {
|
|||
let diagnostics_publisher = diagnostics_publisher.clone();
|
||||
let token = token.clone();
|
||||
let snapshot = snapshot.clone();
|
||||
let config = config.clone();
|
||||
let config = snapshot.config.clone();
|
||||
let url_map = url_map.clone();
|
||||
async move {
|
||||
if let Some(previous_handle) = previous_deps_handle {
|
||||
|
@ -604,7 +598,7 @@ impl DiagnosticsServer {
|
|||
let diagnostics_publisher = diagnostics_publisher.clone();
|
||||
let token = token.clone();
|
||||
let snapshot = snapshot.clone();
|
||||
let config = config.clone();
|
||||
let config = snapshot.config.clone();
|
||||
let url_map = url_map.clone();
|
||||
async move {
|
||||
if let Some(previous_handle) = previous_lint_handle {
|
||||
|
@ -784,7 +778,7 @@ fn ts_json_to_diagnostics(
|
|||
|
||||
fn generate_lint_diagnostics(
|
||||
snapshot: &language_server::StateSnapshot,
|
||||
config: &ConfigSnapshot,
|
||||
config: &Config,
|
||||
token: CancellationToken,
|
||||
) -> DiagnosticVec {
|
||||
let documents = snapshot
|
||||
|
@ -865,7 +859,7 @@ fn generate_document_lint_diagnostics(
|
|||
|
||||
async fn generate_ts_diagnostics(
|
||||
snapshot: Arc<language_server::StateSnapshot>,
|
||||
config: &ConfigSnapshot,
|
||||
config: &Config,
|
||||
ts_server: &tsc::TsServer,
|
||||
token: CancellationToken,
|
||||
) -> Result<DiagnosticVec, AnyError> {
|
||||
|
@ -1532,7 +1526,7 @@ fn diagnose_dependency(
|
|||
/// an import map to shorten an URL.
|
||||
fn generate_deno_diagnostics(
|
||||
snapshot: &language_server::StateSnapshot,
|
||||
config: &ConfigSnapshot,
|
||||
config: &Config,
|
||||
token: CancellationToken,
|
||||
) -> DiagnosticVec {
|
||||
let mut diagnostics_vec = Vec::new();
|
||||
|
@ -1575,7 +1569,6 @@ mod tests {
|
|||
use crate::cache::GlobalHttpCache;
|
||||
use crate::cache::RealDenoCacheEnv;
|
||||
use crate::lsp::config::Config;
|
||||
use crate::lsp::config::ConfigSnapshot;
|
||||
use crate::lsp::config::Settings;
|
||||
use crate::lsp::config::WorkspaceSettings;
|
||||
use crate::lsp::documents::Documents;
|
||||
|
@ -1630,14 +1623,14 @@ mod tests {
|
|||
cache_metadata: cache::CacheMetadata::new(Arc::new(
|
||||
GlobalHttpCache::new(location.to_path_buf(), RealDenoCacheEnv),
|
||||
)),
|
||||
config: config.snapshot(),
|
||||
config: Arc::new(config),
|
||||
resolver,
|
||||
}
|
||||
}
|
||||
|
||||
fn mock_config() -> ConfigSnapshot {
|
||||
fn mock_config() -> Config {
|
||||
let root_uri = resolve_url("file:///").unwrap();
|
||||
ConfigSnapshot {
|
||||
Config {
|
||||
settings: Settings {
|
||||
unscoped: WorkspaceSettings {
|
||||
enable: Some(true),
|
||||
|
|
|
@ -48,7 +48,6 @@ use super::client::Client;
|
|||
use super::code_lens;
|
||||
use super::completions;
|
||||
use super::config::Config;
|
||||
use super::config::ConfigSnapshot;
|
||||
use super::config::UpdateImportsOnFileMoveEnabled;
|
||||
use super::config::WorkspaceSettings;
|
||||
use super::config::SETTINGS_SECTION;
|
||||
|
@ -127,7 +126,7 @@ pub struct StateSnapshot {
|
|||
pub project_version: usize,
|
||||
pub assets: AssetsSnapshot,
|
||||
pub cache_metadata: cache::CacheMetadata,
|
||||
pub config: Arc<ConfigSnapshot>,
|
||||
pub config: Arc<Config>,
|
||||
pub documents: Documents,
|
||||
pub resolver: Arc<LspResolver>,
|
||||
}
|
||||
|
@ -593,7 +592,7 @@ impl Inner {
|
|||
project_version: self.project_version,
|
||||
assets: self.assets.snapshot(),
|
||||
cache_metadata: self.cache_metadata.clone(),
|
||||
config: self.config.snapshot(),
|
||||
config: Arc::new(self.config.clone()),
|
||||
documents: self.documents.clone(),
|
||||
resolver: self.resolver.snapshot(),
|
||||
})
|
||||
|
@ -2145,7 +2144,7 @@ impl Inner {
|
|||
response = completions::get_import_completions(
|
||||
&specifier,
|
||||
¶ms.text_document_position.position,
|
||||
&self.config.snapshot(),
|
||||
&self.config,
|
||||
&self.client,
|
||||
&self.module_registries,
|
||||
&self.jsr_search_api,
|
||||
|
@ -2839,7 +2838,6 @@ impl Inner {
|
|||
fn send_diagnostics_update(&self) {
|
||||
let snapshot = DiagnosticServerUpdateMessage {
|
||||
snapshot: self.snapshot(),
|
||||
config: self.config.snapshot(),
|
||||
url_map: self.url_map.clone(),
|
||||
};
|
||||
if let Err(err) = self.diagnostics_server.update(snapshot) {
|
||||
|
|
|
@ -5102,7 +5102,7 @@ mod tests {
|
|||
documents,
|
||||
assets: Default::default(),
|
||||
cache_metadata: CacheMetadata::new(cache),
|
||||
config: config.snapshot(),
|
||||
config: Arc::new(config),
|
||||
resolver,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue