Skip to content

Commit c677ab5

Browse files
committed
Handle zip paths for LSP
1 parent 04a8564 commit c677ab5

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

_extension/src/client.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,14 @@ export class Client {
2828
this.clientOptions = {
2929
documentSelector: [
3030
...jsTsLanguageModes.map(language => ({ scheme: "file", language })),
31-
...jsTsLanguageModes.map(language => ({ scheme: "untitled", language })),
31+
...jsTsLanguageModes.map(language => ({
32+
scheme: "untitled",
33+
language,
34+
})),
35+
...jsTsLanguageModes.map(language => ({
36+
scheme: "zip",
37+
language,
38+
})),
3239
],
3340
outputChannel: this.outputChannel,
3441
traceOutputChannel: this.traceOutputChannel,

internal/ls/converters.go

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

131-
return lsproto.DocumentUri("file://" + volume + strings.Join(parts, "/"))
131+
var prefix string
132+
if tspath.IsZipPath(fileName) {
133+
prefix = "zip:"
134+
} else {
135+
prefix = "file:"
136+
}
137+
138+
return lsproto.DocumentUri(prefix + "//" + volume + strings.Join(parts, "/"))
132139
}
133140

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

internal/ls/converters_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ func TestDocumentURIToFileName(t *testing.T) {
3131
{"file://localhost/c%24/GitDevelopment/express", "//localhost/c$/GitDevelopment/express"},
3232
{"file:///c%3A/test%20with%20%2525/c%23code", "c:/test with %25/c#code"},
3333

34+
{"zip:///path/to/archive.zip/file.ts", "/path/to/archive.zip/file.ts"},
35+
{"zip:///d:/work/tsgo932/lib/archive.zip/utils.ts", "d:/work/tsgo932/lib/archive.zip/utils.ts"},
36+
3437
{"untitled:Untitled-1", "^/untitled/ts-nul-authority/Untitled-1"},
3538
{"untitled:Untitled-1#fragment", "^/untitled/ts-nul-authority/Untitled-1#fragment"},
3639
{"untitled:c:/Users/jrieken/Code/abc.txt", "^/untitled/ts-nul-authority/c:/Users/jrieken/Code/abc.txt"},
@@ -69,6 +72,9 @@ func TestFileNameToDocumentURI(t *testing.T) {
6972
{"//localhost/c$/GitDevelopment/express", "file://localhost/c%24/GitDevelopment/express"},
7073
{"c:/test with %25/c#code", "file:///c%3A/test%20with%20%2525/c%23code"},
7174

75+
{"/path/to/archive.zip/file.ts", "zip:///path/to/archive.zip/file.ts"},
76+
{"d:/work/tsgo932/lib/archive.zip/utils.ts", "zip:///d%3A/work/tsgo932/lib/archive.zip/utils.ts"},
77+
7278
{"^/untitled/ts-nul-authority/Untitled-1", "untitled:Untitled-1"},
7379
{"^/untitled/ts-nul-authority/c:/Users/jrieken/Code/abc.txt", "untitled:c:/Users/jrieken/Code/abc.txt"},
7480
{"^/untitled/ts-nul-authority///wsl%2Bubuntu/home/jabaile/work/TypeScript-go/newfile.ts", "untitled://wsl%2Bubuntu/home/jabaile/work/TypeScript-go/newfile.ts"},

internal/lsp/lsproto/lsp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
type DocumentUri string // !!!
1515

1616
func (uri DocumentUri) FileName() string {
17-
if strings.HasPrefix(string(uri), "file://") {
17+
if strings.HasPrefix(string(uri), "file://") || strings.HasPrefix(string(uri), "zip:") {
1818
parsed := core.Must(url.Parse(string(uri)))
1919
if parsed.Host != "" {
2020
return "//" + parsed.Host + parsed.Path

0 commit comments

Comments
 (0)