-
Notifications
You must be signed in to change notification settings - Fork 186
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
Allow attaching to URI schemes other than the 'file' scheme #1758
Conversation
This allows servers to attach to schemes like: - `buffer`: in-memory buffers - `res`: ST resource files in .sublime-packages - other foreign schemes, like `deno`, `json-schema`, `jdt`, etc The way this works is that we have a new client configuration setting called `"schemes"` which is a list of allowable URI schemes. If `"schemes"` is not specified, then it's by default `["file"]`.
plugin/documents.py
Outdated
def _on_settings_object_changed(self) -> None: | ||
new_syntax = self.view.settings().get("syntax") | ||
if new_syntax != self._current_syntax: | ||
self._current_syntax = new_syntax | ||
self._cleanup() | ||
self._setup() | ||
|
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.
Don't we have to unregister the listener and then register it back and trigger "on_activated" to trigger didOpen?
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.
No need: container of SessionViews is cleared, _is_registered is set to False, and then on_activated_async is called by ST.
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 checked but I've assumed that on_activated_async
won't necessarily be called. Not unless the user changes the focus of the files manually.
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.
fixed in 5294c95
Don't have time to investigate now but noticed that |
@rchl in what circumstances is languageid empty? do you have an example? |
We don't seem to be handling file renames and are sending the old file name to the server even after rename. |
Also found some bad issue where LSP gets confused with what file (URI) was closed and reports one for a different file. I'm not entirely sure how this happens but have sort of solid repro so can look closer when I have more time. EDIT: It's probably related to backward-compatibility problem with files that were already open before those changes were introduced. |
Works fine for me in pyright:
pyright does have problems with publishing diagnostics though. It publishes diagnostics for |
Saving existing files on disk to a different filename also works:
|
I don't mean saving files. I mean open a normal file and use |
Seems to be missing callbacks in the ST API. |
made an issue for it sublimehq/sublime_text#4540 |
Instead of waiting for a fix in ST, maybe we should consider only falling back to a saved URI when the file has no filename so that we in most cases always access native view.file_name(). Otherwise it's easy for regressions and corner cases to bite us (besides the already mentioned one). |
Sorry, could you expand more on what you mean here? |
Basically what I'm thinking is to only set I'm not sure how much of a performance impact it would have but it would ensure that we always ask the real source of truth for the file name instead of relying on our cached value and having to worry about invalidating it in all cases. |
Trying to figure out why the CI fails |
This reverts commit 8f8c394.
Something in 3a495bc makes the CI fail spectacularly :D |
What's your plan regarding this issue: #1758 (comment) ? Integrate with that flaw, wait or have my suggested workaround? While previously we didn't detect the renames either (I guess those would ideally trigger didClose and didOpen), now renames cause various errors with various servers (I guess because we notify about file that is no longer on disk). |
I would go ahead with this in spite of not handling renames as it doesn’t work on main as well. |
def uri_to_filename(uri: str) -> str: | ||
""" | ||
DEPRECATED: An URI associated to a view does not necessarily have a "file:" scheme. | ||
Use urllib.parse.urlparse to determine the scheme and go from there. | ||
Use urllib.parse.unquote to unquote the path. | ||
""" | ||
parsed = urlparse(uri) | ||
assert parsed.scheme == "file" | ||
if os.name == 'nt': | ||
# url2pathname does not understand %3A (VS Code's encoding forced on all servers :/) | ||
return url2pathname(parsed.path).strip('\\') | ||
else: | ||
return url2pathname(parsed.path) | ||
|
||
|
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.
Can we have an alternative helper function for getting filename from URI? I'd need to use something in eslint.
Having to play with urllib doesn't sound like fun and also I wonder if such helper needs to apply some path transformations to stay consistent.
I imagine such helper could return a tuple with scheme and file path (if file
scheme at least).
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.
Let's also do that in another PR?
But I could argue that the situation is worse now. Previously at least the server would more or less happily work after rename. Now there are errors like:
Though, won't hold it against this change as previous behavior wasn't perfect either. |
…sp#1758) This allows servers to attach to schemes like: - `buffer`: in-memory buffers - `res`: ST resource files in .sublime-packages - other foreign schemes, like `deno`, `json-schema`, `jdt`, etc The way this works is that we have a new client configuration setting called `"schemes"` which is a list of allowable URI schemes. If `"schemes"` is not specified, then it's by default `["file"]`.
This allows servers to attach to schemes like:
buffer
: in-memory buffersres
: ST resource files in .sublime-packagesdeno
,json-schema
,jdt
, etcThe way this works is that we have a new client configuration setting
called
"schemes"
which is a list of allowable URI schemes.If
"schemes"
is not specified, then it's by default["file"]
.Resolves #1739
I've tried this with LSP-json, LSP-pyright and these language servers
are working well with non-file URIs. clangd on the other hand refuses
to work with in-memory buffers.