AstroNvim / astrocommunity

A community repository of common plugin specifications
GNU General Public License v3.0
1.09k stars 222 forks source link

[ SOLVED ] No inlay Hints with: lsp-inlayhints-nvim #268

Closed MrMic closed 1 year ago

MrMic commented 1 year ago

Hi,

To have inlay hints I need to use this package:

with the configuration:

{
    "junnplus/lsp-setup.nvim",
    dependencies = {
      "neovim/nvim-lspconfig",
    },
    event = { "User AstroFile" },
    config = function(_, opts) require("lsp-setup").setup(opts) end,
    opts = {
      inlay_hints = {
        enabled = true,
        parameter_hints = true,
        type_hints = true,
        highlight = "Comment",
        -- priority = 0,
      },
      servers = {
        tsserver = {
          settings = {
            typescript = {
              inlayHints = {
                includeInlayParameterNameHints = "all",
                includeInlayParameterNameHintsWhenArgumentMatchesName = true,
                includeInlayFunctionParameterTypeHints = true,
                includeInlayVariableTypeHints = true,
                includeInlayVariableTypeHintsWhenTypeMatchesName = true,
                includeInlayPropertyDeclarationTypeHints = true,
                includeInlayFunctionLikeReturnTypeHints = true,
                includeInlayEnumMemberValueHints = true,
              },
            },
            javascript = {
              inlayHints = {
                includeInlayEnumMemberValueHints = true,
                includeInlayFunctionLikeReturnTypeHints = true,
                includeInlayFunctionParameterTypeHints = true,
                includeInlayParameterNameHints = "all", -- 'none' | 'literals' | 'all';
                includeInlayParameterNameHintsWhenArgumentMatchesName = true,
                includeInlayPropertyDeclarationTypeHints = true,
                includeInlayVariableTypeHints = true,
              },
            },
          },
        },
        gopls = {
          settings = {
            gopls = {
              hints = {
                rangeVariableTypes = true,
                parameterNames = true,
                constantValues = true,
                assignVariableTypes = true,
                compositeLiteralFields = true,
                compositeLiteralTypes = true,
                functionTypeParameters = true,
              },
            },
          },
        },
      },
    },
  }

Where to put this in the lsp-inlayhints-nvim package, and get rid of the above config?

Thanks for the reply. Rgds,

mehalter commented 1 year ago

Just out of curiousity, why are you using this rather than the built in lsp.config setup?

mehalter commented 1 year ago

I don't think we want to add this to the astrocommunity delivery of lsp-inlayhints-nvim

MrMic commented 1 year ago

As mentioned above, I have not found where and how to add the config for: gopls, tsserver ... in lsp-inlayhints-nvim. I tried the "opts", but that was not working, so I decided to use this new plugin above lsp-inlayhints-nvim, and it works. But I am sure there is a simple way to achieve the same result but do not know how and where to put the config ...

mehalter commented 1 year ago

You want to use the core lsp.config table for setting these rather than using some other plugin as this will decrease your number of plugins, increase performance, and increase integration and stability. Here is how to do this:

Single user/init.lua file ```lua return { lsp = { config = { tsserver = { settings = { typescript = { inlayHints = { includeInlayParameterNameHints = "all", includeInlayParameterNameHintsWhenArgumentMatchesName = true, includeInlayFunctionParameterTypeHints = true, includeInlayVariableTypeHints = true, includeInlayVariableTypeHintsWhenTypeMatchesName = true, includeInlayPropertyDeclarationTypeHints = true, includeInlayFunctionLikeReturnTypeHints = true, includeInlayEnumMemberValueHints = true, }, }, javascript = { inlayHints = { includeInlayEnumMemberValueHints = true, includeInlayFunctionLikeReturnTypeHints = true, includeInlayFunctionParameterTypeHints = true, includeInlayParameterNameHints = "all", -- 'none' | 'literals' | 'all'; includeInlayParameterNameHintsWhenArgumentMatchesName = true, includeInlayPropertyDeclarationTypeHints = true, includeInlayVariableTypeHints = true, }, }, }, }, gopls = { settings = { gopls = { hints = { rangeVariableTypes = true, parameterNames = true, constantValues = true, assignVariableTypes = true, compositeLiteralFields = true, compositeLiteralTypes = true, functionTypeParameters = true, }, }, }, }, }, }, plugins = { "AstroNvim/astrocommunity", { import = "astrocommunity.lsp.lsp-inlayhints-nvim" }, }, } ```
Split User Configuration `user/plugins/community.lua` (or anything in `user/plugins/`): ```lua return { "AstroNvim/astrocommunity", { import = "astrocommunity.lsp.lsp-inlayhints-nvim" }, } ``` `user/lsp/config/tsserver.lua`: ```lua return { settings = { typescript = { inlayHints = { includeInlayParameterNameHints = "all", includeInlayParameterNameHintsWhenArgumentMatchesName = true, includeInlayFunctionParameterTypeHints = true, includeInlayVariableTypeHints = true, includeInlayVariableTypeHintsWhenTypeMatchesName = true, includeInlayPropertyDeclarationTypeHints = true, includeInlayFunctionLikeReturnTypeHints = true, includeInlayEnumMemberValueHints = true, }, }, javascript = { inlayHints = { includeInlayEnumMemberValueHints = true, includeInlayFunctionLikeReturnTypeHints = true, includeInlayFunctionParameterTypeHints = true, includeInlayParameterNameHints = "all", -- 'none' | 'literals' | 'all'; includeInlayParameterNameHintsWhenArgumentMatchesName = true, includeInlayPropertyDeclarationTypeHints = true, includeInlayVariableTypeHints = true, }, }, }, } ``` `user/lsp/config/gopls.lua`: ```lua return { settings = { gopls = { hints = { rangeVariableTypes = true, parameterNames = true, constantValues = true, assignVariableTypes = true, compositeLiteralFields = true, compositeLiteralTypes = true, functionTypeParameters = true, }, }, }, } ```
MrMic commented 1 year ago

Yes indeed, it seems to work perfectly fine! I have used the "Split User configuration" Thank you very, very much! 😁😁😁

Rgds,