Skip to content

Commit

Permalink
Fix nvim-jdtls config. Fix inlay hints function. Add inlay hints togg…
Browse files Browse the repository at this point in the history
…le keymap
  • Loading branch information
MysticalDevil committed Oct 17, 2023
1 parent 330e289 commit 340249e
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 27 deletions.
21 changes: 12 additions & 9 deletions lua/configs/core/keybindings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ local utils = require("utils")
-- term_mode = 't',
-- command_mode = 'c',

local map = vim.api.nvim_set_keymap
local opt = {
noremap = true,
silent = true,
}
-- local map = vim.api.nvim_set_keymap
-- local opt = {
-- noremap = true,
-- silent = true,
-- }
-----------------------------------------------------------

-- leader key is null
Expand Down Expand Up @@ -83,7 +83,7 @@ utils.keymap("t", "<ESC>", "<C-\\><C-n>")
local plugin_keys = {}

-- LSP callback function shortcut key setting
plugin_keys.map_LSP = function(mapbuf)
plugin_keys.map_LSP = function(mapbuf, bufnr)
-- rename
-- Lspsaga replace rn
-- mapbuf("n", "<leader>rn", "<cmd>Lspsaga rename<CR>", opt)
Expand All @@ -103,6 +103,8 @@ plugin_keys.map_LSP = function(mapbuf)
-- ignore_filename = false,
})
end, { desc = "Go to definition" })
mapbuf("n", "gD", vim.lsp.buf.declaration, { desc = "Go to declaration" })
mapbuf("n", "gi", vim.lsp.buf.implementation, { desc = "Go to implementation" })

-- hover document
-- Lspsaga replace gh
Expand All @@ -123,9 +125,10 @@ plugin_keys.map_LSP = function(mapbuf)
mapbuf("n", "gj", "<cmd>Lspsaga diagnostic_jump_next<cr>", { desc = "Jump to next diagnostic" })
mapbuf("n", "gk", "<cmd>Lspsaga diagnostic_jump_prev<cr>", { desc = "Jump to previous diagnostic" })

-- unused
-- mapbuf("n", "gD", "<cmd>lua vim.lsp.buf.declaration()<CR>", opt)
-- mapbuf("n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opt)
-- toggle inlay hints
mapbuf("n", "<leader>L", function()
vim.lsp.inlay_hint(bufnr)
end, { desc = "Toggle LSP inlay hints" })
end

-- gitsigns
Expand Down
17 changes: 17 additions & 0 deletions lua/configs/plugin/flutter-tools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,23 @@ local opts = {
virtual_text = true, -- show the highlight using virtual text
virtual_text_str = "", -- the virtual text character to highlight
},
on_attach = require("lsp.util").default_on_attach,
settings = {
showTodos = true,
completeFunctionCalls = true,
analysisExcludedFolders = {},
renameFilesWithClasses = "prompt", -- "always"
enableSnippets = true,
updateImportsOnRename = true, -- Whether to update imports and other directives when files are renamed. Required for `FlutterRename` command.
enableSdkFormatter = true,
},
init_options = {
closingLabels = true,
flutterOutline = true,
onlyAnalyzeProjectsWithOpenFiles = true,
outline = true,
suggestFromUnimportedLibraries = true,
},
},
}

Expand Down
18 changes: 10 additions & 8 deletions lua/configs/plugin/jdtls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -139,21 +139,23 @@ local config = {
extendedClientCapabilities = extendedClientCapabilities,
},
handlers = {
["language/status"] = function() end,
["workspace/diagnostic/refresh"] = function() end,
["textDocument/codeAction"] = function() end,
["textDocument/rename"] = function() end,
["workspace/applyEdit"] = function() end,
["textDocument/documentHighlight"] = function() end,
-- ["language/status"] = function() end,
-- ["workspace/diagnostic/refresh"] = function() end,
-- ["textDocument/codeAction"] = function() end,
-- ["textDocument/rename"] = function() end,
-- ["workspace/applyEdit"] = function() end,
-- ["textDocument/documentHighlight"] = function() end,
},
on_attach = function(_, bufnr)
on_attach = function(client, bufnr)
if vim.fn.has("nvim-0.10") == 1 then
vim.lsp.inlay_hint(bufnr)
vim.lsp.inlay_hint(bufnr, true)
end
jdtls.setup_dap({ hotcodereplace = "auto" })
require("jdtls.dap").setup_dap_main_class_configs()
require("jdtls.setup").add_commands()
require("lsp.util").default_on_attach(client, bufnr)
end,
filetypes = { "java" },
}

jdtls.start_or_attach(config)
4 changes: 3 additions & 1 deletion lua/configs/plugin/rust-tools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,13 @@ local opts = {
-- these override the defaults set by rust-tools.nvim
-- see https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#rust_analyzer
server = {
on_attach = function(_, bufnr)
on_attach = function(client, bufnr)
-- Hover actions
vim.keymap.set("n", "<leader>rh", rt.hover_actions.hover_actions, { buffer = bufnr })
-- Code action groups
vim.keymap.set("n", "<leader>ra", rt.code_action_group.code_action_group, { buffer = bufnr })

require("lsp.util").default_on_attach(client, bufnr)
end,
-- standalone file support
-- setting it to false may improve startup time
Expand Down
4 changes: 2 additions & 2 deletions lua/lsp/setup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ end
local lsp_servers = require("lsp.check")
lsp_servers = arr_extend(lsp_servers, {
"csharp_ls",
"dartls",
-- "dartls",
"perlpls",
"racket_langserver",
"rust_analyzer",
Expand Down Expand Up @@ -61,7 +61,7 @@ local servers = {
clangd = require("lsp.config.clangd"),
clojure_lsp = require("lsp.config.clojure_lsp"),
cssls = require("lsp.config.cssls"),
dartls = require("lsp.config.dartls"),
-- dartls = require("lsp.config.dartls"),
denols = require("lsp.config.denols"),
emmet_ls = require("lsp.config.emmet_ls"),
eslint = require("lsp.config.eslint"),
Expand Down
12 changes: 5 additions & 7 deletions lua/lsp/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ function M.key_attach(bufnr)
vim.keymap.set(mode, lhs, rhs, vim.tbl_extend("force", default_opts, opts))
end
-- keybingings
require("configs.core.keybindings").map_LSP(buf_set_keymap)
require("configs.core.keybindings").map_LSP(buf_set_keymap, bufnr)

vim.notify("The LSP key settings is attached", vim.log.levels.INFO)
end

-- disable format, handle it to a dedicated plugin
Expand Down Expand Up @@ -45,11 +47,11 @@ function M.default_on_attach(client, bufnr)
M.disable_format(client)
M.key_attach(bufnr)

M.set_inlay_hints(client, bufnr)

vim.api.nvim_set_option_value("formatexpr", "v:lua.vim.lsp.formatexpr()")
vim.api.nvim_set_option_value("omnifunc", "v:lua.vim.lsp.omnifunc")
vim.api.nvim_set_option_value("tagfunc", "v:lua.vim.lsp.tagfunc")

M.set_inlay_hints(client, bufnr)
end

---@return table
Expand All @@ -62,10 +64,6 @@ function M.default_configs()
end

function M.set_inlay_hints(client, bufnr)
if client.name == "null-ls" then
return
end

if not client then
vim.notify_once("LSP inlay hints attached failed: nil client.", vim.log.levels.ERROR)
return
Expand Down

0 comments on commit 340249e

Please sign in to comment.