From 495bf221cb1698a0b2a1c78b9b52901c0dca1ec7 Mon Sep 17 00:00:00 2001 From: Adam Beckmeyer Date: Mon, 28 Oct 2019 11:27:46 -0400 Subject: [PATCH 1/3] Force recalc of line offsets for each document change Closes #403 --- src/requests/textdocument.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/requests/textdocument.jl b/src/requests/textdocument.jl index 1c507ccc..b3924bf1 100644 --- a/src/requests/textdocument.jl +++ b/src/requests/textdocument.jl @@ -127,7 +127,6 @@ function process(r::JSONRPC.Request{Val{Symbol("textDocument/didChange")},DidCha for tdcce in r.params.contentChanges applytextdocumentchanges(doc, tdcce) end - doc._line_offsets = nothing parse_all(doc, server) end end @@ -241,6 +240,7 @@ function applytextdocumentchanges(doc::Document, tdcce::TextDocumentContentChang editrange = get_offset(doc, tdcce.range) doc._content = edit_string(doc._content, editrange, tdcce.text) end + doc._line_offsets = nothing end function edit_string(text, editrange, edit) From faba4faa431212d95708d4c58ce1c301eb8c71ac Mon Sep 17 00:00:00 2001 From: Adam Beckmeyer Date: Tue, 29 Oct 2019 08:23:29 -0400 Subject: [PATCH 2/3] Add unit tests for applytextdocumentchanges --- test/runtests.jl | 4 ++-- test/test_document.jl | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 6600b865..09b9a6f1 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,6 @@ using LanguageServer, CSTParser, Test, SymbolServer -Range = LanguageServer.Range +const LS = LanguageServer +const Range = LanguageServer.Range @testset "LanguageServer" begin @@ -8,5 +9,4 @@ include("test_communication.jl") include("test_hover.jl") include("text_edit.jl") - end diff --git a/test/test_document.jl b/test/test_document.jl index a05db033..4caccd4c 100644 --- a/test/test_document.jl +++ b/test/test_document.jl @@ -50,3 +50,21 @@ s6 = "\n" d6 = Document("untitled", s6, false) @test get_line_offsets(d6) == [0,1] +@testset "applytextdocumentchanges" begin + doc = LS.Document("file:///example/path/example.jl", "function foo()", false) + c1 = LS.TextDocumentContentChangeEvent(LS.Range(LS.Position(0,14), LS.Position(0,14)), + 0, "\n") + c2 = LS.TextDocumentContentChangeEvent(LS.Range(LS.Position(1,0), LS.Position(1,0)), + 0, " ") + c3 = LS.TextDocumentContentChangeEvent(nothing, nothing, "println(\"Hello World\")") + + LS.applytextdocumentchanges(doc, c1) + @test LS.get_text(doc) == "function foo()\n" + # Implicitly test for issue #403 + LS.applytextdocumentchanges(doc, c2) + @test LS.get_text(doc) == "function foo()\n " + LS.applytextdocumentchanges(doc, c3) + @test LS.get_text(doc) == "println(\"Hello World\")" + # doc currently has only one line, applying change to 2nd line should throw + @test_throws BoundsError LS.applytextdocumentchanges(doc, c2) +end From c6645314665a3321a7880c6315cd225241dfed09 Mon Sep 17 00:00:00 2001 From: Adam Beckmeyer Date: Tue, 29 Oct 2019 08:36:20 -0400 Subject: [PATCH 3/3] Test is no longer broken --- test/test_document.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_document.jl b/test/test_document.jl index 4caccd4c..c470d2af 100644 --- a/test/test_document.jl +++ b/test/test_document.jl @@ -36,7 +36,7 @@ d2 = Document("untitled", s2, true) applytextdocumentchanges(d2, LanguageServer.TextDocumentContentChangeEvent(Range(1), 0, "12")) -@test_broken get_line_offsets(d2) == [0, 8, 17] +@test get_line_offsets(d2) == [0, 8, 17] s4 = "1234\r\nabcd" d4 = Document("untitled", s4, false)