Skip to content

Commit

Permalink
Merge pull request #126 from jojorne/patch-1
Browse files Browse the repository at this point in the history
Fix buffer index crashes
  • Loading branch information
microhobby authored Jul 10, 2024
2 parents c7ae745 + a7b794b commit 1a53413
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/AvaloniaLSP/AvaloniaLanguageServer/Services/Buffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ public sealed class Buffer

public string? GetTextTillLine(Position position)
{
string[] lines = _text.Split(separator, StringSplitOptions.RemoveEmptyEntries);
var linesRange = string.Join(string.Empty, lines[0..position.Line]);
string lastLine = lines[position.Line];

return linesRange + lastLine.Substring(0, position.Character);
string[] lines = _text.Split(separator, StringSplitOptions.None);
string text = string.Join("\n", lines[..position.Line]);
string line = lines[position.Line][..position.Character];
return $"{text}\n{line}";
}

public string? GetLine(Position position)
{
string[] lines = _text.Split(separator, StringSplitOptions.RemoveEmptyEntries);
string[] lines = _text.Split(separator, StringSplitOptions.None);
return lines[position.Line];
}

Expand All @@ -27,4 +26,4 @@ public Buffer(string text)

readonly string _text;
private static readonly string[] separator = ["\n", "\r\n"];
}
}

0 comments on commit 1a53413

Please sign in to comment.