Skip to content

Commit 172a08b

Browse files
authored
fix: fix windows compat (#231)
1 parent 73988c9 commit 172a08b

File tree

3 files changed

+14
-23
lines changed

3 files changed

+14
-23
lines changed

cmd/rslint/lsp.go

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/microsoft/typescript-go/shim/ast"
1515
"github.com/microsoft/typescript-go/shim/bundled"
1616
"github.com/microsoft/typescript-go/shim/compiler"
17+
"github.com/microsoft/typescript-go/shim/ls"
1718
"github.com/microsoft/typescript-go/shim/lsp/lsproto"
1819
"github.com/microsoft/typescript-go/shim/scanner"
1920
"github.com/microsoft/typescript-go/shim/vfs"
@@ -99,7 +100,7 @@ func (s *LSPServer) handleInitialize(ctx context.Context, req *jsonrpc2.Request)
99100
} else {
100101
//nolint
101102
if params.RootUri.DocumentUri != nil {
102-
s.rootURI = uriToPath(string(*params.RootUri.DocumentUri))
103+
s.rootURI = uriToPath(*params.RootUri.DocumentUri)
103104
}
104105
}
105106

@@ -184,7 +185,7 @@ func (s *LSPServer) handleCodeAction(ctx context.Context, req *jsonrpc2.Request)
184185
if !exists {
185186
// If no diagnostics exist for this document, try to generate them
186187
// This can happen if the document was opened without a proper didOpen event
187-
filePath := uriToPath(string(uri))
188+
filePath := uriToPath(uri)
188189
if content, err := os.ReadFile(filePath); err == nil {
189190
s.documents[uri] = string(content)
190191
s.runDiagnostics(ctx, uri, string(content))
@@ -250,7 +251,7 @@ func (s *LSPServer) runDiagnostics(ctx context.Context, uri lsproto.DocumentUri,
250251
config.RegisterAllRules()
251252

252253
// Convert URI to file path
253-
filePath := uriToPath(uriString)
254+
filePath := uriToPath(uri)
254255

255256
// Create a temporary file system with the content
256257
vfs := bundled.WrapFS(cachedvfs.From(osvfs.FS()))
@@ -400,19 +401,8 @@ func isTypeScriptFile(uri string) bool {
400401
strings.HasSuffix(path, ".jsx")
401402
}
402403

403-
func uriToPath(uri string) string {
404-
if strings.HasPrefix(uri, "file://") {
405-
path := strings.TrimPrefix(uri, "file://")
406-
// Handle URL encoded characters and normalize path
407-
path = strings.ReplaceAll(path, "%20", " ")
408-
// Normalize path separators for cross-platform compatibility
409-
if len(path) > 0 && path[0] != '/' {
410-
// Windows paths may start without leading slash after file://
411-
return path
412-
}
413-
return path
414-
}
415-
return uri
404+
func uriToPath(uri lsproto.DocumentUri) string {
405+
return ls.DocumentURIToFileName(uri)
416406
}
417407

418408
// findRslintConfig searches for rslint configuration files using multiple strategies
@@ -508,7 +498,7 @@ func runLintWithPrograms(uri lsproto.DocumentUri, programs []*compiler.Program,
508498
defer diagnosticsLock.Unlock()
509499
diagnostics = append(diagnostics, d)
510500
}
511-
filename := uriToPath(string(uri))
501+
filename := uriToPath(uri)
512502

513503
// Run linter with all programs using rule registry
514504
_, err := linter.RunLinter(

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ require (
3636
github.com/microsoft/typescript-go/shim/tspath v0.0.0
3737
github.com/microsoft/typescript-go/shim/vfs v0.0.0
3838
github.com/microsoft/typescript-go/shim/vfs/cachedvfs v0.0.0
39+
github.com/microsoft/typescript-go/shim/ls v0.0.0
3940
github.com/microsoft/typescript-go/shim/vfs/osvfs v0.0.0
4041
github.com/tailscale/hujson v0.0.0-20250605163823-992244df8c5a
4142
golang.org/x/sys v0.35.0

shim/ls/shim.go

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)