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

Fix buffer index crashes #126

merged 2 commits into from
Jul 10, 2024

Conversation

jojorne
Copy link
Contributor

@jojorne jojorne commented Jun 19, 2024

Notes

  • Position.Line doesn't take into account trimmed lines.
  • It appears that the axaml doesn't care about the line feed.

Notes
* Position.Line doesn't take into account trimmed lines.
* It appears that the axaml doesn't care about the line feed.
@jojorne
Copy link
Contributor Author

jojorne commented Jun 19, 2024

But I think something like this would be better, especially if you want to reuse GetLine.

namespace AvaloniaLanguageServer.Services;

public sealed class Buffer
{
    public string GetTextTillLine(Position position)
    {
        var text = string.Join("\n", _lines[..position.Line]);
        var line = GetLine(position)[..position.Character];
        return $"{text}\n{line}";
    }

    public string GetLine(Position position)
    {
        return _lines[position.Line];
    }

    public string GetText()
    {
        return string.Join("\n", _lines);
    }

    public Buffer(string text)
    {
        _lines = text.Split(separator, StringSplitOptions.None);
    }
    
    private readonly string[] _lines;
    private static readonly string[] separator = { "\n", "\r\n" };
}

@microhobby
Copy link
Collaborator

Hey @prashantvc this should fix #110 and #113

@microhobby
Copy link
Collaborator

LGTM, thanks for the contribution @jojorne !

@microhobby microhobby merged commit 1a53413 into AvaloniaUI:main Jul 10, 2024
1 check passed
@jojorne
Copy link
Contributor Author

jojorne commented Oct 4, 2024

Any idea when the vscode extension will be updated? 🤔
It's just that this project seems abandoned... 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants