mirror of
https://github.com/NotAShelf/neovim-flake.git
synced 2024-11-07 20:35:59 +01:00
languages/kotlin: init (#390)
* 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>
This commit is contained in:
parent
7dbd1cd8d1
commit
c0790c5494
4 changed files with 111 additions and 0 deletions
|
@ -51,6 +51,7 @@ isMaximal: {
|
|||
css.enable = isMaximal;
|
||||
sql.enable = isMaximal;
|
||||
java.enable = isMaximal;
|
||||
kotlin.enable = isMaximal;
|
||||
ts.enable = isMaximal;
|
||||
svelte.enable = isMaximal;
|
||||
go.enable = isMaximal;
|
||||
|
|
|
@ -259,6 +259,8 @@ everyone.
|
|||
- Add LSP and Treesitter support for R under `vim.languages.R`.
|
||||
- Add Otter support under `vim.lsp.otter` and an assert to prevent conflict with
|
||||
ccc
|
||||
- Add LSP, diagnostics, formatter and Treesitter support for Kotlin under
|
||||
`vim.languages.kotlin`
|
||||
|
||||
[Bloxx12](https://github.com/Bloxx12)
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ in {
|
|||
./css.nix
|
||||
./elixir.nix
|
||||
./go.nix
|
||||
./kotlin.nix
|
||||
./html.nix
|
||||
./java.nix
|
||||
./lua.nix
|
||||
|
|
107
modules/plugins/languages/kotlin.nix
Normal file
107
modules/plugins/languages/kotlin.nix
Normal file
|
@ -0,0 +1,107 @@
|
|||
{
|
||||
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"}''
|
||||
},
|
||||
}
|
||||
'';
|
||||
})
|
||||
]);
|
||||
}
|
Loading…
Reference in a new issue