Rewrite To_LSP_Column to compute LSP column index at the end

This commit is contained in:
Vadim Godunko
2024-11-19 18:13:29 +04:00
parent d725089a73
commit 9cf1dde888

View File

@@ -22,8 +22,7 @@ package body LSP.Text_Documents.Langkit_Documents is
function To_LSP_Column
(Line_Text : VSS.Strings.Virtual_String;
Column : Langkit_Support.Slocs.Column_Number;
At_Start : Boolean := True) return Natural;
Column : Langkit_Support.Slocs.Column_Number) return Natural;
use type Langkit_Support.Slocs.Line_Number;
@@ -87,7 +86,7 @@ package body LSP.Text_Documents.Langkit_Documents is
an_end =>
(line => To_LSP_Line (A_Range.End_Line),
character => To_LSP_Column
(Self.Line (A_Range.End_Line), A_Range.End_Column, False)));
(Self.Line (A_Range.End_Line), A_Range.End_Column)));
function To_A_Range
(Start_Line_Text : VSS.Strings.Virtual_String;
@@ -101,7 +100,7 @@ package body LSP.Text_Documents.Langkit_Documents is
an_end =>
(line => To_LSP_Line (A_Range.End_Line),
character => To_LSP_Column
(End_Line_Text, A_Range.End_Column, False)));
(End_Line_Text, A_Range.End_Column)));
---------------------
-- To_LSP_Position --
@@ -112,9 +111,8 @@ package body LSP.Text_Documents.Langkit_Documents is
Sloc : Langkit_Support.Slocs.Source_Location)
return LSP.Structures.Position
is
(line => To_LSP_Line (Sloc.Line),
character => To_LSP_Column
(Self.Line (Sloc.Line), Sloc.Column, False));
(line => To_LSP_Line (Sloc.Line),
character => To_LSP_Column (Self.Line (Sloc.Line), Sloc.Column));
-------------------
-- To_LSP_Column --
@@ -122,26 +120,21 @@ package body LSP.Text_Documents.Langkit_Documents is
function To_LSP_Column
(Line_Text : VSS.Strings.Virtual_String;
Column : Langkit_Support.Slocs.Column_Number;
At_Start : Boolean := True) return Natural
Column : Langkit_Support.Slocs.Column_Number) return Natural
is
Iterator : VSS.Strings.Character_Iterators.Character_Iterator :=
Line_Text.At_First_Character;
Success : Boolean with Unreferenced;
begin
-- Iterating forward through the line, initial
-- iterator points to the first characters, thus "starts" from the
-- second one.
-- Iterating forward through the line, initial iterator points to the
-- first characters, thus "starts" from the second one (to improve
-- performance).
for J in 2 .. Column loop
Success := Iterator.Forward;
end loop;
if At_Start then
return Natural (Iterator.First_UTF16_Offset);
else
return Natural (Iterator.Last_UTF16_Offset);
end if;
return Natural (Iterator.First_UTF16_Offset);
end To_LSP_Column;
----------------------