Skip to content

Fix LSP diagnostics on Windows#1274

Merged
a-h merged 1 commit intoa-h:mainfrom
MilkeeyCat:pr_lsp_work_on_windows
Dec 31, 2025
Merged

Fix LSP diagnostics on Windows#1274
a-h merged 1 commit intoa-h:mainfrom
MilkeeyCat:pr_lsp_work_on_windows

Conversation

@MilkeeyCat
Copy link
Copy Markdown
Contributor

@MilkeeyCat MilkeeyCat commented Sep 24, 2025

LSP diagnostics didn't work before because:

  • strings.TrimPrefix was used to get file path, strings.TrimPrefix("file:///c:/Users/uwu", "file://") would return /c:/Users/uwu which is not valid windows path
  • gopls changes uri and makes disk letter uppercase, templ didn't
  • "file://" + path makes invalid URI if the path contains windows path, there should be three /

Functions are taken from https://github.com/golang/tools/blob/4df13e317ce43275bec40ab5c9ce3e926fa92655/gopls/internal/protocol/uri.go

Now it works(don't mind the floating explorer tab, it's windows being windows 😬):
image

I don't have a windows machine so I tested it on docker version of windows, if you have the opportunity to test it yourself, do it!

fixes #1121

@MilkeeyCat MilkeeyCat changed the title fix(lsp): use helper functions to manipulate uris Fix LSP diagnostics for Windows Sep 24, 2025
@MilkeeyCat MilkeeyCat force-pushed the pr_lsp_work_on_windows branch from 702525f to c98f093 Compare September 25, 2025 14:58
@MilkeeyCat MilkeeyCat changed the title Fix LSP diagnostics for Windows Fix LSP diagnostics on Windows Sep 25, 2025
@MilkeeyCat MilkeeyCat marked this pull request as ready for review September 25, 2025 15:12
@MilkeeyCat MilkeeyCat force-pushed the pr_lsp_work_on_windows branch from c98f093 to ec24c82 Compare September 26, 2025 20:23
@MilkeeyCat
Copy link
Copy Markdown
Contributor Author

Maybe it would be a good idea update lsp code to match latest gopls code, it implements UnmarshalText method on DocumentURI which automatically handles windows paths.

@MilkeeyCat MilkeeyCat force-pushed the pr_lsp_work_on_windows branch from ec24c82 to cba0d6a Compare September 26, 2025 20:34
@a-h
Copy link
Copy Markdown
Owner

a-h commented Oct 8, 2025

Thanks a lot! I'll take a proper look when I get chance. URI parsing can result in security issues, so I need to give it some proper time to review.

@a-h a-h merged commit a7df818 into a-h:main Dec 31, 2025
5 checks passed
@a-h
Copy link
Copy Markdown
Owner

a-h commented Dec 31, 2025

Thanks, much appreciated.

@MilkeeyCat MilkeeyCat deleted the pr_lsp_work_on_windows branch December 31, 2025 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LSP diagnostics not working on Windows

2 participants