@@ -10,6 +10,9 @@ import (
10
10
"io"
11
11
"os"
12
12
"sync"
13
+
14
+ "github.com/microsoft/typescript-go/shim/api/encoder"
15
+ "github.com/microsoft/typescript-go/shim/ast"
13
16
)
14
17
15
18
// Protocol implements a binary message protocol similar to esbuild:
@@ -57,13 +60,13 @@ type HandshakeResponse struct {
57
60
58
61
// LintRequest represents a lint request from JS to Go
59
62
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"`
64
67
// Supports both string level and array [level, options] format
65
68
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
67
70
LanguageOptions * LanguageOptions `json:"languageOptions,omitempty"` // Override languageOptions from config file
68
71
}
69
72
@@ -109,16 +112,16 @@ type LintResponse struct {
109
112
110
113
// ApplyFixesRequest represents a request to apply fixes from JS to Go
111
114
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
114
117
}
115
118
116
119
// ApplyFixesResponse represents a response after applying fixes
117
120
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
122
125
}
123
126
124
127
// ErrorResponse represents an error response
@@ -151,9 +154,9 @@ type Diagnostic struct {
151
154
152
155
// Fix represents a single fix that can be applied
153
156
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
157
160
}
158
161
159
162
// Handler defines the interface for handling IPC messages
@@ -282,7 +285,7 @@ func (s *Service) handleExit(msg *Message) {
282
285
func (s * Service ) handleLint (msg * Message ) {
283
286
var req LintRequest
284
287
data , err := json .Marshal (msg .Data )
285
-
288
+
286
289
if err != nil {
287
290
s .sendError (msg .ID , fmt .Sprintf ("failed to marshal data: %v" , err ))
288
291
return
@@ -352,3 +355,7 @@ func (s *Service) sendError(id int, message string) {
352
355
func IsIPCMode () bool {
353
356
return os .Getenv ("RSLINT_IPC" ) == "1"
354
357
}
358
+
359
+ func EncodeAST (sourceFile * ast.SourceFile , id string ) ([]byte , error ) {
360
+ return encoder .EncodeSourceFile (sourceFile , id )
361
+ }
0 commit comments