From cd0e60170ca1e6a9421d15447c68e2b6772cbafb Mon Sep 17 00:00:00 2001 From: moliva Date: Fri, 7 Apr 2023 18:22:59 -0300 Subject: [PATCH 1/3] feat: comment out tsserver adapter fttb --- lua/inlay-hints/adapter/init.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lua/inlay-hints/adapter/init.lua b/lua/inlay-hints/adapter/init.lua index f541abd..5cdf614 100644 --- a/lua/inlay-hints/adapter/init.lua +++ b/lua/inlay-hints/adapter/init.lua @@ -5,9 +5,10 @@ local default = require("inlay-hints.adapter.default") local M = {} function M.adapt_request(client, bufnr, callback) - if client.name == "tsserver" then - tsserver.adapt_request(client, bufnr, callback) - elseif client.name == "clangd" then + -- if client.name == "tsserver" then + -- tsserver.adapt_request(client, bufnr, callback) + -- elseif client.name == "clangd" then + if client.name == "clangd" then clangd.adapt_request(client, bufnr, callback) else default.adapt_request(client, bufnr, callback) From c335c62802d9e0c8b6091b4143dae12fb46275c7 Mon Sep 17 00:00:00 2001 From: moliva Date: Fri, 14 Apr 2023 19:26:50 -0300 Subject: [PATCH 2/3] feat: add configuration to enable or disable tsserver adapter --- lua/inlay-hints/adapter/init.lua | 11 +++++++---- lua/inlay-hints/config.lua | 4 ++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lua/inlay-hints/adapter/init.lua b/lua/inlay-hints/adapter/init.lua index 5cdf614..3d59339 100644 --- a/lua/inlay-hints/adapter/init.lua +++ b/lua/inlay-hints/adapter/init.lua @@ -1,14 +1,17 @@ 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 = {} function M.adapt_request(client, bufnr, callback) - -- if client.name == "tsserver" then - -- tsserver.adapt_request(client, bufnr, callback) - -- elseif client.name == "clangd" then - if client.name == "clangd" then + local opts = ih.config.options or {} + local adapter = opts.adapter or {} + + if client.name == "tsserver" and adapter.tsserver then + tsserver.adapt_request(client, bufnr, callback) + elseif client.name == "clangd" then clangd.adapt_request(client, bufnr, callback) else default.adapt_request(client, bufnr, callback) diff --git a/lua/inlay-hints/config.lua b/lua/inlay-hints/config.lua index 8146a73..684f34e 100644 --- a/lua/inlay-hints/config.lua +++ b/lua/inlay-hints/config.lua @@ -40,6 +40,10 @@ local defaults = { end, }, }, + + adapter = { + tsserver = true, + } } M.options = {} From 32b8b5009137eb01086a6a4c37b84eed4979d5a6 Mon Sep 17 00:00:00 2001 From: moliva Date: Sat, 15 Apr 2023 16:19:10 -0300 Subject: [PATCH 3/3] feat: changing adapter param and adding doc --- README.md | 10 +++++++++- lua/inlay-hints/adapter/init.lua | 26 ++++++++++++++++++++++---- lua/inlay-hints/config.lua | 6 +++++- 3 files changed, 36 insertions(+), 6 deletions(-) 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 3d59339..8070764 100644 --- a/lua/inlay-hints/adapter/init.lua +++ b/lua/inlay-hints/adapter/init.lua @@ -5,11 +5,29 @@ local ih = require("inlay-hints") local M = {} -function M.adapt_request(client, bufnr, callback) - local opts = ih.config.options or {} - local adapter = opts.adapter or {} +--- 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 client.name == "tsserver" and adapter.tsserver then + 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" 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 684f34e..bd1ea92 100644 --- a/lua/inlay-hints/config.lua +++ b/lua/inlay-hints/config.lua @@ -42,7 +42,11 @@ local defaults = { }, adapter = { - tsserver = true, + -- 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', } }