Skip to content
This repository was archived by the owner on Oct 13, 2021. It is now read-only.

fix: health check for ultisnips source#176

Merged
haorenW1025 merged 1 commit intonvim-lua:masterfrom
ybc37:fix/health-ultisnips
Sep 4, 2020
Merged

fix: health check for ultisnips source#176
haorenW1025 merged 1 commit intonvim-lua:masterfrom
ybc37:fix/health-ultisnips

Conversation

@ybc37
Copy link
Copy Markdown
Contributor

@ybc37 ybc37 commented Aug 21, 2020

Hey there,

I noticed the health check for UltiSnips failed for me, but it was correctly installed. The health check looks for ".*ultisnips.*" in rtp, but I think it's case-sensitive and my rtp contained UltiSnips. Does this makes sense?

Thanks!

@haorenW1025
Copy link
Copy Markdown
Collaborator

Hi and sorry for the long wait! Actually my rtp path is ultisnips, so I think matching both upper case and lower case character may be a better solution.

@ybc37
Copy link
Copy Markdown
Contributor Author

ybc37 commented Sep 1, 2020

Thanks for checking :)

I see, it depends on how the repo (plugin) was cloned. I used sirver/UltiSnips with vim-plug (for no reason, just copied it from somewhere).

I wonder if it's worth "fixing" the health check. At least it's a more general issue than related to ultisnips.

We could support both variants:

diff --git a/lua/completion/health.lua b/lua/completion/health.lua
index 1c43d1e..b3f4577 100644
--- a/lua/completion/health.lua
+++ b/lua/completion/health.lua
@@ -21,3 +21,3 @@ local checkSnippetSource = function()
   elseif snippet_source == 'UltiSnips' then
-    if string.match(api.nvim_get_option("rtp"), ".*ultisnips.*") then
+    if string.match(api.nvim_get_option("rtp"), ".*[Uu]lti[Ss]nips.*") then
       health_ok("You are using UltiSnips as your snippet source")

Or better make the string matching case insensitive (also for the other checks; not included in the diff):

diff --git a/lua/completion/health.lua b/lua/completion/health.lua
index 1c43d1e..4dd51d6 100644
--- a/lua/completion/health.lua
+++ b/lua/completion/health.lua
@@ -21,3 +21,4 @@ local checkSnippetSource = function()
   elseif snippet_source == 'UltiSnips' then
-    if string.match(api.nvim_get_option("rtp"), ".*ultisnips.*") then
+    local rtp = string.lower(api.nvim_get_option("rtp"))
+    if string.match(rtp, ".*ultisnips.*") then
       health_ok("You are using UltiSnips as your snippet source")

What do you think? Happy to change the PR :) Of course, feel free to close this PR, if you think it's not worth it.

@haorenW1025
Copy link
Copy Markdown
Collaborator

Hmm I guess having matching all case insensitive is a better solution. Also maybe we should do that for other health check component as well.

@ybc37 ybc37 force-pushed the fix/health-ultisnips branch from c1e11f5 to 5ca4bff Compare September 3, 2020 15:05
@ybc37
Copy link
Copy Markdown
Contributor Author

ybc37 commented Sep 3, 2020

I refactored the check a bit to address DRY. But tbh, I wasn't sure if you want that additional complexity?

@haorenW1025
Copy link
Copy Markdown
Collaborator

The extra complexity would be fine since users aren't going to call healthcheck all the time and slowing down healthcheck is not quite a big deal in my opinion. One small things you probably need is to rebase this PR since we already have snippets.nvim support and you might need to add that as well.

* table to check sources instead of if conditions for each source (dry)
* string matching is case insensitive now
@ybc37 ybc37 force-pushed the fix/health-ultisnips branch from 5ca4bff to a7949c7 Compare September 3, 2020 18:22
@ybc37
Copy link
Copy Markdown
Contributor Author

ybc37 commented Sep 3, 2020

Sure, rebased it on master :) Includes snippets.nvim now.

Comment thread lua/completion/health.lua Outdated
if snippet_source == k then
unknown_snippet_source = false
if string.match(rtp, ".*"..v..".*") then
print("You are using "..k.." as your snippet source")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You should use health_ok or health_error instead of print to integrate with healthcheck.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, sorry for the confusion. I tested the code snippet in a separate lua script and unfortunately left print in there when integrating it. Fixed it when rebasing on master and hoped you haven't seen it yet 😉

@haorenW1025
Copy link
Copy Markdown
Collaborator

LGTM! Thanks for taking the time fixing this. Highly appreciate:)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants