Skip to content

Commit

Permalink
feat: add support for dispatching diagnostics refresh requests
Browse files Browse the repository at this point in the history
  • Loading branch information
fr3shw3b committed Jun 23, 2024
1 parent 8d6d4fa commit 141291b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lsp_3_17/dispatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,10 @@ func (d *Dispatcher) InlineValueRefresh() error {
func (d *Dispatcher) PublishDiagnostics(params PublishDiagnosticsParams) error {
return d.ctx.Notify(MethodPublishDiagnostics, params)
}

// DiagnosticsRefresh requests that the client refreshes all needed document
// and workspace diagnostics. This is useful if the server detects a project wide
// configuration change which requires a re-calculation of all diagnostics.
func (d *Dispatcher) DiagnosticsRefresh() error {
return d.ctx.Call(MethodDiagnosticsRefresh, nil, nil)
}
22 changes: 22 additions & 0 deletions lsp_3_17/dispatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,28 @@ func (s *DispatchTestSuite) Test_server_sends_push_diagnostics_notification() {
s.Require().Equal(MethodPublishDiagnostics, container.clientReceivedMethods[0])
}

func (s *DispatchTestSuite) Test_server_sends_diagnostics_refresh_request() {
ctx, cancel := context.WithTimeout(context.Background(), server.DefaultTimeout)
defer cancel()

serverHandler := newTestServerHandler()
container := createTestConnectionsContainer(serverHandler)

lspCtx := server.NewLSPContext(ctx, container.serverConn, nil)
dispatcher := NewDispatcher(lspCtx)

err := dispatcher.DiagnosticsRefresh()
s.Require().NoError(err)

// Acquire a lock on the received message list shared between goroutines.
container.mu.Lock()
defer container.mu.Unlock()

// Verify the method name.
s.Require().Len(container.clientReceivedMethods, 1)
s.Require().Equal(MethodDiagnosticsRefresh, container.clientReceivedMethods[0])
}

func TestDispatchTestSuite(t *testing.T) {
suite.Run(t, new(DispatchTestSuite))
}
4 changes: 4 additions & 0 deletions lsp_3_17/language_features.go
Original file line number Diff line number Diff line change
Expand Up @@ -2295,3 +2295,7 @@ type WorkspaceUnchangedDocumentDiagnosticReport struct {
// If the document is not marked as upen `null` can be provided.
Version *Integer `json:"version,omitempty"`
}

// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#diagnostic_refresh

const MethodDiagnosticsRefresh = Method("workspace/diagnostic/refresh")

0 comments on commit 141291b

Please sign in to comment.