diff --git a/Cargo.lock b/Cargo.lock index 647215b80..8055b1c4b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2647,7 +2647,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 a49f204a5..38e1d8897 100644 --- a/crates/pgls_catalog/src/snapshot/mod.rs +++ b/crates/pgls_catalog/src/snapshot/mod.rs @@ -197,20 +197,6 @@ impl Snapshot { .collect() } - pub fn find_types(&self, name: &str, schema: Option<&str>) -> Vec<&PostgresType> { - let sanitized_name = Self::sanitize_identifier(name); - self.types - .iter() - .filter(|t| { - t.name == sanitized_name - && schema - .map(Self::sanitize_identifier) - .as_deref() - .is_none_or(|s| s == t.schema.as_str()) - }) - .collect() - } - pub fn find_functions(&self, name: &str, schema: Option<&str>) -> Vec<&Function> { let sanitized_name = Self::sanitize_identifier(name); self.functions diff --git a/crates/pgls_hover/src/hovered_node.rs b/crates/pgls_hover/src/hovered_node.rs index b213bb5e2..49d88e59b 100644 --- a/crates/pgls_hover/src/hovered_node.rs +++ b/crates/pgls_hover/src/hovered_node.rs @@ -9,8 +9,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 0eda1457b..00d76457a 100644 --- a/crates/pgls_hover/src/lib.rs +++ b/crates/pgls_hover/src/lib.rs @@ -18,7 +18,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 @@ -45,21 +44,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 @@ -119,23 +109,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) @@ -172,7 +153,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 74b6b9b9d..e7a94350f 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 776a10291..08a281c6a 100644 --- a/crates/pgls_lsp/Cargo.toml +++ b/crates/pgls_lsp/Cargo.toml @@ -17,7 +17,6 @@ futures = "0.3.31" 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 94f473687..c0d4287f7 100644 --- a/crates/pgls_lsp/src/server.rs +++ b/crates/pgls_lsp/src/server.rs @@ -1,8 +1,6 @@ use crate::capabilities::server_capabilities; use crate::handlers; -use crate::session::{ - CapabilitySet, CapabilityStatus, ClientInformation, Session, SessionHandle, SessionKey, -}; +use crate::session::{CapabilitySet, CapabilityStatus, Session, SessionHandle, SessionKey}; use crate::utils::{into_lsp_error, panic_to_lsp_error}; use futures::FutureExt; use futures::future::ready; @@ -115,10 +113,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 7807a87bb..859d143c8 100644 --- a/crates/pgls_lsp/src/session.rs +++ b/crates/pgls_lsp/src/session.rs @@ -41,16 +41,6 @@ use tracing::{debug, error, info}; /// and the timer resets, so only one analysis run fires per burst. const DIAGNOSTIC_DEBOUNCE: Duration = Duration::from_millis(300); -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); @@ -131,10 +121,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>, } @@ -240,13 +227,11 @@ impl Session { pub(crate) fn initialize( &self, client_capabilities: ls_types::ClientCapabilities, - client_information: Option, root_uri: Option, workspace_folders: Option>, ) { let result = self.initialize_params.set(InitializeParams { client_capabilities, - client_information, root_uri, workspace_folders, }); diff --git a/crates/pgls_lsp/src/utils.rs b/crates/pgls_lsp/src/utils.rs index a4b01f2c0..ac89ee39f 100644 --- a/crates/pgls_lsp/src/utils.rs +++ b/crates/pgls_lsp/src/utils.rs @@ -2,10 +2,6 @@ use crate::adapters::from_lsp::text_range; use crate::adapters::line_index::LineIndex; use crate::adapters::{PositionEncoding, to_lsp}; use anyhow::{Context, Result, ensure}; -use pgls_console::MarkupBuf; -use pgls_console::fmt::Termcolor; -use pgls_console::fmt::{self, Formatter}; -use pgls_diagnostics::termcolor::NoColor; use pgls_diagnostics::{Diagnostic, DiagnosticTags, Location, PrintDescription, Severity, Visit}; use pgls_text_size::{TextRange, TextSize}; use std::any::Any; @@ -141,18 +137,6 @@ impl Visit for RelatedInformationVisitor<'_> { } } -/// Convert a piece of markup into a String -#[allow(unused)] -fn print_markup(markup: &MarkupBuf) -> String { - let mut message = Termcolor(NoColor::new(Vec::new())); - fmt::Display::fmt(markup, &mut Formatter::new(&mut message)) - // SAFETY: Writing to a memory buffer should never fail - .unwrap(); - - // SAFETY: Printing uncolored markup never generates non UTF-8 byte sequences - String::from_utf8(message.0.into_inner()).unwrap() -} - /// Helper to create a [tower_lsp_server::jsonrpc::Error] from a message pub(crate) fn into_lsp_error(msg: impl Display + Debug) -> LspError { let mut error = LspError::internal_error(); diff --git a/crates/pgls_workspace/src/workspace/server.rs b/crates/pgls_workspace/src/workspace/server.rs index 76bb44c26..4c93e6112 100644 --- a/crates/pgls_workspace/src/workspace/server.rs +++ b/crates/pgls_workspace/src/workspace/server.rs @@ -74,7 +74,7 @@ use crate::{ on_hover::{OnHoverParams, OnHoverResult}, }, settings::{Settings, WorkspaceSettings, WorkspaceSettingsHandle, WorkspaceSettingsHandleMut}, - workspace::{AnalyserDiagnosticsMapper, WithCSTandASTMapper}, + workspace::{AnalyserDiagnosticsMapper, WithCSTMapper}, }; use super::{ @@ -86,7 +86,6 @@ use super::{ pub use statement_identifier::StatementId; mod analyser; -mod annotation; #[cfg(feature = "db")] mod async_helper; mod cache_budget; @@ -1738,8 +1737,8 @@ impl Workspace for WorkspaceServer { }; // The innermost statement: the body of a SQL function rather than its `CREATE FUNCTION`. - let result = match doc.iter_at(WithCSTandASTMapper, params.position).last() { - Some((stmt_id, range, ts_tree, maybe_ast)) => { + let result = 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(doc, &stmt_id, range, params.position, snapshot); @@ -1747,7 +1746,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_deref(), 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 209823984..000000000 --- a/crates/pgls_workspace/src/workspace/server/annotation.rs +++ /dev/null @@ -1,99 +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 every cached annotation. - pub fn clear(&self) { - self.db.lock().unwrap().clear(); - } - - /// 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 c2521e872..96074bab0 100644 --- a/crates/pgls_workspace/src/workspace/server/document.rs +++ b/crates/pgls_workspace/src/workspace/server/document.rs @@ -9,7 +9,6 @@ use pgls_text_size::{TextRange, TextSize}; use rustc_hash::FxHashSet; use super::{ - annotation::AnnotationStore, pg_query::{PgQueryStore, convert_to_positional_params_with_metadata}, sql_function::{SQLFunctionSignature, get_sql_fn_body, get_sql_fn_signature}, statement_identifier::StatementId, @@ -24,8 +23,6 @@ pub struct Document { diagnostics: Vec, ast_db: PgQueryStore, cst_db: TreeSitterStore, - #[allow(dead_code)] - annotation_db: AnnotationStore, suppressions: Suppressions, /// Cleared when the content changes. analysis: Mutex>, @@ -35,7 +32,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 suppressions = Suppressions::from(content.as_str()); let split = pgls_statement_splitter::split(&content); @@ -48,7 +44,6 @@ impl Document { version, ast_db, cst_db, - annotation_db, suppressions, analysis: Mutex::default(), } @@ -75,7 +70,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); *self.analysis.get_mut().unwrap() = None; } @@ -102,7 +96,6 @@ impl Document { pub fn clear_caches(&self) { self.ast_db.clear(); self.cst_db.clear(); - self.annotation_db.clear(); *self.analysis.lock().unwrap() = None; } @@ -167,7 +160,6 @@ impl Document { } } - #[allow(dead_code)] pub fn count(&self) -> usize { self.iter(DefaultMapper).count() } @@ -408,28 +400,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: * diff --git a/crates/pgls_workspace/src/workspace/server/sql_function.rs b/crates/pgls_workspace/src/workspace/server/sql_function.rs index 02b9ff36c..88b58642c 100644 --- a/crates/pgls_workspace/src/workspace/server/sql_function.rs +++ b/crates/pgls_workspace/src/workspace/server/sql_function.rs @@ -16,8 +16,6 @@ pub struct SQLFunctionArg { #[derive(Debug, Clone)] pub struct SQLFunctionSignature { - #[allow(dead_code)] - pub schema: Option, pub name: String, pub args: Vec, } @@ -87,7 +85,6 @@ pub fn get_sql_fn_signature(ast: &pgls_query::NodeEnum) -> Option