Skip to content

Commit 1291d07

Browse files
authored
fix: shim encoder module (#314)
1 parent 00f7137 commit 1291d07

File tree

41 files changed

+349
-75
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+349
-75
lines changed

go.mod

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ replace (
1818
github.com/microsoft/typescript-go/shim/vfs => ./shim/vfs
1919
github.com/microsoft/typescript-go/shim/vfs/cachedvfs => ./shim/vfs/cachedvfs
2020
github.com/microsoft/typescript-go/shim/vfs/osvfs => ./shim/vfs/osvfs
21+
github.com/microsoft/typescript-go/shim/api => ./shim/api
22+
github.com/microsoft/typescript-go/shim/api/encoder => ./shim/api/encoder
2123
)
2224

2325
require (
@@ -38,6 +40,8 @@ require (
3840
github.com/microsoft/typescript-go/shim/vfs v0.0.0
3941
github.com/microsoft/typescript-go/shim/vfs/cachedvfs v0.0.0
4042
github.com/microsoft/typescript-go/shim/vfs/osvfs v0.0.0
43+
github.com/microsoft/typescript-go/shim/api v0.0.0
44+
github.com/microsoft/typescript-go/shim/api/encoder v0.0.0
4145
github.com/tailscale/hujson v0.0.0-20250605163823-992244df8c5a
4246
golang.org/x/sync v0.16.0
4347
golang.org/x/sys v0.35.0
@@ -47,14 +51,16 @@ require (
4751

4852
require (
4953
github.com/google/go-cmp v0.7.0 // indirect
54+
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
5055
github.com/mattn/go-colorable v0.1.13 // indirect
5156
github.com/mattn/go-isatty v0.0.20 // indirect
57+
github.com/zeebo/xxh3 v1.0.2 // indirect
5258
golang.org/x/mod v0.26.0 // indirect
5359
)
5460

5561
require (
5662
github.com/dlclark/regexp2 v1.11.5 // indirect
5763
github.com/go-json-experiment/json v0.0.0-20250811204210-4789234c3ea1
58-
github.com/microsoft/typescript-go v0.0.0-20250814234431-ae2bacc8a459 // indirect
64+
github.com/microsoft/typescript-go v0.0.0-20250829050502-5d1d69a77a4c // indirect
5965
golang.org/x/text v0.28.0
6066
)

go.sum

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,23 @@ github.com/go-json-experiment/json v0.0.0-20250811204210-4789234c3ea1 h1:KaJSg7E
88
github.com/go-json-experiment/json v0.0.0-20250811204210-4789234c3ea1/go.mod h1:TiCD2a1pcmjd7YnhGH0f/zKNcCD06B029pHhzV23c2M=
99
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
1010
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
11+
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4=
12+
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
1113
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
1214
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
1315
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
1416
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
1517
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
16-
github.com/microsoft/typescript-go v0.0.0-20250814234431-ae2bacc8a459 h1:i9XPvR7BvGGkaYZfb2Ah6YlcGMK85JaxgEBXHoejjB0=
17-
github.com/microsoft/typescript-go v0.0.0-20250814234431-ae2bacc8a459/go.mod h1:A7HQr1XidFhXZBSB1VVWqMjfrisXlWDPeNwMLxj6mDc=
18+
github.com/microsoft/typescript-go v0.0.0-20250829050502-5d1d69a77a4c h1:VVjgdEKzK3s1M77yec/R7q+C2gOOR0HwXlJz1IDtRNA=
19+
github.com/microsoft/typescript-go v0.0.0-20250829050502-5d1d69a77a4c/go.mod h1:A7HQr1XidFhXZBSB1VVWqMjfrisXlWDPeNwMLxj6mDc=
1820
github.com/peter-evans/patience v0.3.0 h1:rX0JdJeepqdQl1Sk9c9uvorjYYzL2TfgLX1adqYm9cA=
1921
github.com/peter-evans/patience v0.3.0/go.mod h1:Kmxu5sY1NmBLFSStvXjX1wS9mIv7wMcP/ubucyMOAu0=
2022
github.com/tailscale/hujson v0.0.0-20250605163823-992244df8c5a h1:a6TNDN9CgG+cYjaeN8l2mc4kSz2iMiCDQxPEyltUV/I=
2123
github.com/tailscale/hujson v0.0.0-20250605163823-992244df8c5a/go.mod h1:EbW0wDK/qEUYI0A5bqq0C2kF8JTQwWONmGDBbzsxxHo=
24+
github.com/zeebo/assert v1.3.0 h1:g7C04CbJuIDKNPFHmsk4hwZDO5O+kntRxzaUoNXj+IQ=
25+
github.com/zeebo/assert v1.3.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0=
26+
github.com/zeebo/xxh3 v1.0.2 h1:xZmwmqxHZA8AI603jOQ0tMqmBr9lPeFwGg6d+xy9DC0=
27+
github.com/zeebo/xxh3 v1.0.2/go.mod h1:5NWz9Sef7zIDm2JHfFlcQvNekmcEl9ekUZQQKCYaDcA=
2228
golang.org/x/mod v0.26.0 h1:EGMPT//Ezu+ylkCijjPc+f4Aih7sZvaAr+O3EHBxvZg=
2329
golang.org/x/mod v0.26.0/go.mod h1:/j6NAhSk8iQ723BGAUyoAcn7SlD7s15Dp9Nd/SfeaFQ=
2430
golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=

internal/api/api.go

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import (
1010
"io"
1111
"os"
1212
"sync"
13+
14+
"github.com/microsoft/typescript-go/shim/api/encoder"
15+
"github.com/microsoft/typescript-go/shim/ast"
1316
)
1417

1518
// Protocol implements a binary message protocol similar to esbuild:
@@ -57,13 +60,13 @@ type HandshakeResponse struct {
5760

5861
// LintRequest represents a lint request from JS to Go
5962
type LintRequest struct {
60-
Files []string `json:"files,omitempty"`
61-
Config string `json:"config,omitempty"` // Path to rslint.json config file
62-
Format string `json:"format,omitempty"`
63-
WorkingDirectory string `json:"workingDirectory,omitempty"`
63+
Files []string `json:"files,omitempty"`
64+
Config string `json:"config,omitempty"` // Path to rslint.json config file
65+
Format string `json:"format,omitempty"`
66+
WorkingDirectory string `json:"workingDirectory,omitempty"`
6467
// Supports both string level and array [level, options] format
6568
RuleOptions map[string]interface{} `json:"ruleOptions,omitempty"`
66-
FileContents map[string]string `json:"fileContents,omitempty"` // Map of file paths to their contents for VFS
69+
FileContents map[string]string `json:"fileContents,omitempty"` // Map of file paths to their contents for VFS
6770
LanguageOptions *LanguageOptions `json:"languageOptions,omitempty"` // Override languageOptions from config file
6871
}
6972

@@ -109,16 +112,16 @@ type LintResponse struct {
109112

110113
// ApplyFixesRequest represents a request to apply fixes from JS to Go
111114
type ApplyFixesRequest struct {
112-
FileContent string `json:"fileContent"` // Current content of the file
113-
Diagnostics []Diagnostic `json:"diagnostics"` // Diagnostics with fixes to apply
115+
FileContent string `json:"fileContent"` // Current content of the file
116+
Diagnostics []Diagnostic `json:"diagnostics"` // Diagnostics with fixes to apply
114117
}
115118

116119
// ApplyFixesResponse represents a response after applying fixes
117120
type ApplyFixesResponse struct {
118-
FixedContent []string `json:"fixedContent"` // The content after applying fixes (array of intermediate versions)
119-
WasFixed bool `json:"wasFixed"` // Whether any fixes were actually applied
120-
AppliedCount int `json:"appliedCount"` // Number of fixes that were applied
121-
UnappliedCount int `json:"unappliedCount"` // Number of fixes that couldn't be applied
121+
FixedContent []string `json:"fixedContent"` // The content after applying fixes (array of intermediate versions)
122+
WasFixed bool `json:"wasFixed"` // Whether any fixes were actually applied
123+
AppliedCount int `json:"appliedCount"` // Number of fixes that were applied
124+
UnappliedCount int `json:"unappliedCount"` // Number of fixes that couldn't be applied
122125
}
123126

124127
// ErrorResponse represents an error response
@@ -151,9 +154,9 @@ type Diagnostic struct {
151154

152155
// Fix represents a single fix that can be applied
153156
type Fix struct {
154-
Text string `json:"text"`
155-
StartPos int `json:"startPos"` // Character position in the file content
156-
EndPos int `json:"endPos"` // Character position in the file content
157+
Text string `json:"text"`
158+
StartPos int `json:"startPos"` // Character position in the file content
159+
EndPos int `json:"endPos"` // Character position in the file content
157160
}
158161

159162
// Handler defines the interface for handling IPC messages
@@ -282,7 +285,7 @@ func (s *Service) handleExit(msg *Message) {
282285
func (s *Service) handleLint(msg *Message) {
283286
var req LintRequest
284287
data, err := json.Marshal(msg.Data)
285-
288+
286289
if err != nil {
287290
s.sendError(msg.ID, fmt.Sprintf("failed to marshal data: %v", err))
288291
return
@@ -352,3 +355,7 @@ func (s *Service) sendError(id int, message string) {
352355
func IsIPCMode() bool {
353356
return os.Getenv("RSLINT_IPC") == "1"
354357
}
358+
359+
func EncodeAST(sourceFile *ast.SourceFile, id string) ([]byte, error) {
360+
return encoder.EncodeSourceFile(sourceFile, id)
361+
}

shim/api/encoder/go.mod

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module github.com/microsoft/typescript-go/shim/api/encoder
2+
3+
go 1.25
4+
5+
require github.com/microsoft/typescript-go v0.0.0-20250829050502-5d1d69a77a4c
6+
7+
require (
8+
github.com/go-json-experiment/json v0.0.0-20250811204210-4789234c3ea1 // indirect
9+
golang.org/x/sync v0.16.0 // indirect
10+
golang.org/x/text v0.28.0 // indirect
11+
)

shim/api/encoder/go.sum

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
github.com/go-json-experiment/json v0.0.0-20250811204210-4789234c3ea1 h1:KaJSg7Eaxs50Tw1m9QeR4Ua/If27AltydVhyZ184HEI=
2+
github.com/go-json-experiment/json v0.0.0-20250811204210-4789234c3ea1/go.mod h1:TiCD2a1pcmjd7YnhGH0f/zKNcCD06B029pHhzV23c2M=
3+
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
4+
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
5+
github.com/microsoft/typescript-go v0.0.0-20250829050502-5d1d69a77a4c h1:VVjgdEKzK3s1M77yec/R7q+C2gOOR0HwXlJz1IDtRNA=
6+
github.com/microsoft/typescript-go v0.0.0-20250829050502-5d1d69a77a4c/go.mod h1:A7HQr1XidFhXZBSB1VVWqMjfrisXlWDPeNwMLxj6mDc=
7+
github.com/peter-evans/patience v0.3.0 h1:rX0JdJeepqdQl1Sk9c9uvorjYYzL2TfgLX1adqYm9cA=
8+
github.com/peter-evans/patience v0.3.0/go.mod h1:Kmxu5sY1NmBLFSStvXjX1wS9mIv7wMcP/ubucyMOAu0=
9+
golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
10+
golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
11+
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
12+
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
13+
gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
14+
gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=

shim/api/encoder/shim.go

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

shim/api/go.mod

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module github.com/microsoft/typescript-go/shim/api
2+
3+
go 1.25
4+
5+
require github.com/microsoft/typescript-go v0.0.0-20250829050502-5d1d69a77a4c
6+
7+
require (
8+
github.com/dlclark/regexp2 v1.11.5 // indirect
9+
github.com/go-json-experiment/json v0.0.0-20250811204210-4789234c3ea1 // indirect
10+
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
11+
github.com/zeebo/xxh3 v1.0.2 // indirect
12+
golang.org/x/sync v0.16.0 // indirect
13+
golang.org/x/sys v0.35.0 // indirect
14+
golang.org/x/text v0.28.0 // indirect
15+
)

shim/api/go.sum

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
github.com/dlclark/regexp2 v1.11.5 h1:Q/sSnsKerHeCkc/jSTNq1oCm7KiVgUMZRDUoRu0JQZQ=
2+
github.com/dlclark/regexp2 v1.11.5/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
3+
github.com/go-json-experiment/json v0.0.0-20250811204210-4789234c3ea1 h1:KaJSg7Eaxs50Tw1m9QeR4Ua/If27AltydVhyZ184HEI=
4+
github.com/go-json-experiment/json v0.0.0-20250811204210-4789234c3ea1/go.mod h1:TiCD2a1pcmjd7YnhGH0f/zKNcCD06B029pHhzV23c2M=
5+
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
6+
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
7+
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4=
8+
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
9+
github.com/microsoft/typescript-go v0.0.0-20250829050502-5d1d69a77a4c h1:VVjgdEKzK3s1M77yec/R7q+C2gOOR0HwXlJz1IDtRNA=
10+
github.com/microsoft/typescript-go v0.0.0-20250829050502-5d1d69a77a4c/go.mod h1:A7HQr1XidFhXZBSB1VVWqMjfrisXlWDPeNwMLxj6mDc=
11+
github.com/peter-evans/patience v0.3.0 h1:rX0JdJeepqdQl1Sk9c9uvorjYYzL2TfgLX1adqYm9cA=
12+
github.com/peter-evans/patience v0.3.0/go.mod h1:Kmxu5sY1NmBLFSStvXjX1wS9mIv7wMcP/ubucyMOAu0=
13+
github.com/zeebo/assert v1.3.0 h1:g7C04CbJuIDKNPFHmsk4hwZDO5O+kntRxzaUoNXj+IQ=
14+
github.com/zeebo/assert v1.3.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0=
15+
github.com/zeebo/xxh3 v1.0.2 h1:xZmwmqxHZA8AI603jOQ0tMqmBr9lPeFwGg6d+xy9DC0=
16+
github.com/zeebo/xxh3 v1.0.2/go.mod h1:5NWz9Sef7zIDm2JHfFlcQvNekmcEl9ekUZQQKCYaDcA=
17+
golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
18+
golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
19+
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
20+
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
21+
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
22+
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
23+
gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
24+
gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=

shim/api/shim.go

Lines changed: 85 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

shim/ast/go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ module github.com/microsoft/typescript-go/shim/ast
22

33
go 1.25
44

5-
require github.com/microsoft/typescript-go v0.0.0-20250814234431-ae2bacc8a459
5+
require github.com/microsoft/typescript-go v0.0.0-20250829050502-5d1d69a77a4c
66

77
require (
88
github.com/go-json-experiment/json v0.0.0-20250811204210-4789234c3ea1 // indirect
9+
golang.org/x/sync v0.16.0 // indirect
910
golang.org/x/text v0.28.0 // indirect
1011
)

0 commit comments

Comments
 (0)