@@ -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
5962type 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
111114type 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
117120type 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
153156type 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) {
282285func (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) {
352355func 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+ }
0 commit comments