Skip to content

Commit 492ae22

Browse files
authored
fix(lsp): don't normalize paths from uris with exotic schemes (#25)
1 parent f97e702 commit 492ae22

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

internal/ls/lsconv/converters.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,6 @@ func FileNameToDocumentURI(fileName string) lsproto.DocumentUri {
128128
panic("invalid file name: " + fileName)
129129
}
130130
if authority == "ts-nul-authority" {
131-
if scheme == "deno" && !strings.HasPrefix(path, "/") {
132-
path = "/" + path
133-
}
134131
return lsproto.DocumentUri(scheme + ":" + path)
135132
}
136133
return lsproto.DocumentUri(scheme + "://" + authority + "/" + path)

internal/tspath/path.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,11 @@ func reducePathComponents(components []string) []string {
281281
if len(components) == 0 {
282282
return []string{}
283283
}
284+
// Deno: Paths like this can represent URIs with exotic schemes. They shouldn't be
285+
// normalized. TODO(nayeemrmn): Upstream this?
286+
if components[0] == "^/" {
287+
return components
288+
}
284289
reduced := []string{components[0]}
285290
for i := 1; i < len(components); i++ {
286291
component := components[i]
@@ -342,6 +347,11 @@ func GetNormalizedAbsolutePathWithoutRoot(fileName string, currentDirectory stri
342347
}
343348

344349
func GetNormalizedAbsolutePath(fileName string, currentDirectory string) string {
350+
// Deno: Paths like this can represent URIs with exotic schemes. They shouldn't be
351+
// normalized. TODO(nayeemrmn): Upstream this?
352+
if strings.HasPrefix(fileName, "^/") {
353+
return fileName
354+
}
345355
rootLength := GetRootLength(fileName)
346356
if rootLength == 0 && currentDirectory != "" {
347357
fileName = CombinePaths(currentDirectory, fileName)
@@ -549,6 +559,11 @@ func hasRelativePathSegment(p string) bool {
549559

550560
func NormalizePath(path string) string {
551561
path = NormalizeSlashes(path)
562+
// Deno: Paths like this can represent URIs with exotic schemes. They shouldn't be
563+
// normalized. TODO(nayeemrmn): Upstream this?
564+
if strings.HasPrefix(path, "^/") {
565+
return path
566+
}
552567
if normalized, ok := simpleNormalizePath(path); ok {
553568
return normalized
554569
}

0 commit comments

Comments
 (0)