Skip to content

Better textDocument/publishDiagnostic Handling #163

Description

@oisanjaya

Currently we have two paths leading to textDocument/publishDiagnostic sent to client:

1.  Via TDiagnosticsHandler.CheckSyntax() => [ TDiagnosticsHandler.CodeToolsCheckSyntax() => TDiagnosticsHandler.AddCodeToolError() | TDiagnosticsHandler.StrictSyntaxCheck() => Reporter.ReportError() ] => Diagnostics.Add() => Diagnostics.Send()
2.  Via PasLS.Diagnostics.PublishCodeToolsError() => TDiagnosticsHandler.SendDiagnosticMessage => TDiagnosticsHandler.AddCodeToolError() => Notification.Add() => Notification.Send()

Where TDiagnosticsHandler.CheckSyntax() being called in PasLS.Synchronization.pas and PasLS.Diagnostics.PublishCodeToolsError() being called by PasLS.*.pas in src/serverprotocol/

LSP spec states that Newly pushed diagnostics always replace previously pushed diagnostics. There is no merging that happens on the client side. so when client got diagnostics from CheckSyntax (after didOpen or didSave message) then client request textDocument/definition for example, client lost previous diagnostics.

This issue try to discuss what should we do?

The options that i can think of are:

  • Maintain single TPublishDiagnostics instance in TDiagnosticsHandler. Then each time new diagnostic added, we also send previous TDiagnosticItems.
    The downside of this approach is we must handle duplicates and invalidated (already fixed by user) items. Probably quite complex.
  • Prevent PublishCodetoolsError() maintain and send its own TPublishDiagnostics. Make PublishCodetoolsError() call CheckSyntax() while passing errors from CodeToolBoss and/or UserMessage to be merged inside CheckSyntax()
    Downside of this approach is performance hit (?) because each time TDiagnosticItems added, CheckSyntax() also called.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions