Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config/nvim/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@
- 共通 grammar runtime は [modules/neovim.nix](/home/rito528/dotfiles/modules/neovim.nix:1) で `NVIM_TREESITTER_RUNTIME_GLOBAL` として配る
- project 固有 grammar runtime は `templates/*/flake.nix` の `shellHook` で `NVIM_TREESITTER_RUNTIME_PROJECT` として配る
- Neovim 側は [init.lua](/home/rito528/dotfiles/config/nvim/init.lua:1) で両方を `runtimepath` に追加する
- 言語固有の LSP 実行環境は、必要に応じて対応する `templates/*/flake.nix` の dev shell が供給する
- Scala は `templates/seichi-assist/flake.nix` の dev shell で `metals`, `coursier`, `bloop`, `sbt` を揃え、Neovim 側は `nvim-metals` でそれらを利用する
- parser を追加・削除するときは、この判断軸と実際の template の責務が一致しているかを確認する

## 変更時の確認

- `.nix` を変えたら `nixfmt` を実行する
- Home Manager 側の変更は `home-manager build --flake .#testuser` で確認する
- template 側の変更は対応する devShell が評価できることを確認する
- Scala の IDE 機能は `seichi-assist` dev shell 内で Neovim を起動した場合だけを保証する
- Metals 初回起動時は build import や build server 接続に少し時間がかかることがある
- Treesitter の配布先を変えた場合は、この README と関連ドキュメントも更新する
35 changes: 35 additions & 0 deletions config/nvim/lua/config/lsp.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
local M = {}

function M.capabilities()
local base = vim.lsp.protocol.make_client_capabilities()
local ok, blink = pcall(require, "blink.cmp")

if not ok then
return base
end

return blink.get_lsp_capabilities(base)
end

function M.on_attach(_, bufnr)
local map = function(mode, lhs, rhs, desc)
vim.keymap.set(mode, lhs, rhs, {
buffer = bufnr,
silent = true,
desc = desc,
})
end

map("n", "K", vim.lsp.buf.hover, "LSP Hover")
map("n", "gd", vim.lsp.buf.definition, "LSP Definition")
map("n", "gD", vim.lsp.buf.declaration, "LSP Declaration")
map("n", "gi", vim.lsp.buf.implementation, "LSP Implementation")
map("n", "gr", vim.lsp.buf.references, "LSP References")
map("n", "<Leader>rn", vim.lsp.buf.rename, "LSP Rename")
map({ "n", "v" }, "<Leader>ca", vim.lsp.buf.code_action, "LSP Code Action")
map("n", "<Leader>lf", vim.diagnostic.open_float, "Line Diagnostics")
map("n", "[d", vim.diagnostic.goto_prev, "Previous Diagnostic")
map("n", "]d", vim.diagnostic.goto_next, "Next Diagnostic")
end

return M
3 changes: 3 additions & 0 deletions config/nvim/lua/plugins/completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ return {
appearance = {
nerd_font_variant = "mono",
},
sources = {
default = { "lsp", "path", "snippets", "buffer" },
},
completion = {
documentation = {
auto_show = false,
Expand Down
16 changes: 12 additions & 4 deletions config/nvim/lua/plugins/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@ return {
"neovim/nvim-lspconfig",
event = { "BufReadPre", "BufNewFile" },
config = function()
vim.lsp.config("ts_ls", {})
local lsp = require("config.lsp")
local base_config = {
capabilities = lsp.capabilities(),
on_attach = lsp.on_attach,
}

vim.lsp.config("ts_ls", base_config)
vim.lsp.enable("ts_ls")

vim.lsp.config("eslint", {
capabilities = base_config.capabilities,
on_attach = base_config.on_attach,
settings = {
eslint = {
autoFixOnSave = true,
Expand All @@ -15,13 +23,13 @@ return {
})
vim.lsp.enable("eslint")

vim.lsp.config("jsonls", {})
vim.lsp.config("jsonls", base_config)
vim.lsp.enable("jsonls")

vim.lsp.config("rust_analyzer", {})
vim.lsp.config("rust_analyzer", base_config)
vim.lsp.enable("rust_analyzer")

vim.lsp.config("taplo", {})
vim.lsp.config("taplo", base_config)
vim.lsp.enable("taplo")
end,
},
Expand Down
56 changes: 56 additions & 0 deletions config/nvim/lua/plugins/scala.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
return {
{
"scalameta/nvim-metals",
ft = { "scala", "sbt", "java" },
dependencies = {
"nvim-lua/plenary.nvim",
"saghen/blink.cmp",
},
config = function()
if vim.fn.executable("cs") ~= 1 and vim.fn.executable("coursier") ~= 1 then
return
end

if vim.fn.executable("bloop") ~= 1 then
return
end

local lsp = require("config.lsp")
local metals = require("metals")
local metals_config = metals.bare_config()

metals_config.capabilities = lsp.capabilities()
metals_config.init_options = vim.tbl_deep_extend("force", metals_config.init_options or {}, {
statusBarProvider = "on",
})
metals_config.settings = {
showImplicitArguments = true,
showInferredType = true,
}
metals_config.on_attach = function(client, bufnr)
local map = function(mode, lhs, rhs, desc)
vim.keymap.set(mode, lhs, rhs, {
buffer = bufnr,
silent = true,
desc = desc,
})
end

lsp.on_attach(client, bufnr)
map("n", "<Leader>mi", "<Cmd>MetalsImportBuild<CR>", "Metals Import Build")
map("n", "<Leader>md", "<Cmd>MetalsRunDoctor<CR>", "Metals Doctor")
map("n", "<Leader>mr", "<Cmd>MetalsRestartBuild<CR>", "Metals Restart Build Server")
end

local group = vim.api.nvim_create_augroup("nvim-metals", { clear = true })

vim.api.nvim_create_autocmd("FileType", {
group = group,
pattern = { "scala", "sbt", "java" },
callback = function()
metals.initialize_or_attach(metals_config)
end,
})
end,
},
}
3 changes: 3 additions & 0 deletions templates/seichi-assist/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@
{
devShells.${system}.default = pkgs.mkShell {
buildInputs = [
pkgs.bloop
pkgs.coursier
pkgs.jdk17
pkgs.sbt
pkgs.metals
pkgs.scalafmt
pkgs.stdenv.cc.cc.lib
];
shellHook = ''
export JAVA_HOME="${pkgs.jdk17}"
export NVIM_TREESITTER_RUNTIME_PROJECT="${treesitterRuntime}"
export LD_LIBRARY_PATH="${pkgs.stdenv.cc.cc.lib}/lib''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
'';
Expand Down
Loading