WIP: Start on getting project symbols over RPC

This commit is contained in:
Antonio Scandurra 2022-02-22 12:15:38 +01:00
parent 326f1f43fe
commit ab73343323
4 changed files with 75 additions and 47 deletions

View File

@ -1226,7 +1226,7 @@ impl Project {
&self, &self,
query: &str, query: &str,
cx: &mut ModelContext<Self>, cx: &mut ModelContext<Self>,
) -> Task<Result<Vec<ProjectSymbol>>> { ) -> Task<Result<HashMap<String, Vec<ProjectSymbol>>>> {
if self.is_local() { if self.is_local() {
let mut language_servers = HashMap::default(); let mut language_servers = HashMap::default();
for ((_, language_name), language_server) in self.language_servers.iter() { for ((_, language_name), language_server) in self.language_servers.iter() {
@ -1248,13 +1248,16 @@ impl Project {
cx.foreground().spawn(async move { cx.foreground().spawn(async move {
let responses = futures::future::try_join_all(requests).await?; let responses = futures::future::try_join_all(requests).await?;
let mut symbols = Vec::new(); let mut symbols = HashMap::default();
for ((_, language), lsp_symbols) in language_servers.values().zip(responses) { for ((_, language), lsp_symbols) in language_servers.into_values().zip(responses) {
let language_symbols = symbols
.entry(language.name().to_string())
.or_insert(Vec::new());
for lsp_symbol in lsp_symbols.into_iter().flatten() { for lsp_symbol in lsp_symbols.into_iter().flatten() {
let label = language let label = language
.label_for_symbol(&lsp_symbol) .label_for_symbol(&lsp_symbol)
.unwrap_or_else(|| CodeLabel::plain(lsp_symbol.name.clone(), None)); .unwrap_or_else(|| CodeLabel::plain(lsp_symbol.name.clone(), None));
symbols.push(ProjectSymbol { label, lsp_symbol }); language_symbols.push(ProjectSymbol { label, lsp_symbol });
} }
} }
Ok(symbols) Ok(symbols)

View File

@ -180,7 +180,12 @@ impl ProjectSymbolsView {
.project .project
.update(cx, |project, cx| project.symbols(&query, cx)); .update(cx, |project, cx| project.symbols(&query, cx));
self.pending_symbols_task = cx.spawn_weak(|this, mut cx| async move { self.pending_symbols_task = cx.spawn_weak(|this, mut cx| async move {
let symbols = symbols.await.log_err()?; let symbols = symbols
.await
.log_err()?
.into_values()
.flatten()
.collect::<Vec<_>>();
if let Some(this) = this.upgrade(&cx) { if let Some(this) = this.upgrade(&cx) {
this.update(&mut cx, |this, cx| { this.update(&mut cx, |this, cx| {
this.match_candidates = symbols this.match_candidates = symbols

View File

@ -23,53 +23,55 @@ message Envelope {
RemoveProjectCollaborator remove_project_collaborator = 17; RemoveProjectCollaborator remove_project_collaborator = 17;
GetDefinition get_definition = 18; GetDefinition get_definition = 18;
GetDefinitionResponse get_definition_response = 19; GetDefinitionResponse get_definition_response = 19;
GetProjectSymbols get_project_symbols = 20;
GetProjectSymbolsResponse get_project_symbols_response = 21;
RegisterWorktree register_worktree = 20; RegisterWorktree register_worktree = 22;
UnregisterWorktree unregister_worktree = 21; UnregisterWorktree unregister_worktree = 23;
ShareWorktree share_worktree = 22; ShareWorktree share_worktree = 24;
UpdateWorktree update_worktree = 23; UpdateWorktree update_worktree = 25;
UpdateDiagnosticSummary update_diagnostic_summary = 24; UpdateDiagnosticSummary update_diagnostic_summary = 26;
DiskBasedDiagnosticsUpdating disk_based_diagnostics_updating = 25; DiskBasedDiagnosticsUpdating disk_based_diagnostics_updating = 27;
DiskBasedDiagnosticsUpdated disk_based_diagnostics_updated = 26; DiskBasedDiagnosticsUpdated disk_based_diagnostics_updated = 28;
OpenBuffer open_buffer = 27; OpenBuffer open_buffer = 29;
OpenBufferResponse open_buffer_response = 28; OpenBufferResponse open_buffer_response = 30;
CloseBuffer close_buffer = 29; CloseBuffer close_buffer = 31;
UpdateBuffer update_buffer = 30; UpdateBuffer update_buffer = 32;
UpdateBufferFile update_buffer_file = 31; UpdateBufferFile update_buffer_file = 33;
SaveBuffer save_buffer = 32; SaveBuffer save_buffer = 34;
BufferSaved buffer_saved = 33; BufferSaved buffer_saved = 35;
BufferReloaded buffer_reloaded = 34; BufferReloaded buffer_reloaded = 36;
FormatBuffers format_buffers = 35; FormatBuffers format_buffers = 37;
FormatBuffersResponse format_buffers_response = 36; FormatBuffersResponse format_buffers_response = 38;
GetCompletions get_completions = 37; GetCompletions get_completions = 39;
GetCompletionsResponse get_completions_response = 38; GetCompletionsResponse get_completions_response = 40;
ApplyCompletionAdditionalEdits apply_completion_additional_edits = 39; ApplyCompletionAdditionalEdits apply_completion_additional_edits = 41;
ApplyCompletionAdditionalEditsResponse apply_completion_additional_edits_response = 40; ApplyCompletionAdditionalEditsResponse apply_completion_additional_edits_response = 42;
GetCodeActions get_code_actions = 41; GetCodeActions get_code_actions = 43;
GetCodeActionsResponse get_code_actions_response = 42; GetCodeActionsResponse get_code_actions_response = 44;
ApplyCodeAction apply_code_action = 43; ApplyCodeAction apply_code_action = 45;
ApplyCodeActionResponse apply_code_action_response = 44; ApplyCodeActionResponse apply_code_action_response = 46;
PrepareRename prepare_rename = 58; PrepareRename prepare_rename = 47;
PrepareRenameResponse prepare_rename_response = 59; PrepareRenameResponse prepare_rename_response = 48;
PerformRename perform_rename = 60; PerformRename perform_rename = 49;
PerformRenameResponse perform_rename_response = 61; PerformRenameResponse perform_rename_response = 50;
GetChannels get_channels = 45; GetChannels get_channels = 51;
GetChannelsResponse get_channels_response = 46; GetChannelsResponse get_channels_response = 52;
JoinChannel join_channel = 47; JoinChannel join_channel = 53;
JoinChannelResponse join_channel_response = 48; JoinChannelResponse join_channel_response = 54;
LeaveChannel leave_channel = 49; LeaveChannel leave_channel = 55;
SendChannelMessage send_channel_message = 50; SendChannelMessage send_channel_message = 56;
SendChannelMessageResponse send_channel_message_response = 51; SendChannelMessageResponse send_channel_message_response = 57;
ChannelMessageSent channel_message_sent = 52; ChannelMessageSent channel_message_sent = 58;
GetChannelMessages get_channel_messages = 53; GetChannelMessages get_channel_messages = 59;
GetChannelMessagesResponse get_channel_messages_response = 54; GetChannelMessagesResponse get_channel_messages_response = 60;
UpdateContacts update_contacts = 55; UpdateContacts update_contacts = 61;
GetUsers get_users = 56; GetUsers get_users = 62;
GetUsersResponse get_users_response = 57; GetUsersResponse get_users_response = 63;
} }
} }
@ -171,6 +173,21 @@ message Definition {
Anchor target_end = 3; Anchor target_end = 3;
} }
message GetProjectSymbols {
uint64 project_id = 1;
string query = 2;
}
message GetProjectSymbolsResponse {
repeated string languages = 1;
repeated uint64 symbol_counts_per_language = 2;
repeated Symbol symbols = 3;
}
message Symbol {
bytes lsp_symbol = 1;
}
message OpenBuffer { message OpenBuffer {
uint64 project_id = 1; uint64 project_id = 1;
uint64 worktree_id = 2; uint64 worktree_id = 2;

View File

@ -157,6 +157,8 @@ messages!(
(GetCompletionsResponse, Foreground), (GetCompletionsResponse, Foreground),
(GetDefinition, Foreground), (GetDefinition, Foreground),
(GetDefinitionResponse, Foreground), (GetDefinitionResponse, Foreground),
(GetProjectSymbols, Background),
(GetProjectSymbolsResponse, Foreground),
(GetUsers, Foreground), (GetUsers, Foreground),
(GetUsersResponse, Foreground), (GetUsersResponse, Foreground),
(JoinChannel, Foreground), (JoinChannel, Foreground),
@ -204,6 +206,7 @@ request_messages!(
(GetCodeActions, GetCodeActionsResponse), (GetCodeActions, GetCodeActionsResponse),
(GetCompletions, GetCompletionsResponse), (GetCompletions, GetCompletionsResponse),
(GetDefinition, GetDefinitionResponse), (GetDefinition, GetDefinitionResponse),
(GetProjectSymbols, GetProjectSymbolsResponse),
(GetUsers, GetUsersResponse), (GetUsers, GetUsersResponse),
(JoinChannel, JoinChannelResponse), (JoinChannel, JoinChannelResponse),
(JoinProject, JoinProjectResponse), (JoinProject, JoinProjectResponse),