Skip to content

Commit ea5092e

Browse files
authored
Merge branch 'master' into disable-comp
2 parents 8da0d2b + a1ca4ee commit ea5092e

File tree

9 files changed

+74
-38
lines changed

9 files changed

+74
-38
lines changed

src/document.jl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ function get_text(doc::Document)
3737
end
3838

3939
function set_text!(doc::Document, text)
40+
# TODO Remove this check eventually
41+
occursin('\0', text) && throw(LSInvalidFile("Tried to set a text with an embedded NULL as the document content."))
4042
doc._content = text
4143
doc._line_offsets = nothing
4244
doc._line_offsets2 = nothing
@@ -127,7 +129,7 @@ function get_offset2(doc::Document, line::Integer, character::Integer)
127129
pos = nextind(text, pos)
128130
end
129131

130-
return pos
132+
return pos
131133
end
132134

133135
# Note: to be removed
@@ -166,7 +168,7 @@ function get_line_offsets(doc::Document, force=false)
166168
doc._line_offsets = Int[0]
167169
text = get_text(doc)
168170
ind = firstindex(text)
169-
while ind <= lastindex(text)
171+
while ind <= lastindex(text)
170172
c = text[ind]
171173
nl = c == '\n' || c == '\r'
172174
if c == '\r' && ind + 1 <= lastindex(text) && text[ind + 1] == '\n'
@@ -175,7 +177,7 @@ function get_line_offsets(doc::Document, force=false)
175177
nl && push!(doc._line_offsets, ind)
176178
ind = nextind(text, ind)
177179
end
178-
end
180+
end
179181
return doc._line_offsets
180182
end
181183

@@ -184,7 +186,7 @@ function get_line_offsets2!(doc::Document, force=false)
184186
doc._line_offsets2 = Int[1]
185187
text = get_text(doc)
186188
ind = firstindex(text)
187-
while ind <= lastindex(text)
189+
while ind <= lastindex(text)
188190
c = text[ind]
189191
if c == '\n' || c == '\r'
190192
if c == '\r' && ind + 1 <= lastindex(text) && text[ind + 1] == '\n'
@@ -212,7 +214,7 @@ function get_line_of(line_offsets::Vector{Int}, offset::Integer)
212214
end
213215
line += 1
214216
end
215-
end
217+
end
216218
return line, line_offsets[line]
217219
end
218220

@@ -233,7 +235,7 @@ function get_position_at(doc::Document, offset::Integer)
233235
c = read(io, Char)
234236
character += 1
235237
if UInt32(c) >= 0x010000
236-
character += 1
238+
character += 1
237239
end
238240
end
239241
close(io)

src/exception_types.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,12 @@ end
6060

6161
function Base.showerror(io::IO, ex::LSInfiniteLoop)
6262
print(io, ex.msg)
63-
end
63+
end
64+
65+
struct LSInvalidFile <: Exception
66+
msg::AbstractString
67+
end
68+
69+
function Base.showerror(io::IO, ex::LSInvalidFile)
70+
print(io, ex.msg)
71+
end

src/protocol/completion.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,15 @@ struct CompletionRegistrationOptions <: Outbound
7474
resolveProvider::Union{Bool,Missing}
7575
end
7676

77-
@dict_readable struct CompletionContext <: Outbound
77+
struct CompletionContext <: Outbound
7878
triggerKind::CompletionTriggerKind
7979
triggerCharacter::Union{String,Missing}
8080
end
8181

82+
function CompletionContext(d::Dict)
83+
CompletionContext(d["triggerKind"], haskey(d, "triggerCharacter") && d["triggerCharacter"] isa String ? d["triggerCharacter"] : missing)
84+
end
85+
8286
@dict_readable struct CompletionParams <: Outbound
8387
textDocument::TextDocumentIdentifier
8488
position::Position

src/requests/actions.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,13 @@ end
152152

153153
function reexport_package(x::EXPR, server, conn)
154154
(refof(x) isa SymbolServer.ModuleStore || refof(x).type === StaticLint.CoreTypes.Module || (refof(x).val isa StaticLint.Binding && refof(x).val.type === StaticLint.CoreTypes.Module)) || (refof(x).val isa SymbolServer.ModuleStore) || return
155-
mod::SymbolServer.ModuleStore = refof(x) isa SymbolServer.ModuleStore ? refof(x) : refof(x).val
155+
mod = if refof(x) isa SymbolServer.ModuleStore
156+
refof(x)
157+
elseif refof(x).val isa SymbolServer.ModuleStore
158+
refof(x).val
159+
else
160+
return
161+
end
156162
using_stmt = parentof(x)
157163
file, offset = get_file_loc(x)
158164
insertpos = get_next_line_offset(using_stmt)

src/requests/features.jl

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function get_definitions(x::SymbolServer.ModuleStore, tls, server, locations)
2323
end
2424
end
2525

26-
function get_definitions(x::Union{SymbolServer.FunctionStore,SymbolServer.DataTypeStore}, tls, server, locations)
26+
function get_definitions(x::Union{SymbolServer.FunctionStore,SymbolServer.DataTypeStore}, tls, server, locations)
2727
StaticLint.iterate_over_ss_methods(x, tls, server, function (m)
2828
try
2929
if isfile(m.file)
@@ -178,14 +178,33 @@ function textDocument_documentSymbol_request(params::DocumentSymbolParams, serve
178178
uri = params.textDocument.uri
179179
doc = getdocument(server, URI2(uri))
180180

181-
bs = collect_bindings_w_loc(getcst(doc))
182-
for x in bs
183-
p, b = x[1], x[2]
184-
!(b.val isa EXPR) && continue
185-
!is_valid_binding_name(b.name) && continue
186-
push!(syms, SymbolInformation(get_name_of_binding(b.name), _binding_kind(b, server), false, Location(doc._uri, Range(doc, p)), missing))
181+
return collect_document_symbols(getcst(doc), server, doc)
182+
end
183+
184+
function collect_document_symbols(x::EXPR, server::LanguageServerInstance, doc, pos=0, symbols=[])
185+
if bindingof(x) !== nothing
186+
b = bindingof(x)
187+
if b.val isa EXPR && is_valid_binding_name(b.name)
188+
ds = DocumentSymbol(
189+
get_name_of_binding(b.name), # name
190+
missing, # detail
191+
_binding_kind(b, server), # kind
192+
false, # deprecated
193+
Range(doc, (pos .+ (0:x.span))), # range
194+
Range(doc, (pos .+ (0:x.span))), # selection range
195+
DocumentSymbol[] # children
196+
)
197+
push!(symbols, ds)
198+
symbols = ds.children
199+
end
200+
end
201+
if length(x) > 0
202+
for a in x
203+
collect_document_symbols(a, server, doc, pos, symbols)
204+
pos += a.fullspan
205+
end
187206
end
188-
return syms
207+
return symbols
189208
end
190209

191210
function collect_bindings_w_loc(x::EXPR, pos=0, bindings=Tuple{UnitRange{Int},StaticLint.Binding}[])

src/requests/hover.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function get_hover(b::StaticLint.Binding, documentation::String, server)
4646
end
4747
end
4848
else
49-
try
49+
documentation = try
5050
documentation = if binding_has_preceding_docs(b)
5151
string(documentation, Expr(parentof(b.val).args[3]))
5252
elseif const_binding_has_preceding_docs(b)
@@ -56,8 +56,7 @@ function get_hover(b::StaticLint.Binding, documentation::String, server)
5656
end
5757
documentation = string(documentation, "```julia\n", Expr(b.val), "\n```\n")
5858
catch err
59-
doc1, offset1 = get_file_loc(b.val)
60-
throw(LSHoverError(string("get_hover failed to convert the following to code: ", String(codeunits(get_text(doc1))[offset1 .+ (1:b.val.span)]))))
59+
throw(LSHoverError(string("get_hover failed to convert Expr")))
6160
end
6261
end
6362
elseif b.val isa SymbolServer.SymStore

src/requests/init.jl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function has_too_many_files(path, N=5000)
6060
end
6161
end
6262
catch err
63-
isa(err, Base.IOError) || isa(err, Base.SystemError) || (VERSION >= v"1.3.0" && isa(err, Base.TaskFailedException) && isa(err.task.exception, Base.IOError)) || rethrow()
63+
is_walkdir_error(err) || rethrow()
6464
return false
6565
end
6666

@@ -76,7 +76,7 @@ function load_rootpath(path)
7676
!isjuliabasedir(path) &&
7777
!has_too_many_files(path)
7878
catch err
79-
isa(err, Base.IOError) || isa(err, Base.SystemError) || rethrow()
79+
is_walkdir_error(err) || rethrow()
8080
return false
8181
end
8282
end
@@ -103,7 +103,7 @@ function load_folder(path::String, server)
103103
isvalid(s) || continue
104104
s
105105
catch err
106-
isa(err, Base.IOError) || isa(err, Base.SystemError) || rethrow()
106+
is_walkdir_error(err) || rethrow()
107107
continue
108108
end
109109
doc = Document(uri, content, true, server)
@@ -114,11 +114,17 @@ function load_folder(path::String, server)
114114
end
115115
end
116116
catch err
117-
isa(err, Base.IOError) || isa(err, Base.SystemError) || rethrow()
117+
is_walkdir_error(err) || rethrow()
118118
end
119119
end
120120
end
121121

122+
is_walkdir_error(_) = false
123+
is_walkdir_error(::Base.IOError) = true
124+
is_walkdir_error(::Base.SystemError) = true
125+
@static if VERSION > v"1.3.0-"
126+
is_walkdir_error(err::Base.TaskFailedException) = is_walkdir_error(err.task.exception)
127+
end
122128

123129
function initialize_request(params::InitializeParams, server::LanguageServerInstance, conn)
124130
# Only look at rootUri and rootPath if the client doesn't support workspaceFolders

src/requests/workspace.jl

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,10 @@ function request_julia_config(server::LanguageServerInstance, conn)
109109
ConfigurationItem(missing, "julia.lint.disabledDirs")
110110
]))
111111

112-
if server.clientInfo isa InfoParams && (server.clientInfo.name == "Visual Studio Code" || server.clientInfo.name == "Visual Studio Code - Insiders")
113-
server.format_options = DocumentFormat.FormatOptions([isnothing(a) ? (DocumentFormat.default_options[i] isa Bool ? false : DocumentFormat.default_options[i]) : a for (i, a) in enumerate(response[1:12])]...)
114-
new_runlinter = isnothing(response[23]) ? false : true
115-
new_SL_opts = StaticLint.LintOptions([isnothing(a) ? (StaticLint.default_options[i] isa Bool ? false : StaticLint.default_options[i]) : a for (i, a) in enumerate(response[13:22])]...)
116-
else
117-
server.format_options = DocumentFormat.FormatOptions(response[1:12]...)
118-
new_runlinter = something(response[23], true)
119-
new_SL_opts = StaticLint.LintOptions(response[13:22]...)
120-
end
112+
server.format_options = DocumentFormat.FormatOptions(response[1:12]...)
113+
new_runlinter = something(response[23], true)
114+
new_SL_opts = StaticLint.LintOptions(response[13:22]...)
115+
121116
new_lint_missingrefs = Symbol(something(response[24], :all))
122117
new_lint_disableddirs = something(response[25], LINT_DIABLED_DIRS)
123118

src/utilities.jl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,11 @@ function remove_workspace_files(root, server)
141141
fpath = getpath(doc)
142142
isempty(fpath) && continue
143143
get_open_in_editor(doc) && continue
144-
for folder in server.workspaceFolders
145-
if startswith(fpath, folder)
146-
continue
147-
end
144+
# If the file is in any other workspace folder, don't delete it
145+
any(folder -> startswith(fpath, folder), server.workspaceFolders) && continue
148146
deletedocument!(server, uri)
149147
end
150148
end
151-
end
152149

153150

154151
function Base.getindex(server::LanguageServerInstance, r::Regex)

0 commit comments

Comments
 (0)