diff --git a/README.md b/README.md index 0fc229a..98a2478 100644 --- a/README.md +++ b/README.md @@ -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) @@ -144,4 +152,4 @@ lspconfig.gopls.setup({ }, }) -``` \ No newline at end of file +``` diff --git a/lua/inlay-hints/adapter/init.lua b/lua/inlay-hints/adapter/init.lua index f541abd..8070764 100644 --- a/lua/inlay-hints/adapter/init.lua +++ b/lua/inlay-hints/adapter/init.lua @@ -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) diff --git a/lua/inlay-hints/config.lua b/lua/inlay-hints/config.lua index 8146a73..bd1ea92 100644 --- a/lua/inlay-hints/config.lua +++ b/lua/inlay-hints/config.lua @@ -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 = {}