Skip to content

Commit 1e204b1

Browse files
committed
Generate zip URIs for Go to definition
1 parent aa12649 commit 1e204b1

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

internal/ls/converters.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,14 @@ func FileNameToDocumentURI(fileName string) lsproto.DocumentUri {
178178
parts[i] = extraEscapeReplacer.Replace(url.PathEscape(part))
179179
}
180180

181-
return lsproto.DocumentUri("file://" + volume + strings.Join(parts, "/"))
181+
var prefix string
182+
if tspath.IsZipPath(fileName) {
183+
prefix = "zip:"
184+
} else {
185+
prefix = "file:"
186+
}
187+
188+
return lsproto.DocumentUri(prefix + "//" + volume + strings.Join(parts, "/"))
182189
}
183190

184191
func (c *Converters) LineAndCharacterToPosition(script Script, lineAndCharacter lsproto.Position) core.TextPos {

internal/tspath/path.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,3 +920,7 @@ func ForEachAncestorDirectoryPath[T any](directory Path, callback func(directory
920920
func HasExtension(fileName string) bool {
921921
return strings.Contains(GetBaseFileName(fileName), ".")
922922
}
923+
924+
func IsZipPath(path string) bool {
925+
return strings.Contains(path, ".zip/") || strings.HasSuffix(path, ".zip")
926+
}

internal/vfs/zipvfs/zipvfs.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"sync"
1010
"time"
1111

12+
"github.com/microsoft/typescript-go/internal/tspath"
1213
"github.com/microsoft/typescript-go/internal/vfs"
1314
"github.com/microsoft/typescript-go/internal/vfs/iovfs"
1415
)
@@ -131,10 +132,6 @@ func (zipfs *zipFS) WriteFile(path string, data string, writeByteOrderMark bool)
131132
return fs.WriteFile(formattedPath, data, writeByteOrderMark)
132133
}
133134

134-
func isZipPath(path string) bool {
135-
return strings.Contains(path, ".zip/") || strings.HasSuffix(path, ".zip")
136-
}
137-
138135
func splitZipPath(path string) (string, string) {
139136
parts := strings.Split(path, ".zip/")
140137
if len(parts) < 2 {
@@ -144,7 +141,7 @@ func splitZipPath(path string) (string, string) {
144141
}
145142

146143
func getMatchingFS(zipfs *zipFS, path string) (vfs.FS, string, string) {
147-
if !isZipPath(path) {
144+
if !tspath.IsZipPath(path) {
148145
return zipfs.fs, path, ""
149146
}
150147

0 commit comments

Comments
 (0)