@@ -128,10 +128,14 @@ func (h *IPCHandler) HandleLint(req api.LintRequest) (*api.LintResponse, error)
128
128
programs = append (programs , program )
129
129
}
130
130
131
- // Collect diagnostics
131
+ // Collect diagnostics and source files
132
132
var diagnostics []api.Diagnostic
133
133
var diagnosticsLock sync.Mutex
134
134
errorsCount := 0
135
+
136
+ // Track source files for encoding
137
+ sourceFiles := make (map [string ]* ast.SourceFile )
138
+ var sourceFilesLock sync.Mutex
135
139
136
140
// Create collector function
137
141
diagnosticCollector := func (d rule.RuleDiagnostic ) {
@@ -181,6 +185,12 @@ func (h *IPCHandler) HandleLint(req api.LintRequest) (*api.LintResponse, error)
181
185
182
186
diagnostics = append (diagnostics , diagnostic )
183
187
errorsCount ++
188
+
189
+ // Track source file for encoding
190
+ sourceFilesLock .Lock ()
191
+ filePath := tspath .ConvertToRelativePath (d .SourceFile .FileName (), comparePathOptions )
192
+ sourceFiles [filePath ] = d .SourceFile
193
+ sourceFilesLock .Unlock ()
184
194
}
185
195
186
196
// Run linter
@@ -209,13 +219,30 @@ func (h *IPCHandler) HandleLint(req api.LintRequest) (*api.LintResponse, error)
209
219
if diagnostics == nil {
210
220
diagnostics = []api.Diagnostic {}
211
221
}
222
+
212
223
// Create response
213
- return & api.LintResponse {
224
+ response := & api.LintResponse {
214
225
Diagnostics : diagnostics ,
215
226
ErrorCount : errorsCount ,
216
227
FileCount : int (lintedFilesCount ),
217
228
RuleCount : len (rulesWithOptions ),
218
- }, nil
229
+ }
230
+ // Only include encoded source files if requested
231
+ if req .IncludeEncodedSourceFiles {
232
+ encodedSourceFiles := make (map [string ]api.ByteArray )
233
+ for filePath , sourceFile := range sourceFiles {
234
+ encoded , err := api .EncodeAST (sourceFile , filePath )
235
+
236
+ if err != nil {
237
+ // Log error but don't fail the entire request
238
+ fmt .Fprintf (os .Stderr , "warning: failed to encode source file %s: %v\n " , filePath , err )
239
+ continue
240
+ }
241
+ encodedSourceFiles [filePath ] = encoded
242
+ }
243
+ response .EncodedSourceFiles = encodedSourceFiles
244
+ }
245
+ return response , nil
219
246
}
220
247
221
248
// HandleApplyFixes handles apply fixes requests in IPC mode
0 commit comments