-
-
Notifications
You must be signed in to change notification settings - Fork 53
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
🐛 BUG: Neovim broken lsp on dynamic routes #802
Comments
Hmm, since this works fine in VS Code, Zed and other editors, I assume it's something specific to Neovim. Not too sure what, my guess would be something with the path handling, since this only happens on dynamic routes with |
I have had the exact same issue and the solution with downgrading fixed the problem as @frametreon said. I will try to see what I can find, when time allows for it on my end. |
If there's any logs or something that Neovim outputs, I'd be happy to take a look |
I think I have the time during the weekend, so I will give some update then! |
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as off-topic.
This comment was marked as off-topic.
After turning on logging in neovim. Probably a little hard to read, but I can't make it much more readable than this😅 Just a note, this is when I save the file after making a change. Using version 2.7.6 |
screenrecord.mp4Here is a small video of the issue in action, this is purely for reference. |
Thank you, the logs are helpful. I assume that perhaps VS Code decodes the paths and Neovim doesn't, not sure who's right. We'll investigate! |
Let me know if you need any more logs, I can always send a lot more😆 |
Something that would be useful is logs from 2.6.3 if you have them, just to see the difference in encoding |
Yes let me get them those real quick. |
Here is a bunch, just from multiple times of me saving (using version 2.6.3) |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
unfortunately I am very new to programming in general and not good at debugging. The logs don't show anything useful for me( as in lsp.log is blank). What I have found so far is that when inspecting the context object that's passed into volar stuff, the snapshot that ends up getting generated is a StringScriptSnapshot on dynamic routes. In fact, any characters that would be url enocded anywhere in the file path will break it. so /[path]/test.astro will also not have any lsp. My guess is that somewhere a URI.parse or URI.file is being used incorrectly or there is an assumption that a path either is or isn't encoded and that's causing a bad uri. I really appreciate all the effort so we can struggle in agony in neovim instead of using vscode lol. |
I don't know if the following can help but from my observation it seems that the problem only applies to diagnostics, completion and highlighting. The server is correctly running and code action and documentSymbol work fine, the diagnostics response is always an empty array for some reason and the response from completion request never comes back. |
It is definitely not the URI. As the URI is the exact same when I used v2.6.3. |
While it might not be related to the URI shown in the logs, it might still be something related to path encoding. I investigated a little and couldn't quite find what just yet, though |
I noticed that the content these 2 logs provide are different, the last one has a added EDIT (sorry for the messy
Second log msg:
|
Any update on this @stauersbol? |
Not anymore than what I gave, so you'd have to wait for @Princesseuh to have an update for you |
Right on, @stauersbol. @Princesseuh Let me know how I can help. Happy to provide logs, etc. |
A little update! I think I can find a way to debug the language server. Mason does all the things to setup the actual language server. I can change the local files and see how it behaves and possibly find the place where it fails. I did some digging on the boilerplate that EDIT: I'll also try disabling any formatting (prettier in this case), and saving to see if that is one of the reasons for the appearance of multiple close tags EDIT 2: Looks like a possible solution was found in the comment below by Aaron. |
@Princesseuh again, I'll mention that I really don't know what I'm doing but I believe I have a solution. The issue seems to be in Volar. Is the next step bringing this up in volar? There are some places in volar where we do a .get() on a key where the case was changed. Here you can see the encoding case has changed. in @volar/language-server/lib/uri.js the fileNameToURI function I added a tolowercase in the return and we're now working in neovim. This was because in project/typescriptProject.js there is a context.documents.get() that was checking on a key that hadn't been lower cased yet for whatever reason. function fileNameToUri(fileName) {
if (fileName.startsWith('/') && fileName.includes('@@')) {
const parts = fileName.slice(1).split('@@');
if (parts.length !== 3) {
throw new Error('Invalid file name');
}
return vscode_uri_1.URI.from({
scheme: parts[0],
authority: parts[1],
path: parts[2],
}).toString();
}
return vscode_uri_1.URI.file(fileName).toString().toLowerCase() Here is where the key is checked. Because somewhere the encoding is lowercased this key is not found and no snapshot is returned. The no snapshot causes all sort of problems such as inability to save updated state, no completion etc. So either we should just add the tolowercase in the filenametouri, or maybe figuring out why we are changing the case of the encoding. |
Awesome work investigating this! I have brought it up internally in Volar and we'll attempt to get a fix out. I wonder why it works in VS Code then. |
of course the more I test I realize that if you add the lowercase it disables lsp in other areas. : ( At least now we know that somewhere it's the changing of case in the encoding that's messing things up. I tried to figure out where but was having a hard time. I'm actually not sure why we lowercase at all in uriMap.js |
Please try the last version! |
Seems like it is still causing some issues on my end after updating. screenrecord.mp4Video illustrates the latest update 2.9.0. EDIT: |
Arf that's annoying. This update fixed a similar issue for other editors and it of course still works as it always has in VS Code, so not sure. We'll keep investigating. The fact that it's on save is weird, do you have a formatting on save or anything else going on? |
Yes, I do have prettier running, I can try and see if that is also causing some trouble. But it's funny that I get that function imported and then when I save it just removes it🤔 |
screenrecord.mp4Alright tried again and with formatting off and on, doesn't impact anything. The "No info" prompt is just when I press a keybind to see function signatures and types. It doesn't show up on those functions because the line they are at is not the same as when the old file state was, that is also why when you see the module file path to when I do that over the function name The duplication of the closing tags seems to also be because of the state, but it is not present here for some reason. |
screenrecord.mp4Here is an example with me restarting the LSP with |
Sorry for the constant spam on this issue, but this looks like a state problem. The duplication stops as soon as I turned off the formatter. So it looks like the file state that is stored never gets updated, or whenever it sends the updated file state it refuses to update it internally(?). Sadly I have no idea how volar works under the hood with this other than from the brief time I looked at it. |
@stauersbol Can you reproduce the issue with minimal operations and share the LSP logs? |
Yes I will give it a try. |
https://gist.github.com/stauersbol/6db13542237c08563107b179f1f17497 Had to paste it to a gist as the logs hit the character support that github supports for comments. There was some more above this, but it was primarily start logs for tailwind and the astro lsp. |
Hello @johnsoncodehk, I think it has to do with the conversion or normalization of case based on what system is detected. This is why it works in VS code but not other systems, at least mine, neovim on wsl. in URI.file from vscode-uri the encoding is upper case while in our uriMap we lowercase. in typescriptProject.js we fail to get the uri from the weakmap which is what I believe causes the issue. getScriptSnapshot(fileName) {
askedFiles.pathSet(fileName, true);
//uri_1.fileNameToUri(fileName) outputs an upper cased encoding
//while server.documents will all be lowercased at some point.
//Only the encoding is lower cased.
const doc = server.documents.get((0, uri_1.fileNameToUri)(fileName));
if (doc) {
return doc.getSnapshot();
}
}, |
@aaronjconway Is your file system case sensitive? You can add the following log to the code to check this. getScriptSnapshot(fileName) {
+ console.warn(ts.sys.useCaseSensitiveFileNames);
askedFiles.pathSet(fileName, true);
const doc = server.documents.get(fileNameToUri(fileName));
if (doc) {
return doc.getSnapshot();
}
}, |
I know this was not directed at me, but all Linux distributions are case sensitive. Even if it's in WSL it still runs Linux. |
@johnsoncodehk it is case sensitive but it seems like we're only lowercasing the encoding. Everywhere I can find the uri's keep the filename case but lower the encoding case. I can't find where we are lowering the encoding case. in vscode-uri I just manually changed the encoding to the lower version and have full functionality. |
I tried solving this problem via volarjs/volar.js#181, please let me know if the problem is still there after updating. |
Just released 2.10.0 of the language server with this update, let us know if that works! |
I'll give it a try when I get home! Will update when I have tested. |
Great news! |
Awesome! I'll wait for a confirmation from @aaronjconway before closing, just in case. |
@stauersbol @Princesseuh @johnsoncodehk thank you guys! |
Seems to be fully resolved for me! Thanks guys. |
Describe the Bug
Currently when using dynamic [anything].astro routes I am having issues in neovim. No issues on other .astro files.
I get minimal lsp support but html, css and most ts not working.
Some but not all diagnostics work.
Formatting is either non existent or sometimes breaks on save. If I delete a line and save, it adds the line back.
vscode has no issues.
Thank you!!
Steps to Reproduce
I have a minimal neovim config at https://github.com/aaronjconway/astro_config
Steps to reproduce
https://github.com/withastro/prettier-plugin-astro
test lsp in new astro file and no lsp
The text was updated successfully, but these errors were encountered: