Compare commits

...

6 commits

Author SHA1 Message Date
ksonj
4858a6998c
Merge 78a52d75ca into 618e709276 2024-10-06 00:24:36 +02:00
618e709276
docs: update 0.7 release notes 2024-10-06 01:18:04 +03:00
90fbfe1d6c
meta: improve github pull request template 2024-10-06 01:16:18 +03:00
ksonj
78a52d75ca
Merge branch 'main' into scala-support 2024-10-05 18:27:15 +02:00
Kalle Jepsen
7c5122abb0 Format 2024-10-05 16:12:19 +02:00
Kalle Jepsen
aa236a7f7e languages/scala: Add scala language support
Adds LSP support for Scala via nvim-metals
2024-10-05 16:09:55 +02:00
7 changed files with 212 additions and 25 deletions

View file

@ -1,39 +1,56 @@
# Description <!--
^ Please include a clear and concise description of the aim of your Pull Request above this line ^
A clear and concise description of the aim of your Pull Request. For plugin dependency/module additions, please make sure to link the source link of the added plugin
or dependency in this section.
**If your pull request aims to fix an open issue or a present bug, please link the relevant issue below. If not, please remove this section** If your pull request aims to fix an open issue or a please bug, please also link the relevant issue
Fixes #(issue) below this line. You may attach an issue to your pull request with `Fixes #<issue number>` outside
this comment.
-->
## Type of change ## Type of change
Please delete any options that are not relevant. <!--
Please check all that apply. This section is not a hard requirement, but it helps prioritize critical pull requests
for reviewers and contributors.
-->
- Bug fix (non-breaking change which fixes an issue) - [ ] Bug fix (**non-breaking** change which fixes an issue)
- New feature (non-breaking change which adds functionality) - [ ] New feature (**non-breaking** change which adds functionality)
- Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Breaking change (fix or feature that would cause existing functionality to
- Translation/Language update not work as expected)
- Docs - [ ] Translation/Language update
- Other - [ ] Changes to module documentation or the nvf manual (`docs/manual`)
- [ ] Other
## Checklist ## Sanity Checking
Please try to check at least a majority of the checklist before opening your pull request. Exceptions to this will be reviewed on a case by case basis. <!--
Please check all that apply. As before, this section is not a hard requirement but checklists with more checked
items are likely to be merged faster. You may save some time in maintainer review by performing self-reviews here
before submitting your pull request.
-->
- [ ] My code follows the style and contributing guidelines of this project. - [ ] My code follows the style and contributing guidelines of this project.
- [ ] I ran Alejandra to format my code (`nix fmt`). - [ ] I ran Alejandra to format my code (`nix fmt`).
- [ ] My code conforms to the `Editorconfig` styles in the project root.
- [ ] I have performed a self-review of my own code and tested it. - [ ] I have performed a self-review of my own code and tested it.
- Package(s) built:
- [ ] `.#nix`
- [ ] `.#maximal`
- [ ] `.#docs-html`
- [ ] I have commented my code, particularly in hard-to-understand areas. - [ ] I have commented my code, particularly in hard-to-understand areas.
- [ ] My changes generate no new warnings. - [ ] My changes generate no new errors or warnings.
- [ ] This change requires a documentation update. - [ ] This change requires a documentation update.
- [ ] I have updated the documentation accordingly. - [ ] I have have added a change-log entry (see `docs/manual/release-notes`).
- If new changes are particularly complex:
- [ ] I have added a section in the manual.
- [ ] (For breaking changes) I have included a migration guide..
## Screenshots & Logs ---
You are kindly requested to attach screenshots of your changes in actions and preferably your build/run logs for all available packages. If you are not sure how to do this, you can refer to the [documentation](https://notashelf.github.io/neovim-flake/). Add a :+1: [reaction] to [pull requests you find important].
**Please do not use any external image service. Instead, just paste in or drag and drop the image here, and it will be uploaded automatically.** [reaction]: https://github.blog/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/
[pull requests you find important]: https://github.com/NixOS/nixpkgs/pulls?q=is%3Aopen+sort%3Areactions-%2B1-desc
```console
# Paste your logs here
```

View file

@ -68,6 +68,7 @@ isMaximal: {
lsp.server = "clangd"; lsp.server = "clangd";
}; };
scala.enable = isMaximal;
rust = { rust = {
enable = isMaximal; enable = isMaximal;
crates.enable = isMaximal; crates.enable = isMaximal;

View file

@ -89,7 +89,8 @@ everyone.
- Add [new-file-template.nvim] to automatically fill new file contents using - Add [new-file-template.nvim] to automatically fill new file contents using
templates templates
- Make [neo-tree.nvim] display file icons properly by enabling `visuals.nvimWebDevicons` - Make [neo-tree.nvim] display file icons properly by enabling
`visuals.nvimWebDevicons`
[diniamo](https://github.com/diniamo): [diniamo](https://github.com/diniamo):
@ -206,8 +207,12 @@ everyone.
- Fixed `project-nvim` command and keybinding - Fixed `project-nvim` command and keybinding
- Added default ikeybind/command for `Telescope resume` (`<leader>fr`) - Added default ikeybind/command for `Telescope resume` (`<leader>fr`)
[Soliprem](https://github.com/Soliprem) [Soliprem](https://github.com/Soliprem):
- Add LSP and Treesitter support for R under `vim.languages.R`. - 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 - Add Otter support under `vim.lsp.otter` and an assert to prevent conflict with
ccc ccc
[Bloxx12](https://github.com/Bloxx12):
- Fix internal breakage in `elixir-tools` setup.

17
flake.lock generated
View file

@ -1149,6 +1149,22 @@
"type": "github" "type": "github"
} }
}, },
"plugin-nvim-metals": {
"flake": false,
"locked": {
"lastModified": 1728033462,
"narHash": "sha256-XqOkZ/5eex1mrNUf6vrJjDjibBbb0bSMYSciKAoVD0A=",
"owner": "ksonj",
"repo": "nvim-metals",
"rev": "4d86c32f6c028de197e28dab0f6a0250c0d1c16a",
"type": "github"
},
"original": {
"owner": "ksonj",
"repo": "nvim-metals",
"type": "github"
}
},
"plugin-nvim-navbuddy": { "plugin-nvim-navbuddy": {
"flake": false, "flake": false,
"locked": { "locked": {
@ -1863,6 +1879,7 @@
"plugin-nvim-docs-view": "plugin-nvim-docs-view", "plugin-nvim-docs-view": "plugin-nvim-docs-view",
"plugin-nvim-lightbulb": "plugin-nvim-lightbulb", "plugin-nvim-lightbulb": "plugin-nvim-lightbulb",
"plugin-nvim-lspconfig": "plugin-nvim-lspconfig", "plugin-nvim-lspconfig": "plugin-nvim-lspconfig",
"plugin-nvim-metals": "plugin-nvim-metals",
"plugin-nvim-navbuddy": "plugin-nvim-navbuddy", "plugin-nvim-navbuddy": "plugin-nvim-navbuddy",
"plugin-nvim-navic": "plugin-nvim-navic", "plugin-nvim-navic": "plugin-nvim-navic",
"plugin-nvim-neoclip": "plugin-nvim-neoclip", "plugin-nvim-neoclip": "plugin-nvim-neoclip",

View file

@ -206,6 +206,11 @@
flake = false; flake = false;
}; };
plugin-nvim-metals = {
url = "github:ksonj/nvim-metals";
flake = false;
};
# Copying/Registers # Copying/Registers
plugin-registers = { plugin-registers = {
url = "github:tversteeg/registers.nvim"; url = "github:tversteeg/registers.nvim";

View file

@ -19,6 +19,7 @@ in {
./python.nix ./python.nix
./r.nix ./r.nix
./rust.nix ./rust.nix
./scala.nix
./sql.nix ./sql.nix
./svelte.nix ./svelte.nix
./tailwind.nix ./tailwind.nix

View file

@ -0,0 +1,141 @@
{
config,
pkgs,
lib,
...
}: let
inherit (lib) types optionalString;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.nvim.types) mkGrammarOption;
inherit (lib.nvim.binds) mkMappingOption;
inherit (lib.options) mkOption mkEnableOption;
inherit (lib.nvim.dag) entryAfter;
mkBinding = binding: "vim.api.nvim_buf_set_keymap(bufnr, 'n', '${binding.value}', '<cmd>lua ${binding.action}<CR>', {noremap=true, silent=true, desc='${binding.description}'})";
listCommandsBinding = {
value = cfg.lsp.extraMappings.listCommands;
description = "List Metals commands";
action =
if config.vim.telescope.enable
then ''require("telescope").extensions.metals.commands()''
else ''require("metals").commands()'';
};
cfg = config.vim.languages.scala;
usingDap = config.vim.debugger.nvim-dap.enable && cfg.dap.enable;
usingLualine = config.vim.statusline.lualine.enable;
in {
options.vim.languages.scala = {
enable = mkEnableOption "Scala language support";
treesitter = {
enable = mkEnableOption "Scala treesitter" // {default = config.vim.languages.enableTreesitter;};
package = mkGrammarOption pkgs "scala";
};
lsp = {
enable = mkEnableOption "Scala LSP support (metals)" // {default = config.vim.languages.enableLSP;};
package = mkOption {
type = types.package;
default = pkgs.metals;
description = ''
metals package to use
'';
};
extraMappings = {
listCommands = mkMappingOption "List Metals commands" "<leader>lc";
};
};
dap = {
enable = mkOption {
description = "Scala Debug Adapter support";
type = types.bool;
default = config.vim.languages.enableDAP;
};
config = mkOption {
description = "Lua configuration for dap";
type = types.str;
default = ''
dap.configurations.scala = {
{
type = "scala",
request = "launch",
name = "RunOrTest",
metals = {
runType = "runOrTestFile",
--args = { "firstArg", "secondArg", "thirdArg" }, -- here just as an example
},
},
{
type = "scala",
request = "launch",
name = "Test Target",
metals = {
runType = "testTarget",
},
},
}
'';
};
};
};
config = mkIf cfg.enable (
mkMerge [
(mkIf cfg.treesitter.enable {
vim.treesitter.enable = true;
vim.treesitter.grammars = [cfg.treesitter.package];
})
(mkIf (cfg.lsp.enable || cfg.dap.enable) {
vim = {
startPlugins = ["nvim-metals"];
luaConfigRC.nvim-metals = entryAfter ["lsp-setup"] ''
-- Scala nvim-metals config
local metals_caps = capabilities -- from lsp-setup
local attach_metals_keymaps = function(client, bufnr)
attach_keymaps(client, bufnr) -- from lsp-setup
${mkBinding listCommandsBinding}
end
metals_config = require('metals').bare_config()
${optionalString usingLualine "metals_config.init_options.statusBarProvider = 'on'"}
metals_config.capabilities = metals_caps
metals_config.on_attach = function(client, bufnr)
${optionalString usingDap "require('metals').setup_dap()"}
attach_metals_keymaps(client, bufnr)
end
metals_config.settings = {
metalsBinaryPath = "${cfg.lsp.package}/bin/metals",
showImplicitArguments = true,
showImplicitConversionsAndClasses = true,
showInferredType = true,
excludedPackages = {
"akka.actor.typed.javadsl",
"com.github.swagger.akka.javadsl"
},
}
metals_config.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
vim.lsp.diagnostic.on_publish_diagnostics, {
virtual_text = {
prefix = '',
}
}
)
-- without doing this, autocommands that deal with filetypes prohibit messages from being shown
vim.opt_global.shortmess:remove("F")
vim.cmd([[augroup lsp]])
vim.cmd([[autocmd!]])
vim.cmd([[autocmd FileType java,scala,sbt lua require('metals').initialize_or_attach(metals_config)]])
vim.cmd([[augroup end]])
'';
};
})
]
);
}