@@ -14,6 +14,7 @@ import (
14
14
"github.com/microsoft/typescript-go/shim/ast"
15
15
"github.com/microsoft/typescript-go/shim/bundled"
16
16
"github.com/microsoft/typescript-go/shim/compiler"
17
+ "github.com/microsoft/typescript-go/shim/ls"
17
18
"github.com/microsoft/typescript-go/shim/lsp/lsproto"
18
19
"github.com/microsoft/typescript-go/shim/scanner"
19
20
"github.com/microsoft/typescript-go/shim/vfs"
@@ -99,7 +100,7 @@ func (s *LSPServer) handleInitialize(ctx context.Context, req *jsonrpc2.Request)
99
100
} else {
100
101
//nolint
101
102
if params .RootUri .DocumentUri != nil {
102
- s .rootURI = uriToPath (string ( * params .RootUri .DocumentUri ) )
103
+ s .rootURI = uriToPath (* params .RootUri .DocumentUri )
103
104
}
104
105
}
105
106
@@ -184,7 +185,7 @@ func (s *LSPServer) handleCodeAction(ctx context.Context, req *jsonrpc2.Request)
184
185
if ! exists {
185
186
// If no diagnostics exist for this document, try to generate them
186
187
// This can happen if the document was opened without a proper didOpen event
187
- filePath := uriToPath (string ( uri ) )
188
+ filePath := uriToPath (uri )
188
189
if content , err := os .ReadFile (filePath ); err == nil {
189
190
s .documents [uri ] = string (content )
190
191
s .runDiagnostics (ctx , uri , string (content ))
@@ -250,7 +251,7 @@ func (s *LSPServer) runDiagnostics(ctx context.Context, uri lsproto.DocumentUri,
250
251
config .RegisterAllRules ()
251
252
252
253
// Convert URI to file path
253
- filePath := uriToPath (uriString )
254
+ filePath := uriToPath (uri )
254
255
255
256
// Create a temporary file system with the content
256
257
vfs := bundled .WrapFS (cachedvfs .From (osvfs .FS ()))
@@ -400,19 +401,8 @@ func isTypeScriptFile(uri string) bool {
400
401
strings .HasSuffix (path , ".jsx" )
401
402
}
402
403
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 )
416
406
}
417
407
418
408
// findRslintConfig searches for rslint configuration files using multiple strategies
@@ -508,7 +498,7 @@ func runLintWithPrograms(uri lsproto.DocumentUri, programs []*compiler.Program,
508
498
defer diagnosticsLock .Unlock ()
509
499
diagnostics = append (diagnostics , d )
510
500
}
511
- filename := uriToPath (string ( uri ) )
501
+ filename := uriToPath (uri )
512
502
513
503
// Run linter with all programs using rule registry
514
504
_ , err := linter .RunLinter (
0 commit comments