mirror of
https://github.com/NotAShelf/nvf.git
synced 2026-05-12 18:29:24 +00:00
languages/java: refactor lsp.servers to use lsp/presets/<name>
This commit is contained in:
parent
6d075667e7
commit
d6035ff6bc
2 changed files with 13 additions and 140 deletions
|
|
@ -93,6 +93,8 @@
|
||||||
|
|
||||||
- Renamed `jsonls` to `vscode-json-language-server`.
|
- Renamed `jsonls` to `vscode-json-language-server`.
|
||||||
|
|
||||||
|
- Renamed `jdtls` to `jdt-language-server`.
|
||||||
|
|
||||||
- Removed `languages.tailwind` which only provided an LSP. Use
|
- Removed `languages.tailwind` which only provided an LSP. Use
|
||||||
`lsp.presets.tailwindcss-language-server` instead.
|
`lsp.presets.tailwindcss-language-server` instead.
|
||||||
|
|
||||||
|
|
@ -228,6 +230,7 @@
|
||||||
{command}`:healthcheck` doesn't know that.
|
{command}`:healthcheck` doesn't know that.
|
||||||
- Remove [which-key.nvim] `<leader>o` `+Notes` description which did not
|
- Remove [which-key.nvim] `<leader>o` `+Notes` description which did not
|
||||||
actually correspond to any keybinds.
|
actually correspond to any keybinds.
|
||||||
|
|
||||||
- Allow disabling nvf's vendored keymaps by toggling `vendoredKeymaps.enable`.
|
- Allow disabling nvf's vendored keymaps by toggling `vendoredKeymaps.enable`.
|
||||||
|
|
||||||
[pyrox0](https://github.com/pyrox0):
|
[pyrox0](https://github.com/pyrox0):
|
||||||
|
|
|
||||||
|
|
@ -6,60 +6,14 @@
|
||||||
}: let
|
}: let
|
||||||
inherit (lib.options) literalExpression mkEnableOption mkOption;
|
inherit (lib.options) literalExpression mkEnableOption mkOption;
|
||||||
inherit (lib.modules) mkIf mkMerge;
|
inherit (lib.modules) mkIf mkMerge;
|
||||||
inherit (lib.meta) getExe;
|
inherit (lib) genAttrs;
|
||||||
inherit (builtins) attrNames;
|
|
||||||
inherit (lib.types) listOf enum;
|
inherit (lib.types) listOf enum;
|
||||||
inherit (lib.nvim.types) mkGrammarOption;
|
inherit (lib.nvim.types) mkGrammarOption;
|
||||||
inherit (lib.nvim.attrsets) mapListToAttrs;
|
|
||||||
inherit (lib.nvim.dag) entryBefore;
|
|
||||||
inherit (lib.generators) mkLuaInline;
|
|
||||||
|
|
||||||
cfg = config.vim.languages.java;
|
cfg = config.vim.languages.java;
|
||||||
|
|
||||||
defaultServers = ["jdtls"];
|
defaultServers = ["jdt-language-server"];
|
||||||
servers = {
|
servers = ["jdt-language-server"];
|
||||||
jdtls = {
|
|
||||||
enable = true;
|
|
||||||
cmd =
|
|
||||||
mkLuaInline
|
|
||||||
/*
|
|
||||||
lua
|
|
||||||
*/
|
|
||||||
''
|
|
||||||
{
|
|
||||||
'${getExe pkgs.jdt-language-server}',
|
|
||||||
'-configuration',
|
|
||||||
get_jdtls_config_dir(),
|
|
||||||
'-data',
|
|
||||||
get_jdtls_workspace_dir(),
|
|
||||||
get_jdtls_jvm_args(),
|
|
||||||
}
|
|
||||||
'';
|
|
||||||
filetypes = ["java"];
|
|
||||||
root_markers = [
|
|
||||||
# Multi-module projects
|
|
||||||
".git"
|
|
||||||
"build.gradle"
|
|
||||||
"build.gradle.kts"
|
|
||||||
# Single-module projects
|
|
||||||
"build.xml" # Ant
|
|
||||||
"pom.xml" # Maven
|
|
||||||
"settings.gradle" # Gradle
|
|
||||||
"settings.gradle.kts" # Gradle
|
|
||||||
];
|
|
||||||
init_options = {
|
|
||||||
workspace = mkLuaInline "get_jdtls_workspace_dir()";
|
|
||||||
jvm_args = {};
|
|
||||||
os_config = mkLuaInline "nil";
|
|
||||||
};
|
|
||||||
handlers = {
|
|
||||||
"textDocument/codeAction" = mkLuaInline "jdtls_on_textdocument_codeaction";
|
|
||||||
"textDocument/rename" = mkLuaInline "jdtls_on_textdocument_rename";
|
|
||||||
"workspace/applyEdit" = mkLuaInline "jdtls_on_workspace_applyedit";
|
|
||||||
"language/status" = mkLuaInline "vim.schedule_wrap(jdtls_on_language_status)";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
in {
|
in {
|
||||||
options.vim.languages.java = {
|
options.vim.languages.java = {
|
||||||
enable = mkEnableOption "Java language support";
|
enable = mkEnableOption "Java language support";
|
||||||
|
|
@ -82,7 +36,7 @@ in {
|
||||||
defaultText = literalExpression "config.vim.lsp.enable";
|
defaultText = literalExpression "config.vim.lsp.enable";
|
||||||
};
|
};
|
||||||
servers = mkOption {
|
servers = mkOption {
|
||||||
type = listOf (enum (attrNames servers));
|
type = listOf (enum servers);
|
||||||
default = defaultServers;
|
default = defaultServers;
|
||||||
description = "Java LSP server to use";
|
description = "Java LSP server to use";
|
||||||
};
|
};
|
||||||
|
|
@ -91,96 +45,12 @@ in {
|
||||||
|
|
||||||
config = mkIf cfg.enable (mkMerge [
|
config = mkIf cfg.enable (mkMerge [
|
||||||
(mkIf cfg.lsp.enable {
|
(mkIf cfg.lsp.enable {
|
||||||
vim.luaConfigRC.jdtls-util =
|
vim.lsp = {
|
||||||
entryBefore ["lsp-servers"]
|
presets = genAttrs cfg.lsp.servers (_: {enable = true;});
|
||||||
/*
|
servers = genAttrs cfg.lsp.servers (_: {
|
||||||
lua
|
filetypes = ["java"];
|
||||||
*/
|
});
|
||||||
''
|
};
|
||||||
local jdtls_handlers = require 'vim.lsp.handlers'
|
|
||||||
|
|
||||||
local jdtls_env = {
|
|
||||||
HOME = vim.uv.os_homedir(),
|
|
||||||
XDG_CACHE_HOME = os.getenv 'XDG_CACHE_HOME',
|
|
||||||
JDTLS_JVM_ARGS = os.getenv 'JDTLS_JVM_ARGS',
|
|
||||||
}
|
|
||||||
|
|
||||||
local function get_cache_dir()
|
|
||||||
return jdtls_env.XDG_CACHE_HOME and jdtls_env.XDG_CACHE_HOME or jdtls_env.HOME .. '/.cache'
|
|
||||||
end
|
|
||||||
|
|
||||||
local function get_jdtls_cache_dir()
|
|
||||||
return get_cache_dir() .. '/jdtls'
|
|
||||||
end
|
|
||||||
|
|
||||||
local function get_jdtls_config_dir()
|
|
||||||
return get_jdtls_cache_dir() .. '/config'
|
|
||||||
end
|
|
||||||
|
|
||||||
local function get_jdtls_workspace_dir()
|
|
||||||
return get_jdtls_cache_dir() .. '/workspace'
|
|
||||||
end
|
|
||||||
|
|
||||||
local function get_jdtls_jvm_args()
|
|
||||||
local args = {}
|
|
||||||
for a in string.gmatch((jdtls_env.JDTLS_JVM_ARGS or '''), '%S+') do
|
|
||||||
local arg = string.format('--jvm-arg=%s', a)
|
|
||||||
table.insert(args, arg)
|
|
||||||
end
|
|
||||||
return unpack(args)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- TextDocument version is reported as 0, override with nil so that
|
|
||||||
-- the client doesn't think the document is newer and refuses to update
|
|
||||||
-- See: https://github.com/eclipse/eclipse.jdt.ls/issues/1695
|
|
||||||
local function jdtls_fix_zero_version(workspace_edit)
|
|
||||||
if workspace_edit and workspace_edit.documentChanges then
|
|
||||||
for _, change in pairs(workspace_edit.documentChanges) do
|
|
||||||
local text_document = change.textDocument
|
|
||||||
if text_document and text_document.version and text_document.version == 0 then
|
|
||||||
text_document.version = nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return workspace_edit
|
|
||||||
end
|
|
||||||
|
|
||||||
local function jdtls_on_textdocument_codeaction(err, actions, ctx)
|
|
||||||
for _, action in ipairs(actions) do
|
|
||||||
-- TODO: (steelsojka) Handle more than one edit?
|
|
||||||
if action.command == 'java.apply.workspaceEdit' then -- 'action' is Command in java format
|
|
||||||
action.edit = jdtls_fix_zero_version(action.edit or action.arguments[1])
|
|
||||||
elseif type(action.command) == 'table' and action.command.command == 'java.apply.workspaceEdit' then -- 'action' is CodeAction in java format
|
|
||||||
action.edit = jdtls_fix_zero_version(action.edit or action.command.arguments[1])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
jdtls_handlers[ctx.method](err, actions, ctx)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function jdtls_on_textdocument_rename(err, workspace_edit, ctx)
|
|
||||||
jdtls_handlers[ctx.method](err, jdtls_fix_zero_version(workspace_edit), ctx)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function jdtls_on_workspace_applyedit(err, workspace_edit, ctx)
|
|
||||||
jdtls_handlers[ctx.method](err, jdtls_fix_zero_version(workspace_edit), ctx)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Non-standard notification that can be used to display progress
|
|
||||||
local function jdtls_on_language_status(_, result)
|
|
||||||
local command = vim.api.nvim_command
|
|
||||||
command 'echohl ModeMsg'
|
|
||||||
command(string.format('echo "%s"', result.message))
|
|
||||||
command 'echohl None'
|
|
||||||
end
|
|
||||||
'';
|
|
||||||
|
|
||||||
vim.lsp.servers =
|
|
||||||
mapListToAttrs (n: {
|
|
||||||
name = n;
|
|
||||||
value = servers.${n};
|
|
||||||
})
|
|
||||||
cfg.lsp.servers;
|
|
||||||
})
|
})
|
||||||
|
|
||||||
(mkIf cfg.treesitter.enable {
|
(mkIf cfg.treesitter.enable {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue