@@ -655,6 +655,18 @@ defmodule ElixirLS.LanguageServer.SourceFileTest do
655655 assert { 1 , 2 } == SourceFile . lsp_position_to_elixir ( "abcde" , { 0 , 1 } )
656656 end
657657
658+ # This is not specified in LSP but some clients fail to synchronize text properly
659+ test "lsp_position_to_elixir single line before line start" do
660+ assert { 1 , 1 } == SourceFile . lsp_position_to_elixir ( "abcde" , { 0 , - 1 } )
661+ end
662+
663+ # LSP spec 3.17 https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#position
664+ # position character If the character value is greater than the line length it defaults back to the line length
665+ test "lsp_position_to_elixir single line after line end" do
666+ assert { 1 , 6 } == SourceFile . lsp_position_to_elixir ( "abcde" , { 0 , 15 } )
667+ assert { 1 , 1 } == SourceFile . lsp_position_to_elixir ( "" , { 0 , 15 } )
668+ end
669+
658670 test "lsp_position_to_elixir single line utf8" do
659671 assert { 1 , 2 } == SourceFile . lsp_position_to_elixir ( "🏳️🌈abcde" , { 0 , 6 } )
660672 end
@@ -663,6 +675,16 @@ defmodule ElixirLS.LanguageServer.SourceFileTest do
663675 assert { 2 , 2 } == SourceFile . lsp_position_to_elixir ( "abcde\n 1234" , { 1 , 1 } )
664676 end
665677
678+ # This is not specified in LSP but some clients fail to synchronize text properly
679+ test "lsp_position_to_elixir multi line before first line" do
680+ assert { 1 , 1 } == SourceFile . lsp_position_to_elixir ( "abcde\n 1234" , { - 1 , 2 } )
681+ end
682+
683+ # This is not specified in LSP but some clients fail to synchronize text properly
684+ test "lsp_position_to_elixir multi line after last line" do
685+ assert { 2 , 5 } == SourceFile . lsp_position_to_elixir ( "abcde\n 1234" , { 8 , 2 } )
686+ end
687+
666688 test "elixir_position_to_lsp empty" do
667689 assert { 0 , 0 } == SourceFile . elixir_position_to_lsp ( "" , { 1 , 1 } )
668690 end
0 commit comments