updated neovim config
This commit is contained in:
parent
98ad2ee32a
commit
8674b85494
|
@ -0,0 +1,196 @@
|
||||||
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||||
|
local path = {}
|
||||||
|
|
||||||
|
path.data_dir = vim.fn.stdpath('cache') .. '/nvim-jdtls'
|
||||||
|
local data_dir = path.data_dir .. '/' .. vim.fn.fnamemodify(vim.fn.getcwd(), ':p:h:t')
|
||||||
|
|
||||||
|
local jdtls_install = require('mason-registry')
|
||||||
|
.get_package('jdtls')
|
||||||
|
:get_install_path()
|
||||||
|
|
||||||
|
path.java_agent = jdtls_install .. '/lombok.jar'
|
||||||
|
path.launcher_jar = vim.fn.glob(jdtls_install .. '/plugins/org.eclipse.equinox.launcher_*.jar')
|
||||||
|
path.platform_config = jdtls_install .. '/config_mac'
|
||||||
|
|
||||||
|
|
||||||
|
-- See `:help vim.lsp.start_client` for an overview of the supported `config` options.
|
||||||
|
local config = {
|
||||||
|
-- The command that starts the language server
|
||||||
|
-- See: https://github.com/eclipse/eclipse.jdt.ls#running-from-the-command-line
|
||||||
|
cmd = {
|
||||||
|
|
||||||
|
-- 💀
|
||||||
|
-- 'java', -- or '/path/to/java17_or_newer/bin/java'
|
||||||
|
-- depends on if `java` is in your $PATH env variable and if it points to the right version.
|
||||||
|
'/Library/Java/JavaVirtualMachines/temurin-19.jdk/Contents/Home/bin/java',
|
||||||
|
-- '/Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/bin/java',
|
||||||
|
-- '/Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home/bin/java',
|
||||||
|
|
||||||
|
'-Declipse.application=org.eclipse.jdt.ls.core.id1',
|
||||||
|
'-Dosgi.bundles.defaultStartLevel=4',
|
||||||
|
'-Declipse.product=org.eclipse.jdt.ls.core.product',
|
||||||
|
'-Dlog.protocol=true',
|
||||||
|
'-Dlog.level=ALL',
|
||||||
|
'-javaagent:' .. path.java_agent,
|
||||||
|
'-Xmx1g',
|
||||||
|
'--add-modules=ALL-SYSTEM',
|
||||||
|
'--add-opens', 'java.base/java.util=ALL-UNNAMED',
|
||||||
|
'--add-opens', 'java.base/java.lang=ALL-UNNAMED',
|
||||||
|
|
||||||
|
-- 💀
|
||||||
|
-- '-jar', '/path/to/jdtls_install_location/plugins/org.eclipse.equinox.launcher_VERSION_NUMBER.jar',
|
||||||
|
'-jar', path.launcher_jar,
|
||||||
|
-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^
|
||||||
|
-- Must point to the Change this to
|
||||||
|
-- eclipse.jdt.ls installation the actual version
|
||||||
|
|
||||||
|
|
||||||
|
-- 💀
|
||||||
|
-- '-configuration', '/path/to/jdtls_install_location/config_SYSTEM',
|
||||||
|
'-configuration', path.platform_config,
|
||||||
|
-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^
|
||||||
|
-- Must point to the Change to one of `linux`, `win` or `mac`
|
||||||
|
-- eclipse.jdt.ls installation Depending on your system.
|
||||||
|
|
||||||
|
|
||||||
|
-- 💀
|
||||||
|
-- See `data directory configuration` section in the README
|
||||||
|
-- '-data', '/path/to/unique/per/project/workspace/folder'
|
||||||
|
'-data', data_dir,
|
||||||
|
},
|
||||||
|
|
||||||
|
-- 💀
|
||||||
|
-- This is the default if not provided, you can remove it. Or adjust as needed.
|
||||||
|
-- One dedicated LSP server & client will be started per unique root_dir
|
||||||
|
-- root_dir = require('jdtls.setup').find_root({'.git', 'mvnw', 'gradlew', 'pom.xml', 'build.gradle'}),
|
||||||
|
root_dir = vim.fs.dirname(vim.fs.find({ '.git', 'mvnw', 'gradlew', 'pom.xml', 'build.gradle' }, { upward = true })
|
||||||
|
[1]),
|
||||||
|
-- Here you can configure eclipse.jdt.ls specific settings
|
||||||
|
-- See https://github.com/eclipse/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request
|
||||||
|
-- for a list of options
|
||||||
|
settings = {
|
||||||
|
java = {
|
||||||
|
home = '/Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home',
|
||||||
|
eclipse = {
|
||||||
|
downloadSources = true,
|
||||||
|
},
|
||||||
|
maven = {
|
||||||
|
downloadSources = true,
|
||||||
|
},
|
||||||
|
configuration = {
|
||||||
|
updateBuildConfiguration = "interactive",
|
||||||
|
runtimes = {
|
||||||
|
name = 'JavaSE-1.8',
|
||||||
|
path = '/Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home',
|
||||||
|
default = true,
|
||||||
|
},
|
||||||
|
-- runtimes = {
|
||||||
|
-- name = 'JavaSE-19',
|
||||||
|
-- path = '/Library/Java/JavaVirtualMachines/temurin-19.jdk',
|
||||||
|
-- default = true,
|
||||||
|
-- },
|
||||||
|
},
|
||||||
|
import = {
|
||||||
|
gradle = {
|
||||||
|
enabled = true,
|
||||||
|
java = {
|
||||||
|
home = '/Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
-- Language server `initializationOptions`
|
||||||
|
-- You need to extend the `bundles` with paths to jar files
|
||||||
|
-- if you want to use additional eclipse.jdt.ls plugins.
|
||||||
|
--
|
||||||
|
-- See https://github.com/mfussenegger/nvim-jdtls#java-debug-installation
|
||||||
|
--
|
||||||
|
-- If you don't plan on using the debugger or other eclipse.jdt.ls plugins you can remove this
|
||||||
|
init_options = {
|
||||||
|
bundles = {}
|
||||||
|
},
|
||||||
|
on_attach = function(client, bufnr)
|
||||||
|
-- Diagnostic keymaps
|
||||||
|
-- vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous diagnostic message' })
|
||||||
|
-- vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnostic message' })
|
||||||
|
-- vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, { desc = 'Open floating diagnostic message' })
|
||||||
|
-- vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostics list' })
|
||||||
|
|
||||||
|
-- [[ Configure LSP ]]
|
||||||
|
-- This function gets run when an LSP connects to a particular buffer.
|
||||||
|
-- local on_attach = function(_, bufnr)
|
||||||
|
-- NOTE: Remember that lua is a real programming language, and as such it is possible
|
||||||
|
-- to define small helper and utility functions so you don't have to repeat yourself
|
||||||
|
-- many times.
|
||||||
|
--
|
||||||
|
-- In this case, we create a function that lets us more easily define mappings specific
|
||||||
|
-- for LSP related items. It sets the mode, buffer and description for us each time.
|
||||||
|
local nmap = function(keys, func, desc)
|
||||||
|
if desc then
|
||||||
|
desc = 'LSP: ' .. desc
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc })
|
||||||
|
end
|
||||||
|
|
||||||
|
nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
|
||||||
|
nmap('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction')
|
||||||
|
|
||||||
|
nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition')
|
||||||
|
nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
|
||||||
|
nmap('gI', vim.lsp.buf.implementation, '[G]oto [I]mplementation')
|
||||||
|
nmap('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition')
|
||||||
|
nmap('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols')
|
||||||
|
nmap('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols')
|
||||||
|
|
||||||
|
-- See `:help K` for why this keymap
|
||||||
|
nmap('K', vim.lsp.buf.hover, 'Hover Documentation')
|
||||||
|
nmap('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation')
|
||||||
|
|
||||||
|
-- Lesser used LSP functionality
|
||||||
|
nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
|
||||||
|
nmap('<leader>wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder')
|
||||||
|
nmap('<leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder')
|
||||||
|
nmap('<leader>wl', function()
|
||||||
|
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
||||||
|
end, '[W]orkspace [L]ist Folders')
|
||||||
|
|
||||||
|
-- Create a command `:Format` local to the LSP buffer
|
||||||
|
vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_)
|
||||||
|
vim.lsp.buf.format()
|
||||||
|
end, { desc = 'Format current buffer with LSP' })
|
||||||
|
-- end
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
-- This starts a new client & server,
|
||||||
|
-- or attaches to an existing client & server depending on the `root_dir`.
|
||||||
|
require('jdtls').start_or_attach(config)
|
||||||
|
|
||||||
|
-- local opts = {
|
||||||
|
-- noremap = true,
|
||||||
|
-- silent = true,
|
||||||
|
-- }
|
||||||
|
-- vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist)
|
||||||
|
-- vim.api.nvim_set_keymap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
|
||||||
|
-- vim.api.nvim_set_keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
|
||||||
|
-- vim.api.nvim_set_keymap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
|
||||||
|
-- vim.api.nvim_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
|
||||||
|
-- vim.api.nvim_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
|
||||||
|
-- vim.api.nvim_set_keymap('n', '<leader>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
|
||||||
|
-- vim.api.nvim_set_keymap('n', '<leader>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
|
||||||
|
-- vim.api.nvim_set_keymap('n', '<leader>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
|
||||||
|
-- vim.api.nvim_set_keymap('n', '<leader>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
|
||||||
|
-- vim.api.nvim_set_keymap('n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
|
||||||
|
-- vim.api.nvim_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
|
||||||
|
-- vim.api.nvim_set_keymap('n', '<leader>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
|
||||||
|
-- vim.api.nvim_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next<CR>', opts)
|
||||||
|
-- vim.api.nvim_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev<CR>', opts)
|
||||||
|
-- -- vim.api.nvim_set_keymap('n', '<leader>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
|
||||||
|
-- vim.api.nvim_set_keymap('n', '<leader>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
|
||||||
|
-- vim.api.nvim_set_keymap('n', '<leader>lg', '<cmd>lua vim.lsp.buf.formatting_sync(nil, 1000)<CR>', opts)
|
||||||
|
--
|
||||||
|
-- vim.api.nvim_set_keymap('n', '<leader>lA', '<cmd>lua vim.lsp.buf.code_action()<CR>', { silent = true })
|
||||||
|
-- vim.api.nvim_set_keymap('n', '<leader>lA', '<cmd>lua require(\'jdtls\').code_action()<CR>', { silent = true })
|
36
init.lua
36
init.lua
|
@ -1,3 +1,4 @@
|
||||||
|
---@diagnostic disable: missing-fields
|
||||||
--[[
|
--[[
|
||||||
|
|
||||||
=====================================================================
|
=====================================================================
|
||||||
|
@ -84,6 +85,10 @@ require('lazy').setup({
|
||||||
{ 'williamboman/mason.nvim', config = true },
|
{ 'williamboman/mason.nvim', config = true },
|
||||||
'williamboman/mason-lspconfig.nvim',
|
'williamboman/mason-lspconfig.nvim',
|
||||||
|
|
||||||
|
-- Extensions for the built-in LSP support in Neovim
|
||||||
|
-- for eclipse.jdt.ls to enable LSPs for Java
|
||||||
|
'mfussenegger/nvim-jdtls',
|
||||||
|
|
||||||
-- Useful status updates for LSP
|
-- Useful status updates for LSP
|
||||||
-- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})`
|
-- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})`
|
||||||
{ 'j-hui/fidget.nvim', tag = 'legacy', opts = {} },
|
{ 'j-hui/fidget.nvim', tag = 'legacy', opts = {} },
|
||||||
|
@ -124,7 +129,8 @@ require('lazy').setup({
|
||||||
changedelete = { text = '~' },
|
changedelete = { text = '~' },
|
||||||
},
|
},
|
||||||
on_attach = function(bufnr)
|
on_attach = function(bufnr)
|
||||||
vim.keymap.set('n', '<leader>gp', require('gitsigns').prev_hunk, { buffer = bufnr, desc = '[G]o to [P]revious Hunk' })
|
vim.keymap.set('n', '<leader>gp', require('gitsigns').prev_hunk,
|
||||||
|
{ buffer = bufnr, desc = '[G]o to [P]revious Hunk' })
|
||||||
vim.keymap.set('n', '<leader>gn', require('gitsigns').next_hunk, { buffer = bufnr, desc = '[G]o to [N]ext Hunk' })
|
vim.keymap.set('n', '<leader>gn', require('gitsigns').next_hunk, { buffer = bufnr, desc = '[G]o to [N]ext Hunk' })
|
||||||
vim.keymap.set('n', '<leader>ph', require('gitsigns').preview_hunk, { buffer = bufnr, desc = '[P]review [H]unk' })
|
vim.keymap.set('n', '<leader>ph', require('gitsigns').preview_hunk, { buffer = bufnr, desc = '[P]review [H]unk' })
|
||||||
end,
|
end,
|
||||||
|
@ -189,6 +195,23 @@ require('lazy').setup({
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{ 'echasnovski/mini.pairs', version = false },
|
||||||
|
|
||||||
|
{
|
||||||
|
"folke/flash.nvim",
|
||||||
|
event = "VeryLazy",
|
||||||
|
---@type Flash.Config
|
||||||
|
opts = {},
|
||||||
|
-- stylua: ignore
|
||||||
|
keys = {
|
||||||
|
{ "s", mode = { "n", "o", "x" }, function() require("flash").jump() end, desc = "Flash" },
|
||||||
|
{ "S", mode = { "n", "o", "x" }, function() require("flash").treesitter() end, desc = "Flash Treesitter" },
|
||||||
|
{ "r", mode = "o", function() require("flash").remote() end, desc = "Remote Flash" },
|
||||||
|
{ "R", mode = { "o", "x" }, function() require("flash").treesitter_search() end, desc = "Treesitter Search" },
|
||||||
|
{ "<c-s>", mode = { "c" }, function() require("flash").toggle() end, desc = "Toggle Flash Search" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
-- Highlight, edit, and navigate code
|
-- Highlight, edit, and navigate code
|
||||||
'nvim-treesitter/nvim-treesitter',
|
'nvim-treesitter/nvim-treesitter',
|
||||||
|
@ -254,6 +277,9 @@ vim.o.completeopt = 'menuone,noselect'
|
||||||
-- NOTE: You should make sure your terminal supports this
|
-- NOTE: You should make sure your terminal supports this
|
||||||
vim.o.termguicolors = true
|
vim.o.termguicolors = true
|
||||||
|
|
||||||
|
-- Center the cursor in the middle of the screen when scrolling
|
||||||
|
vim.o.scrolloff = 999
|
||||||
|
|
||||||
-- [[ Basic Keymaps ]]
|
-- [[ Basic Keymaps ]]
|
||||||
|
|
||||||
-- Keymaps for better default experience
|
-- Keymaps for better default experience
|
||||||
|
@ -439,7 +465,7 @@ local servers = {
|
||||||
-- gopls = {},
|
-- gopls = {},
|
||||||
-- pyright = {},
|
-- pyright = {},
|
||||||
-- rust_analyzer = {},
|
-- rust_analyzer = {},
|
||||||
-- tsserver = {},
|
tsserver = {},
|
||||||
-- html = { filetypes = { 'html', 'twig', 'hbs'} },
|
-- html = { filetypes = { 'html', 'twig', 'hbs'} },
|
||||||
|
|
||||||
lua_ls = {
|
lua_ls = {
|
||||||
|
@ -450,9 +476,13 @@ local servers = {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
require('flash').toggle(false)
|
||||||
|
|
||||||
-- Setup neovim lua configuration
|
-- Setup neovim lua configuration
|
||||||
require('neodev').setup()
|
require('neodev').setup()
|
||||||
|
|
||||||
|
require('mini.pairs').setup()
|
||||||
|
|
||||||
-- nvim-cmp supports additional completion capabilities, so broadcast that to servers
|
-- nvim-cmp supports additional completion capabilities, so broadcast that to servers
|
||||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||||
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
|
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
|
||||||
|
@ -475,6 +505,8 @@ mason_lspconfig.setup_handlers {
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vim.lsp.set_log_level('debug')
|
||||||
|
|
||||||
-- [[ Configure nvim-cmp ]]
|
-- [[ Configure nvim-cmp ]]
|
||||||
-- See `:help cmp`
|
-- See `:help cmp`
|
||||||
local cmp = require 'cmp'
|
local cmp = require 'cmp'
|
||||||
|
|
Loading…
Reference in New Issue