[go: up one dir, main page]

Skip to content

A plugin to simplify enabling neovim inlay hints(neovim 0.10+).

License

Notifications You must be signed in to change notification settings

MysticalDevil/inlay-hints.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

inlay-hints.nvim

A plugin to simplify enabling neovim offical inlay hints

Important

This is a VERY SIMPLE plugin. I just integrated how to enable the inlay hint of each LSP.

Installation

Add MysticalDevil/inlay-hints.nvim using your favorite plugin manager, like this:

lazy.nvim

require("lazy").setup({
    "MysticalDevil/inlay-hints.nvim",
    event = "LspAttach",
    dependencies = { "neovim/nvim-lspconfig" },
    config = function()
        require("inlay-hints").setup()
    end
})

pckr.nvim

require("pckr").add({
    "MysticalDevil/inlay-hints.nvim",
    requires = { "neovim/nvim-lspconfig" },
    config = function()
        require("inlay-hints").setup()
    end
})

If you don't want to enable it globally, you can config at the on_attach function

on_attach

require("lspconfig").[server_name].setup({
  on_attach = function(client, bufnr)
    require("inlay-hints").on_attach(client, bufnr)
  end
})

Configuration

Default config

You only need to pass the options you want to override.

require("inlay-hints").setup({
  commands = { enable = true } -- Enable InlayHints commands, include `InlayHintsToggle`, `InlayHintsEnable` and `InlayHintsDisable`
  autocmd = { enable = true } -- Enable the inlay hints on `LspAttach` event
})

Languages

The inlay hints is not enabled by default, so you need the following settings, use nvim-lspconfig

You should make sure that the LSP you are using supported inlay hints

lua_ls

Here's how to enable inlay hints for lua-language-server

require("lspconfig").lua_ls.setup({
  settings = {
    Lua = {
      hint = {
        enable = true, -- necessary
      }
    }
  }
})

clangd

If you're using p00f/clangd_extensions.nvim, please set autoSetHints = false

Here's how to enable inlay hints for clangd

require("lspconfig").clangd.setup({
  settings = {
    clangd = {
      InlayHints = {
        Designators = true,
        Enabled = true,
        ParameterNames = true,
        DeducedTypes = true,
      },
      fallbackFlags = { "-std=c++20" },
    },
  }
})

denols

Here's how to enable inlay hints for denols

require("lspconfig").denols.setup({
  settings = {
    deno = {
      inlayHints = {
        parameterNames = { enabled = "all", suppressWhenArgumentMatchesName = true },
        parameterTypes = { enabled = true },
        variableTypes = { enabled = true, suppressWhenTypeMatchesName = true },
        propertyDeclarationTypes = { enabled = true },
        functionLikeReturnTypes = { enable = true },
        enumMemberValues = { enabled = true },
      },
    }
  }
})

gopls

Here's how to enable inlay hints for gopls

require("lspconfig").gopls.setup({
  settings = {
    gopls = {
      hints = {
        rangeVariableTypes = true,
        parameterNames = true,
        constantValues = true,
        assignVariableTypes = true,
        compositeLiteralFields = true,
        compositeLiteralTypes = true,
        functionTypeParameters = true,
      },
    }
  }
})

rust-analyzer

If you're using mrcjkb/rustaceanvim, you can enable it like

vim.g.rustaceanvim = {
  server = {
    settings = {
      ["rust-analyzer"] = {
        inlayHints = {
          bindingModeHints = {
            enable = false,
          },
          chainingHints = {
            enable = true,
          },
          closingBraceHints = {
            enable = true,
            minLines = 25,
          },
          closureReturnTypeHints = {
            enable = "never",
          },
          lifetimeElisionHints = {
            enable = "never",
            useParameterNames = false,
          },
          maxLength = 25,
          parameterHints = {
            enable = true,
          },
          reborrowHints = {
            enable = "never",
          },
          renderColons = true,
          typeHints = {
            enable = true,
            hideClosureInitialization = false,
            hideNamedConstructor = false,
          },
        },
      },
    },
  },
}

Here's how to enable inlay hints for rust-analyzer

require("lspconfig").rust_analyzer.setup({
  settings = {
    ["rust-analyzer"] = {
      inlayHints = {
        bindingModeHints = {
          enable = false,
        },
        chainingHints = {
          enable = true,
        },
        closingBraceHints = {
          enable = true,
          minLines = 25,
        },
        closureReturnTypeHints = {
          enable = "never",
        },
        lifetimeElisionHints = {
          enable = "never",
          useParameterNames = false,
        },
        maxLength = 25,
        parameterHints = {
          enable = true,
        },
        reborrowHints = {
          enable = "never",
        },
        renderColons = true,
        typeHints = {
          enable = true,
          hideClosureInitialization = false,
          hideNamedConstructor = false,
        },
      },
    }
  }
})

typescript-language-server (tsserver)

If you're using pmizio/typescript-tools.nvim, you enable it like this

require("typescript-tools").setup({
  settings = {
    tsserver_file_preferences = {
      includeInlayParameterNameHints = "all",
      includeInlayParameterNameHintsWhenArgumentMatchesName = false,
      includeInlayFunctionParameterTypeHints = true,
      includeInlayVariableTypeHints = true,
      includeInlayVariableTypeHintsWhenTypeMatchesName = false,
      includeInlayPropertyDeclarationTypeHints = true,
      includeInlayFunctionLikeReturnTypeHints = true,
      includeInlayEnumMemberValueHints = true,
    }
  }
})

Here's how to enable inlay hints for tsserver

require("lspconfig").tsserver.setup({
  settings = {
    typescript = {
      inlayHints = {
        includeInlayParameterNameHints = "all",
        includeInlayParameterNameHintsWhenArgumentMatchesName = true,
        includeInlayFunctionParameterTypeHints = true,
        includeInlayVariableTypeHints = true,
        includeInlayVariableTypeHintsWhenTypeMatchesName = true,
        includeInlayPropertyDeclarationTypeHints = true,
        includeInlayFunctionLikeReturnTypeHints = true,
        includeInlayEnumMemberValueHints = true,
      },
    },
    javascript = {
      inlayHints = {
        includeInlayParameterNameHints = "all",
        includeInlayParameterNameHintsWhenArgumentMatchesName = true,
        includeInlayFunctionParameterTypeHints = true,
        includeInlayVariableTypeHints = true,
        includeInlayVariableTypeHintsWhenTypeMatchesName = true,
        includeInlayPropertyDeclarationTypeHints = true,
        includeInlayFunctionLikeReturnTypeHints = true,
        includeInlayEnumMemberValueHints = true,
      },
    },
  }
})

svelte-language-server

Here's how to enable inlay hints for svelte-language-server

require('lspconfig').svelte.setup {
  settings = {
    typescript = {
      inlayHints = {
        parameterNames = { enabled = 'all' },
        parameterTypes = { enabled = true },
        variableTypes = { enabled = true },
        propertyDeclarationTypes = { enabled = true },
        functionLikeReturnTypes = { enabled = true },
        enumMemberValues = { enabled = true },
      },
    },
  },
}

vtsls

Here's how to enable inlay hints for vtsls

contribute by lucicoreyli

require('lspconfig').vtsls.setup {
  -- capabilities = capabilities,
  -- flags = lsp_flags,
  -- on_attach = on_attach,
  settings = {
    typescript = {
      inlayHints = {
        parameterNames = { enabled = 'all' },
        parameterTypes = { enabled = true },
        variableTypes = { enabled = true },
        propertyDeclarationTypes = { enabled = true },
        functionLikeReturnTypes = { enabled = true },
        enumMemberValues = { enabled = true },
      },
    },
  },
}

zls

Here's how to enable inlay hints for zls

require("lspconfig").zls.setup({
  settings = {
    zls = {
      enable_inlay_hints = true,
      inlay_hints_show_builtin = true,
      inlay_hints_exclude_single_argument = true,
      inlay_hints_hide_redundant_param_names = false,
      inlay_hints_hide_redundant_param_names_last_token = false,
    },
  }
})

basedpyright

Here's how to enable inlay hints for basedpyright When you configure inlay hint correctly, the basedpyright's feature will be automatically enabled.

require('lspconfig').basedpyright.setup({
  settings = {
    basedpyright = {
      analysis = {
        autoSearchPaths = true,
        diagnosticMode = "openFilesOnly",
        useLibraryCodeForTypes = true
      }
    }
  }
})

pylyzer

Here's how to enable inlay hints for pylyzer

require("lspconfig").pylyzer.setup({
  settings = {
    python = {
      inlayHints = true
    }
  }
})

kotlin-language-server

Here's how to enable inlay hints for kotlin-language-server

require("lspconfig").kotlin_language_server.setup({
  settings = {
    kotlin = {
      hints = {
        typeHints = true,
        parameterHints = true,
        chaineHints = true,
      },
    },
  }
})

eclipse.jdt.ls

Here's how to enable inlay hints for eslipse.jdt.ls

require("lspconfig").jdtls.setup({
  settings = {
    java = {
      inlayHints = {
        parameterNames = {
          enabled = "all",
          exclusions = { "this" },
        },
      },
    }
  }
})

OmniSharp

Here's how to enable inlay hints for OmniSharp might work

require("lspconfig").omnisharp.setup({
  settings = {
    RoslynExtensionsOptions = {
        InlayHintsOptions = {
        EnableForParameters = true,
        ForLiteralParameters = true,
        ForIndexerParameters = true,
        ForObjectCreationParameters = true,
        ForOtherParameters = true,
        SuppressForParametersThatDifferOnlyBySuffix = false,
        SuppressForParametersThatMatchMethodIntent = false,
        SuppressForParametersThatMatchArgumentName = false,
        EnableForTypes = true,
        ForImplicitVariableTypes = true,
        ForLambdaParameterTypes = true,
        ForImplicitObjectCreatio = true,
      },
    },
  }
})