Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into restructure-languag…
Browse files Browse the repository at this point in the history
…e-server
  • Loading branch information
Schottkyc137 committed Jun 10, 2024
2 parents 488f3e0 + 21c51b3 commit 71869fc
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 5 deletions.
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 @@ -307,6 +307,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
1 change: 1 addition & 0 deletions vhdl_ls/src/vhdl_server/lifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,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
34 changes: 29 additions & 5 deletions vhdl_ls/src/vhdl_server/text_document.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::vhdl_server::{
from_lsp_pos, from_lsp_range, srcpos_to_location, uri_to_file_name, NonProjectFileHandling,
VHDLServer,
from_lsp_pos, from_lsp_range, srcpos_to_location, to_lsp_range, uri_to_file_name,
NonProjectFileHandling, VHDLServer,
};
use lsp_types::{
DidChangeTextDocumentParams, DidOpenTextDocumentParams, GotoDefinitionResponse, Hover,
HoverContents, Location, MarkupContent, MarkupKind, ReferenceParams, TextDocumentItem,
TextDocumentPositionParams,
DidChangeTextDocumentParams, DidOpenTextDocumentParams, DocumentHighlight,
DocumentHighlightKind, GotoDefinitionResponse, Hover, HoverContents, Location, MarkupContent,
MarkupKind, ReferenceParams, TextDocumentItem, TextDocumentPositionParams,
};
use vhdl_lang::{Message, Source};

Expand Down Expand Up @@ -139,4 +139,28 @@ impl VHDLServer {
Vec::new()
}
}

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
.find_all_references_in_source(&source, ent)
.iter()
.map(|pos| DocumentHighlight {
range: to_lsp_range(pos.range()),
kind: Some(DocumentHighlightKind::TEXT),
})
.collect(),
)
}
}

0 comments on commit 71869fc

Please sign in to comment.