-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add an LSP init flag that enables flaky diagnostics tracking #4710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
961c47d
54b55c2
ecfdda7
6ec948e
54b4c97
467bcea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ import ( | |
|
|
||
| "github.com/microsoft/typescript-go/internal/api" | ||
| "github.com/microsoft/typescript-go/internal/collections" | ||
| "github.com/microsoft/typescript-go/internal/compiler" | ||
| "github.com/microsoft/typescript-go/internal/core" | ||
| "github.com/microsoft/typescript-go/internal/diagnostics" | ||
| "github.com/microsoft/typescript-go/internal/fswatch" | ||
|
|
@@ -217,6 +218,8 @@ type Server struct { | |
| projectProgress *projectLoadingProgress | ||
|
|
||
| startWatchdog func(parentPID int) | ||
|
|
||
| flakeLogging lsproto.DiagnosticFlakeLogLevel | ||
| } | ||
|
|
||
| func (s *Server) Session() *project.Session { return s.session } | ||
|
|
@@ -1038,6 +1041,9 @@ func (s *Server) handleInitialize(ctx context.Context, params *lsproto.Initializ | |
| s.logger.SetVerbosity(v) | ||
| } | ||
| } | ||
| if s.initializationOptions.TrackFlakyDiagnostics != nil { | ||
| s.flakeLogging = *s.initializationOptions.TrackFlakyDiagnostics | ||
| } | ||
| s.clientCapabilities = params.Capabilities.Resolve() | ||
| if s.clientCapabilities.Window.WorkDoneProgress { | ||
| s.projectProgress = newProjectLoadingProgress(s, s.progressDelay) | ||
|
|
@@ -1363,7 +1369,60 @@ func (s *Server) handleSetLogVerbosity(_ context.Context, params *lsproto.SetLog | |
|
|
||
| func (s *Server) handleDocumentDiagnostic(ctx context.Context, ls *ls.LanguageService, params *lsproto.DocumentDiagnosticParams) (lsproto.DocumentDiagnosticResponse, error) { | ||
| ctx = core.WithCheckerLifetime(ctx, core.CheckerLifetimeDiagnostics) | ||
| return ls.ProvideDiagnostics(ctx, params.TextDocument.Uri) | ||
| if s.flakeLogging == lsproto.DiagnosticFlakeLogLevelOff { | ||
| return ls.ProvideDiagnostics(ctx, params.TextDocument.Uri) | ||
| } | ||
| direct, err := ls.ProvideDiagnostics(ctx, params.TextDocument.Uri) | ||
| if err != nil { | ||
| return direct, err | ||
| } | ||
| ls.GetProgram().Emit(ctx, compiler.EmitOptions{ | ||
| WriteFile: func(fileName, text string, data *compiler.WriteFileData) error { | ||
| // do nothing | ||
| return nil | ||
| }, | ||
| }) | ||
| secondary, err2 := ls.ProvideDiagnostics(ctx, params.TextDocument.Uri) | ||
| if err2 != nil { | ||
| return direct, err | ||
| } | ||
| missingFromPre, missingFromPost := lsproto.CompareDiagnostics(direct.FullDocumentDiagnosticReport.Items, secondary.FullDocumentDiagnosticReport.Items) | ||
| if len(missingFromPre) == 0 && len(missingFromPost) == 0 { | ||
| return direct, err | ||
| } | ||
|
|
||
| diff := generateDiagnosticDiffString(missingFromPre, missingFromPost, (*lsproto.Diagnostic).AsString) | ||
|
|
||
| s.logger.Error(diff) | ||
|
|
||
| if s.telemetryEnabled { | ||
| sanitizedDiff := generateDiagnosticDiffString(missingFromPre, missingFromPost, (*lsproto.Diagnostic).CodeAsString) | ||
| _ = sendNotification(s, lsproto.TelemetryEventInfo, lsproto.TelemetryEvent{ | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm also sending a request failure telemetry event with a new
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not exactly the ideal way to do this, but it will automatically appear in the dashboards so it's probably fine for now. |
||
| RequestFailureTelemetryEvent: &lsproto.RequestFailureTelemetryEvent{ | ||
| Properties: &lsproto.RequestFailureTelemetryProperties{ | ||
| ErrorCode: lsproto.ErrorCodeInternalError.String(), | ||
| RequestMethod: "textDocument.diagnostic.flakeLog", | ||
| Stack: sanitizedDiff, | ||
| }, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| if s.flakeLogging == lsproto.DiagnosticFlakeLogLevelPanic { | ||
| panic("flaky diagnostic(s) logged:\n" + diff) | ||
| } | ||
| return direct, err | ||
| } | ||
|
|
||
| func generateDiagnosticDiffString(missingFromPre []*lsproto.Diagnostic, missingFromPost []*lsproto.Diagnostic, stringifier func(*lsproto.Diagnostic) string) string { | ||
| var b strings.Builder | ||
| for _, elem := range missingFromPre { | ||
| b.WriteString(fmt.Sprintf("Diagnostic %v was present after emit but not before emit\n", stringifier(elem))) | ||
| } | ||
| for _, elem := range missingFromPost { | ||
| b.WriteString(fmt.Sprintf("Diagnostic %v was present before emit but not after emit\n", stringifier(elem))) | ||
| } | ||
| return b.String() | ||
| } | ||
|
|
||
| func (s *Server) handleHover(ctx context.Context, ls *ls.LanguageService, params *lsproto.HoverParams) (lsproto.HoverResponse, error) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.