Skip to content

Commit d3569de

Browse files
authored
Merge branch 'master' into rmactions
2 parents 55d7ab1 + 8a92dea commit d3569de

File tree

5 files changed

+17
-10
lines changed

5 files changed

+17
-10
lines changed

src/document.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ end
6363
"""
6464
get_offset(doc, line, char)
6565
66-
Returns the byte offset position corresponding to a line/character position.
66+
Returns the byte offset position corresponding to a line/character position.
6767
This takes 0 based line/char inputs. Corresponding functions are available for
6868
Position and Range arguments, the latter returning a UnitRange{Int}.
6969
"""
@@ -101,10 +101,10 @@ function get_offset2(doc::Document, line::Integer, character::Integer)
101101
text = get_text(doc)
102102

103103
if line >= length(line_offsets)
104-
error("Invalid arguments.")
104+
throw(LSOffsetError("get_offset2 crashed. More diagnostics:\nline=$line\nline_offsets='$line_offsets'"))
105105
return nextind(text, lastindex(text))
106106
elseif line < 0
107-
error("Invalid arguments.")
107+
throw(LSOffsetError("get_offset2 crashed. More diagnostics:\nline=$line\nline_offsets='$line_offsets'"))
108108
end
109109

110110
line_offset = line_offsets[line + 1]
@@ -153,9 +153,9 @@ end
153153

154154
"""
155155
get_line_offsets(doc::Document)
156-
157-
Updates the doc._line_offsets field, an n length Array each entry of which
158-
gives the byte offset position of the start of each line. This always starts
156+
157+
Updates the doc._line_offsets field, an n length Array each entry of which
158+
gives the byte offset position of the start of each line. This always starts
159159
with 0 for the first line (even if empty).
160160
"""
161161
function get_line_offsets(doc::Document, force=false)

src/requests/init.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@ function initialize_request(params::InitializeParams, server::LanguageServerInst
131131
elseif (params.workspaceFolders !== nothing) & (params.workspaceFolders !== missing)
132132
for wksp in params.workspaceFolders
133133
if wksp.uri !== nothing
134-
push!(server.workspaceFolders, uri2filepath(wksp.uri))
134+
fpath = uri2filepath(wksp.uri)
135+
if fpath !== nothing
136+
push!(server.workspaceFolders, fpath)
137+
end
135138
end
136139
end
137140
end

src/requests/textdocument.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ end
7070
function textDocument_didChange_notification(params::DidChangeTextDocumentParams, server::LanguageServerInstance, conn)
7171
doc = getdocument(server, URI2(params.textDocument.uri))
7272
if params.textDocument.version < doc._version
73-
error("The client and server have different textDocument versions for $(doc._uri).")
73+
error("The client and server have different textDocument versions for $(doc._uri). LS version is $(doc._version), request version is $(params.textDocument.version).")
7474
end
7575
doc._version = params.textDocument.version
7676

@@ -433,7 +433,7 @@ function is_parentof(parent_path, child_path, server)
433433
end
434434
pdoc = Document(puri, content, false, server)
435435
setdocument!(server, URI2(puri), pdoc)
436-
CSTParser.parse(get_text(pdoc))
436+
CSTParser.parse(get_text(pdoc), true)
437437
if typof(pdoc.cst) === CSTParser.FileH
438438
pdoc.cst.val = getpath(pdoc)
439439
set_doc(pdoc.cst, pdoc)

src/utilities.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ end
120120
# the include follow logic.
121121
function remove_workspace_files(root, server)
122122
for (uri, doc) in getdocuments_pair(server)
123+
# We first check whether the doc still exists on the server
124+
# because a previous loop iteration could have deleted it
125+
# via dependency removal of files
126+
hasdocument(server, uri) || continue
123127
fpath = getpath(doc)
124128
isempty(fpath) && continue
125129
get_open_in_editor(doc) && continue

test/test_document.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ d6 = Document("untitled", s6, false)
6464
LS.applytextdocumentchanges(doc, c3)
6565
@test LS.get_text(doc) == "println(\"Hello World\")"
6666
# doc currently has only one line, applying change to 2nd line should throw
67-
@test_throws ErrorException LS.applytextdocumentchanges(doc, c2)
67+
@test_throws LanguageServer.LSOffsetError LS.applytextdocumentchanges(doc, c2)
6868
end
6969

7070
@testset "UTF16 handling" begin

0 commit comments

Comments
 (0)