Skip to content

Commit 7cfd1d5

Browse files
committed
fix uri filename roundtrip
1 parent e7d941f commit 7cfd1d5

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

internal/ls/lsconv/converters.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ var extraEscapeReplacer = strings.NewReplacer(
112112
)
113113

114114
func FileNameToDocumentURI(fileName string) lsproto.DocumentUri {
115+
if suffix, found := strings.CutPrefix(fileName, "asset:///"); found {
116+
return lsproto.DocumentUri("deno:/asset/" + suffix)
117+
}
115118
if bundled.IsBundled(fileName) {
116119
return lsproto.DocumentUri(fileName)
117120
}
@@ -125,6 +128,9 @@ func FileNameToDocumentURI(fileName string) lsproto.DocumentUri {
125128
panic("invalid file name: " + fileName)
126129
}
127130
if authority == "ts-nul-authority" {
131+
if scheme == "deno" && !strings.HasPrefix(path, "/") {
132+
path = "/" + path
133+
}
128134
return lsproto.DocumentUri(scheme + ":" + path)
129135
}
130136
return lsproto.DocumentUri(scheme + "://" + authority + "/" + path)

internal/lsp/server.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"iter"
99
"runtime/debug"
1010
"slices"
11-
"strings"
1211
"sync"
1312
"sync/atomic"
1413
"time"
@@ -252,15 +251,8 @@ func (v *DenoVFS) FileExists(path string) bool {
252251
return ok
253252
}
254253

255-
func denoPathToDocumentUri(path string) lsproto.DocumentUri {
256-
if suffix, found := strings.CutPrefix(path, "asset:///"); found {
257-
return lsproto.DocumentUri("deno:/asset/" + suffix)
258-
}
259-
return lsconv.FileNameToDocumentURI(path)
260-
}
261-
262254
func (v *DenoVFS) GetDocument(path string) *lsproto.DenoDocumentData {
263-
uri := denoPathToDocumentUri(path)
255+
uri := lsconv.FileNameToDocumentURI(path)
264256
v.server.deno.documentCacheMu.Lock()
265257
defer v.server.deno.documentCacheMu.Unlock()
266258
if v.server.deno.documentCache != nil {
@@ -438,7 +430,7 @@ func (r *denoResolver) ResolveModuleName(moduleName string, containingFile strin
438430
params := lsproto.DenoCallbackParams{
439431
ResolveModuleName: &lsproto.DenoResolveModuleNameParams{
440432
ModuleName: moduleName,
441-
ReferrerUri: denoPathToDocumentUri(containingFile),
433+
ReferrerUri: lsconv.FileNameToDocumentURI(containingFile),
442434
ImportAttributeType: importAttributeType,
443435
ResolutionMode: int32(resolutionMode),
444436
CompilerOptionsKey: r.compilerOptionsKey,

0 commit comments

Comments
 (0)