Skip to content

Commit aba1226

Browse files
committed
fix(lsp): ensure Windows paths have leading slash in file URIs
The url.URL with path 'D:/path' produces 'file://D:/path' which interprets D: as host:port. We need '/D:/path' to produce 'file:///D:/path'.
1 parent 998631f commit aba1226

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

internal/lsp/server_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@ import (
1616
// pathToFileURI converts a file path to a proper file:// URI that works on all platforms.
1717
// On Windows, this properly handles drive letters (e.g., C:\path -> file:///C:/path).
1818
func pathToFileURI(path string) string {
19+
// Convert to forward slashes
20+
path = filepath.ToSlash(path)
21+
// On Windows, absolute paths like "C:/path" need a leading slash for proper file URIs
22+
if len(path) >= 2 && path[1] == ':' {
23+
path = "/" + path
24+
}
1925
u := url.URL{
2026
Scheme: "file",
21-
Path: filepath.ToSlash(path),
27+
Path: path,
2228
}
2329
return u.String()
2430
}

0 commit comments

Comments
 (0)