mirror of
https://github.com/NotAShelf/neovim-flake.git
synced 2024-11-08 21:45:57 +01:00
c0790c5494
* merge * created otter file merge * update merge * update merge * committing flake.lock merge * merge * haskell: added LSP and treesitter * haskell: default to isMaximal * haskell: haskell support * kotlin: LSP and treesitter * haskell: LSP cmd definition * haskell: LSP cmd definition (currently broken) * kotlin: LSP and treesitter working * removing haskell from kotlin branch * merge * merge * kotlin: capitalisation * kotlin: implemented formatter * kotlin: cleanup * kotlin: formatter and linter both work * kotlin: cleanup * kotlin: massive speedup in loadtimes for lsp * otter: cleanup * kotlin: changelog entry * flake.lock: reverting accidental formatting * kotlin: removed redundant description * kotlin: fixed typo * kotlin: using symlinkjoin better * kotlin: moved wrapper to example * kotlin: cleaning up and fixing docs render --------- Co-authored-by: raf <raf@notashelf.dev>
107 lines
3.1 KiB
Nix
107 lines
3.1 KiB
Nix
{
|
|
config,
|
|
pkgs,
|
|
lib,
|
|
...
|
|
}: let
|
|
inherit (lib.options) mkEnableOption mkOption literalExpression;
|
|
inherit (lib.modules) mkIf mkMerge;
|
|
inherit (lib.meta) getExe;
|
|
inherit (lib.nvim.languages) diagnosticsToLua;
|
|
inherit (lib.types) package;
|
|
inherit (lib.nvim.types) mkGrammarOption diagnostics;
|
|
inherit (lib.lists) isList;
|
|
inherit (lib.nvim.lua) expToLua;
|
|
|
|
cfg = config.vim.languages.kotlin;
|
|
|
|
defaultDiagnosticsProvider = ["ktlint"];
|
|
diagnosticsProviders = {
|
|
ktlint = {
|
|
package = pkgs.ktlint;
|
|
nullConfig = pkg: ''
|
|
table.insert(
|
|
ls_sources,
|
|
null_ls.builtins.diagnostics.ktlint.with({
|
|
command = "${getExe pkg}",
|
|
})
|
|
)
|
|
'';
|
|
};
|
|
};
|
|
in {
|
|
options.vim.languages.kotlin = {
|
|
enable = mkEnableOption "Kotlin/HCL support";
|
|
|
|
treesitter = {
|
|
enable = mkEnableOption "Kotlin treesitter" // {default = config.vim.languages.enableTreesitter;};
|
|
package = mkGrammarOption pkgs "kotlin";
|
|
};
|
|
|
|
lsp = {
|
|
enable = mkEnableOption "Kotlin LSP support" // {default = config.vim.languages.enableLSP;};
|
|
|
|
package = mkOption {
|
|
description = "kotlin_language_server package with Kotlin runtime";
|
|
type = package;
|
|
example = literalExpression ''
|
|
pkgs.symlinkJoin {
|
|
name = "kotlin-language-server-wrapped";
|
|
paths = [pkgs.kotlin-language-server];
|
|
nativeBuildInputs = [pkgs.makeWrapper];
|
|
postBuild = '''
|
|
wrapProgram $out/bin/kotlin-language-server \
|
|
--prefix PATH : ''${pkgs.kotlin}/bin
|
|
''';
|
|
};
|
|
'';
|
|
default = pkgs.kotlin-language-server;
|
|
};
|
|
};
|
|
|
|
extraDiagnostics = {
|
|
enable = mkEnableOption "extra Kotlin diagnostics" // {default = config.vim.languages.enableExtraDiagnostics;};
|
|
|
|
types = diagnostics {
|
|
langDesc = "Kotlin";
|
|
inherit diagnosticsProviders;
|
|
inherit defaultDiagnosticsProvider;
|
|
};
|
|
};
|
|
};
|
|
config = mkIf cfg.enable (mkMerge [
|
|
(mkIf cfg.treesitter.enable {
|
|
vim.treesitter.enable = true;
|
|
vim.treesitter.grammars = [cfg.treesitter.package];
|
|
})
|
|
|
|
(mkIf cfg.extraDiagnostics.enable {
|
|
vim.lsp.null-ls.enable = true;
|
|
vim.lsp.null-ls.sources = diagnosticsToLua {
|
|
lang = "kotlin";
|
|
config = cfg.extraDiagnostics.types;
|
|
inherit diagnosticsProviders;
|
|
};
|
|
})
|
|
|
|
(mkIf cfg.lsp.enable {
|
|
vim.lsp.lspconfig.enable = true;
|
|
vim.lsp.lspconfig.sources.kotlin_language_server = ''
|
|
lspconfig.kotlin_language_server.setup {
|
|
capabilities = capabilities,
|
|
root_dir = lspconfig.util.root_pattern("main.kt", ".git"),
|
|
on_attach=default_on_attach,
|
|
init_options = {
|
|
-- speeds up the startup time for the LSP
|
|
storagePath = vim.fn.stdpath('state') .. '/kotlin',
|
|
},
|
|
cmd = ${
|
|
if isList cfg.lsp.package
|
|
then expToLua cfg.lsp.package
|
|
else ''{"${cfg.lsp.package}/bin/kotlin-language-server"}''
|
|
},
|
|
}
|
|
'';
|
|
})
|
|
]);
|
|
}
|