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

feat(builtins): add completion source for nvim-snippets #201

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

Conversation

przepompownia
Copy link
Contributor

@przepompownia
Copy link
Contributor Author

przepompownia commented Oct 21, 2024

I see that none-ls cannot recognize the prefix boundary if the snippet is prefixed with non-keyword character like this (/**):

https://github.com/rafamadriz/friendly-snippets/blob/de8fce94985873666bd9712ea3e49ee17aadb1ed/snippets/cpp/cppdoc.json#L20-L30

local get_word_to_complete = function(params)
local line = params.content[params.row]
local line_to_cursor = line:sub(1, params.col)
local regex = vim.regex("\\k*$")
return line:sub(regex:match_str(line_to_cursor) + 1, params.col)
end

@mochaaP mochaaP self-requested a review October 21, 2024 23:06
@przepompownia
Copy link
Contributor Author

przepompownia commented Oct 22, 2024

Thanks to the case for /** prefix I noticed buggy filtering and fixed it with a separated regex stolen from cmp-luasnip and slightly modified. I'm not sure if such pattern should be hardcoded or configured per filetype. Maybe someone else can find some example, for which such hardcoded pattern is incorrect.

Expanding such snippets is longer incorrect. For /** */ and label (prefix) /** I get /**/** */), but I see that the same happens without none-ls (and needs the repro for clean Nvim). To show this behavior I modified locally my unmerged branch on Phpactor phpactor/phpactor#2622.

diff --git a/lib/Completion/Bridge/TolerantParser/WorseReflection/KeywordCompletor.php b/lib/Completion/Bridge/TolerantParser/WorseReflection/KeywordCompletor.php
index 37190f27..562c0c48 100644
--- a/lib/Completion/Bridge/TolerantParser/WorseReflection/KeywordCompletor.php
+++ b/lib/Completion/Bridge/TolerantParser/WorseReflection/KeywordCompletor.php
@@ -47,6 +47,7 @@ class KeywordCompletor implements TolerantCompletor
         'try' => " {\$3\n} catch (\${1:Exception} \\\$\${2:error}) {\$4\n}",
         'while' => " (\$1) {\$0\n}",
         'yield' => ' $1;$0',
+        '/**' => ' $1 */$0',
     ];

@przepompownia
Copy link
Contributor Author

Full Nvim example: neovim/neovim#30905

- empty line case can be checked once per cb
- no need to iterate through snippets twice
@przepompownia
Copy link
Contributor Author

przepompownia commented Nov 11, 2024

Using textEdit allows to workaround non-keyword labels problem but not always: for example, if phpactor is attached to the PHP buffer too.

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.

1 participant