diff --git a/configuration.nix b/configuration.nix index b21b26aa..e5b9c65a 100644 --- a/configuration.nix +++ b/configuration.nix @@ -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; diff --git a/docs/release-notes/rl-0.7.md b/docs/release-notes/rl-0.7.md index bb9f3d36..a21baadb 100644 --- a/docs/release-notes/rl-0.7.md +++ b/docs/release-notes/rl-0.7.md @@ -28,10 +28,11 @@ configuration formats. ### `vim.maps` rewrite {#sec-vim-maps-rewrite} -Instead of specifying map modes using submodules (eg.: `vim.maps.normal`), a new `vim.keymaps` -submodule with support for a `mode` option has been introduced. It can be either a string, or a -list of strings, where a string represents the short-name of the map mode(s), that the mapping -should be set for. See `:help map-modes` for more information. +Instead of specifying map modes using submodules (eg.: `vim.maps.normal`), a new +`vim.keymaps` submodule with support for a `mode` option has been introduced. It +can be either a string, or a list of strings, where a string represents the +short-name of the map mode(s), that the mapping should be set for. See +`:help map-modes` for more information. For example: @@ -62,7 +63,6 @@ Note that we are looking to add more alternatives in the future like dressing.nvim and actions-preview.nvim, in case fastaction doesn't work for everyone. - ## Changelog {#sec-release-0.7-changelog} [ItsSorae](https://github.com/ItsSorae): @@ -150,12 +150,15 @@ everyone. - Replace `vim.lsp.nvimCodeActionMenu` with `vim.ui.fastaction`, see the breaking changes section above for more details -- Add a `setupOpts` option to nvim-surround, which allows modifying options that aren't defined in nvf. Move the alternate nvim-surround keybinds to use `setupOpts`. +- Add a `setupOpts` option to nvim-surround, which allows modifying options that + aren't defined in nvf. Move the alternate nvim-surround keybinds to use + `setupOpts`. [Neovim documentation on `vim.cmd`]: https://neovim.io/doc/user/lua.html#vim.cmd() - Make Neovim's configuration file entirely Lua based. This comes with a few breaking changes: + - `vim.configRC` has been removed. You will need to migrate your entries to Neovim-compliant Lua code, and add them to `vim.luaConfigRC` instead. Existing vimscript configurations may be preserved in `vim.cmd` functions. @@ -242,10 +245,11 @@ 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) - Add support for [base16 theming](https://github.com/RRethy/base16-nvim) under `vim.theme` - Fix internal breakage in `elixir-tools` setup. - diff --git a/modules/plugins/languages/default.nix b/modules/plugins/languages/default.nix index 28c1fd8f..b46d992c 100644 --- a/modules/plugins/languages/default.nix +++ b/modules/plugins/languages/default.nix @@ -8,6 +8,7 @@ in { ./css.nix ./elixir.nix ./go.nix + ./kotlin.nix ./html.nix ./java.nix ./lua.nix diff --git a/modules/plugins/languages/kotlin.nix b/modules/plugins/languages/kotlin.nix new file mode 100644 index 00000000..8faf19f4 --- /dev/null +++ b/modules/plugins/languages/kotlin.nix @@ -0,0 +1,111 @@ +{ + config, + pkgs, + lib, + ... +}: let + inherit (lib.options) mkEnableOption mkOption; + 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; + + # Creating a version of the LSP with access to the kotlin binary. + # This is necessary for the LSP to load the standard library + kotlinLspWithRuntime = pkgs.symlinkJoin { + name = "kotlin-language-server-with-runtime"; + paths = [ + pkgs.kotlin-language-server + pkgs.kotlin + ]; + buildInputs = [pkgs.makeWrapper]; + postBuild = '' + wrapProgram $out/bin/kotlin-language-server \ + --prefix PATH : ${pkgs.lib.makeBinPath [pkgs.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 (kotlin_language_server)" // {default = config.vim.languages.enableLSP;}; + + package = mkOption { + description = "kotlin_language_server package with Kotlin runtime"; + type = package; + default = kotlinLspWithRuntime; + }; + }; + + 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 = "ts"; + 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"}'' + }, + } + ''; + }) + ]); +}