mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-26 22:05:14 +00:00
Implement DocumentHighlight
This commit is contained in:
parent
f9b58454a4
commit
79941a9e70
@ -28,7 +28,7 @@ pub fn server_capabilities() -> ServerCapabilities {
|
|||||||
type_definition_provider: None,
|
type_definition_provider: None,
|
||||||
implementation_provider: None,
|
implementation_provider: None,
|
||||||
references_provider: Some(true),
|
references_provider: Some(true),
|
||||||
document_highlight_provider: None,
|
document_highlight_provider: Some(true),
|
||||||
document_symbol_provider: Some(true),
|
document_symbol_provider: Some(true),
|
||||||
workspace_symbol_provider: Some(true),
|
workspace_symbol_provider: Some(true),
|
||||||
code_action_provider: Some(CodeActionProviderCapability::Simple(true)),
|
code_action_provider: Some(CodeActionProviderCapability::Simple(true)),
|
||||||
|
@ -300,6 +300,7 @@ fn on_request(
|
|||||||
.on::<req::Rename>(handlers::handle_rename)?
|
.on::<req::Rename>(handlers::handle_rename)?
|
||||||
.on::<req::References>(handlers::handle_references)?
|
.on::<req::References>(handlers::handle_references)?
|
||||||
.on::<req::Formatting>(handlers::handle_formatting)?
|
.on::<req::Formatting>(handlers::handle_formatting)?
|
||||||
|
.on::<req::DocumentHighlightRequest>(handlers::handle_document_highlight)?
|
||||||
.finish();
|
.finish();
|
||||||
match req {
|
match req {
|
||||||
Ok(id) => {
|
Ok(id) => {
|
||||||
|
@ -6,9 +6,8 @@ use languageserver_types::{
|
|||||||
DiagnosticSeverity, DocumentSymbol, Documentation, FoldingRange, FoldingRangeKind,
|
DiagnosticSeverity, DocumentSymbol, Documentation, FoldingRange, FoldingRangeKind,
|
||||||
FoldingRangeParams, Location, MarkupContent, MarkupKind, MarkedString, Position,
|
FoldingRangeParams, Location, MarkupContent, MarkupKind, MarkedString, Position,
|
||||||
PrepareRenameResponse, RenameParams, SymbolInformation, TextDocumentIdentifier, TextEdit,
|
PrepareRenameResponse, RenameParams, SymbolInformation, TextDocumentIdentifier, TextEdit,
|
||||||
Range,
|
Range, WorkspaceEdit, ParameterInformation, ParameterLabel, SignatureInformation, Hover,
|
||||||
WorkspaceEdit, ParameterInformation, ParameterLabel, SignatureInformation, Hover, HoverContents,
|
HoverContents, DocumentFormattingParams, DocumentHighlight,
|
||||||
DocumentFormattingParams,
|
|
||||||
};
|
};
|
||||||
use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FileRange, FilePosition, Severity};
|
use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FileRange, FilePosition, Severity};
|
||||||
use ra_syntax::{TextUnit, text_utils::intersect};
|
use ra_syntax::{TextUnit, text_utils::intersect};
|
||||||
@ -673,6 +672,28 @@ pub fn handle_code_action(
|
|||||||
Ok(Some(CodeActionResponse::Commands(res)))
|
Ok(Some(CodeActionResponse::Commands(res)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn handle_document_highlight(
|
||||||
|
world: ServerWorld,
|
||||||
|
params: req::TextDocumentPositionParams,
|
||||||
|
) -> Result<Option<Vec<DocumentHighlight>>> {
|
||||||
|
let file_id = params.text_document.try_conv_with(&world)?;
|
||||||
|
let line_index = world.analysis().file_line_index(file_id);
|
||||||
|
let offset = params.position.conv_with(&line_index);
|
||||||
|
|
||||||
|
let refs = world
|
||||||
|
.analysis()
|
||||||
|
.find_all_refs(FilePosition { file_id, offset })?;
|
||||||
|
|
||||||
|
Ok(Some(
|
||||||
|
refs.into_iter()
|
||||||
|
.map(|r| DocumentHighlight {
|
||||||
|
range: r.1.conv_with(&line_index),
|
||||||
|
kind: None,
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn publish_diagnostics(
|
pub fn publish_diagnostics(
|
||||||
world: &ServerWorld,
|
world: &ServerWorld,
|
||||||
file_id: FileId,
|
file_id: FileId,
|
||||||
|
Loading…
Reference in New Issue
Block a user