-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
refactor(diagnostic)!: replace 'show_*' functions with 'open_float' #16057
Conversation
Worth it :) (Especially with that handy migration table ❤️ ) |
Not perfectly sold on the But the alternatives I can come up with ( EDIT |
Maybe |
I also prefer float over popup where possible, and would favor an enum over string based scope. Also, I kinda like show more than preview, as preview implies a slice of diagnostics, which you could argue is a slice of the diagnostic cache, but I like the semantics of show more and would also favor reworking other usages of it. If we're doing this breaking change, I would also favor at the same time handling the deprecations of all of the lsp.diagnostics holdover, so we avoid multiple breaking changes, and merging this around the 0.6 feature freeze. |
Also we should fix the flakey win32 test (unrelated to this PR, just noting). Gradually these windows tests are becoming more and more reliable...
|
This is looking great already ❤️ I'm still not sure about the function name as I feel it can suggest that there's a more detailed diagnostics view, when in most cases the "preview" is all you're gonna get anyway. I think it might be worth it to (re-)consider |
I don't think there are any (user-visible) instances of "popup" anywhere (except for the return type of
I would too, but with module scopes an enum quickly becomes unwieldy:
IMO
Are you suggesting hard-deprecating |
Referring to the internal usage, but I see you changed it.
I'm suggesting a soft deprecation with printed warnings and removing the compatibility layer during the stabilization period leading up to 0.6. Additionally we should be removing the remaining internal usages of deprecated functions (there are still some)
Fair, I still like display/hide and show() from the old style but I may be in the minority.
I was thinking like vim.diagnostic.location.BUFFER with validation the location type is in the enum. |
'previewwindow' has long-established semantics in Vim already. I wonder where
Those are better than randomly sprinkling "preview" in function names for no reason. In general though the |
@justinmk Yeah I've never liked preview as a name, or popup becomes of the semantic association with prior vim semantics.
+1 to changing this |
798daab
to
c62d0d6
Compare
Since this is a breaking change, I wanted to throw this out there as well (as a follow-up to a convo with @clason on Gitter). I know it's not exactly what you're addressing here, but might be worth at least thinking about it since we are breaking stuff. Right now we treating severity the same all over the space at a global level with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a good direction. Thanks @gpanders again for your attention to detail :)
1a97e2e
to
d94711b
Compare
+1 other than virt textual (unless you want to go even farther and make it virtual textual reality)
This was me. I'm of two thoughts of this:
I'm not strongly opposed to making severity_sort the default, given it now serves more sources than lsp, but these were the original two justifications I gave for not making this the default as it was introduced. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
virt textual but then LGTM
'show_line_diagnostics()' and 'show_position_diagnostics()' are almost identical; they differ only in the fact that the latter also accepts a column to form a full position, rather than just a line. This is not enough to justify two separate interfaces for this common functionality. Renaming this to simply 'show_diagnostics()' is one step forward, but that is also not a good name as the '_diagnostics()' suffix is redundant. However, we cannot name it simply 'show()' since that function already exists with entirely different semantics. Instead, combine these two into a single 'open_float()' function that handles all of the cases of showing diagnostics in a floating window. Also add a "float" key to 'vim.diagnostic.config()' to provide global values of configuration options that can be overriden ephemerally. This makes the float API consistent with the rest of the diagnostic API. BREAKING CHANGE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. Really great improvement 👍
error("Invalid value for option 'pos'") | ||
end | ||
elseif scope ~= "buffer" then | ||
error("Invalid value for option 'scope'") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if worth it here - but including the user provided value and the valid options often help users figure out what went wrong.
do | ||
-- Resolve options with user settings from vim.diagnostic.config | ||
-- Unlike the other decoration functions (e.g. set_virtual_text, set_signs, etc.) `open_float` | ||
-- does not have a dedicated table for configuration options; instead, the options are mixed in | ||
-- with its `opts` table which also includes "keyword" parameters. So we create a dedicated | ||
-- options table that inherits missing keys from the global configuration before resolving. | ||
local t = global_diagnostic_options.float | ||
local float_opts = vim.tbl_extend("keep", opts, type(t) == "table" and t or {}) | ||
opts = get_resolved_options({ float = float_opts }, nil, bufnr).float | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks to @kylo252 for pointing this out. open_float
works differently than set_virtual_text
and friends since it doesn't have a dedicated table for configuration options, so if we resolve opts
directly that table clobbers the global configuration. As an example, consider
vim.diagnostic.config({ float = { show_header = false } })
vim.diagnostic.open_float(0, { scope = "line" })
If we pass {scope="line"}
directly to get_resolved_options
then it will assume that that is the full options table, which is missing show_header
and therefore will default to its unset value (true
) even though it's set to false
in the global configuration.
One way to fix this would be to use tbl_deep_extend
in get_resolved_options
, which is what I tried first, but that removes the ability to use an empty table to revert to default values (#16043). Another way would be to make a nested opts
table:
vim.diagnostic.open_float(0, {scope="line", opts = {...}})
But that seems confusing and non-intuitive to me. So instead just fill in missing keys from the global configuration before doing option resolution.
@gpanders I just tried this out and one thing that no longer acts the same way is that triggering Is there a way to get this functionality? |
That is a regression, it's an easy fix though. I'll address that in a follow up PR. |
@gpanders Awesome 🎉 Thank you! I also noted that |
It is: vim.diagnostic.goto_next { float = { show_header = true } } |
Damned ! Sorry, I didn't think my commit would appear here :/ |
- nightly neovim/neovim#16057 changed how line diagnostics are shown/rendered.
I would be surprised if this PR were the cause of that. It looks like "BufLeave" was removed from the default list of autocommands in #14649. You can try adding close_events = { "CursorMoved", "CursorMovedI", "BufHidden", "InsertCharPre", "BufLeave" } to the options table you pass to |
`open_float()` is replacement for `show_line_diagnostic()`, the opts still the same, but buffer number required as the first arguments, 0 for current buffer. ref: neovim/neovim#16057
Replace `enable_popup` and `popup_opts`. ref: neovim/neovim#16057
…eovim#16057) 'show_line_diagnostics()' and 'show_position_diagnostics()' are almost identical; they differ only in the fact that the latter also accepts a column to form a full position, rather than just a line. This is not enough to justify two separate interfaces for this common functionality. Renaming this to simply 'show_diagnostics()' is one step forward, but that is also not a good name as the '_diagnostics()' suffix is redundant. However, we cannot name it simply 'show()' since that function already exists with entirely different semantics. Instead, combine these two into a single 'open_float()' function that handles all of the cases of showing diagnostics in a floating window. Also add a "float" key to 'vim.diagnostic.config()' to provide global values of configuration options that can be overridden ephemerally. This makes the float API consistent with the rest of the diagnostic API. BREAKING CHANGE
See explainations here: neovim/neovim#16057
There have been breaking changes to that API: ref neovim/neovim#16057
show_line_diagnostics()
andshow_position_diagnostics()
are almost identical; they differ only in the fact that the latter also accepts a column to form a full position, rather than just a line. This is not enough to justify two separate interfaces for this common functionality.Renaming this to simply
show_diagnostics()
is one step forward, but that is also not a good name as the_diagnostics()
suffix is redundant. However, we cannot name it simplyshow()
since that function already exists with entirely different semantics.Instead, combine these two into a single
open_float()
function that handles all of the cases of previewing diagnostics in a floating window. Also add a "float" key tovim.diagnostic.config()
to provide global values of configuration options that can be overridden ephemerally. This makes the preview API consistent with the rest of the diagnostic API.This is a breaking change.
Differences in API usage:
vim.diagnostic.show_line_diagnostics()
vim.diagnostic.open_float(0, {scope="line"})
vim.diagnostic.show_position_diagnostics()
vim.diagnostic.open_float(0, {scope="cursor"})
vim.diagnostic.goto_next { enable_popup = true, popup_opts = {...}
vim.diagnostic.goto_next { float = {...} }
vim.diagnostic.show_line_diagnostics({opts}, buffer, 17)
vim.diagnostic.open_float(buffer, {{opts}, scope="line", pos=17}
vim.diagnostic.show_position_diagnositcs({opts}, buffer, {row, col})
vim.diagnostic.open_float(buffer, {{opts}, scope="cursor", pos={row, col}}