From 35299dab8954e5a61d43194761de172ec9927711 Mon Sep 17 00:00:00 2001 From: Andre Sutherland Date: Fri, 21 Jun 2024 02:46:49 +0100 Subject: [PATCH] feat: add dispatch functionality for refreshing inlay hints --- lsp_3_17/dispatch.go | 6 ++++++ lsp_3_17/dispatch_test.go | 23 +++++++++++++++++++++++ lsp_3_17/language_features.go | 4 ++++ 3 files changed, 33 insertions(+) diff --git a/lsp_3_17/dispatch.go b/lsp_3_17/dispatch.go index 9a95cb3..c52ff6b 100644 --- a/lsp_3_17/dispatch.go +++ b/lsp_3_17/dispatch.go @@ -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) +} diff --git a/lsp_3_17/dispatch_test.go b/lsp_3_17/dispatch_test.go index 196d2ac..b780867 100644 --- a/lsp_3_17/dispatch_test.go +++ b/lsp_3_17/dispatch_test.go @@ -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)) } diff --git a/lsp_3_17/language_features.go b/lsp_3_17/language_features.go index a86b58b..05b11ff 100644 --- a/lsp_3_17/language_features.go +++ b/lsp_3_17/language_features.go @@ -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")