Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix buffer index crashes #126

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"];
}
}