-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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(uri): don't use full path for custom schema #19773
Conversation
deno lsp uses a custom schema `deno:` `uri_from_bufnr` returns the full path of the buf file but this doesn't work with custom schema This fixes the last remaining bug here <neovim/nvim-lspconfig#2005> `relative dependencies inside virtual text document is not resolved correctly` Notes: - maybe `if relative_name:match("deno:")` should become `if is_custom_schema(realtive_name)` where is_custom_schema matches `URI_SCHEME_PATTERN` but is not equal to `file:///` - this changes fixes all my issues with denols (with some minor modifications that I can pr later) This is more to start a discussion I thought showing code is easier to discuss then raising an issue
For example here is how coc-deno is currently working-around the issue https://github.com/fannheyward/coc-deno/blob/1b42c38a9d78baf14ac90de2347a4e240f020de5/src/extension.ts#L126 |
Btw the full path in the buffer name is coming from
for example in deno lsp case:
|
Co-authored-by: ii14 <[email protected]>
I don't think handling every custom URI scheme globally is a good solution. In my opinion a better alternative would be to make URI translation configurable per LSP client. I'm not sure what are all the contexts where |
My personal opinion is
|
I'm fine with any option that works but I'm not sure how to implement this |
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.
I think the proper solution is to fix the URI recognition.
Where is the conversion happening? Is
neovim/runtime/lua/vim/uri.lua
Line 128 in 6264aa5
return vim.fn.bufadd(uri_to_fname(uri)) |
The problem, or bufadd itself?
I think bufname returns the path relative to the current directory, but with LSP the workspace root might be different than the current directory, so this approach here could break with that.
And there's also #19534 which kinda contradicts with this PR
Yes the problem is in bufadd |
bufadd calls eventually Line 1755 in 54a165d
|
Personally I want to just change It could be debated that any thing that relied on this bug is incorrect though. |
The problem is that unlike Windows, Linux only reserves the Maybe this could be disambiguated by |
|
||
--- Get a URI from a bufnr | ||
---@param bufnr number | ||
---@return string URI | ||
local function uri_from_bufnr(bufnr) | ||
local relative_name = vim.fn.bufname(bufnr) | ||
local maybe_scheme = relative_name:match(URI_SCHEME_PATTERN) |
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.
I haven't followed the thread, so sorry if this has been covered, but why can't relative_name
be fname
here?
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.
nvim_buf_get_name
always returns the full path. When you create a buffer with a name deno:some/file
, the current directory will be prepended to it (/home/user/deno:some/file
). With bufname()
it prefers returning the short name (deno:some/file
), but it's generally not 100% reliable.
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.
Then this is all a nasty hack. nvim_buf_get_name
is doing exactly the right thing. We shouldn't be relying on the cwd the parse the correct uri.
deno should be using something like deno://some/file
?
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.
deno:some/file
is technically compliant with the spec, vim just treats it like a normal path.
Two potential solutions we have right now is to start complying with the URI spec, or translate paths to and from deno://
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.
How feasible do we think it is to comply with the URI spec? I think that would be preferable if it doesn't break too much.
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.
It should be straightforward, all checks for ://
have to be replaced with :
, I think it's just in few places. But yeah, the question is how much of the user stuff would it break.
I opened #19797 to propose changing path_is_url |
Closing for #19797 |
Problem: path_to_url() returns false for single-slash URIs ("foo:/" vs "foo://"). This is not compliant with the URI spec. https://url.spec.whatwg.org/#url-representation LSP in particular allows single-slash URIs. Solution: Relax path_to_url() to accept single-slash URIs. This is not fully compliant (only ":" is required by the spec), but it is hopefully good enough without causing false-positives in typical text files. ref https://url.spec.whatwg.org/#windows-drive-letter ref #19773 ref #19773 (comment)
Problem: path_to_url() returns false for single-slash URIs ("foo:/" vs "foo://"). This is not compliant with the URI spec. https://url.spec.whatwg.org/#url-representation LSP in particular allows single-slash URIs. Solution: Relax path_to_url() to accept single-slash URIs. This is not fully compliant (only ":" is required by the spec), but it is hopefully good enough without causing false-positives in typical text files. ref https://url.spec.whatwg.org/#windows-drive-letter ref neovim#19773 ref neovim#19773 (comment)
deno lsp uses a custom schema
deno:
uri_from_bufnr
returns the full path of the buf file but this doesn't work with custom schemaThis fixes the last remaining bug here neovim/nvim-lspconfig#2005
relative dependencies inside virtual text document is not resolved correctly
Notes:
if relative_name:match("deno:")
should becomeif is_custom_schema(realtive_name)
whereis_custom_schema
returns true for any schema that matchesURI_SCHEME_PATTERN
but is not equal tofile:///
This is more to start a discussion I thought showing code is easier to discuss then raising an issue