diff --git a/vhdl_lang/src/analysis/root.rs b/vhdl_lang/src/analysis/root.rs index d08b8d08..6b85317b 100644 --- a/vhdl_lang/src/analysis/root.rs +++ b/vhdl_lang/src/analysis/root.rs @@ -520,6 +520,12 @@ impl DesignRoot { searcher.references } + pub fn find_all_references_in_source(&self, source: &Source, ent: EntRef) -> Vec { + let mut searcher = FindAllReferences::new(self, ent); + let _ = self.search_source(source, &mut searcher); + searcher.references + } + pub fn public_symbols<'a>(&'a self) -> Box> + 'a> { Box::new(self.libraries.values().flat_map(|library| { std::iter::once(self.arenas.get(library.id)).chain(library.units.values().flat_map( diff --git a/vhdl_lang/src/project.rs b/vhdl_lang/src/project.rs index 12b72775..c1ee5409 100644 --- a/vhdl_lang/src/project.rs +++ b/vhdl_lang/src/project.rs @@ -309,6 +309,10 @@ impl Project { self.root.find_all_references(ent) } + pub fn find_all_references_in_source(&self, source: &Source, ent: &AnyEnt) -> Vec { + self.root.find_all_references_in_source(source, ent) + } + /// Get source positions that are not resolved to a declaration /// This is used for development to test where the language server is blind pub fn find_all_unresolved(&self) -> (usize, Vec) { diff --git a/vhdl_ls/src/stdio_server.rs b/vhdl_ls/src/stdio_server.rs index 743e574a..ff2fd329 100644 --- a/vhdl_ls/src/stdio_server.rs +++ b/vhdl_ls/src/stdio_server.rs @@ -190,6 +190,14 @@ impl ConnectionRpcChannel { } Err(request) => request, }; + let request = match extract::(request) { + Ok((id, params)) => { + let result = server.document_highlight(¶ms.text_document_position_params); + self.send_response(lsp_server::Response::new_ok(id, result)); + return; + } + Err(request) => request, + }; let request = match extract::(request) { Ok((id, params)) => { let result = server.text_document_hover(¶ms.text_document_position_params); diff --git a/vhdl_ls/src/vhdl_server.rs b/vhdl_ls/src/vhdl_server.rs index 38877cf8..e2371974 100644 --- a/vhdl_ls/src/vhdl_server.rs +++ b/vhdl_ls/src/vhdl_server.rs @@ -182,6 +182,7 @@ impl VHDLServer { })), workspace_symbol_provider: Some(OneOf::Left(true)), document_symbol_provider: Some(OneOf::Left(true)), + document_highlight_provider: Some(OneOf::Left(true)), completion_provider: Some(CompletionOptions { resolve_provider: Some(true), trigger_characters: Some(trigger_chars), @@ -681,6 +682,30 @@ impl VHDLServer { }) } + pub fn document_highlight( + &mut self, + params: &TextDocumentPositionParams, + ) -> Option> { + let source = self + .project + .get_source(&uri_to_file_name(¶ms.text_document.uri))?; + + let ent = self + .project + .find_declaration(&source, from_lsp_pos(params.position))?; + + Some( + self.project + .find_all_references_in_source(&source, ent) + .iter() + .map(|pos| DocumentHighlight { + range: to_lsp_range(pos.range()), + kind: Some(DocumentHighlightKind::TEXT), + }) + .collect(), + ) + } + pub fn workspace_symbol( &self, params: &WorkspaceSymbolParams,