Skip to content
jinzhongjia edited this page Jul 31, 2024 · 4 revisions

To use bind a key with the lua api, use require("LspUI").api, for example:

local LspUI_api = require("LspUI").api

vim.keymap.set("n", "K", LspUI_api.hover, { desc = "LSP Hover" })
vim.keymap.set("n", "<leader>ca", LspUI_api.code_action, { desc = "LSP Code Action" })
-- ...etc.
-- see more in api.lua

Or you can use command:

vim.keymap.set("n", "K", "<cmd>LspUI hover<CR>", { desc = "LSP Hover" })
vim.keymap.set("n", "<leader>ca", "<cmd>LspUI code_action<CR>", { desc = "LSP Code Action" })
--- ...etc.

Command:

  • LspUI hover: Open an LSP hover window above cursor
  • LspUI rename: Rename the symbol below the cursor
  • LspUI code_action: Open a code action selection prompt
  • LspUI diagnostic next: Go to the next diagnostic
  • LspUI diagnostic prev: Go to the previous diagnostic
  • LspUI definition: Open the definition
  • LspUI type_definition: Open the type definition
  • LspUI declaration: Open the declaration
  • LspUI reference: Open the reference
  • LspUI implementation: Open the implementation
  • LspUI inlay_hint: Quickly open or close inlay hint

For api.definition, api.type_definition, api.declaration, api.reference, api.implementation, you can pass a callback funcaion to it, just like this:

language server lua_ls can identify type declarations about data

LspUI.api.definition(function(data)
    if data then
        print("data",vim.inspect(data))
    else
        print("no data")
    end
end)
Clone this wiki locally