-
Notifications
You must be signed in to change notification settings - Fork 184
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 unsaved buffers pyright incompatibility #2360
Conversation
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.
Tested ✔️
Can confirm that this fixes pyright.
Not really working as expected. Right after I type import os
os. the server goes to 100% CPU again and won't repsonse anymore. |
The “sublime” path was meant to signify to langservers that it was an in-memory buffer from sublime text. But I don’t think any maintainer cares. |
Make sure that you test on a newly opened buffer because the one you had open before has the previous uri saved already. |
Nor should they have a sublime specific logic, probably... The protocol itself ("buffer:" in this case) is already enough imo. As long as it's a protocol that it doesn't know how to handle, it should be treated more or less like a non-file and not assume that it's accessible on disk. |
That's what I did.
Weirdly if I kill the server by Windows Task Manager, a new server process is auto created and then it works in the unsaved buffer. |
I will have a look if you find a way to reproduce. |
It's working here for in-memory buffers for Ubuntu 22. Maybe it's a Windows-only issue? Maybe pyright has special case handling for Windows to account for drive letters? Just thinking out loud here. |
I managed to reproduce your issue on both Linux and Windows.
import os
// then type anything and you will see that things do not work It is enough to just Screencast.from.2023-11-10.23-14-38.webm |
My observations (on Windows):
|
Yeah, I don't get why it doesn't parse it correctly in this case. Probably there is a good reason though... |
Looks like it's just a bug in the urllib library. It works as expected in recent Python version(s):
|
I have been thinking for a while to just port https://github.com/microsoft/vscode-uri to python. The main benefit being that it would also handle path normalization (the slashes and the Windows drive letter case which have been problematic for us before). Doesn't seem like a big lift. |
I tried to fix the urllib bug for the --- a/plugin/core/url.py
+++ b/plugin/core/url.py
@@ -60,6 +60,9 @@ def parse_uri(uri: str) -> Tuple[str, str]:
else:
return parsed.scheme, path
return parsed.scheme, path
+ elif parsed.scheme == '' and ':' in parsed.path:
+ # workaround for bug in urllib.parse.urlparse
+ return parsed.path.split(':')[0], uri
return parsed.scheme, uri |
Note that VS Code seems to normalize drive letters to lowercase, but we need to use uppercase drive letters in the ST API functions for them to work correctly. So I don't think we could simply use a ported version of what VS Code does. See Lines 83 to 86 in d5be23a
|
Hmm...
So it works if the path starts with a letter... |
The
sublime
part inbuffer://sublime/[view_id]
URIs that we were using for unsaved buffers triggered an infinite loop in pyrights file traversing code. While I don't pretend to understand its code fully, thesublime
in our made-up URIs is not really necessary or makes a lot of sense even.Fixes sublimelsp/LSP-pyright#281