Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ members = [
"crates/streaming_diff",
"crates/sum_tree",
"crates/svg_preview",
"crates/symbol_index",
"crates/syntax_theme",
"crates/system_specs",
"crates/tab_switcher",
Expand Down Expand Up @@ -468,6 +469,7 @@ sqlez_macros = { path = "crates/sqlez_macros" }
streaming_diff = { path = "crates/streaming_diff" }
sum_tree = { path = "crates/sum_tree" }
svg_preview = { path = "crates/svg_preview" }
symbol_index = { path = "crates/symbol_index" }
syntax_theme = { path = "crates/syntax_theme" }
system_specs = { path = "crates/system_specs" }
tab_switcher = { path = "crates/tab_switcher" }
Expand Down
8 changes: 8 additions & 0 deletions assets/settings/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,14 @@
// - "on": Use the language server's `textDocument/documentSymbol` LSP response. When enabled, tree-sitter is not used for document symbols.
"document_symbols": "off",

// Controls the source of project symbols used by "Go to Symbol in Project".
//
// Options:
// - "auto": Use the language server's `workspace/symbol` when available, falling back to the tree-sitter symbol index for languages without a supporting language server (default).
// - "language_server": Always use `workspace/symbol`. Languages without a supporting language server have no project symbols.
// - "tree_sitter": Always use the tree-sitter symbol index.
"project_symbols": "auto",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would also need to add this to all-settings.md to have zed.dev/docs updated.


// When to automatically save edited buffers. This setting can
// take four values.
//
Expand Down
8 changes: 0 additions & 8 deletions crates/language/src/available_languages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,6 @@ impl AvailableLanguages {
.collect()
}

#[cfg(any(test, feature = "test-support"))]
pub(super) fn name_for_id(&self, id: LanguageId) -> Option<LanguageName> {
self.0
.iter()
.find(|language| language.id == id)
.map(|language| language.name.clone())
}

pub(super) fn get_language(&self, id: LanguageId) -> Option<&AvailableLanguage> {
self.0.iter().find(|language| language.id == id)
}
Expand Down
8 changes: 6 additions & 2 deletions crates/language/src/language_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,9 +572,13 @@ impl LanguageRegistry {
async move { rx.await? }
}

#[cfg(any(test, feature = "test-support"))]
/// Returns the name of the language with the given id, if one is registered.
pub fn language_name_for_id(&self, id: LanguageId) -> Option<LanguageName> {
self.state.read().available_languages.name_for_id(id)
self.state
.read()
.available_languages
.get_language(id)
.map(|language| language.name.clone())
}

pub fn language_name_for_extension(self: &Arc<Self>, extension: &str) -> Option<LanguageName> {
Expand Down
5 changes: 4 additions & 1 deletion crates/language/src/language_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use ec4rs::{
use globset::{Glob, GlobMatcher, GlobSet, GlobSetBuilder};
use gpui::{App, Modifiers, SharedString};
use itertools::Itertools;
use settings::{DelayMs, DocumentFoldingRanges, DocumentSymbols, IntoGpui, SemanticTokens};
use settings::{DelayMs, DocumentFoldingRanges, DocumentSymbols, IntoGpui, ProjectSymbols, SemanticTokens};

pub use settings::{
AutoIndentMode, CompletionSettingsContent, ConfiguredLanguageServer,
Expand Down Expand Up @@ -110,6 +110,8 @@ pub struct LanguageSettings {
pub document_folding_ranges: DocumentFoldingRanges,
/// Controls the source of document symbols used for outlines and breadcrumbs.
pub document_symbols: DocumentSymbols,
/// Controls the source of project symbols used by "Go to Symbol in Project".
pub project_symbols: ProjectSymbols,
/// Controls where the `editor::Rewrap` action is allowed for this language.
///
/// Note: This setting has no effect in Vim mode, as rewrap is already
Expand Down Expand Up @@ -840,6 +842,7 @@ impl settings::Settings for AllLanguageSettings {
semantic_tokens: settings.semantic_tokens.unwrap(),
document_folding_ranges: settings.document_folding_ranges.unwrap(),
document_symbols: settings.document_symbols.unwrap(),
project_symbols: settings.project_symbols.unwrap(),
allow_rewrap: settings.allow_rewrap.unwrap(),
show_edit_predictions: settings.show_edit_predictions.unwrap(),
edit_predictions_disabled_in: settings.edit_predictions_disabled_in.unwrap(),
Expand Down
1 change: 1 addition & 0 deletions crates/project/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ smallvec.workspace = true
smol.workspace = true
snippet.workspace = true
snippet_provider.workspace = true
symbol_index.workspace = true
sum_tree.workspace = true
task.workspace = true
tempfile.workspace = true
Expand Down
61 changes: 60 additions & 1 deletion crates/project/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub mod prettier_store;
pub mod project_search;
pub mod project_settings;
pub mod search;
pub mod symbol_index_manager;
pub mod task_inventory;
pub mod task_store;
pub mod telemetry_snapshot;
Expand Down Expand Up @@ -54,6 +55,7 @@ pub use git_store::{
};
pub use manifest_tree::ManifestTree;
pub use project_search::{Search, SearchResults};
pub use symbol_index_manager::{SymbolIndexEvent, SymbolIndexManager};
pub use worktree_store::WorktreePaths;

use anyhow::{Context as _, Result, anyhow};
Expand Down Expand Up @@ -98,7 +100,7 @@ use language::{
use lsp::{
CodeActionKind, CompletionContext, CompletionItemKind, DocumentHighlightKind, InsertTextMode,
LanguageServerBinary, LanguageServerId, LanguageServerName, LanguageServerSelector,
MessageActionItem,
MessageActionItem, OneOf,
};
pub use lsp_command::EditPredictionDefinition;
use lsp_command::*;
Expand Down Expand Up @@ -255,6 +257,7 @@ pub struct Project {
agent_location: Option<AgentLocation>,
downloading_files: Arc<Mutex<HashMap<(WorktreeId, String), DownloadingFile>>>,
last_worktree_paths: WorktreePaths,
symbol_index: Option<Entity<symbol_index_manager::SymbolIndexManager>>,
}

struct DownloadingFile {
Expand Down Expand Up @@ -470,6 +473,14 @@ impl ProjectPath {
})
}

/// Construct from a worktree ID (as u64) and a unix-style path string.
pub fn from_worktree_and_path(worktree_id: u64, path: &str) -> Option<Self> {
Some(Self {
worktree_id: WorktreeId::from_proto(worktree_id),
path: RelPath::from_unix_str(path).log_err()?.into(),
})
}

pub fn to_proto(&self) -> proto::ProjectPath {
proto::ProjectPath {
worktree_id: self.worktree_id.to_proto(),
Expand Down Expand Up @@ -1417,6 +1428,7 @@ impl Project {
agent_location: None,
downloading_files: Default::default(),
last_worktree_paths: WorktreePaths::default(),
symbol_index: None,
}
})
}
Expand Down Expand Up @@ -1660,6 +1672,7 @@ impl Project {
agent_location: None,
downloading_files: Default::default(),
last_worktree_paths: WorktreePaths::default(),
symbol_index: None,
};

// remote server -> local machine handlers
Expand Down Expand Up @@ -1951,6 +1964,7 @@ impl Project {
agent_location: None,
downloading_files: Default::default(),
last_worktree_paths: WorktreePaths::default(),
symbol_index: None,
};
project.set_role(role, cx);
for worktree in worktrees {
Expand Down Expand Up @@ -2263,6 +2277,25 @@ impl Project {
&self.languages
}

/// Returns the lazy-initialized symbol index manager for tree-sitter based symbol search.
pub fn symbol_index(
&mut self,
cx: &mut Context<Self>,
) -> Entity<symbol_index_manager::SymbolIndexManager> {
self.symbol_index
.get_or_insert_with(|| {
cx.new(|cx| {
symbol_index_manager::SymbolIndexManager::new(
self.languages.clone(),
self.fs.clone(),
&self.worktree_store,
cx,
)
})
})
.clone()
}

#[inline]
pub fn client(&self) -> Arc<Client> {
self.collab_client.clone()
Expand Down Expand Up @@ -6414,6 +6447,32 @@ impl Project {
.any(|capabilities| capabilities.semantic_tokens_provider.is_some())
}

/// Returns true if a running language server for the given language supports
/// `workspace/symbol` requests.
pub fn has_lsp_project_symbols(&self, language_name: &LanguageName, cx: &App) -> bool {
let lsp_store = self.lsp_store.read(cx);
let relevant_language_servers = lsp_store
.languages
.lsp_adapters(language_name)
.into_iter()
.map(|lsp_adapter| lsp_adapter.name())
.collect::<HashSet<_>>();
lsp_store
.language_server_statuses()
.filter_map(|(server_id, server_status)| {
relevant_language_servers
.contains(&server_status.name)
.then_some(server_id)
})
.filter_map(|server_id| lsp_store.lsp_server_capabilities.get(&server_id))
.any(|capabilities| {
matches!(
capabilities.workspace_symbol_provider,
Some(OneOf::Left(true)) | Some(OneOf::Right(_))
)
})
}

pub fn language_server_id_for_name(
&self,
buffer: &Buffer,
Expand Down
Loading
Loading