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

[Feature Request]: Allow multiline text in TextEventReplace #3628

Open
usfbih8u opened this issue Jan 23, 2025 · 1 comment
Open

[Feature Request]: Allow multiline text in TextEventReplace #3628

usfbih8u opened this issue Jan 23, 2025 · 1 comment

Comments

@usfbih8u
Copy link

usfbih8u commented Jan 23, 2025

I am contributing to the Micro Language Server Protocol (mlsp) and have encountered an issue with the ExecuteTextEvent() method when handling TextEventReplace events. Currently, when deltas are created, it assumes that there are no newline characters within the text.

Is this an edge case that has not been considered, a bug, or an intended feature?

Please refer to line 130, where the same Y value is used for both Start and End:

} else if t.EventType == TextEventReplace {
for i, d := range t.Deltas {
t.Deltas[i].Text = buf.remove(d.Start, d.End)
buf.insert(d.Start, d.Text)
t.Deltas[i].Start = d.Start
t.Deltas[i].End = Loc{d.Start.X + util.CharacterCount(d.Text), d.Start.Y}
}
for i, j := 0, len(t.Deltas)-1; i < j; i, j = i+1, j-1 {
t.Deltas[i], t.Deltas[j] = t.Deltas[j], t.Deltas[i]
}
}

You can find more details about the issue in these messages:

We need to send the same changes to the LSP that Micro does. A possible solution on our side (similar to what needs to be done in Micro) could be the following:

-- treat as pseudocode
local splits = strings.Split(delta.Text)
local nsplits = #splits
local last_split_len = util.CharacterCountInString(splits[nsplits])
local char_begin = nsplits == 1 and delta.Start.X or 0
range["start"]  = ...
range["end"] = {
    line = delta.Start.Y + nsplits - 1,
    character = char_begin + last_split_len
}

The LineArray functions remove and insert appear to handle newlines (likely for deleting multiline selections), but the upstream ExecuteTextEvent does not.

@usfbih8u usfbih8u changed the title [Feature Request]: Allow multiline TextEventReplace events [Feature Request]: Allow multiline text in TextEventReplace Jan 23, 2025
@JoeKar
Copy link
Collaborator

JoeKar commented Jan 23, 2025

Looks like a bug.

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

No branches or pull requests

2 participants