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(config): make blink lua config fields optional #18

Merged
merged 1 commit into from
Oct 9, 2024

Conversation

scottmckendry
Copy link
Collaborator

@scottmckendry scottmckendry commented Oct 8, 2024

Hello @Saghen

First of all, congrats on the plugin! My initial impression has been great.

This patch fixes a somewhat selfish issue of mine. I prefer to use the config function to run configure plugins over opts just for a bit more flexibility and the added benefit of completions for option names.

However, in the current blink.cmp.Config class, all fields are required. This results in a bit of an unsightly warning:

image

With this fix, the options aren't required anymore (which reflects reality) and the warning is no longer present when configuring via the config option in lazy.

Let me know if you have any questions!

@Saghen
Copy link
Owner

Saghen commented Oct 8, 2024

Thanks for the kind words! I'd like to maintain type safety within the codebase, so could we create a separate type with everything marked as optional? Does Lua have something like Partial<T> from TS to make this easy?

@scottmckendry
Copy link
Collaborator Author

Completely understandable!

I'm not aware of anything like this, but will look into a suitable compromise.

@simifalaye
Copy link

@scottmckendry See this from nvim-best-practices which talks about exactly how you would solve this specific issue: /~https://github.com/nvim-neorocks/nvim-best-practices?tab=readme-ov-file#wrench-configuration

@Saghen I would recommend looking at some of the other recommendations in this repo (it is currently being upstreamed to neovim documentation at the request of a main neovim contributor) as I believe this plugin would benefit from some of the other notes also. Amazing plugin by the way! I was thinking about writing one myself because of some of the pitfalls of cmp and this plugin came in at the perfect time.

@scottmckendry
Copy link
Collaborator Author

Thanks for the steer @simifalaye. This is a really handy resource.

In this case, I'll leave the decision to @Saghen. The benefits of the multi-class approach are there, but my opinion is that they're not worth the effort of maintaining for Blink.

My reasoning for this:

  • There are very few references to blink's config types outside of their definitions in config.lua. I counted less than 10 (as of right now in main).
  • We're not really losing out on any type-safety by making the fields optional. You'll still get type warnings, and the defaults are set on every field where nil isn't valid.
  • I started adding the internal type annotations started to get pretty crazy looking. It might be overwhelming for other contributors in the future, as mentioned in the best-practices doc:

As this is fairly uncommon, first-time contributors will often overlook one of the configuration types.

I'm fine with whatever decision, just thought I would put my two cents in 🙂

@Saghen Saghen merged commit 9c73b0d into Saghen:main Oct 9, 2024
@Saghen
Copy link
Owner

Saghen commented Oct 9, 2024

Makes sense, thanks for the PR!

lopi-py pushed a commit to lopi-py/blink.cmp that referenced this pull request Oct 10, 2024
lopi-py pushed a commit to lopi-py/blink.cmp that referenced this pull request Oct 10, 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.

3 participants