From 0bfd2d7cf046e2ec5bc53e3496b35debb228b971 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 15 Jul 2026 12:46:01 +0200 Subject: [PATCH] language_core: Remove lsp-types dependency (#61041) Release Notes: - N/A or Added/Fixed/Improved ... --- Cargo.lock | 1 - crates/language/src/diagnostic.rs | 77 +++++++++++++++- crates/language/src/language.rs | 87 +++++++++++++++++-- crates/language_core/Cargo.toml | 1 - crates/language_core/src/code_label.rs | 66 +++++++++++++- crates/language_core/src/diagnostic.rs | 76 ---------------- crates/language_core/src/language_core.rs | 8 +- crates/language_core/src/lsp_adapter.rs | 17 ---- .../src/extension_lsp_adapter.rs | 57 ++++++------ crates/languages/src/c.rs | 14 +-- crates/languages/src/go.rs | 14 +-- crates/languages/src/python.rs | 6 +- crates/languages/src/rust.rs | 26 +++--- crates/project/src/lsp_command.rs | 15 ++-- crates/project/src/lsp_store.rs | 16 ++-- .../project/src/lsp_store/document_symbols.rs | 3 +- crates/project/src/project.rs | 4 +- 17 files changed, 301 insertions(+), 187 deletions(-) delete mode 100644 crates/language_core/src/diagnostic.rs diff --git a/Cargo.lock b/Cargo.lock index a3cc732382..6293cb2a21 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9755,7 +9755,6 @@ dependencies = [ "gpui_shared_string", "gpui_util", "log", - "lsp-types", "parking_lot", "path", "regex", diff --git a/crates/language/src/diagnostic.rs b/crates/language/src/diagnostic.rs index 951feec0da..9a468a14b8 100644 --- a/crates/language/src/diagnostic.rs +++ b/crates/language/src/diagnostic.rs @@ -1 +1,76 @@ -pub use language_core::diagnostic::{Diagnostic, DiagnosticSourceKind}; +use gpui::SharedString; +use lsp::{DiagnosticSeverity, NumberOrString}; +use serde::{Deserialize, Serialize}; +use serde_json::Value; + +/// A diagnostic associated with a certain range of a buffer. +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct Diagnostic { + /// The name of the service that produced this diagnostic. + pub source: Option, + /// The ID provided by the dynamic registration that produced this diagnostic. + pub registration_id: Option, + /// A machine-readable code that identifies this diagnostic. + pub code: Option, + pub code_description: Option, + /// Whether this diagnostic is a hint, warning, or error. + pub severity: DiagnosticSeverity, + /// The human-readable message associated with this diagnostic. + pub message: String, + /// The human-readable message (in markdown format) + pub markdown: Option, + /// An id that identifies the group to which this diagnostic belongs. + /// + /// When a language server produces a diagnostic with + /// one or more associated diagnostics, those diagnostics are all + /// assigned a single group ID. + pub group_id: usize, + /// Whether this diagnostic is the primary diagnostic for its group. + /// + /// In a given group, the primary diagnostic is the top-level diagnostic + /// returned by the language server. The non-primary diagnostics are the + /// associated diagnostics. + pub is_primary: bool, + /// Whether this diagnostic is considered to originate from an analysis of + /// files on disk, as opposed to any unsaved buffer contents. This is a + /// property of a given diagnostic source, and is configured for a given + /// language server via the `LspAdapter::disk_based_diagnostic_sources` method + /// for the language server. + pub is_disk_based: bool, + /// Whether this diagnostic marks unnecessary code. + pub is_unnecessary: bool, + /// Quick separation of diagnostics groups based by their source. + pub source_kind: DiagnosticSourceKind, + /// Data from language server that produced this diagnostic. Passed back to the LS when we request code actions for this diagnostic. + pub data: Option, + /// Whether to underline the corresponding text range in the editor. + pub underline: bool, +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub enum DiagnosticSourceKind { + Pulled, + Pushed, + Other, +} + +impl Default for Diagnostic { + fn default() -> Self { + Self { + source: Default::default(), + source_kind: DiagnosticSourceKind::Other, + code: None, + code_description: None, + severity: DiagnosticSeverity::ERROR, + message: Default::default(), + markdown: None, + group_id: 0, + is_primary: false, + is_disk_based: false, + is_unnecessary: false, + underline: true, + data: None, + registration_id: None, + } + } +} diff --git a/crates/language/src/language.rs b/crates/language/src/language.rs index b9f87265c0..9a031347ec 100644 --- a/crates/language/src/language.rs +++ b/crates/language/src/language.rs @@ -39,7 +39,10 @@ use futures::lock::OwnedMutexGuard; use gpui::{App, AsyncApp, Entity}; use http_client::HttpClient; -pub use language_core::highlight_map::{HighlightId, HighlightMap}; +pub use language_core::{ + SymbolKind, + highlight_map::{HighlightId, HighlightMap}, +}; use futures::future::FutureExt as _; pub use language_core::{ @@ -48,10 +51,10 @@ pub use language_core::{ DecreaseIndentConfig, Grammar, GrammarId, HighlightsConfig, IndentConfig, InjectionConfig, InjectionPatternConfig, JsxTagAutoCloseConfig, LanguageConfig, LanguageConfigOverride, LanguageId, LanguageMatcher, OrderedListConfig, OutlineConfig, Override, OverrideConfig, - OverrideEntry, PromptResponseContext, RedactionConfig, RunnableCapture, RunnableConfig, - SoftWrap, Symbol, TaskListConfig, TextObject, TextObjectConfig, ToLspPosition, - WrapCharactersConfig, default_true, deserialize_regex, deserialize_regex_vec, - regex_json_schema, regex_vec_json_schema, serialize_regex, + OverrideEntry, RedactionConfig, RunnableCapture, RunnableConfig, SoftWrap, Symbol, + TaskListConfig, TextObject, TextObjectConfig, WrapCharactersConfig, default_true, + deserialize_regex, deserialize_regex_vec, regex_json_schema, regex_vec_json_schema, + serialize_regex, }; pub use language_registry::{ LanguageName, LanguageServerStatusUpdate, LoadedLanguage, ServerHealth, @@ -216,6 +219,69 @@ pub static PLAIN_TEXT: LazyLock> = LazyLock::new(|| { )) }); +pub fn symbol_kind_to_lsp(kind: SymbolKind) -> lsp::SymbolKind { + match kind { + SymbolKind::File => lsp::SymbolKind::FILE, + SymbolKind::Module => lsp::SymbolKind::MODULE, + SymbolKind::Namespace => lsp::SymbolKind::NAMESPACE, + SymbolKind::Package => lsp::SymbolKind::PACKAGE, + SymbolKind::Class => lsp::SymbolKind::CLASS, + SymbolKind::Method => lsp::SymbolKind::METHOD, + SymbolKind::Property => lsp::SymbolKind::PROPERTY, + SymbolKind::Field => lsp::SymbolKind::FIELD, + SymbolKind::Constructor => lsp::SymbolKind::CONSTRUCTOR, + SymbolKind::Enum => lsp::SymbolKind::ENUM, + SymbolKind::Interface => lsp::SymbolKind::INTERFACE, + SymbolKind::Function => lsp::SymbolKind::FUNCTION, + SymbolKind::Variable => lsp::SymbolKind::VARIABLE, + SymbolKind::Constant => lsp::SymbolKind::CONSTANT, + SymbolKind::String => lsp::SymbolKind::STRING, + SymbolKind::Number => lsp::SymbolKind::NUMBER, + SymbolKind::Boolean => lsp::SymbolKind::BOOLEAN, + SymbolKind::Array => lsp::SymbolKind::ARRAY, + SymbolKind::Object => lsp::SymbolKind::OBJECT, + SymbolKind::Key => lsp::SymbolKind::KEY, + SymbolKind::Null => lsp::SymbolKind::NULL, + SymbolKind::EnumMember => lsp::SymbolKind::ENUM_MEMBER, + SymbolKind::Struct => lsp::SymbolKind::STRUCT, + SymbolKind::Event => lsp::SymbolKind::EVENT, + SymbolKind::Operator => lsp::SymbolKind::OPERATOR, + SymbolKind::TypeParameter => lsp::SymbolKind::TYPE_PARAMETER, + } +} + +pub fn lsp_to_symbol_kind(kind: lsp::SymbolKind) -> SymbolKind { + match kind { + lsp::SymbolKind::FILE => SymbolKind::File, + lsp::SymbolKind::MODULE => SymbolKind::Module, + lsp::SymbolKind::NAMESPACE => SymbolKind::Namespace, + lsp::SymbolKind::PACKAGE => SymbolKind::Package, + lsp::SymbolKind::CLASS => SymbolKind::Class, + lsp::SymbolKind::METHOD => SymbolKind::Method, + lsp::SymbolKind::PROPERTY => SymbolKind::Property, + lsp::SymbolKind::FIELD => SymbolKind::Field, + lsp::SymbolKind::CONSTRUCTOR => SymbolKind::Constructor, + lsp::SymbolKind::ENUM => SymbolKind::Enum, + lsp::SymbolKind::INTERFACE => SymbolKind::Interface, + lsp::SymbolKind::FUNCTION => SymbolKind::Function, + lsp::SymbolKind::VARIABLE => SymbolKind::Variable, + lsp::SymbolKind::CONSTANT => SymbolKind::Constant, + lsp::SymbolKind::STRING => SymbolKind::String, + lsp::SymbolKind::NUMBER => SymbolKind::Number, + lsp::SymbolKind::BOOLEAN => SymbolKind::Boolean, + lsp::SymbolKind::ARRAY => SymbolKind::Array, + lsp::SymbolKind::OBJECT => SymbolKind::Object, + lsp::SymbolKind::KEY => SymbolKind::Key, + lsp::SymbolKind::NULL => SymbolKind::Null, + lsp::SymbolKind::ENUM_MEMBER => SymbolKind::EnumMember, + lsp::SymbolKind::STRUCT => SymbolKind::Struct, + lsp::SymbolKind::EVENT => SymbolKind::Event, + lsp::SymbolKind::OPERATOR => SymbolKind::Operator, + lsp::SymbolKind::TYPE_PARAMETER => SymbolKind::TypeParameter, + _ => SymbolKind::Null, + } +} + /// Commands that the client (editor) handles locally rather than forwarding /// to the language server. Servers embed these in code lens and code action /// responses when they want the editor to perform a well-known UI action. @@ -233,6 +299,17 @@ pub struct Location { pub range: Range, } +/// Context provided to LSP adapters when a user responds to a ShowMessageRequest prompt. +/// This allows adapters to intercept preference selections (like "Always" or "Never") +/// and potentially persist them to Zed's settings. +#[derive(Debug, Clone)] +pub struct PromptResponseContext { + /// The original message shown to the user + pub message: String, + /// The action (button) the user selected + pub selected_action: lsp::MessageActionItem, +} + type ServerBinaryCache = futures::lock::Mutex>; type DownloadableLanguageServerBinary = LocalBoxFuture<'static, Result>; pub type LanguageServerBinaryLocations = LocalBoxFuture< diff --git a/crates/language_core/Cargo.toml b/crates/language_core/Cargo.toml index 47a30d8316..7d77847a9c 100644 --- a/crates/language_core/Cargo.toml +++ b/crates/language_core/Cargo.toml @@ -13,7 +13,6 @@ collections.workspace = true gpui_shared_string.workspace = true gpui_util.workspace = true log.workspace = true -lsp-types.workspace = true parking_lot.workspace = true path.workspace = true regex.workspace = true diff --git a/crates/language_core/src/code_label.rs b/crates/language_core/src/code_label.rs index 74e1d43e0c..d171527478 100644 --- a/crates/language_core/src/code_label.rs +++ b/crates/language_core/src/code_label.rs @@ -1,10 +1,74 @@ use crate::highlight_map::HighlightId; use std::ops::Range; +#[derive(Debug, Eq, PartialEq, Copy, Clone)] +pub enum SymbolKind { + File, + Module, + Namespace, + Package, + Class, + Method, + Property, + Field, + Constructor, + Enum, + Interface, + Function, + Variable, + Constant, + String, + Number, + Boolean, + Array, + Object, + Key, + Null, + EnumMember, + Struct, + Event, + Operator, + TypeParameter, +} + +impl SymbolKind { + pub fn from_proto(i32: i32) -> Self { + match i32 { + 1 => SymbolKind::File, + 2 => SymbolKind::Module, + 3 => SymbolKind::Namespace, + 4 => SymbolKind::Package, + 5 => SymbolKind::Class, + 6 => SymbolKind::Method, + 7 => SymbolKind::Property, + 8 => SymbolKind::Field, + 9 => SymbolKind::Constructor, + 10 => SymbolKind::Enum, + 11 => SymbolKind::Interface, + 12 => SymbolKind::Function, + 13 => SymbolKind::Variable, + 14 => SymbolKind::Constant, + 15 => SymbolKind::String, + 16 => SymbolKind::Number, + 17 => SymbolKind::Boolean, + 18 => SymbolKind::Array, + 19 => SymbolKind::Object, + 20 => SymbolKind::Key, + 21 => SymbolKind::Null, + 22 => SymbolKind::EnumMember, + 23 => SymbolKind::Struct, + 24 => SymbolKind::Event, + 25 => SymbolKind::Operator, + 26 => SymbolKind::TypeParameter, + _ => SymbolKind::Null, + } + } +} + #[derive(Debug, Clone)] pub struct Symbol { pub name: String, - pub kind: lsp_types::SymbolKind, + pub kind: SymbolKind, pub container_name: Option, } diff --git a/crates/language_core/src/diagnostic.rs b/crates/language_core/src/diagnostic.rs deleted file mode 100644 index b8c4fe8535..0000000000 --- a/crates/language_core/src/diagnostic.rs +++ /dev/null @@ -1,76 +0,0 @@ -use gpui_shared_string::SharedString; -use lsp_types::{DiagnosticSeverity, NumberOrString}; -use serde::{Deserialize, Serialize}; -use serde_json::Value; - -/// A diagnostic associated with a certain range of a buffer. -#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] -pub struct Diagnostic { - /// The name of the service that produced this diagnostic. - pub source: Option, - /// The ID provided by the dynamic registration that produced this diagnostic. - pub registration_id: Option, - /// A machine-readable code that identifies this diagnostic. - pub code: Option, - pub code_description: Option, - /// Whether this diagnostic is a hint, warning, or error. - pub severity: DiagnosticSeverity, - /// The human-readable message associated with this diagnostic. - pub message: String, - /// The human-readable message (in markdown format) - pub markdown: Option, - /// An id that identifies the group to which this diagnostic belongs. - /// - /// When a language server produces a diagnostic with - /// one or more associated diagnostics, those diagnostics are all - /// assigned a single group ID. - pub group_id: usize, - /// Whether this diagnostic is the primary diagnostic for its group. - /// - /// In a given group, the primary diagnostic is the top-level diagnostic - /// returned by the language server. The non-primary diagnostics are the - /// associated diagnostics. - pub is_primary: bool, - /// Whether this diagnostic is considered to originate from an analysis of - /// files on disk, as opposed to any unsaved buffer contents. This is a - /// property of a given diagnostic source, and is configured for a given - /// language server via the `LspAdapter::disk_based_diagnostic_sources` method - /// for the language server. - pub is_disk_based: bool, - /// Whether this diagnostic marks unnecessary code. - pub is_unnecessary: bool, - /// Quick separation of diagnostics groups based by their source. - pub source_kind: DiagnosticSourceKind, - /// Data from language server that produced this diagnostic. Passed back to the LS when we request code actions for this diagnostic. - pub data: Option, - /// Whether to underline the corresponding text range in the editor. - pub underline: bool, -} - -#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] -pub enum DiagnosticSourceKind { - Pulled, - Pushed, - Other, -} - -impl Default for Diagnostic { - fn default() -> Self { - Self { - source: Default::default(), - source_kind: DiagnosticSourceKind::Other, - code: None, - code_description: None, - severity: DiagnosticSeverity::ERROR, - message: Default::default(), - markdown: None, - group_id: 0, - is_primary: false, - is_disk_based: false, - is_unnecessary: false, - underline: true, - data: None, - registration_id: None, - } - } -} diff --git a/crates/language_core/src/language_core.rs b/crates/language_core/src/language_core.rs index 8a45bd57a2..2edbcbea9d 100644 --- a/crates/language_core/src/language_core.rs +++ b/crates/language_core/src/language_core.rs @@ -1,12 +1,10 @@ // language_core: tree-sitter grammar infrastructure, LSP adapter traits, // language configuration, and highlight mapping. -pub mod diagnostic; pub mod grammar; pub mod highlight_map; pub mod language_config; -pub use diagnostic::{Diagnostic, DiagnosticSourceKind}; pub use grammar::{ BracketsConfig, BracketsPatternConfig, DebugVariablesConfig, DebuggerTextObject, Grammar, GrammarId, HighlightsConfig, IndentConfig, InjectionConfig, InjectionPatternConfig, @@ -29,11 +27,9 @@ pub mod manifest; pub mod queries; pub mod toolchain; -pub use code_label::{CodeLabel, CodeLabelBuilder, Symbol}; +pub use code_label::{CodeLabel, CodeLabelBuilder, Symbol, SymbolKind}; pub use language_name::{LanguageId, LanguageName}; -pub use lsp_adapter::{ - BinaryStatus, LanguageServerStatusUpdate, PromptResponseContext, ServerHealth, ToLspPosition, -}; +pub use lsp_adapter::{BinaryStatus, LanguageServerStatusUpdate, ServerHealth}; pub use manifest::ManifestName; pub use queries::{LanguageQueries, QUERY_FILENAME_PREFIXES}; pub use toolchain::{Toolchain, ToolchainList, ToolchainMetadata, ToolchainScope}; diff --git a/crates/language_core/src/lsp_adapter.rs b/crates/language_core/src/lsp_adapter.rs index 230e1b4aa1..34fac0790b 100644 --- a/crates/language_core/src/lsp_adapter.rs +++ b/crates/language_core/src/lsp_adapter.rs @@ -1,23 +1,6 @@ use gpui_shared_string::SharedString; use serde::{Deserialize, Serialize}; -/// Converts a value into an LSP position. -pub trait ToLspPosition { - /// Converts the value into an LSP position. - fn to_lsp_position(self) -> lsp_types::Position; -} - -/// Context provided to LSP adapters when a user responds to a ShowMessageRequest prompt. -/// This allows adapters to intercept preference selections (like "Always" or "Never") -/// and potentially persist them to Zed's settings. -#[derive(Debug, Clone)] -pub struct PromptResponseContext { - /// The original message shown to the user - pub message: String, - /// The action (button) the user selected - pub selected_action: lsp_types::MessageActionItem, -} - #[derive(Clone, Debug, PartialEq, Eq)] pub enum LanguageServerStatusUpdate { Binary(BinaryStatus), diff --git a/crates/language_extension/src/extension_lsp_adapter.rs b/crates/language_extension/src/extension_lsp_adapter.rs index 44092bf263..d9f28100d8 100644 --- a/crates/language_extension/src/extension_lsp_adapter.rs +++ b/crates/language_extension/src/extension_lsp_adapter.rs @@ -476,7 +476,7 @@ impl LspAdapter for ExtensionLspAdapter { container_name, }| extension::Symbol { name, - kind: lsp_symbol_kind_to_extension(kind), + kind: symbol_kind_to_extension(kind), container_name, }, ) @@ -636,35 +636,34 @@ fn lsp_insert_text_format_to_extension( } } -fn lsp_symbol_kind_to_extension(value: lsp::SymbolKind) -> extension::SymbolKind { +fn symbol_kind_to_extension(value: language::SymbolKind) -> extension::SymbolKind { match value { - lsp::SymbolKind::FILE => extension::SymbolKind::File, - lsp::SymbolKind::MODULE => extension::SymbolKind::Module, - lsp::SymbolKind::NAMESPACE => extension::SymbolKind::Namespace, - lsp::SymbolKind::PACKAGE => extension::SymbolKind::Package, - lsp::SymbolKind::CLASS => extension::SymbolKind::Class, - lsp::SymbolKind::METHOD => extension::SymbolKind::Method, - lsp::SymbolKind::PROPERTY => extension::SymbolKind::Property, - lsp::SymbolKind::FIELD => extension::SymbolKind::Field, - lsp::SymbolKind::CONSTRUCTOR => extension::SymbolKind::Constructor, - lsp::SymbolKind::ENUM => extension::SymbolKind::Enum, - lsp::SymbolKind::INTERFACE => extension::SymbolKind::Interface, - lsp::SymbolKind::FUNCTION => extension::SymbolKind::Function, - lsp::SymbolKind::VARIABLE => extension::SymbolKind::Variable, - lsp::SymbolKind::CONSTANT => extension::SymbolKind::Constant, - lsp::SymbolKind::STRING => extension::SymbolKind::String, - lsp::SymbolKind::NUMBER => extension::SymbolKind::Number, - lsp::SymbolKind::BOOLEAN => extension::SymbolKind::Boolean, - lsp::SymbolKind::ARRAY => extension::SymbolKind::Array, - lsp::SymbolKind::OBJECT => extension::SymbolKind::Object, - lsp::SymbolKind::KEY => extension::SymbolKind::Key, - lsp::SymbolKind::NULL => extension::SymbolKind::Null, - lsp::SymbolKind::ENUM_MEMBER => extension::SymbolKind::EnumMember, - lsp::SymbolKind::STRUCT => extension::SymbolKind::Struct, - lsp::SymbolKind::EVENT => extension::SymbolKind::Event, - lsp::SymbolKind::OPERATOR => extension::SymbolKind::Operator, - lsp::SymbolKind::TYPE_PARAMETER => extension::SymbolKind::TypeParameter, - _ => extension::SymbolKind::Other(extract_int(value)), + language::SymbolKind::File => extension::SymbolKind::File, + language::SymbolKind::Module => extension::SymbolKind::Module, + language::SymbolKind::Namespace => extension::SymbolKind::Namespace, + language::SymbolKind::Package => extension::SymbolKind::Package, + language::SymbolKind::Class => extension::SymbolKind::Class, + language::SymbolKind::Method => extension::SymbolKind::Method, + language::SymbolKind::Property => extension::SymbolKind::Property, + language::SymbolKind::Field => extension::SymbolKind::Field, + language::SymbolKind::Constructor => extension::SymbolKind::Constructor, + language::SymbolKind::Enum => extension::SymbolKind::Enum, + language::SymbolKind::Interface => extension::SymbolKind::Interface, + language::SymbolKind::Function => extension::SymbolKind::Function, + language::SymbolKind::Variable => extension::SymbolKind::Variable, + language::SymbolKind::Constant => extension::SymbolKind::Constant, + language::SymbolKind::String => extension::SymbolKind::String, + language::SymbolKind::Number => extension::SymbolKind::Number, + language::SymbolKind::Boolean => extension::SymbolKind::Boolean, + language::SymbolKind::Array => extension::SymbolKind::Array, + language::SymbolKind::Object => extension::SymbolKind::Object, + language::SymbolKind::Key => extension::SymbolKind::Key, + language::SymbolKind::Null => extension::SymbolKind::Null, + language::SymbolKind::EnumMember => extension::SymbolKind::EnumMember, + language::SymbolKind::Struct => extension::SymbolKind::Struct, + language::SymbolKind::Event => extension::SymbolKind::Event, + language::SymbolKind::Operator => extension::SymbolKind::Operator, + language::SymbolKind::TypeParameter => extension::SymbolKind::TypeParameter, } } diff --git a/crates/languages/src/c.rs b/crates/languages/src/c.rs index eb24dea0de..ee2d214caf 100644 --- a/crates/languages/src/c.rs +++ b/crates/languages/src/c.rs @@ -300,43 +300,43 @@ impl super::LspAdapter for CLspAdapter { ) -> Option { let name = &symbol.name; let (text, filter_range, display_range) = match symbol.kind { - lsp::SymbolKind::METHOD | lsp::SymbolKind::FUNCTION => { + language::SymbolKind::Method | language::SymbolKind::Function => { let text = format!("void {} () {{}}", name); let filter_range = 0..name.len(); let display_range = 5..5 + name.len(); (text, filter_range, display_range) } - lsp::SymbolKind::STRUCT => { + language::SymbolKind::Struct => { let text = format!("struct {} {{}}", name); let filter_range = 7..7 + name.len(); let display_range = 0..filter_range.end; (text, filter_range, display_range) } - lsp::SymbolKind::ENUM => { + language::SymbolKind::Enum => { let text = format!("enum {} {{}}", name); let filter_range = 5..5 + name.len(); let display_range = 0..filter_range.end; (text, filter_range, display_range) } - lsp::SymbolKind::INTERFACE | lsp::SymbolKind::CLASS => { + language::SymbolKind::Interface | language::SymbolKind::Class => { let text = format!("class {} {{}}", name); let filter_range = 6..6 + name.len(); let display_range = 0..filter_range.end; (text, filter_range, display_range) } - lsp::SymbolKind::CONSTANT => { + language::SymbolKind::Constant => { let text = format!("const int {} = 0;", name); let filter_range = 10..10 + name.len(); let display_range = 0..filter_range.end; (text, filter_range, display_range) } - lsp::SymbolKind::MODULE => { + language::SymbolKind::Module => { let text = format!("namespace {} {{}}", name); let filter_range = 10..10 + name.len(); let display_range = 0..filter_range.end; (text, filter_range, display_range) } - lsp::SymbolKind::TYPE_PARAMETER => { + language::SymbolKind::TypeParameter => { let text = format!("typename {} {{}};", name); let filter_range = 9..9 + name.len(); let display_range = 0..filter_range.end; diff --git a/crates/languages/src/go.rs b/crates/languages/src/go.rs index 87efea16c8..d2e68be4f1 100644 --- a/crates/languages/src/go.rs +++ b/crates/languages/src/go.rs @@ -394,43 +394,43 @@ impl LspAdapter for GoLspAdapter { ) -> Option { let name = &symbol.name; let (text, filter_range, display_range) = match symbol.kind { - lsp::SymbolKind::METHOD | lsp::SymbolKind::FUNCTION => { + language::SymbolKind::Method | language::SymbolKind::Function => { let text = format!("func {} () {{}}", name); let filter_range = 5..5 + name.len(); let display_range = 0..filter_range.end; (text, filter_range, display_range) } - lsp::SymbolKind::STRUCT => { + language::SymbolKind::Struct => { let text = format!("type {} struct {{}}", name); let filter_range = 5..5 + name.len(); let display_range = 0..text.len(); (text, filter_range, display_range) } - lsp::SymbolKind::INTERFACE => { + language::SymbolKind::Interface => { let text = format!("type {} interface {{}}", name); let filter_range = 5..5 + name.len(); let display_range = 0..text.len(); (text, filter_range, display_range) } - lsp::SymbolKind::CLASS => { + language::SymbolKind::Class => { let text = format!("type {} T", name); let filter_range = 5..5 + name.len(); let display_range = 0..filter_range.end; (text, filter_range, display_range) } - lsp::SymbolKind::CONSTANT => { + language::SymbolKind::Constant => { let text = format!("const {} = nil", name); let filter_range = 6..6 + name.len(); let display_range = 0..filter_range.end; (text, filter_range, display_range) } - lsp::SymbolKind::VARIABLE => { + language::SymbolKind::Variable => { let text = format!("var {} = nil", name); let filter_range = 4..4 + name.len(); let display_range = 0..filter_range.end; (text, filter_range, display_range) } - lsp::SymbolKind::MODULE => { + language::SymbolKind::Module => { let text = format!("package {}", name); let filter_range = 8..8 + name.len(); let display_range = 0..filter_range.end; diff --git a/crates/languages/src/python.rs b/crates/languages/src/python.rs index 7764f8f240..01d2b450c5 100644 --- a/crates/languages/src/python.rs +++ b/crates/languages/src/python.rs @@ -220,19 +220,19 @@ fn label_for_python_symbol( ) -> Option { let name = &symbol.name; let (text, filter_range, display_range) = match symbol.kind { - lsp::SymbolKind::METHOD | lsp::SymbolKind::FUNCTION => { + language::SymbolKind::Method | language::SymbolKind::Function => { let text = format!("def {}():\n", name); let filter_range = 4..4 + name.len(); let display_range = 0..filter_range.end; (text, filter_range, display_range) } - lsp::SymbolKind::CLASS => { + language::SymbolKind::Class => { let text = format!("class {}:", name); let filter_range = 6..6 + name.len(); let display_range = 0..filter_range.end; (text, filter_range, display_range) } - lsp::SymbolKind::CONSTANT => { + language::SymbolKind::Constant => { let text = format!("{} = 0", name); let filter_range = 0..name.len(); let display_range = 0..filter_range.end; diff --git a/crates/languages/src/rust.rs b/crates/languages/src/rust.rs index b34e92bbd9..4091be97ed 100644 --- a/crates/languages/src/rust.rs +++ b/crates/languages/src/rust.rs @@ -622,15 +622,15 @@ impl LspAdapter for RustLspAdapter { ) -> Option { let name = &symbol.name; let (prefix, suffix) = match symbol.kind { - lsp::SymbolKind::METHOD | lsp::SymbolKind::FUNCTION => ("fn ", "();"), - lsp::SymbolKind::STRUCT => ("struct ", ";"), - lsp::SymbolKind::ENUM => ("enum ", "{}"), - lsp::SymbolKind::INTERFACE => ("trait ", "{}"), - lsp::SymbolKind::CONSTANT => ("const ", ":()=();"), - lsp::SymbolKind::MODULE => ("mod ", ";"), - lsp::SymbolKind::PACKAGE => ("extern crate ", ";"), - lsp::SymbolKind::TYPE_PARAMETER => ("type ", "=();"), - lsp::SymbolKind::ENUM_MEMBER => { + language::SymbolKind::Method | language::SymbolKind::Function => ("fn ", "();"), + language::SymbolKind::Struct => ("struct ", ";"), + language::SymbolKind::Enum => ("enum ", "{}"), + language::SymbolKind::Interface => ("trait ", "{}"), + language::SymbolKind::Constant => ("const ", ":()=();"), + language::SymbolKind::Module => ("mod ", ";"), + language::SymbolKind::Package => ("extern crate ", ";"), + language::SymbolKind::TypeParameter => ("type ", "=();"), + language::SymbolKind::EnumMember => { let prefix = "enum E {"; return Some(CodeLabel::new( name.to_string(), @@ -1972,7 +1972,7 @@ mod tests { .label_for_symbol( &language::Symbol { name: "hello".to_string(), - kind: lsp::SymbolKind::FUNCTION, + kind: language::SymbolKind::Function, container_name: None, }, &language @@ -1990,7 +1990,7 @@ mod tests { .label_for_symbol( &language::Symbol { name: "World".to_string(), - kind: lsp::SymbolKind::TYPE_PARAMETER, + kind: language::SymbolKind::TypeParameter, container_name: None, }, &language @@ -2008,7 +2008,7 @@ mod tests { .label_for_symbol( &language::Symbol { name: "zed".to_string(), - kind: lsp::SymbolKind::PACKAGE, + kind: language::SymbolKind::Package, container_name: None, }, &language @@ -2026,7 +2026,7 @@ mod tests { .label_for_symbol( &language::Symbol { name: "Variant".to_string(), - kind: lsp::SymbolKind::ENUM_MEMBER, + kind: language::SymbolKind::EnumMember, container_name: None, }, &language diff --git a/crates/project/src/lsp_command.rs b/crates/project/src/lsp_command.rs index 038950a045..7ed33f280d 100644 --- a/crates/project/src/lsp_command.rs +++ b/crates/project/src/lsp_command.rs @@ -19,7 +19,7 @@ use language::{ Anchor, Bias, Buffer, BufferSnapshot, CachedLspAdapter, CharKind, CharScopeContext, OffsetRangeExt, PointUtf16, ToOffset, ToPointUtf16, Transaction, Unclipped, language_settings::{InlayHintKind, LanguageSettings}, - point_from_lsp, point_to_lsp, + lsp_to_symbol_kind, point_from_lsp, point_to_lsp, proto::{ deserialize_anchor, deserialize_anchor_range, deserialize_version, serialize_anchor, serialize_anchor_range, serialize_version, @@ -35,9 +35,7 @@ use lsp::{ use serde_json::Value; use signature_help::{lsp_to_proto_signature, proto_to_lsp_signature}; -use std::{ - cmp::Reverse, collections::hash_map, mem, ops::Range, path::Path, str::FromStr, sync::Arc, -}; +use std::{cmp::Reverse, collections::hash_map, ops::Range, path::Path, str::FromStr, sync::Arc}; use text::{BufferId, LineEnding}; use util::rel_path::RelPath; use util::{ResultExt as _, debug_panic}; @@ -2035,7 +2033,7 @@ impl LspCommand for GetDocumentSymbols { .into_iter() .map(|lsp_symbol| DocumentSymbol { name: lsp_symbol.name, - kind: lsp_symbol.kind, + kind: lsp_to_symbol_kind(lsp_symbol.kind), range: range_from_lsp(lsp_symbol.location.range), selection_range: range_from_lsp(lsp_symbol.location.range), children: Vec::new(), @@ -2045,7 +2043,7 @@ impl LspCommand for GetDocumentSymbols { fn convert_symbol(lsp_symbol: lsp::DocumentSymbol) -> DocumentSymbol { DocumentSymbol { name: lsp_symbol.name, - kind: lsp_symbol.kind, + kind: lsp_to_symbol_kind(lsp_symbol.kind), range: range_from_lsp(lsp_symbol.range), selection_range: range_from_lsp(lsp_symbol.selection_range), children: lsp_symbol @@ -2097,7 +2095,7 @@ impl LspCommand for GetDocumentSymbols { fn convert_symbol_to_proto(symbol: DocumentSymbol) -> proto::DocumentSymbol { proto::DocumentSymbol { name: symbol.name.clone(), - kind: unsafe { mem::transmute::(symbol.kind) }, + kind: symbol.kind as i32, start: Some(proto::PointUtf16 { row: symbol.range.start.0.row, column: symbol.range.start.0.column, @@ -2140,8 +2138,7 @@ impl LspCommand for GetDocumentSymbols { fn deserialize_symbol_with_children( serialized_symbol: proto::DocumentSymbol, ) -> Result { - let kind = - unsafe { mem::transmute::(serialized_symbol.kind) }; + let kind = language::SymbolKind::from_proto(serialized_symbol.kind); let start = serialized_symbol.start.context("invalid start")?; let end = serialized_symbol.end.context("invalid end")?; diff --git a/crates/project/src/lsp_store.rs b/crates/project/src/lsp_store.rs index e943edd62e..38117a9731 100644 --- a/crates/project/src/lsp_store.rs +++ b/crates/project/src/lsp_store.rs @@ -83,7 +83,7 @@ use language::{ AllLanguageSettings, FormatOnSave, Formatter, LanguageSettings, LineEndingSetting, all_language_settings, }, - modeline, point_to_lsp, + lsp_to_symbol_kind, modeline, point_to_lsp, proto::{ deserialize_anchor, deserialize_anchor_range, deserialize_version, serialize_anchor, serialize_anchor_range, serialize_version, @@ -98,7 +98,7 @@ use lsp::{ FileOperationRegistrationOptions, FileRename, FileSystemWatcher, LanguageServer, LanguageServerBinary, LanguageServerBinaryOptions, LanguageServerId, LanguageServerName, LanguageServerSelector, LspRequestFuture, MessageActionItem, MessageType, OneOf, - RenameFilesParams, SymbolKind, TextDocumentSyncSaveOptions, TextEdit, Uri, WillRenameFiles, + RenameFilesParams, TextDocumentSyncSaveOptions, TextEdit, Uri, WillRenameFiles, WorkDoneProgressCancelParams, WorkspaceFolder, notification::DidRenameFiles, }; use node_runtime::read_package_installed_version; @@ -4273,7 +4273,7 @@ struct CoreSymbol { pub source_language_server_id: LanguageServerId, pub path: SymbolLocation, pub name: String, - pub kind: lsp::SymbolKind, + pub kind: language::SymbolKind, pub range: Range>, pub container_name: Option, } @@ -8173,7 +8173,7 @@ impl LspStore { server_id: LanguageServerId, lsp_adapter: Arc, worktree: WeakEntity, - lsp_symbols: Vec<(String, SymbolKind, lsp::Location, Option)>, + lsp_symbols: Vec<(String, language::SymbolKind, lsp::Location, Option)>, } let mut requests = Vec::new(); @@ -8243,7 +8243,7 @@ impl LspStore { .map(|lsp_symbol| { ( lsp_symbol.name, - lsp_symbol.kind, + lsp_to_symbol_kind(lsp_symbol.kind), lsp_symbol.location, lsp_symbol.container_name, ) @@ -8267,7 +8267,7 @@ impl LspStore { }; Some(( lsp_symbol.name, - lsp_symbol.kind, + lsp_to_symbol_kind(lsp_symbol.kind), location, lsp_symbol.container_name, )) @@ -12569,7 +12569,7 @@ impl LspStore { source_worktree_id: symbol.source_worktree_id.to_proto(), language_server_id: symbol.source_language_server_id.to_proto(), name: symbol.name.clone(), - kind: unsafe { mem::transmute::(symbol.kind) }, + kind: symbol.kind as i32, start: Some(proto::PointUtf16 { row: symbol.range.start.0.row, column: symbol.range.start.0.column, @@ -12602,7 +12602,7 @@ impl LspStore { fn deserialize_symbol(serialized_symbol: proto::Symbol) -> Result { let source_worktree_id = WorktreeId::from_proto(serialized_symbol.source_worktree_id); let worktree_id = WorktreeId::from_proto(serialized_symbol.worktree_id); - let kind = unsafe { mem::transmute::(serialized_symbol.kind) }; + let kind = language::SymbolKind::from_proto(serialized_symbol.kind); let path = if serialized_symbol.signature.is_empty() { SymbolLocation::InProject(ProjectPath { diff --git a/crates/project/src/lsp_store/document_symbols.rs b/crates/project/src/lsp_store/document_symbols.rs index 98f66d9fdb..babb08ffc1 100644 --- a/crates/project/src/lsp_store/document_symbols.rs +++ b/crates/project/src/lsp_store/document_symbols.rs @@ -328,6 +328,7 @@ fn enriched_symbol_text( mod tests { use super::*; use gpui::TestAppContext; + use language::lsp_to_symbol_kind; use text::{OffsetRangeExt, Point, Unclipped}; fn make_symbol( @@ -340,7 +341,7 @@ mod tests { use text::PointUtf16; DocumentSymbol { name: name.to_string(), - kind, + kind: lsp_to_symbol_kind(kind), range: Unclipped(PointUtf16::new(range.start.0, range.start.1)) ..Unclipped(PointUtf16::new(range.end.0, range.end.1)), selection_range: Unclipped(PointUtf16::new( diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 17308d9d5a..3ceed0412f 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -865,7 +865,7 @@ pub struct Symbol { pub path: SymbolLocation, pub label: CodeLabel, pub name: String, - pub kind: lsp::SymbolKind, + pub kind: language::SymbolKind, pub range: Range>, pub container_name: Option, } @@ -873,7 +873,7 @@ pub struct Symbol { #[derive(Clone, Debug)] pub struct DocumentSymbol { pub name: String, - pub kind: lsp::SymbolKind, + pub kind: language::SymbolKind, pub range: Range>, pub selection_range: Range>, pub children: Vec,