mirror of
https://github.com/NotAShelf/nvf.git
synced 2025-02-24 12:28:32 +00:00
Apply suggested improvements
This commit is contained in:
parent
78a52d75ca
commit
9d02a48553
3 changed files with 28 additions and 31 deletions
10
flake.lock
generated
10
flake.lock
generated
|
@ -1152,15 +1152,15 @@
|
||||||
"plugin-nvim-metals": {
|
"plugin-nvim-metals": {
|
||||||
"flake": false,
|
"flake": false,
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1728033462,
|
"lastModified": 1728295172,
|
||||||
"narHash": "sha256-XqOkZ/5eex1mrNUf6vrJjDjibBbb0bSMYSciKAoVD0A=",
|
"narHash": "sha256-ja/+MNxZ3H9io9jDwm5rhE6iKNi86a22eCOY75g19O8=",
|
||||||
"owner": "ksonj",
|
"owner": "scalameta",
|
||||||
"repo": "nvim-metals",
|
"repo": "nvim-metals",
|
||||||
"rev": "4d86c32f6c028de197e28dab0f6a0250c0d1c16a",
|
"rev": "f861db9fda55939797ac1b05238c49b0dcdc3bdb",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "ksonj",
|
"owner": "scalameta",
|
||||||
"repo": "nvim-metals",
|
"repo": "nvim-metals",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
|
|
|
@ -207,7 +207,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
plugin-nvim-metals = {
|
plugin-nvim-metals = {
|
||||||
url = "github:ksonj/nvim-metals";
|
url = "github:scalameta/nvim-metals";
|
||||||
flake = false;
|
flake = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -4,23 +4,17 @@
|
||||||
lib,
|
lib,
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
inherit (lib) types optionalString;
|
inherit (lib) types optionalString mkPackageOption;
|
||||||
inherit (lib.modules) mkIf mkMerge;
|
inherit (lib.modules) mkIf mkMerge;
|
||||||
inherit (lib.nvim.types) mkGrammarOption;
|
inherit (lib.nvim.types) mkGrammarOption;
|
||||||
inherit (lib.nvim.binds) mkMappingOption;
|
inherit (lib.nvim.binds) mkMappingOption;
|
||||||
inherit (lib.options) mkOption mkEnableOption;
|
inherit (lib.options) mkOption mkEnableOption;
|
||||||
inherit (lib.nvim.dag) entryAfter;
|
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}'})";
|
listCommandsAction =
|
||||||
|
|
||||||
listCommandsBinding = {
|
|
||||||
value = cfg.lsp.extraMappings.listCommands;
|
|
||||||
description = "List Metals commands";
|
|
||||||
action =
|
|
||||||
if config.vim.telescope.enable
|
if config.vim.telescope.enable
|
||||||
then ''require("telescope").extensions.metals.commands()''
|
then ''require("telescope").extensions.metals.commands()''
|
||||||
else ''require("metals").commands()'';
|
else ''require("metals").commands()'';
|
||||||
};
|
|
||||||
|
|
||||||
cfg = config.vim.languages.scala;
|
cfg = config.vim.languages.scala;
|
||||||
|
|
||||||
|
@ -29,23 +23,22 @@
|
||||||
in {
|
in {
|
||||||
options.vim.languages.scala = {
|
options.vim.languages.scala = {
|
||||||
enable = mkEnableOption "Scala language support";
|
enable = mkEnableOption "Scala language support";
|
||||||
|
|
||||||
treesitter = {
|
treesitter = {
|
||||||
enable = mkEnableOption "Scala treesitter" // {default = config.vim.languages.enableTreesitter;};
|
enable = mkEnableOption "Scala treesitter" // {default = config.vim.languages.enableTreesitter;};
|
||||||
package = mkGrammarOption pkgs "scala";
|
package = mkGrammarOption pkgs "scala";
|
||||||
};
|
};
|
||||||
|
|
||||||
lsp = {
|
lsp = {
|
||||||
enable = mkEnableOption "Scala LSP support (metals)" // {default = config.vim.languages.enableLSP;};
|
enable = mkEnableOption "Scala LSP support (metals)" // {default = config.vim.languages.enableLSP;};
|
||||||
package = mkOption {
|
package = mkPackageOption pkgs "metals" {
|
||||||
type = types.package;
|
default = ["metals"];
|
||||||
default = pkgs.metals;
|
|
||||||
description = ''
|
|
||||||
metals package to use
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
extraMappings = {
|
extraMappings = {
|
||||||
listCommands = mkMappingOption "List Metals commands" "<leader>lc";
|
listCommands = mkMappingOption "List Metals commands" "<leader>lc";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
dap = {
|
dap = {
|
||||||
enable = mkOption {
|
enable = mkOption {
|
||||||
description = "Scala Debug Adapter support";
|
description = "Scala Debug Adapter support";
|
||||||
|
@ -79,6 +72,7 @@ in {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable (
|
config = mkIf cfg.enable (
|
||||||
mkMerge [
|
mkMerge [
|
||||||
(mkIf cfg.treesitter.enable {
|
(mkIf cfg.treesitter.enable {
|
||||||
|
@ -88,13 +82,12 @@ in {
|
||||||
(mkIf (cfg.lsp.enable || cfg.dap.enable) {
|
(mkIf (cfg.lsp.enable || cfg.dap.enable) {
|
||||||
vim = {
|
vim = {
|
||||||
startPlugins = ["nvim-metals"];
|
startPlugins = ["nvim-metals"];
|
||||||
luaConfigRC.nvim-metals = entryAfter ["lsp-setup"] ''
|
pluginRC.nvim-metals = entryAfter ["lsp-setup"] ''
|
||||||
-- Scala nvim-metals config
|
|
||||||
local metals_caps = capabilities -- from lsp-setup
|
local metals_caps = capabilities -- from lsp-setup
|
||||||
|
|
||||||
local attach_metals_keymaps = function(client, bufnr)
|
local attach_metals_keymaps = function(client, bufnr)
|
||||||
attach_keymaps(client, bufnr) -- from lsp-setup
|
attach_keymaps(client, bufnr) -- from lsp-setup
|
||||||
${mkBinding listCommandsBinding}
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', '${cfg.lsp.extraMappings.listCommands}', '<cmd>lua ${listCommandsAction}<CR>', {noremap=true, silent=true, desc='Show all Metals commands'})
|
||||||
end
|
end
|
||||||
|
|
||||||
metals_config = require('metals').bare_config()
|
metals_config = require('metals').bare_config()
|
||||||
|
@ -125,14 +118,18 @@ in {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
-- without doing this, autocommands that deal with filetypes prohibit messages from being shown
|
-- without doing this, autocommands that deal with filetypes prohibit messages from being shown
|
||||||
vim.opt_global.shortmess:remove("F")
|
vim.opt_global.shortmess:remove("F")
|
||||||
|
|
||||||
vim.cmd([[augroup lsp]])
|
local lsp_group = vim.api.nvim_create_augroup('lsp', { clear = true })
|
||||||
vim.cmd([[autocmd!]])
|
|
||||||
vim.cmd([[autocmd FileType java,scala,sbt lua require('metals').initialize_or_attach(metals_config)]])
|
vim.api.nvim_create_autocmd('FileType', {
|
||||||
vim.cmd([[augroup end]])
|
group = lsp_group,
|
||||||
|
pattern = {'java', 'scala', 'sbt'},
|
||||||
|
callback = function()
|
||||||
|
require('metals').initialize_or_attach(metals_config)
|
||||||
|
end,
|
||||||
|
})
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Reference in a new issue