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: resolve #986 avoid wrong offset on Neovim for some postfix snippets #966

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Eric-Song-Nop
Copy link
Collaborator

@Eric-Song-Nop Eric-Song-Nop commented Dec 8, 2024

resolve #986

image1
image2

According to lsp spec, additional text edit is not supposed to be used here.

/**

  • An optional array of additional text edits that are applied when
  • selecting this completion. Edits must not overlap (including the same
  • insert position) with the main edit nor with themselves.
  • Additional text edits should be used to change text unrelated to the
  • current cursor position (for example adding an import statement at the
  • top of the file if the completion item will insert an unqualified type).
    */

@Eric-Song-Nop
Copy link
Collaborator Author

Other uses of additional_text_edits should also be replaced gradually

detail: Some(snippet.description.clone().into()),
insert_text_format: Some(InsertTextFormat::SNIPPET),
..Default::default()
};
if let Some(node_before_before_cursor) = &node_before_before_cursor {
let node_content = node.get().clone().into_text();
let before = TextEdit {
range: self.ctx.to_lsp_range(rng.start..self.from, &src),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The range of main edit can only start at the cursor, but rng.start is before the cursor.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not, the lsp spec says, "it must be a [single line] and they must contain the position at which completion has been requested," rather than "start with the position".

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's why it is ended in self.from.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I should use the insertandreplace capability of lsp

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the lsp spec said above, rng.start..self.from may span across multiple lines but the spec requires it MUST be in a single line so I don't think this is a valid fix. Btw, I checked it in my local neovim, and at least the case in #986 can work as expected. It might be worth to checking whether some neovim completion plugins don't work while others do work. I use the default LazyVim plus the tinymist.lua from the commit.

@Eric-Song-Nop Eric-Song-Nop changed the title fix: avoid additional text_edit fix: avoid wrong offset on Neovim for some postfix snippets Dec 11, 2024
@Eric-Song-Nop
Copy link
Collaborator Author

Eric-Song-Nop commented Dec 11, 2024

I am not sure if this is a common problem, so I am turning this pr in to a specific one for #986, thus the current implementation should be enough.

@Eric-Song-Nop Eric-Song-Nop marked this pull request as ready for review December 11, 2024 15:45
@Eric-Song-Nop Eric-Song-Nop changed the title fix: avoid wrong offset on Neovim for some postfix snippets fix: fix #986 avoid wrong offset on Neovim for some postfix snippets Dec 11, 2024
@Eric-Song-Nop Eric-Song-Nop changed the title fix: fix #986 avoid wrong offset on Neovim for some postfix snippets fix: resolve #986 avoid wrong offset on Neovim for some postfix snippets Dec 11, 2024
@Eric-Song-Nop Eric-Song-Nop self-assigned this Dec 17, 2024
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.

Some postfix snippets are applied in wrong order in Neovim
2 participants