@@ -48,23 +48,36 @@ s6 = "\n"
4848d6 = Document (TextDocument (uri " untitled:none" , s6, 0 ), false )
4949@test get_line_offsets (get_text_document (d6)) == [0 ,1 ]
5050
51- @testset " applytextdocumentchanges" begin
52- doc = LS. Document (TextDocument (uri " file:///example/path/example.jl" , " function foo()" , 0 ), false )
53- c1 = LS. TextDocumentContentChangeEvent (LS. Range (LS. Position (0 , 14 ), LS. Position (0 , 14 )),
54- 0 , " \n " )
55- c2 = LS. TextDocumentContentChangeEvent (LS. Range (LS. Position (1 , 0 ), LS. Position (1 , 0 )),
56- 0 , " " )
51+ @testset " apply_text_edits" begin
52+ version = 0
53+ doc = TextDocument (uri " file:///example/path/example.jl" , " function foo()" , version)
54+ c1 = LS. TextDocumentContentChangeEvent (LS. Range (LS. Position (0 , 14 ), LS. Position (0 , 14 )), 0 , " \n " )
55+ c2 = LS. TextDocumentContentChangeEvent (LS. Range (LS. Position (1 , 0 ), LS. Position (1 , 0 )), 0 , " " )
5756 c3 = LS. TextDocumentContentChangeEvent (missing , missing , " println(\" Hello World\" )" )
5857
59- LS. applytextdocumentchanges (doc, c1 )
58+ doc = LS. apply_text_edits (doc, [c1], version += 1 )
6059 @test LS. get_text (doc) == " function foo()\n "
6160 # Implicitly test for issue #403
62- LS. applytextdocumentchanges (doc, c2 )
61+ doc = LS. apply_text_edits (doc, [c2], version += 1 )
6362 @test LS. get_text (doc) == " function foo()\n "
64- LS. applytextdocumentchanges (doc, c3 )
63+ doc = LS. apply_text_edits (doc, [c3], version += 1 )
6564 @test LS. get_text (doc) == " println(\" Hello World\" )"
65+
66+ # Test muliple edits (#1118)
67+ doc = TextDocument (uri " file:///example/path/example.jl" , " module Crash\n\n\n\n end # module Crash\n " , version)
68+ edits = [
69+ LS. TextDocumentContentChangeEvent (LS. Range (LS. Position (2 , 0 ), LS. Position (2 , 0 )), 0 , " p" ),
70+ LS. TextDocumentContentChangeEvent (LS. Range (LS. Position (2 , 1 ), LS. Position (2 , 1 )), 0 , " r" ),
71+ LS. TextDocumentContentChangeEvent (LS. Range (LS. Position (2 , 2 ), LS. Position (2 , 2 )), 0 , " i" ),
72+ LS. TextDocumentContentChangeEvent (LS. Range (LS. Position (2 , 3 ), LS. Position (2 , 3 )), 0 , " n" ),
73+ LS. TextDocumentContentChangeEvent (LS. Range (LS. Position (2 , 4 ), LS. Position (2 , 4 )), 0 , " t" ),
74+ ]
75+ doc = LS. apply_text_edits (doc, edits, version += 1 )
76+ @test LS. get_text (doc) == " module Crash\n\n print\n\n end # module Crash\n "
77+
6678 # doc currently has only one line, applying change to 2nd line should throw
67- @test_throws LanguageServer. LSOffsetError LS. applytextdocumentchanges (doc, c2)
79+ doc = LS. apply_text_edits (doc, [c3], version += 1 )
80+ @test_throws LanguageServer. LSOffsetError LS. apply_text_edits (doc, [c2], version += 1 )
6881end
6982
7083@testset " UTF16 handling" begin
0 commit comments