Skip to content

Commit d5f3ef9

Browse files
authored
Add no-op semanticTokens handlers (#202)
`lsp` falsely advertises `semanticTokens` capabilities, regardless of what we support. Register some no-op handlers so that clients which trust the LSP server don't crash out. See: haskell/lsp#640
1 parent 0894a83 commit d5f3ef9

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/StaticLS/Handlers.hs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,24 @@ handleResolveInlayHint :: Handlers (LspT c StaticLsM)
112112
handleResolveInlayHint = LSP.requestHandler LSP.SMethod_InlayHintResolve $ \_ _ -> do
113113
pure ()
114114

115+
-- The lsp library (>=2.7.0.1) unconditionally advertises `semanticTokensProvider`
116+
-- in initialize, even when no semantic-token handlers are registered. Clients
117+
-- (notably Neovim's built-in LSP client) then send `textDocument/semanticTokens/*`
118+
-- requests, which fall through to the library's `missingRequestHandler` and are
119+
-- logged at Error severity -- the default logger surfaces those as `window/showMessage`
120+
-- popups. Register stub handlers that return Null so the requests resolve quietly.
121+
handleSemanticTokensFull :: Handlers (LspT c StaticLsM)
122+
handleSemanticTokensFull = LSP.requestHandler LSP.SMethod_TextDocumentSemanticTokensFull $ \_ res ->
123+
res $ Right $ InR Null
124+
125+
handleSemanticTokensFullDelta :: Handlers (LspT c StaticLsM)
126+
handleSemanticTokensFullDelta = LSP.requestHandler LSP.SMethod_TextDocumentSemanticTokensFullDelta $ \_ res ->
127+
res $ Right $ InR $ InR Null
128+
129+
handleSemanticTokensRange :: Handlers (LspT c StaticLsM)
130+
handleSemanticTokensRange = LSP.requestHandler LSP.SMethod_TextDocumentSemanticTokensRange $ \_ res ->
131+
res $ Right $ InR Null
132+
115133
handleReferencesRequest :: Handlers (LspT c StaticLsM)
116134
handleReferencesRequest = LSP.requestHandler LSP.SMethod_TextDocumentReferences $ \req res -> do
117135
let params = req._params

src/StaticLS/Server.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ serverDef options logger = do
227227
, handleDocumentSymbols
228228
, handleCompletion
229229
, handleCompletionItemResolve
230+
, handleSemanticTokensFull
231+
, handleSemanticTokensFullDelta
232+
, handleSemanticTokensRange
230233
]
231234
<> (if options.provideInlays then [handleInlayHintRequest options, handleResolveInlayHint] else [])
232235
<> ( case options.fourmoluCommand of

0 commit comments

Comments
 (0)