Added java-jdtls code actions shortcut <leader>ca
This commit is contained in:
parent
d1a6798981
commit
19244408c1
|
|
@ -1,26 +1,53 @@
|
|||
-- print 'Loaded ftplugin/java.lua'
|
||||
---- print 'Loaded ftplugin/java.lua'
|
||||
--local jdtls = require 'jdtls'
|
||||
--
|
||||
--local root_dir = require('jdtls.setup').find_root { '.git', 'mvnw', 'gradlew', 'pom.xml', '.project' }
|
||||
--if root_dir == '' then
|
||||
-- root_dir = vim.fn.getcwd()
|
||||
--end
|
||||
--
|
||||
---- print('JDTLS root_dir = ' .. root_dir)
|
||||
--
|
||||
--local workspace_dir = vim.fn.stdpath 'data' .. '/jdtls-workspace/' .. vim.fn.fnamemodify(root_dir, ':p:h:t')
|
||||
--
|
||||
--local config = {
|
||||
-- cmd = { vim.fn.stdpath 'data' .. '/mason/packages/jdtls/bin/jdtls' },
|
||||
-- root_dir = root_dir,
|
||||
-- workspace_folder = workspace_dir,
|
||||
-- settings = {
|
||||
-- java = {
|
||||
-- project = {
|
||||
-- sourcePaths = { 'src' },
|
||||
-- },
|
||||
-- },
|
||||
-- },
|
||||
--}
|
||||
--
|
||||
--jdtls.start_or_attach(config)
|
||||
local jdtls = require 'jdtls'
|
||||
|
||||
local root_dir = require('jdtls.setup').find_root { '.git', 'mvnw', 'gradlew', 'pom.xml' }
|
||||
local root_dir = require('jdtls.setup').find_root { '.git', 'pom.xml', 'build.gradle' }
|
||||
if root_dir == '' then
|
||||
root_dir = vim.fn.getcwd()
|
||||
end
|
||||
|
||||
print('JDTLS root_dir = ' .. root_dir)
|
||||
|
||||
local workspace_dir = vim.fn.stdpath 'data' .. '/jdtls-workspace/' .. vim.fn.fnamemodify(root_dir, ':p:h:t')
|
||||
|
||||
local config = {
|
||||
cmd = { vim.fn.stdpath 'data' .. '/mason/packages/jdtls/bin/jdtls' }, -- 👈 absolute path
|
||||
root_dir = root_dir,
|
||||
workspace_folder = workspace_dir,
|
||||
settings = {
|
||||
java = {
|
||||
project = {
|
||||
sourcePaths = { 'src' }, -- 👈 tells jdtls where sources begin
|
||||
},
|
||||
},
|
||||
cmd = {
|
||||
vim.fn.stdpath 'data' .. '/mason/packages/jdtls/bin/jdtls',
|
||||
'-data',
|
||||
workspace_dir,
|
||||
},
|
||||
root_dir = root_dir,
|
||||
}
|
||||
|
||||
jdtls.start_or_attach(config)
|
||||
|
||||
-- LSP keymaps (for rename, code actions, etc.)
|
||||
local opts = { buffer = true }
|
||||
vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, vim.tbl_extend('force', opts, { desc = 'LSP: Rename' }))
|
||||
vim.keymap.set('n', '<leader>ca', vim.lsp.buf.code_action, vim.tbl_extend('force', opts, { desc = 'LSP: Code Action' }))
|
||||
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, vim.tbl_extend('force', opts, { desc = 'LSP: Go to Definition' }))
|
||||
vim.keymap.set('n', 'gr', vim.lsp.buf.references, vim.tbl_extend('force', opts, { desc = 'LSP: Find References' }))
|
||||
vim.keymap.set('n', 'K', vim.lsp.buf.hover, vim.tbl_extend('force', opts, { desc = 'LSP: Hover Doc' }))
|
||||
|
|
|
|||
20
init.lua
20
init.lua
|
|
@ -89,7 +89,10 @@ P.S. You can delete this when you're done too. It's your config now! :)
|
|||
-- NOTE: Must happen before plugins are loaded (otherwise wrong leader will be used)
|
||||
vim.g.mapleader = ' '
|
||||
vim.g.maplocalleader = ' '
|
||||
|
||||
-- vim.cmd [[
|
||||
-- syntax enable
|
||||
-- filetype plugin indent on
|
||||
-- ]]
|
||||
-- Set to true if you have a Nerd Font installed and selected in the terminal
|
||||
vim.g.have_nerd_font = false
|
||||
|
||||
|
|
@ -256,7 +259,17 @@ require('lazy').setup({
|
|||
-- keys can be used to configure plugin behavior/loading/etc.
|
||||
--
|
||||
-- Use `opts = {}` to automatically pass options to a plugin's `setup()` function, forcing the plugin to be loaded.
|
||||
--
|
||||
{
|
||||
'fatih/vim-go',
|
||||
build = ':GoInstallBinaries',
|
||||
},
|
||||
{
|
||||
'hrsh7th/nvim-cmp',
|
||||
dependencies = {
|
||||
'hrsh7th/cmp-nvim-lsp',
|
||||
'neovim/nvim-lspconfig',
|
||||
},
|
||||
},
|
||||
|
||||
-- Alternatively, use `config = function() ... end` for full control over the configuration.
|
||||
-- If you prefer to call `setup` explicitly, use:
|
||||
|
|
@ -950,11 +963,12 @@ require('lazy').setup({
|
|||
main = 'nvim-treesitter.configs', -- Sets main module to use for opts
|
||||
-- [[ Configure Treesitter ]] See `:help nvim-treesitter`
|
||||
opts = {
|
||||
ensure_installed = { 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc' },
|
||||
ensure_installed = { 'bash', 'java', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc' },
|
||||
-- Autoinstall languages that are not installed
|
||||
auto_install = true,
|
||||
highlight = {
|
||||
enable = true,
|
||||
disable = { 'java' },
|
||||
-- Some languages depend on vim's regex highlighting system (such as Ruby) for indent rules.
|
||||
-- If you are experiencing weird indenting issues, add the language to
|
||||
-- the list of additional_vim_regex_highlighting and disabled languages for indent.
|
||||
|
|
|
|||
Loading…
Reference in New Issue