my configuration
This commit is contained in:
parent
58f2dbab70
commit
dc9f6a8b1f
97
init.lua
97
init.lua
|
@ -110,7 +110,11 @@ require('lazy').setup({
|
|||
},
|
||||
|
||||
-- Useful plugin to show you pending keybinds.
|
||||
{ 'folke/which-key.nvim', opts = {} },
|
||||
{
|
||||
'folke/which-key.nvim',
|
||||
opts = {}
|
||||
},
|
||||
|
||||
{
|
||||
-- Adds git related signs to the gutter, as well as utilities for managing changes
|
||||
'lewis6991/gitsigns.nvim',
|
||||
|
@ -218,8 +222,8 @@ require('lazy').setup({
|
|||
-- NOTE: Next Step on Your Neovim Journey: Add/Configure additional "plugins" for kickstart
|
||||
-- These are some example plugins that I've included in the kickstart repository.
|
||||
-- Uncomment any of the lines below to enable them.
|
||||
-- require 'kickstart.plugins.autoformat',
|
||||
-- require 'kickstart.plugins.debug',
|
||||
require 'kickstart.plugins.autoformat',
|
||||
require 'kickstart.plugins.debug',
|
||||
|
||||
-- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua`
|
||||
-- You can use this folder to prevent any conflicts with this init.lua if you're interested in keeping
|
||||
|
@ -227,7 +231,7 @@ require('lazy').setup({
|
|||
-- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going.
|
||||
--
|
||||
-- For additional information see: https://github.com/folke/lazy.nvim#-structuring-your-plugins
|
||||
-- { import = 'custom.plugins' },
|
||||
{ import = 'custom.plugins' },
|
||||
}, {})
|
||||
|
||||
-- [[ Setting options ]]
|
||||
|
@ -241,13 +245,32 @@ vim.o.hlsearch = false
|
|||
vim.wo.number = true
|
||||
|
||||
-- Enable mouse mode
|
||||
vim.o.mouse = 'a'
|
||||
vim.o.mouse = false
|
||||
|
||||
-- Sync clipboard between OS and Neovim.
|
||||
-- Remove this option if you want your OS clipboard to remain independent.
|
||||
-- See `:help 'clipboard'`
|
||||
vim.o.clipboard = 'unnamedplus'
|
||||
-- vim.o.clipboard = 'unnamedplus'
|
||||
--- Copy-paste
|
||||
vim.keymap.set('v', '<leader>p', '"_dP')
|
||||
vim.keymap.set('n', '<leader>y', '"+y')
|
||||
vim.keymap.set('v', '<leader>y', '"+y')
|
||||
vim.keymap.set('n', '<leader>Y', 'gg"+yG')
|
||||
vim.keymap.set('n', '<leader>d', '"_d')
|
||||
vim.keymap.set('v', '<leader>d', '"_d')
|
||||
|
||||
vim.g.clipboard = {
|
||||
name= 'WslClipboard',
|
||||
copy= {
|
||||
['+'] = 'clip.exe',
|
||||
['*'] = 'clip.exe',
|
||||
},
|
||||
paste = {
|
||||
['+'] = 'powershell.exe -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))',
|
||||
['*'] = 'powershell.exe -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))',
|
||||
},
|
||||
cache_enabled= 0,
|
||||
}
|
||||
-- Enable break indent
|
||||
vim.o.breakindent = true
|
||||
|
||||
|
@ -296,6 +319,8 @@ vim.api.nvim_create_autocmd('TextYankPost', {
|
|||
-- See `:help telescope` and `:help telescope.setup()`
|
||||
require('telescope').setup {
|
||||
defaults = {
|
||||
path_display = { shorten = { len = 3, exclude = { 1, 2, 3, -3, -2, -1 } } },
|
||||
|
||||
mappings = {
|
||||
i = {
|
||||
['<C-u>'] = false,
|
||||
|
@ -333,7 +358,7 @@ vim.keymap.set('n', '<leader>sr', require('telescope.builtin').resume, { desc =
|
|||
vim.defer_fn(function()
|
||||
require('nvim-treesitter.configs').setup {
|
||||
-- Add languages to be installed here that you want installed for treesitter
|
||||
ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'tsx', 'javascript', 'typescript', 'vimdoc', 'vim', 'bash' },
|
||||
ensure_installed = { 'java', 'go', 'lua', 'python', 'rust', 'javascript', 'vimdoc', 'vim', 'bash' },
|
||||
|
||||
-- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!)
|
||||
auto_install = false,
|
||||
|
@ -403,50 +428,7 @@ vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, { desc = 'Open float
|
|||
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', require('telescope.builtin').lsp_implementations, '[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
|
||||
|
||||
local lsp_settings = require('lsp.keymap')
|
||||
-- document existing key chains
|
||||
require('which-key').register {
|
||||
['<leader>c'] = { name = '[C]ode', _ = 'which_key_ignore' },
|
||||
|
@ -478,7 +460,6 @@ local servers = {
|
|||
-- rust_analyzer = {},
|
||||
-- tsserver = {},
|
||||
-- html = { filetypes = { 'html', 'twig', 'hbs'} },
|
||||
|
||||
lua_ls = {
|
||||
Lua = {
|
||||
workspace = { checkThirdParty = false },
|
||||
|
@ -498,14 +479,22 @@ capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
|
|||
local mason_lspconfig = require 'mason-lspconfig'
|
||||
|
||||
mason_lspconfig.setup {
|
||||
ensure_installed = vim.tbl_keys(servers),
|
||||
ensure_installed = vim.list_extend(vim.tbl_keys(servers), { "jdtls" })
|
||||
}
|
||||
|
||||
mason_lspconfig.setup_handlers {
|
||||
function(server_name)
|
||||
if server_name == 'jdtls' then
|
||||
-- disable jdtls config from lspconfig. jdtls will be configured by nvim-jdtls since it much more powerful
|
||||
require('lspconfig')[server_name].setup = function()
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
-- enable language servers for all other
|
||||
require('lspconfig')[server_name].setup {
|
||||
capabilities = capabilities,
|
||||
on_attach = on_attach,
|
||||
on_attach = lsp_settings.on_attach,
|
||||
settings = servers[server_name],
|
||||
filetypes = (servers[server_name] or {}).filetypes,
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
return {
|
||||
"windwp/nvim-autopairs",
|
||||
-- Optional dependency
|
||||
dependencies = { 'hrsh7th/nvim-cmp' },
|
||||
config = function()
|
||||
require("nvim-autopairs").setup {}
|
||||
-- If you want to automatically add `(` after selecting a function or method
|
||||
local cmp_autopairs = require('nvim-autopairs.completion.cmp')
|
||||
local cmp = require('cmp')
|
||||
cmp.event:on(
|
||||
'confirm_done',
|
||||
cmp_autopairs.on_confirm_done()
|
||||
)
|
||||
end,
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
-- Unless you are still migrating, remove the deprecated commands from v1.x
|
||||
vim.cmd([[ let g:neo_tree_remove_legacy_commands = 1 ]])
|
||||
|
||||
return {
|
||||
"nvim-neo-tree/neo-tree.nvim",
|
||||
version = "*",
|
||||
dependencies = {
|
||||
"nvim-lua/plenary.nvim",
|
||||
"nvim-tree/nvim-web-devicons", -- not strictly required, but recommended
|
||||
"MunifTanjim/nui.nvim",
|
||||
},
|
||||
config = function ()
|
||||
require('neo-tree').setup {
|
||||
filesystem = {
|
||||
hide_by_pattern = { -- uses glob style patterns
|
||||
--"*.meta",
|
||||
--"*/src/*/tsconfig.json",
|
||||
"*/dk/nykredit/*"
|
||||
},
|
||||
follow_current_file = {
|
||||
enabled = true, -- This will find and focus the file in the active buffer every time
|
||||
leave_dirs_open = false
|
||||
}
|
||||
}
|
||||
}
|
||||
end,
|
||||
}
|
|
@ -0,0 +1,169 @@
|
|||
return {
|
||||
|
||||
-- correctly setup mason lsp / dap extensions
|
||||
-- {
|
||||
-- "williamboman/mason.nvim",
|
||||
-- opts = function(_, opts)
|
||||
-- vim.list_extend(opts.ensure_installed, {"jdtls", "java-test", "java-debug-adapter" })
|
||||
-- end,
|
||||
-- },
|
||||
{
|
||||
"mfussenegger/nvim-jdtls",
|
||||
ft = "java",
|
||||
config = function()
|
||||
local home = os.getenv('HOME')
|
||||
local mason_registry = require("mason-registry")
|
||||
local jdtls_pkg = mason_registry.get_package("jdtls")
|
||||
local jdtls_path = jdtls_pkg:get_install_path()
|
||||
local jdtls_bin = jdtls_path .. "/bin/jdtls"
|
||||
|
||||
local java_test_pkg = mason_registry.get_package("java-test")
|
||||
local java_test_path = java_test_pkg:get_install_path()
|
||||
|
||||
local java_dbg_pkg = mason_registry.get_package("java-debug-adapter")
|
||||
local java_dbg_path = java_dbg_pkg:get_install_path()
|
||||
|
||||
local vscode_java_test_path = home .. "/.config/nvim/vscode-java-test"
|
||||
|
||||
local jar_patterns = {
|
||||
java_dbg_path .. "/extension/server/com.microsoft.java.debug.plugin-*.jar",
|
||||
java_test_path .. "/extension/server/*.jar",
|
||||
vscode_java_test_path .. "/*.jar"
|
||||
}
|
||||
|
||||
local bundles = {}
|
||||
for _, jar_pattern in ipairs(jar_patterns) do
|
||||
for _, bundle in ipairs(vim.split(vim.fn.glob(jar_pattern), '\n')) do
|
||||
table.insert(bundles, bundle)
|
||||
end
|
||||
end
|
||||
|
||||
local settings = {
|
||||
java = {
|
||||
signatureHelp = { enabled = true },
|
||||
contentProvider = { preferred = 'fernflower' },
|
||||
completion = {
|
||||
favoriteStaticMembers = {
|
||||
"org.hamcrest.MatcherAssert.assertThat",
|
||||
"org.hamcrest.Matchers.*",
|
||||
"org.hamcrest.CoreMatchers.*",
|
||||
"org.junit.jupiter.api.Assertions.*",
|
||||
"java.util.Objects.requireNonNull",
|
||||
"java.util.Objects.requireNonNullElse",
|
||||
"org.mockito.Mockito.*"
|
||||
}
|
||||
},
|
||||
sources = {
|
||||
organizeImports = {
|
||||
starThreshold = 9999,
|
||||
staticStarThreshold = 9999,
|
||||
},
|
||||
},
|
||||
codeGeneration = {
|
||||
toString = {
|
||||
template = "${object.className}{${member.name()}=${member.value}, ${otherMembers}}"
|
||||
}
|
||||
},
|
||||
maven = {
|
||||
downloadSources = true,
|
||||
},
|
||||
import = {
|
||||
maven = {
|
||||
enabled = true,
|
||||
},
|
||||
},
|
||||
configuration = {
|
||||
runtimes = {
|
||||
{
|
||||
name = "JavaSE-1.8",
|
||||
path = "/usr/lib/jvm/java-8-openjdk-amd64",
|
||||
},
|
||||
{
|
||||
name = "JavaSE-11",
|
||||
path = "/usr/lib/jvm/java-11-openjdk-amd64",
|
||||
default = true,
|
||||
},
|
||||
{
|
||||
name = "JavaSE-17",
|
||||
path = "/usr/lib/jvm/java-17-openjdk-amd64",
|
||||
},
|
||||
-- {
|
||||
-- name = "JavaSE-19",
|
||||
-- path = "/usr/lib/jvm/java-19-openjdk-amd64",
|
||||
-- },
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
local function print_test_results(items)
|
||||
if #items > 0 then
|
||||
vim.cmd([[Trouble quickfix]])
|
||||
else
|
||||
vim.cmd([[TroubleClose quickfix]])
|
||||
end
|
||||
end
|
||||
|
||||
local extendedClientCapabilities = require('jdtls').extendedClientCapabilities
|
||||
extendedClientCapabilities.resolveAdditionalTextEditsSupport = true
|
||||
extendedClientCapabilities.progressReportProvider = false
|
||||
|
||||
|
||||
local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":p:h:t")
|
||||
-- calculate workspace dir
|
||||
local workspace_folder = home .. "/.cache/jdtls/workspace/" .. project_name
|
||||
|
||||
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
||||
|
||||
local on_attach = function(_, buffer)
|
||||
require('lsp.keymap').on_attach(_, buffer)
|
||||
|
||||
-- custom keymaps
|
||||
vim.keymap.set("n", "<leader>co", function() require("jdtls").organize_imports() end,
|
||||
{ buffer = buffer, desc = "LSP: Organize Imports" })
|
||||
|
||||
vim.keymap.set("n", "<leader>ct",
|
||||
function() require("jdtls").pick_test({ bufnr = buffer, after_test = print_test_results }) end,
|
||||
{ buffer = buffer, desc = "LSP: Run Test" })
|
||||
require("jdtls").setup_dap({ hotcodereplace = "auto" })
|
||||
require("jdtls.dap").setup_dap_main_class_configs()
|
||||
end
|
||||
|
||||
-- get the mason install path
|
||||
local config = {
|
||||
init_options = {
|
||||
bundles = bundles,
|
||||
extendedClientCapabilities = extendedClientCapabilities,
|
||||
},
|
||||
cmd = {
|
||||
jdtls_bin,
|
||||
"--jvm-arg=-javaagent:" .. jdtls_path .. "/lombok.jar",
|
||||
"-data",
|
||||
workspace_folder,
|
||||
},
|
||||
-- attach general lsp 'on_attach function'
|
||||
-- on_attach = require("lsp.keymap").on_attach,
|
||||
on_attach = on_attach,
|
||||
capabilities = capabilities,
|
||||
-- we naively believe that the whole project is versioned through git, and therefore
|
||||
root_dir = vim.fs.dirname(
|
||||
vim.fs.find({ ".git" }, { upward = true })[1]
|
||||
),
|
||||
settings = settings,
|
||||
flags = {
|
||||
allow_incremental_sync = true,
|
||||
},
|
||||
on_init = function(client, _)
|
||||
client.notify('workspace/didChangeConfiguration', { settings = settings })
|
||||
end,
|
||||
}
|
||||
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = "java",
|
||||
callback = function()
|
||||
require("jdtls").start_or_attach(config)
|
||||
end,
|
||||
})
|
||||
end,
|
||||
}
|
||||
}
|
|
@ -50,6 +50,11 @@ return {
|
|||
return
|
||||
end
|
||||
|
||||
-- disable auto format for java
|
||||
if client.name == 'jdtls' then
|
||||
return
|
||||
end
|
||||
|
||||
-- Create an autocmd that will run *before* we save the buffer.
|
||||
-- Run the formatting command for the LSP that has just attached.
|
||||
vim.api.nvim_create_autocmd('BufWritePre', {
|
||||
|
|
|
@ -29,6 +29,7 @@ return {
|
|||
-- Makes a best effort to setup the various debuggers with
|
||||
-- reasonable debug configurations
|
||||
automatic_setup = true,
|
||||
automatic_installation = true,
|
||||
|
||||
-- You can provide additional configuration to the handlers,
|
||||
-- see mason-nvim-dap README for more information
|
||||
|
@ -38,7 +39,8 @@ return {
|
|||
-- online, please don't ask me how to install them :)
|
||||
ensure_installed = {
|
||||
-- Update this to ensure that you have the debuggers for the langs you want
|
||||
'delve',
|
||||
'java-test',
|
||||
'java-debug-adapter',
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
|
||||
|
||||
-- This function gets run when an LSP connects to a particular buffer.
|
||||
return {
|
||||
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', require('telescope.builtin').lsp_implementations, '[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
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
/home/jfw/.dotfiles/nvim/dependencies/java/vscode-java-test
|
Loading…
Reference in New Issue