language_core: Remove lsp-types dependency (#61041)

Release Notes:

- N/A or Added/Fixed/Improved ...
This commit is contained in:
Lukas Wirth authored and GitHub committed 2026-07-15 10:46:01 +00:00
1 parent 3565c49dad
commit 0bfd2d7cf0
17 files changed
+301 -187

No files matched your search

Generated
-1
View File
@@ -9755,7 +9755,6 @@ dependencies = [
"gpui_shared_string",
"gpui_util",
"log",
"lsp-types",
"parking_lot",
"path",
"regex",
+76 -1
View File
@@ -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<String>,
/// The ID provided by the dynamic registration that produced this diagnostic.
pub registration_id: Option<SharedString>,
/// A machine-readable code that identifies this diagnostic.
pub code: Option<NumberOrString>,
pub code_description: Option<lsp::Uri>,
/// 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<String>,
/// 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<Value>,
/// 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,
}
}
}
+82 -5
View File
@@ -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<Arc<Language>> = 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<Anchor>,
}
/// 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<Option<(bool, LanguageServerBinary)>>;
type DownloadableLanguageServerBinary = LocalBoxFuture<'static, Result<LanguageServerBinary>>;
pub type LanguageServerBinaryLocations = LocalBoxFuture<
-1
View File
@@ -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
+65 -1
View File
@@ -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<String>,
}
-76
View File
@@ -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<String>,
/// The ID provided by the dynamic registration that produced this diagnostic.
pub registration_id: Option<SharedString>,
/// A machine-readable code that identifies this diagnostic.
pub code: Option<NumberOrString>,
pub code_description: Option<lsp_types::Uri>,
/// 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<String>,
/// 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<Value>,
/// 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,
}
}
}
+2 -6
View File
@@ -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};
-17
View File
@@ -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),
@@ -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,
}
}
+7 -7
View File
@@ -300,43 +300,43 @@ impl super::LspAdapter for CLspAdapter {
) -> Option<CodeLabel> {
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;
+7 -7
View File
@@ -394,43 +394,43 @@ impl LspAdapter for GoLspAdapter {
) -> Option<CodeLabel> {
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;
+3 -3
View File
@@ -220,19 +220,19 @@ fn label_for_python_symbol(
) -> Option<language::CodeLabel> {
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;
+13 -13
View File
@@ -622,15 +622,15 @@ impl LspAdapter for RustLspAdapter {
) -> Option<CodeLabel> {
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
+6 -9
View File
@@ -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::<lsp::SymbolKind, i32>(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<DocumentSymbol> {
let kind =
unsafe { mem::transmute::<i32, lsp::SymbolKind>(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")?;
+8 -8
View File
@@ -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<Unclipped<PointUtf16>>,
pub container_name: Option<String>,
}
@@ -8173,7 +8173,7 @@ impl LspStore {
server_id: LanguageServerId,
lsp_adapter: Arc<CachedLspAdapter>,
worktree: WeakEntity<Worktree>,
lsp_symbols: Vec<(String, SymbolKind, lsp::Location, Option<String>)>,
lsp_symbols: Vec<(String, language::SymbolKind, lsp::Location, Option<String>)>,
}
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::<lsp::SymbolKind, i32>(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<CoreSymbol> {
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::<i32, lsp::SymbolKind>(serialized_symbol.kind) };
let kind = language::SymbolKind::from_proto(serialized_symbol.kind);
let path = if serialized_symbol.signature.is_empty() {
SymbolLocation::InProject(ProjectPath {
@@ -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(
+2 -2
View File
@@ -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<Unclipped<PointUtf16>>,
pub container_name: Option<String>,
}
@@ -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<Unclipped<PointUtf16>>,
pub selection_range: Range<Unclipped<PointUtf16>>,
pub children: Vec<DocumentSymbol>,