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(extmark): window scoped namespace #27361

Merged
merged 1 commit into from
Feb 21, 2024

Conversation

altermo
Copy link
Contributor

@altermo altermo commented Feb 6, 2024

By @bfredl suggestion #27361 (comment):
Make namespaces have the possibility of being window-local (only show the namespaces's extmarks in specific windows).
Currently, one needs to set a flag on the extmark (called scoped) to make this take effect (may be changed).

Closes #19654

@zeertzjq zeertzjq added the marks marks, extmarks, decorations, virtual text, namespaces label Feb 6, 2024
@bfredl
Copy link
Member

bfredl commented Feb 6, 2024

Alternative representation: for each decoration, just store a single bit (in the flags field for the extmark) whether this is a "scoped" extmark. then for each window, store a set of all the active namespaces from which scoped extmarks are considered.

It is less granular in one way (either all or nothing of scoped marks in a namespace is visible) but a lot more flexible in another (a given extmark category can be displayed in a subset of windows, not just one).

@altermo
Copy link
Contributor Author

altermo commented Feb 6, 2024

I thought about instead of having a scoped option for the extmark; have a scoped option for the namespace, as I don't see many people creating a namespace with a combination of scoped and unscoped extmarks.
But as namespaces don't have any struct and are just numbers, I don't know where to store this information.

@altermo altermo force-pushed the buf-win-local-extmarks branch 2 times, most recently from ffaf361 to 2d82edb Compare February 6, 2024 14:12
@altermo altermo changed the title feat(extmark): window scoped extmark feat(extmark): window scoped namespace Feb 6, 2024
@altermo altermo force-pushed the buf-win-local-extmarks branch 5 times, most recently from 0883afc to f58c8b9 Compare February 6, 2024 21:00
@bfredl
Copy link
Member

bfredl commented Feb 6, 2024

That might be an option as well.

But as namespaces don't have any struct and are just numbers, I don't know where to store this information.

That's mostly a consequence of just a single item of info being used currently. changing that to a struct would be fine if we go that path.

src/nvim/marktree_defs.h Outdated Show resolved Hide resolved
@altermo altermo force-pushed the buf-win-local-extmarks branch 14 times, most recently from 87a7bf0 to a2ba753 Compare February 9, 2024 13:03
@altermo altermo marked this pull request as ready for review February 9, 2024 13:04
test/functional/ui/decorations_spec.lua Outdated Show resolved Hide resolved
test/functional/ui/decorations_spec.lua Outdated Show resolved Hide resolved
test/functional/ui/decorations_spec.lua Outdated Show resolved Hide resolved
src/nvim/api/extmark.c Outdated Show resolved Hide resolved
src/nvim/api/extmark.c Outdated Show resolved Hide resolved
src/nvim/marktree.h Outdated Show resolved Hide resolved
Copy link
Member

@bfredl bfredl left a comment

Choose a reason for hiding this comment

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

otherwise LGTM. thanks for looking into this.

src/nvim/api/extmark.c Outdated Show resolved Hide resolved
@altermo
Copy link
Contributor Author

altermo commented Feb 21, 2024

I don't really favor the current PR so I thought a bit more about whether it would be better to have the namespaces themselves be scoped and this is what I came up with (only a proposal):

Each namespace would have some scopes. By default(if there are no scopes set) the namespace would fallback to the default behavior (which is that namespace-highlight won't be displayed anywhere and extmarks would be displayed everywhere).

If multiple scopes are set then they are a union instead of an intersection.

These are the scopes:

  • Window-scoped: Only display in specific window.
  • Buffer-scoped: Only display in specific buffer.
  • Tab-scoped: Only display in specific tabpage.
  • UI-scoped: Only display in specific UI.
  • Global-scoped: Display everywhere.

The affected namespace elements would be: buffer-local-extmark(and any other future extmark) and namespace-highlight.

Some api for this (not final design):

  • nvim_ns_add_{win,buf,tab,global}_scope: Adds the scope to namespace. Takes one (or zero for global) argument of bufnr/winid/tabpage.
  • nvim_ns_get_scopes: Get the scopes.
  • nvim_ns_del_{win,buf,tab,global}_scope: Deletes a scope of namespace. Takes one (or zero for global) argument of bufnr/winid/tabpage.
  • nvim_get_ns_scoped: Gets all namespaces with specific scope. Takes some arguments.

Depreciated api functions and their replacements:

  • nvim_get_hl_ns: Use nvim_get_ns_scoped to get global scoped namespaces and check if the namespace has higlight with nvim_get_hl.
  • nvim_set_hl_ns: Use nvim_ns_add_global_scope.
  • nvim_set_hl_ns_fast: I don't know a good replacement.
  • nvim_win_set_hl_ns: Use nvim_ns_add_win_scope.

NOTE: I won't implement namespace-highlight in this PR (if the proposal is good to go).

If you're okay with this proposal then signal so that I can start working on it.

@altermo altermo force-pushed the buf-win-local-extmarks branch 5 times, most recently from 7868823 to ce88b44 Compare February 21, 2024 09:01
@bfredl
Copy link
Member

bfredl commented Feb 21, 2024

Hmm, I'd still like to just get window-scoped extmarks merged first and then extend upon it as needed.

As far as I can tell this PR by itself is mostly forward-compatible with this extended proposal. The only difference I think is if we want to "mark" each individual extmark as scoped, or as you say, mark the entire namespace as scoped and then need to opt-in to it in specific windows.

nvim_ns_add_tabpage_scope would be a convenient short-hand for marking each individual window in that tab. convenient, but can be done as an addon. buffer-scoped would be mostly relevant for highlight namespaces, which we can consider but is separate work from this (and needs design discussion on its own. I have some other ideas how to rework those)

IMO I would first merge this pr pretty much as-is so that plugin authors can play with it. From there one we can gather feedback of what add-on features are mostly desired.

@altermo
Copy link
Contributor Author

altermo commented Feb 21, 2024

Then this PR is ready to merge.

src/nvim/decoration.c Outdated Show resolved Hide resolved
Co-authored-by: zeertzjq <zeertzjq@outlook.com>
Comment on lines +2794 to +2795
• scoped: boolean that indicates that the extmark should
only be displayed in the namespace scope. (experimental)
Copy link
Member

@justinmk justinmk May 12, 2024

Choose a reason for hiding this comment

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

This extra flag seems kind of random. It allows opt-ing out ("ignore the scopes for the given namespace"). If you don't want an extmark to obey the properties of its namespace, why not create a separate namespace ?

Edit: #28469

Copy link
Member

@zeertzjq zeertzjq May 12, 2024

Choose a reason for hiding this comment

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

If opting out is not allowed, that means an extmark will be invisible until its namespace is added to a window, which is undesirable.

Copy link
Member

Choose a reason for hiding this comment

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

an extmark will be invisible until its namespace is added to a window

Why must it be like that? If a namespace has no "window scopes", can't we assume it has "all windows" scope?

@justinmk
Copy link
Member

But as namespaces don't have any struct and are just numbers, I don't know where to store this information.

That's mostly a consequence of just a single item of info being used currently. changing that to a struct would be fine if we go that path.

💯

Alternatively, we could use options/variables (b:/w:/t:) to manage scopes. For example, window-scoped namespaces could be controlled by w:nvim.ns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
marks marks, extmarks, decorations, virtual text, namespaces
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Window-local display of extmarks
4 participants