Skip to content

Commit

Permalink
feat: add dispatch functionality for refreshing inlay hints
Browse files Browse the repository at this point in the history
  • Loading branch information
fr3shw3b committed Jun 21, 2024
1 parent 6706b22 commit 35299da
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lsp_3_17/dispatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,9 @@ func (d *Dispatcher) CodeLensRefresh() error {
func (d *Dispatcher) SemanticTokensRefresh() error {
return d.ctx.Call(MethodSemanticTokensRefresh, nil, nil)
}

// InlayHintRefresh requests the client to refresh inlay hints
// currently shown in editors.
func (d *Dispatcher) InlayHintRefresh() error {
return d.ctx.Call(MethodInlayHintRefresh, nil, nil)
}
23 changes: 23 additions & 0 deletions lsp_3_17/dispatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,29 @@ func (s *DispatchTestSuite) Test_server_sends_refresh_semantic_tokens_message()
s.Require().Equal(MethodSemanticTokensRefresh, container.clientReceivedMethods[0])
}

func (s *DispatchTestSuite) Test_server_sends_refresh_inlay_hints_message() {
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.InlayHintRefresh()
s.Require().NoError(err)

// Acquire a lock on the received message list shared between goroutines.
container.mu.Lock()
defer container.mu.Unlock()
// Verify that the client received the refresh message.
s.Require().Len(container.clientReceivedMessages, 1)
// Verify the method name.
s.Require().Len(container.clientReceivedMethods, 1)
s.Require().Equal(MethodInlayHintRefresh, 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 @@ -1140,3 +1140,7 @@ type InlayHintResolveHandlerFunc func(
ctx *common.LSPContext,
params *InlayHint,
) (*InlayHint, error)

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

const MethodInlayHintRefresh = Method("workspace/inlayHint/refresh")

0 comments on commit 35299da

Please sign in to comment.