Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ require("inlay-hints").setup({
eol = {
right_align = true,
}

adapter = {
-- one of:
-- - force: use adapter for tsserver always
-- - disable: never adapt inlay hints for tsserver
-- - auto: checks whether the tsserver provides this capability as a standard one or adapts the request otherwise
tsserver = 'auto',
}
})
```
Take a look at all the possible configuration options [here](https://github.com/simrat39/inlay-hints.nvim/blob/main/lua/inlay-hints/config.lua#L3)
Expand Down Expand Up @@ -144,4 +152,4 @@ lspconfig.gopls.setup({
},
})

```
```
24 changes: 23 additions & 1 deletion lua/inlay-hints/adapter/init.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
local tsserver = require("inlay-hints.adapter.tsserver")
local clangd = require("inlay-hints.adapter.clangd")
local default = require("inlay-hints.adapter.default")
local ih = require("inlay-hints")

local M = {}

--- Checks the user configuration for adapting the current LSP calls for inlay hints
--- given the following criteria:
--- - force: use adapter always depending on the custom implementation of the server (previous behavior)
--- - disable: never adapt requests, using the default support for inlays in LSP
--- - auto: checks whether the current server provides this capability as a standard LSP one or adapts the request otherwise
--- Returns true to adapt the request, false to use the standard method
--- @return boolean
local function should_apply_tsserver_adapter(client)
local mode = ih.config.options.adapter.tsserver

if mode == 'force' then
return true
elseif mode == 'auto' then
-- as per current implementation of the typescript-language-server and protocol spec
-- https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_inlayHint
return not client.server_capabilities.inlayHintProvider
else -- assume 'disable'
return false
end
end

function M.adapt_request(client, bufnr, callback)
if client.name == "tsserver" then
if client.name == "tsserver" and should_apply_tsserver_adapter(client) then
tsserver.adapt_request(client, bufnr, callback)
elseif client.name == "clangd" then
clangd.adapt_request(client, bufnr, callback)
Expand Down
8 changes: 8 additions & 0 deletions lua/inlay-hints/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ local defaults = {
end,
},
},

adapter = {
-- one of:
-- - force: use adapter for tsserver always
-- - disable: never adapt inlay hints for tsserver
-- - auto: checks whether the tsserver provides this capability as a standard one or adapts the request otherwise
tsserver = 'auto',
}
}

M.options = {}
Expand Down