Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
15 changes: 10 additions & 5 deletions src/requests/features.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,24 @@ function find_references(textDocument::TextDocumentIdentifier, position::Positio
locations = Location[]
doc = getdocument(server, URI2(textDocument.uri))
offset = get_offset(doc, position)
x = get_identifier(getcst(doc), offset)
x = get_expr1(getcst(doc), offset)
for_each_ref(x) do r, doc1, o
push!(locations, Location(doc1._uri, Range(doc1, o .+ (0:r.span))))
end
return locations
end

if x isa EXPR && StaticLint.hasref(x) && refof(x) isa StaticLint.Binding
for r in refof(x).refs
function for_each_ref(f, identifier::EXPR)
if identifier isa EXPR && StaticLint.hasref(identifier) && refof(identifier) isa StaticLint.Binding
for r in refof(identifier).refs
if r isa EXPR
doc1, o = get_file_loc(r)
if doc1 isa Document
push!(locations, Location(doc1._uri, Range(doc1, o .+ (0:r.span))))
f(r, doc1, o)
end
end
end
end
return locations
end

function textDocument_references_request(params::ReferenceParams, server::LanguageServerInstance, conn)
Expand Down
11 changes: 4 additions & 7 deletions src/requests/highlight.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@ function textDocument_documentHighlight_request(params::DocumentHighlightParams,
identifier = get_identifier(getcst(doc), offset)
identifier !== nothing || return nothing
highlights = DocumentHighlight[]
if StaticLint.hasref(identifier) && refof(identifier) isa StaticLint.Binding
for ref in refof(identifier).refs
doc1, o = get_file_loc(ref)
if ref isa EXPR && doc1._uri == doc._uri
kind = StaticLint.hasbinding(ref) ? DocumentHighlightKinds.Write : DocumentHighlightKinds.Read
push!(highlights, DocumentHighlight(Range(doc, o .+ (0:ref.span)), kind))
end
for_each_ref(identifier) do ref, doc1, o
if doc1._uri == doc._uri
kind = StaticLint.hasbinding(ref) ? DocumentHighlightKinds.Write : DocumentHighlightKinds.Read
push!(highlights, DocumentHighlight(Range(doc, o .+ (0:ref.span)), kind))
end
end
return isempty(highlights) ? nothing : highlights
Expand Down