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: completeFunctionCalls adds brackets when writing JSX #240

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

m-gail
Copy link

@m-gail m-gail commented Feb 23, 2024

Solves #239

Fixes brackets being placed wrongly (for example with JSX and import statements) when complete_function_calls is set to true as described in the linked issue.

Old behavior

oldbehavior

New behavior

newbehavior

@m-gail m-gail changed the title Feature/239 Fix completeFunctionCalls adding brackets when writing JSX Feb 23, 2024
@m-gail m-gail changed the title Fix completeFunctionCalls adding brackets when writing JSX fix: completeFunctionCalls adds brackets when writing JSX Feb 23, 2024
@pmizio
Copy link
Owner

pmizio commented Feb 24, 2024

Hi, thanks for your contribution. I'm still on my vacation so I'll test it next week!

@@ -137,6 +137,12 @@ end
function M.handler(request, response, params)
local requested_bufnr = vim.uri_to_bufnr(vim.uri_from_fname(params.data.file))
local filetype = vim.bo[requested_bufnr].filetype
local is_valid_context_for_function_snippet = utils.is_valid_context_for_function_snippet(
requested_bufnr,
params.data,
Copy link
Author

@m-gail m-gail Feb 26, 2024

Choose a reason for hiding this comment

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

After using this PR for a bit, I've noticed that the position here does under some circumstances not get updated between when it first appears as a completion item and when it is chosen as a completion.
For example, when you are in insert mode and press backspace, the results and positions remain the same, which can lead to some unexpected behavior like this (| indicates cursor position):

# go into insert mode
{fooBarBaz|}<Component></Component>
# press backspace once, if you complete now, a snippet is used correctly
{fooBarBa|}<Component></Component>
# press backspace two more times, if you complete now, a snippet is not used
# even though it should be
# because the position is still the same as in step 1, but there is a '<'
# on that position now
{fooBar|}<Component></Component>

The problem could be solved, by querying the current cursor position from nvim here, instead of using the params, but I'm not sure if there is a better solution to this.

@GitMurf
Copy link

GitMurf commented May 28, 2024

Any updates on this?

@mmirus
Copy link

mmirus commented Jul 9, 2024

This would be a really nice improvement. 🙏

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.

4 participants