Skip to content

Commit cf3e869

Browse files
committed
lsp/testing: Ensure test locations sent at boot
This was missed in #1888 This makes test locations more similar to diagnostics. Signed-off-by: Charlie Egan <charlie_egan@apple.com>
1 parent c97f88c commit cf3e869

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

internal/lsp/server.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2150,12 +2150,23 @@ func (l *LanguageServer) loadWorkspaceContents(ctx context.Context, newOnly bool
21502150
return nil
21512151
}
21522152

2153-
if _, err = updateParse(ctx, l.parseOpts(fileURI, l.builtinsForCurrentCapabilities())); err != nil {
2153+
parseSuccess, err := updateParse(ctx, l.parseOpts(fileURI, l.builtinsForCurrentCapabilities()))
2154+
if err != nil {
21542155
failed = append(failed, fileLoadFailure{URI: fileURI, Error: fmt.Errorf("failed to update parse: %w", err)})
21552156

21562157
return nil // continue processing other files
21572158
}
21582159

2160+
if parseSuccess {
2161+
l.testLocationJobs <- lintFileJob{Reason: "server initialized", URI: fileURI}
2162+
} else {
2163+
// this is covering the case where the client starts and the state
2164+
// is different (the client remembers test locations and state).
2165+
if err := l.sendTestLocations(ctx, fileURI, []any{}); err != nil {
2166+
l.log.Message("failed to send empty test locations after parse failure: %s", err)
2167+
}
2168+
}
2169+
21592170
changedOrNewURIs = append(changedOrNewURIs, fileURI)
21602171

21612172
return nil
@@ -2221,6 +2232,12 @@ func (l *LanguageServer) handleWorkspaceDidChangeWatchedFiles(
22212232
}
22222233

22232234
func (l *LanguageServer) sendFileDiagnostics(ctx context.Context, fileURI string) {
2235+
if l.conn == nil {
2236+
l.log.Debug("sendFileDiagnostics called with no connection: %s", fileURI)
2237+
2238+
return
2239+
}
2240+
22242241
// first, set the diagnostics for the file to the current parse errors
22252242
fileDiags, _ := l.cache.GetParseErrors(fileURI)
22262243
if len(fileDiags) == 0 {

internal/lsp/testing.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ func (l *LanguageServer) processTestLocationsUpdate(ctx context.Context, fileURI
7878
}
7979

8080
func (l *LanguageServer) sendTestLocations(ctx context.Context, fileURI string, locations any) error {
81+
if l.conn == nil {
82+
l.log.Debug("sendTestLocations called with no connection: %s", fileURI)
83+
84+
return nil
85+
}
86+
8187
params := map[string]any{
8288
"uri": fileURI,
8389
"locations": locations,

0 commit comments

Comments
 (0)