From f27a1d41be8d0497f0a8586bed3ff316da96f082 Mon Sep 17 00:00:00 2001 From: psteinroe Date: Mon, 26 Oct 2026 14:36:45 +0000 Subject: [PATCH] chore: remove dead code Removes AnnotationStore, the unused ast of hover's parameters with WithCSTandASTMapper, HoveredNode::Trigger, Snapshot::find_types, the client information and workspace folders that the LSP session stored without reading them, and the pgls_console dependency of pgls_lsp. --- Cargo.lock | 1 - crates/pgls_catalog/src/snapshot/mod.rs | 7 -- crates/pgls_hover/src/hovered_node.rs | 2 - crates/pgls_hover/src/lib.rs | 46 +++------ .../tests/hover_integration_tests.rs | 1 - crates/pgls_lsp/Cargo.toml | 1 - crates/pgls_lsp/src/server.rs | 6 +- crates/pgls_lsp/src/session.rs | 17 ---- crates/pgls_workspace/src/workspace/server.rs | 8 +- .../src/workspace/server/annotation.rs | 94 ------------------- .../src/workspace/server/document.rs | 29 ------ 11 files changed, 17 insertions(+), 195 deletions(-) delete mode 100644 crates/pgls_workspace/src/workspace/server/annotation.rs diff --git a/Cargo.lock b/Cargo.lock index c99237b66..eb213303b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2650,7 +2650,6 @@ dependencies = [ "pgls_analyse", "pgls_completions", "pgls_configuration", - "pgls_console", "pgls_diagnostics", "pgls_fs", "pgls_test_utils", diff --git a/crates/pgls_catalog/src/snapshot/mod.rs b/crates/pgls_catalog/src/snapshot/mod.rs index 1862e78b7..cdd41f441 100644 --- a/crates/pgls_catalog/src/snapshot/mod.rs +++ b/crates/pgls_catalog/src/snapshot/mod.rs @@ -180,13 +180,6 @@ impl Snapshot { .collect() } - pub fn find_types(&self, name: &str, schema: Option<&str>) -> Vec<&PostgresType> { - self.types - .iter() - .filter(|t| t.name == name && schema.is_none_or(|s| s == t.schema)) - .collect() - } - pub fn find_functions(&self, name: &str, schema: Option<&str>) -> Vec<&Function> { self.functions .iter() diff --git a/crates/pgls_hover/src/hovered_node.rs b/crates/pgls_hover/src/hovered_node.rs index f66f7a1a7..63d2dd743 100644 --- a/crates/pgls_hover/src/hovered_node.rs +++ b/crates/pgls_hover/src/hovered_node.rs @@ -10,8 +10,6 @@ pub(crate) enum HoveredNode { Role(String), PostgresType((Option, String)), - #[allow(unused)] - Trigger((Option, String)), #[allow(dead_code)] Policy((Option, String)), } diff --git a/crates/pgls_hover/src/lib.rs b/crates/pgls_hover/src/lib.rs index 52f5dd9bf..5a0ac1666 100644 --- a/crates/pgls_hover/src/lib.rs +++ b/crates/pgls_hover/src/lib.rs @@ -21,7 +21,6 @@ pub struct OnHoverParams<'a> { pub position: TextSize, pub snapshot: &'a Snapshot, pub stmt_sql: &'a str, - pub ast: Option<&'a pgls_query::NodeEnum>, pub ts_tree: &'a tree_sitter::Tree, /// The references of [`pgls_catalog::resolve::resolve`] whose span contains the cursor. /// When one of them is of the hovered kind, hover shows the object it resolves to instead of @@ -54,21 +53,12 @@ pub fn on_hover(params: OnHoverParams) -> Option> { } let items: Vec = match hovered_node { - HoveredNode::Table(node_identification) => match node_identification { - (None, n) => params - .snapshot - .find_tables(n.as_str(), None) - .into_iter() - .map(Hoverable::from) - .collect(), - - (Some(s), n) => params - .snapshot - .find_tables(n.as_str(), Some(&s)) - .into_iter() - .map(Hoverable::from) - .collect(), - }, + HoveredNode::Table((schema, table_name)) => params + .snapshot + .find_tables(&table_name, schema.as_deref()) + .into_iter() + .map(Hoverable::from) + .collect(), HoveredNode::Column(node_identification) => match node_identification { (None, None, column_name) => params @@ -128,23 +118,14 @@ pub fn on_hover(params: OnHoverParams) -> Option> { .map(|s| vec![s]) .unwrap_or_default(), - HoveredNode::PostgresType(node_identification) => match node_identification { - (None, type_name) => params - .snapshot - .find_type(&type_name, None) - .map(Hoverable::from) - .map(|s| vec![s]) - .unwrap_or_default(), - - (Some(schema), type_name) => params - .snapshot - .find_type(&type_name, Some(schema.as_str())) - .map(Hoverable::from) - .map(|s| vec![s]) - .unwrap_or_default(), - }, + HoveredNode::PostgresType((schema, type_name)) => params + .snapshot + .find_type(&type_name, schema.as_deref()) + .map(Hoverable::from) + .into_iter() + .collect(), - HoveredNode::Policy(_) | HoveredNode::Trigger(_) => return None, + HoveredNode::Policy(_) => return None, }; let markdown_blocks: Vec = prioritize_by_context(items, &ctx) @@ -185,7 +166,6 @@ mod tests { position: TextSize::new(position as u32), snapshot: &snapshot, stmt_sql: &sql, - ast: None, ts_tree: &tree, references: &[], }); diff --git a/crates/pgls_hover/tests/hover_integration_tests.rs b/crates/pgls_hover/tests/hover_integration_tests.rs index ead6d3a84..ec851185e 100644 --- a/crates/pgls_hover/tests/hover_integration_tests.rs +++ b/crates/pgls_hover/tests/hover_integration_tests.rs @@ -62,7 +62,6 @@ async fn test_hover_at_cursor(name: &str, query: String, setup: Option<&str>, te position, snapshot: &snapshot, stmt_sql: &sql, - ast: ast.as_ref(), ts_tree: &tree, references: &references, }) diff --git a/crates/pgls_lsp/Cargo.toml b/crates/pgls_lsp/Cargo.toml index 95b8103ff..54e4e4b1e 100644 --- a/crates/pgls_lsp/Cargo.toml +++ b/crates/pgls_lsp/Cargo.toml @@ -18,7 +18,6 @@ parking_lot = "0.12.3" pgls_analyse = { workspace = true } pgls_completions = { workspace = true } pgls_configuration = { workspace = true } -pgls_console = { workspace = true } pgls_diagnostics = { workspace = true } pgls_fs = { workspace = true } pgls_text_edit = { workspace = true } diff --git a/crates/pgls_lsp/src/server.rs b/crates/pgls_lsp/src/server.rs index 0ed616362..fa06903ed 100644 --- a/crates/pgls_lsp/src/server.rs +++ b/crates/pgls_lsp/src/server.rs @@ -1,6 +1,6 @@ use crate::capabilities::server_capabilities; use crate::handlers; -use crate::session::{ClientInformation, Session, SessionHandle, SessionKey}; +use crate::session::{Session, SessionHandle, SessionKey}; use crate::utils::{into_lsp_error, panic_to_lsp_error}; use futures::FutureExt; use futures::future::ready; @@ -71,10 +71,6 @@ impl LanguageServer for LSPServer { self.session.initialize( params.capabilities, - params.client_info.map(|client_info| ClientInformation { - name: client_info.name, - version: client_info.version, - }), params.root_uri, params.workspace_folders, ); diff --git a/crates/pgls_lsp/src/session.rs b/crates/pgls_lsp/src/session.rs index e79d0bcb4..a53deb171 100644 --- a/crates/pgls_lsp/src/session.rs +++ b/crates/pgls_lsp/src/session.rs @@ -55,16 +55,6 @@ const DIAGNOSTIC_DEBOUNCE: Duration = Duration::from_millis(300); /// configuration, so that a burst of changes causes one reload. const CONFIGURATION_RELOAD_DEBOUNCE: Duration = Duration::from_millis(200); -pub(crate) struct ClientInformation { - #[allow(dead_code)] - /// The name of the client - pub(crate) name: String, - - #[allow(dead_code)] - /// The version of the client - pub(crate) version: Option, -} - /// Key, uniquely identifying a LSP session. #[derive(Clone, Copy, Eq, PartialEq, Hash, Debug)] pub(crate) struct SessionKey(pub u64); @@ -171,11 +161,7 @@ pub(crate) struct Session { struct InitializeParams { /// The capabilities provided by the client as part of [`ls_types::InitializeParams`] client_capabilities: ls_types::ClientCapabilities, - #[allow(dead_code)] - client_information: Option, root_uri: Option, - #[allow(unused)] - workspace_folders: Option>, } #[repr(u8)] @@ -287,7 +273,6 @@ impl Session { pub(crate) fn initialize( &self, client_capabilities: ls_types::ClientCapabilities, - client_information: Option, root_uri: Option, workspace_folders: Option>, ) { @@ -308,9 +293,7 @@ impl Session { }); let result = self.initialize_params.set(InitializeParams { client_capabilities, - client_information, root_uri, - workspace_folders, }); if let Err(err) = result { diff --git a/crates/pgls_workspace/src/workspace/server.rs b/crates/pgls_workspace/src/workspace/server.rs index 3716645fc..d26a085fc 100644 --- a/crates/pgls_workspace/src/workspace/server.rs +++ b/crates/pgls_workspace/src/workspace/server.rs @@ -67,7 +67,7 @@ use crate::{ semantic_tokens::{PullSemanticTokensParams, PullSemanticTokensResult, SemanticToken}, }, settings::{Settings, WorkspaceSettings, WorkspaceSettingsHandle, WorkspaceSettingsHandleMut}, - workspace::{AnalyserDiagnosticsMapper, WithCSTandASTMapper}, + workspace::{AnalyserDiagnosticsMapper, WithCSTMapper}, }; use super::{ @@ -79,7 +79,6 @@ use super::{ pub use statement_identifier::StatementId; mod analyser; -mod annotation; #[cfg(feature = "db")] mod async_helper; #[cfg(feature = "db")] @@ -1739,8 +1738,8 @@ impl Workspace for WorkspaceServer { }; // The innermost statement: the body of a SQL function rather than its `CREATE FUNCTION`. - match doc.iter_at(WithCSTandASTMapper, params.position).last() { - Some((stmt_id, range, ts_tree, maybe_ast)) => { + match doc.iter_at(WithCSTMapper, params.position).last() { + Some((stmt_id, range, ts_tree)) => { let position_in_stmt = params.position - range.start(); let (references, snapshot) = self.hover_references( settings, @@ -1754,7 +1753,6 @@ impl Workspace for WorkspaceServer { let markdown_blocks = pgls_hover::on_hover(pgls_hover::OnHoverParams { ts_tree: &ts_tree, snapshot: &snapshot, - ast: maybe_ast.as_ref(), position: position_in_stmt, stmt_sql: stmt_id.content(), references: &references, diff --git a/crates/pgls_workspace/src/workspace/server/annotation.rs b/crates/pgls_workspace/src/workspace/server/annotation.rs deleted file mode 100644 index 756deac2d..000000000 --- a/crates/pgls_workspace/src/workspace/server/annotation.rs +++ /dev/null @@ -1,94 +0,0 @@ -use std::sync::{Arc, Mutex}; - -use pgls_lexer::SyntaxKind; -use rustc_hash::FxHashMap; - -use super::statement_identifier::StatementId; - -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct StatementAnnotations { - ends_with_semicolon: bool, -} - -pub struct AnnotationStore { - db: Mutex>>, -} - -const WHITESPACE_TOKENS: [SyntaxKind; 6] = [ - SyntaxKind::SPACE, - SyntaxKind::TAB, - SyntaxKind::VERTICAL_TAB, - SyntaxKind::FORM_FEED, - SyntaxKind::LINE_ENDING, - SyntaxKind::EOF, -]; - -impl AnnotationStore { - pub fn new() -> AnnotationStore { - AnnotationStore { - db: Mutex::default(), - } - } - - /// Drops the annotations of the statements for which `keep` returns `false`. - pub fn retain(&self, keep: impl Fn(&StatementId) -> bool) { - self.db.lock().unwrap().retain(|id, _| keep(id)); - } - - #[allow(unused)] - pub fn get_annotations( - &self, - statement_id: &StatementId, - content: &str, - ) -> Arc { - let mut cache = self.db.lock().unwrap(); - - if let Some(existing) = cache.get(statement_id) { - return existing.clone(); - } - - let lexed = pgls_lexer::lex(content); - - let ends_with_semicolon = (0..lexed.len()) - .rfind(|t| !WHITESPACE_TOKENS.contains(&lexed.kind(*t))) - .map(|t| lexed.kind(t) == SyntaxKind::SEMICOLON) - .unwrap_or(false); - - let annotations = Arc::new(StatementAnnotations { - ends_with_semicolon, - }); - - cache.insert(statement_id.clone(), annotations.clone()); - - annotations - } -} - -#[cfg(test)] -mod tests { - use crate::workspace::StatementId; - - use super::AnnotationStore; - - #[test] - fn annotates_correctly() { - let store = AnnotationStore::new(); - - let test_cases = [ - ("SELECT * FROM foo", false), - ("SELECT * FROM foo;", true), - ("SELECT * FROM foo ;", true), - ("SELECT * FROM foo ; ", true), - ("SELECT * FROM foo ;\n", true), - ("SELECT * FROM foo\n", false), - ]; - - for (content, expected) in test_cases.iter() { - let statement_id = StatementId::new(content); - - let annotations = store.get_annotations(&statement_id, content); - - assert_eq!(annotations.ends_with_semicolon, *expected); - } - } -} diff --git a/crates/pgls_workspace/src/workspace/server/document.rs b/crates/pgls_workspace/src/workspace/server/document.rs index 6482113c4..7777bc2d8 100644 --- a/crates/pgls_workspace/src/workspace/server/document.rs +++ b/crates/pgls_workspace/src/workspace/server/document.rs @@ -8,7 +8,6 @@ use pgls_text_size::{TextRange, TextSize}; use rustc_hash::FxHashSet; use super::{ - annotation::AnnotationStore, pg_query::{PgQueryStore, convert_to_positional_params_with_metadata}, statement_identifier::StatementId, tree_sitter::TreeSitterStore, @@ -21,8 +20,6 @@ pub struct Document { diagnostics: Vec, ast_db: PgQueryStore, cst_db: TreeSitterStore, - #[allow(dead_code)] - annotation_db: AnnotationStore, suppressions: Suppressions, } @@ -30,7 +27,6 @@ impl Document { pub fn new(content: String, version: i32) -> Document { let cst_db = TreeSitterStore::new(); let ast_db = PgQueryStore::new(); - let annotation_db = AnnotationStore::new(); let (ranges, diagnostics) = split_with_diagnostics(&content, None); let suppressions = Suppressions::from(content.as_str()).with_statements(ranges.clone()); @@ -41,7 +37,6 @@ impl Document { version, ast_db, cst_db, - annotation_db, suppressions, } } @@ -67,7 +62,6 @@ impl Document { |id: &StatementId| statements.contains(id.parent_content().unwrap_or(id.content())); self.ast_db.retain(is_present); self.cst_db.retain(is_present); - self.annotation_db.retain(is_present); } pub fn suppressions(&self) -> &Suppressions { @@ -130,7 +124,6 @@ impl Document { } } - #[allow(dead_code)] pub fn count(&self) -> usize { self.iter(DefaultMapper).count() } @@ -346,28 +339,6 @@ impl<'a> StatementMapper<'a> for WithCSTMapper { } } -pub struct WithCSTandASTMapper; -impl<'a> StatementMapper<'a> for WithCSTandASTMapper { - type Output = ( - StatementId, - TextRange, - Arc, - Option, - ); - - fn map(&self, parser: &'a Document, id: StatementId, range: TextRange) -> Self::Output { - let tree = parser.cst_db.get_or_cache_tree(&id); - let ast_result = parser.ast_db.get_or_cache_ast(&id); - - let ast_option = match &*ast_result { - Ok(node) => Some(node.clone()), - Err(_) => None, - }; - - (id.clone(), range, tree, ast_option) - } -} - /* * We allow an offset of two for the statement: *