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

Lua/stdlib: behavior of global vs local "enable" (and other config) #28603

Open
justinmk opened this issue May 2, 2024 · 1 comment
Open
Labels
enhancement feature request lua stdlib needs:decision A discussion has run its course and a decision has to be made how to proceed needs:discussion For PRs that propose significant changes to some part of the architecture or API options configuration, settings
Milestone

Comments

@justinmk
Copy link
Member

justinmk commented May 2, 2024

Problem

vim.diagnostic.enable(nil) and vim.lsp.inlay_hint.enable(nil) both actively override any buffer-local flags that were previously set by enable(..., {bufnr=...}.

That seems a bit "destructive". I tend to think that global enable() should act like a gate:

  • if globally enabled, then defer to the buffer-local flag
  • if globally disabled, don't check the buffer-local flag

IOW: buffer-local "enable" flag has precedence unless the feature is globally disabled.

Expected behavior

Need a clear pattern for all such modules to follow. This may have implications for other kinds of "config" besides mere "enablement".

The behavior of vim options (:help global-local, ignoring other kinds of option scopes) would imply that the global setting is only the "default", and any buffer-local setting should always override the global default.

@justinmk justinmk added enhancement feature request lua stdlib labels May 2, 2024
@justinmk justinmk added this to the 0.11 milestone May 2, 2024
@justinmk justinmk changed the title Lua/stdlib: global vs local "enable" behavior Lua/stdlib: behavior of global vs local "enable" (and other config) May 2, 2024
@justinmk justinmk added options configuration, settings needs:decision A discussion has run its course and a decision has to be made how to proceed needs:discussion For PRs that propose significant changes to some part of the architecture or API labels May 2, 2024
@ofseed
Copy link
Contributor

ofseed commented May 4, 2024

IMO the current behavior of enable is good enough, even if we provide something like vim.g.inlay_hint = true and vim.b.inlay_hint = false, we should keep the current behavior.

A summary of the current pattern:

Keep buffer-local states only when it is different from the global one. This means that after it is equalized, its state will change as the global state changes.

As I said in #28543 (comment):

The logic behind this design is that if it can be globally enable or locally enable, when the user selects local enable, we think the user's purpose is to distinguish the local state from the global state. I think this design is good for interaction,

It is the best choice that can be made under the following constraints:

...there is no way to remove "local variables" by using enable. Once the user manages a buffer's bufstate, it means that they must manage it all the time, there's no way to make them follow the globalstate.

And if we add more filters, like what #28521 tries to do, it should be hard to manage by global or buffer variables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement feature request lua stdlib needs:decision A discussion has run its course and a decision has to be made how to proceed needs:discussion For PRs that propose significant changes to some part of the architecture or API options configuration, settings
Projects
None yet
Development

No branches or pull requests

2 participants