Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for textDocument/documentHighlight request #308

Merged
merged 2 commits into from
Jun 4, 2024
Merged
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
6 changes: 6 additions & 0 deletions vhdl_lang/src/analysis/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,12 @@ impl DesignRoot {
searcher.references
}

pub fn find_all_references_in_source(&self, source: &Source, ent: EntRef) -> Vec<SrcPos> {
let mut searcher = FindAllReferences::new(self, ent);
let _ = self.search_source(source, &mut searcher);
searcher.references
}

pub fn public_symbols<'a>(&'a self) -> Box<dyn Iterator<Item = EntRef<'a>> + 'a> {
Box::new(self.libraries.values().flat_map(|library| {
std::iter::once(self.arenas.get(library.id)).chain(library.units.values().flat_map(
Expand Down
4 changes: 4 additions & 0 deletions vhdl_lang/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SrcPos> {
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<SrcPos>) {
Expand Down
8 changes: 8 additions & 0 deletions vhdl_ls/src/stdio_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,14 @@ impl ConnectionRpcChannel {
}
Err(request) => request,
};
let request = match extract::<request::DocumentHighlightRequest>(request) {
Ok((id, params)) => {
let result = server.document_highlight(&params.text_document_position_params);
self.send_response(lsp_server::Response::new_ok(id, result));
return;
}
Err(request) => request,
};
let request = match extract::<request::HoverRequest>(request) {
Ok((id, params)) => {
let result = server.text_document_hover(&params.text_document_position_params);
Expand Down
25 changes: 25 additions & 0 deletions vhdl_ls/src/vhdl_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -681,6 +682,30 @@ impl VHDLServer {
})
}

pub fn document_highlight(
&mut self,
params: &TextDocumentPositionParams,
) -> Option<Vec<DocumentHighlight>> {
let source = self
.project
.get_source(&uri_to_file_name(&params.text_document.uri))?;

let ent = self
.project
.find_declaration(&source, from_lsp_pos(params.position))?;

Some(
self.project
rapgenic marked this conversation as resolved.
Show resolved Hide resolved
.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,
Expand Down
Loading