mirror of
https://github.com/NotAShelf/nvf.git
synced 2025-02-24 12:28:32 +00:00
kotlin: formatter and linter both work
This commit is contained in:
parent
f8303e101c
commit
c5235ae8fb
1 changed files with 45 additions and 4 deletions
|
@ -6,9 +6,11 @@
|
||||||
}: let
|
}: let
|
||||||
inherit (lib.options) mkEnableOption mkOption;
|
inherit (lib.options) mkEnableOption mkOption;
|
||||||
inherit (lib.modules) mkIf mkMerge;
|
inherit (lib.modules) mkIf mkMerge;
|
||||||
|
inherit (lib.meta) getExe;
|
||||||
|
inherit (lib.nvim.languages) diagnosticsToLua;
|
||||||
inherit (lib.types) package enum;
|
inherit (lib.types) package enum;
|
||||||
inherit (lib.attrsets) attrNames;
|
inherit (lib.attrsets) attrNames;
|
||||||
inherit (lib.nvim.types) mkGrammarOption;
|
inherit (lib.nvim.types) mkGrammarOption diagnostics;
|
||||||
inherit (lib.lists) isList;
|
inherit (lib.lists) isList;
|
||||||
inherit (lib.nvim.lua) expToLua;
|
inherit (lib.nvim.lua) expToLua;
|
||||||
|
|
||||||
|
@ -32,11 +34,11 @@
|
||||||
defaultFormat = "ktlint";
|
defaultFormat = "ktlint";
|
||||||
formats = {
|
formats = {
|
||||||
ktlint = {
|
ktlint = {
|
||||||
package = pkgs.kitlint;
|
package = pkgs.ktlint;
|
||||||
nullConfig = ''
|
nullConfig = ''
|
||||||
table.insert(
|
table.insert(
|
||||||
ls_sources,
|
ls_sources,
|
||||||
null_ls.builtins.formatting.kotlinfmt.with({
|
null_ls.builtins.formatting.ktlint.with({
|
||||||
command = "${cfg.format.package}/bin/ktlint",
|
command = "${cfg.format.package}/bin/ktlint",
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
@ -47,13 +49,27 @@
|
||||||
nullConfig = ''
|
nullConfig = ''
|
||||||
table.insert(
|
table.insert(
|
||||||
ls_sources,
|
ls_sources,
|
||||||
null_ls.builtins.formatting.kotlinfmt.with({
|
null_ls.builtins.formatting.ktlint.with({
|
||||||
command = "${cfg.format.package}/bin/ktfmt",
|
command = "${cfg.format.package}/bin/ktfmt",
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
defaultDiagnosticsProvider = ["ktlint"];
|
||||||
|
diagnosticsProviders = {
|
||||||
|
ktlint = {
|
||||||
|
package = pkgs.ktlint;
|
||||||
|
nullConfig = pkg: ''
|
||||||
|
table.insert(
|
||||||
|
ls_sources,
|
||||||
|
null_ls.builtins.diagnostics.ktlint.with({
|
||||||
|
command = "${getExe pkg}",
|
||||||
|
})
|
||||||
|
)
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
in {
|
in {
|
||||||
options.vim.languages.kotlin = {
|
options.vim.languages.kotlin = {
|
||||||
enable = mkEnableOption "Kotlin/HCL support";
|
enable = mkEnableOption "Kotlin/HCL support";
|
||||||
|
@ -72,6 +88,7 @@ in {
|
||||||
default = kotlinLspWithRuntime;
|
default = kotlinLspWithRuntime;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
format = {
|
format = {
|
||||||
enable = mkEnableOption "Kotlin document formatting" // {default = config.vim.languages.enableFormat;};
|
enable = mkEnableOption "Kotlin document formatting" // {default = config.vim.languages.enableFormat;};
|
||||||
|
|
||||||
|
@ -87,6 +104,16 @@ in {
|
||||||
default = formats.${cfg.format.type}.package;
|
default = formats.${cfg.format.type}.package;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extraDiagnostics = {
|
||||||
|
enable = mkEnableOption "extra Kotlin diagnostics" // {default = config.vim.languages.enableExtraDiagnostics;};
|
||||||
|
|
||||||
|
types = diagnostics {
|
||||||
|
langDesc = "Kotlin";
|
||||||
|
inherit diagnosticsProviders;
|
||||||
|
inherit defaultDiagnosticsProvider;
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
config = mkIf cfg.enable (mkMerge [
|
config = mkIf cfg.enable (mkMerge [
|
||||||
(mkIf cfg.treesitter.enable {
|
(mkIf cfg.treesitter.enable {
|
||||||
|
@ -94,6 +121,20 @@ in {
|
||||||
vim.treesitter.grammars = [cfg.treesitter.package];
|
vim.treesitter.grammars = [cfg.treesitter.package];
|
||||||
})
|
})
|
||||||
|
|
||||||
|
# (mkIf cfg.format.enable {
|
||||||
|
# vim.lsp.null-ls.enable = true;
|
||||||
|
# vim.lsp.null-ls.sources.kotlin-format = formats.${cfg.format.type}.nullConfig;
|
||||||
|
# })
|
||||||
|
|
||||||
|
(mkIf cfg.extraDiagnostics.enable {
|
||||||
|
vim.lsp.null-ls.enable = true;
|
||||||
|
vim.lsp.null-ls.sources = diagnosticsToLua {
|
||||||
|
lang = "ts";
|
||||||
|
config = cfg.extraDiagnostics.types;
|
||||||
|
inherit diagnosticsProviders;
|
||||||
|
};
|
||||||
|
})
|
||||||
|
|
||||||
(mkIf cfg.lsp.enable {
|
(mkIf cfg.lsp.enable {
|
||||||
vim.lsp.lspconfig.enable = true;
|
vim.lsp.lspconfig.enable = true;
|
||||||
vim.lsp.lspconfig.sources.kotlin_language_server = ''
|
vim.lsp.lspconfig.sources.kotlin_language_server = ''
|
||||||
|
|
Loading…
Add table
Reference in a new issue