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: set properties on namespaces #28728

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

altermo
Copy link
Contributor

@altermo altermo commented May 13, 2024

Use a singular function that can specify properties on the namespace.

Removed nvim__win_xx_ns functions as they are no longer needed.

@github-actions github-actions bot added the column sign/number column label May 13, 2024
@altermo altermo force-pushed the ns_scope branch 3 times, most recently from fff7048 to 60665db Compare May 13, 2024 01:31
@zeertzjq
Copy link
Member

zeertzjq commented May 13, 2024

It may be better to be able to change a namespace from global scope to window scope in one API call. The API will be like nvim_ns_set_scope or nvim_set_ns_scope or some other variation.

@zeertzjq zeertzjq added marks marks, extmarks, decorations, virtual text, namespaces and removed column sign/number column labels May 13, 2024
@altermo altermo changed the title feat: by default add namespace to global scope feat: option for namespace to be scoped May 13, 2024
@altermo altermo force-pushed the ns_scope branch 6 times, most recently from 0c96b4a to 32e9982 Compare May 14, 2024 16:40
@justinmk
Copy link
Member

The API will be like nvim_ns_set_scope

Can we have a generic nvim_ns_set() function which sets various properties of the namespace?

@altermo altermo force-pushed the ns_scope branch 4 times, most recently from 24cbad6 to 2ca429b Compare May 14, 2024 18:42
@altermo altermo marked this pull request as ready for review May 14, 2024 18:50
@github-actions github-actions bot requested a review from bfredl May 14, 2024 18:50
@altermo altermo force-pushed the ns_scope branch 4 times, most recently from 8d80e61 to 0c91dab Compare May 16, 2024 15:28
src/nvim/plines.c Outdated Show resolved Hide resolved
src/nvim/api/extmark.h Outdated Show resolved Hide resolved
@altermo altermo force-pushed the ns_scope branch 2 times, most recently from 2f2787f to 1fca1d1 Compare May 17, 2024 12:57
@altermo altermo changed the title feat: option for namespace to be scoped feat: set properties on namespaces May 17, 2024
@altermo altermo force-pushed the ns_scope branch 7 times, most recently from ac306b4 to 9ff9697 Compare May 17, 2024 16:48
src/nvim/window.c Outdated Show resolved Hide resolved
@altermo altermo force-pushed the ns_scope branch 3 times, most recently from 87d940b to 7bbe030 Compare May 17, 2024 23:22
@altermo altermo force-pushed the ns_scope branch 7 times, most recently from 95d9399 to fcaac92 Compare May 25, 2024 22:52
Comment on lines 20 to 25
if (!set_has(uint32_t, &namespace_scoped, ns_id)) {
return true;
}

return set_has(uint32_t, &wp->w_ns_set, ns_id);
Copy link
Member

@justinmk justinmk May 28, 2024

Choose a reason for hiding this comment

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

This seems strange. If ns_id is not in namespace_scoped, this function returns true? Why isn't the decision fully decided by w_ns_set, why is namespace_scoped needed at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

namespace_scoped is needed because it currently is equivalent to "namespace is scoped in at least one window" and if it doesn't contain the namespace, then that namespace is "global scoped" (which is what you asked for).

Though namespace_scoped can sometimes contain namespaces that are not scoped in any windows, because if a window is deleted, and that window was the only window where the namespace was scoped, then namespace_scoped isn't updated. (I could change this so that it's always synced, but that would entail that when a window is deleted, a namespace can suddenly become global scope, which is probably not what one wants.)

Copy link
Member

@justinmk justinmk May 28, 2024

Choose a reason for hiding this comment

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

right, the docstring and names were confusing.

namespace_scoped is needed because it currently is equivalent to "namespace is scoped in at least one window"

Sounds like an unnecessary optimization. We don't need namespace_scoped, we can iterate through all windows and check w_ns_set. That is simpler and requires less bookkeeping.

oh I missed this:

but that would entail that when a window is deleted, a namespace can suddenly become global scope, which is probably not what one wants.

Ok. namespace_scoped is confusing because "global scope" is also a scope. Maybe namespace_localscope is a better name.

src/nvim/api/extmark.h Outdated Show resolved Hide resolved
@altermo altermo force-pushed the ns_scope branch 2 times, most recently from 761d0be to acf7866 Compare May 28, 2024 17:14
src/nvim/api/extmark.h Outdated Show resolved Hide resolved
Comment on lines 13 to 14
EXTERN Map(String, int) namespace_ids INIT( = MAP_INIT);
EXTERN Set(uint32_t) namespace_scoped INIT( = SET_INIT);
Copy link
Member

@justinmk justinmk May 28, 2024

Choose a reason for hiding this comment

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

Is it too early to introduce (pseudocode):

namespaces: Map<id, NamespaceProps>

where NamespaceProps is a struct like:

{ scope: NsScope; ... }

Arguably that is similar to namespace_scope_map which I questioned for other reasons. 😓

@altermo altermo force-pushed the ns_scope branch 2 times, most recently from 4d9c8e7 to df9e46b Compare May 28, 2024 22:28
Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
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.

None yet

3 participants