Skip to content

Commit a82b28d

Browse files
authored
Merge pull request #911 from julia-vscode/sp/document-highlight
Document highlight refactor
2 parents 8f77b37 + 3a549f6 commit a82b28d

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

src/requests/features.jl

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,19 +126,25 @@ function find_references(textDocument::TextDocumentIdentifier, position::Positio
126126
locations = Location[]
127127
doc = getdocument(server, URI2(textDocument.uri))
128128
offset = get_offset(doc, position)
129-
x = get_identifier(getcst(doc), offset)
129+
x = get_expr1(getcst(doc), offset)
130+
x === nothing && return locations
131+
for_each_ref(x) do r, doc1, o
132+
push!(locations, Location(doc1._uri, Range(doc1, o .+ (0:r.span))))
133+
end
134+
return locations
135+
end
130136

131-
if x isa EXPR && StaticLint.hasref(x) && refof(x) isa StaticLint.Binding
132-
for r in refof(x).refs
137+
function for_each_ref(f, identifier::EXPR)
138+
if identifier isa EXPR && StaticLint.hasref(identifier) && refof(identifier) isa StaticLint.Binding
139+
for r in refof(identifier).refs
133140
if r isa EXPR
134141
doc1, o = get_file_loc(r)
135142
if doc1 isa Document
136-
push!(locations, Location(doc1._uri, Range(doc1, o .+ (0:r.span))))
143+
f(r, doc1, o)
137144
end
138145
end
139146
end
140147
end
141-
return locations
142148
end
143149

144150
function textDocument_references_request(params::ReferenceParams, server::LanguageServerInstance, conn)

src/requests/highlight.jl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@ function textDocument_documentHighlight_request(params::DocumentHighlightParams,
44
identifier = get_identifier(getcst(doc), offset)
55
identifier !== nothing || return nothing
66
highlights = DocumentHighlight[]
7-
if StaticLint.hasref(identifier) && refof(identifier) isa StaticLint.Binding
8-
for ref in refof(identifier).refs
9-
doc1, o = get_file_loc(ref)
10-
if ref isa EXPR && doc1._uri == doc._uri
11-
kind = StaticLint.hasbinding(ref) ? DocumentHighlightKinds.Write : DocumentHighlightKinds.Read
12-
push!(highlights, DocumentHighlight(Range(doc, o .+ (0:ref.span)), kind))
13-
end
7+
for_each_ref(identifier) do ref, doc1, o
8+
if doc1._uri == doc._uri
9+
kind = StaticLint.hasbinding(ref) ? DocumentHighlightKinds.Write : DocumentHighlightKinds.Read
10+
push!(highlights, DocumentHighlight(Range(doc, o .+ (0:ref.span)), kind))
1411
end
1512
end
1613
return isempty(highlights) ? nothing : highlights

0 commit comments

Comments
 (0)