Skip to content

Commit dfe48e0

Browse files
authored
Merge pull request #828 from julia-vscode/improve-errors
Add better error message
2 parents e76424a + f0dd00d commit dfe48e0

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
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)

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)