From f1cd9b036f7c16edadf3617215098b3cb21d9cb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9ana=20=E6=B1=9F?= Date: Tue, 8 Jul 2025 23:47:47 +0200 Subject: [PATCH] nvim: move hls to lsp.haskell module --- .config/nvim/ftplugin/haskell.lua | 3 ++ .config/nvim/init.lua | 2 ++ .config/nvim/lua/lsp/haskell.lua | 47 +++++++++++++++++++++++++++++++ .config/nvim/plugin/lsp.lua | 41 --------------------------- 4 files changed, 52 insertions(+), 41 deletions(-) create mode 100644 .config/nvim/lua/lsp/haskell.lua diff --git a/.config/nvim/ftplugin/haskell.lua b/.config/nvim/ftplugin/haskell.lua index ef0c55e6..9a1eb6f3 100644 --- a/.config/nvim/ftplugin/haskell.lua +++ b/.config/nvim/ftplugin/haskell.lua @@ -1,2 +1,5 @@ local opts = require("opts") opts.matchit_let_in() + +vim.bo.shiftwidth = 2 +vim.bo.expandtab = true diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index 5f15d853..50a0b577 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -3,4 +3,6 @@ require("opts") require("_lazy") +require("lsp.haskell") + vim.cmd.colorscheme("curry") diff --git a/.config/nvim/lua/lsp/haskell.lua b/.config/nvim/lua/lsp/haskell.lua new file mode 100644 index 00000000..b578403b --- /dev/null +++ b/.config/nvim/lua/lsp/haskell.lua @@ -0,0 +1,47 @@ +local mylsp = require("lsp") +local border = mylsp.border +local on_attach = mylsp.on_attach + +-- Haskell +vim.g.haskell_tools = { + tools = { + log = { level = vim.log.levels.OFF }, + hover = { + border = border, + stylize_markdown = true, + }, + }, + hls = { + on_attach = function(client, bufnr) + local ht = require("haskell-tools") + local nnoremap = function(bind, callback, userargs) + local args = userargs or {} + args.buffer = bufnr + vim.keymap.set("n", bind, callback, args) + end + + nnoremap("hhe", ht.lsp.buf_eval_all) + nnoremap("hhs", ht.hoogle.hoogle_signature) + nnoremap("hhr", ht.repl.toggle) + + on_attach(client, bufnr) + end, + default_settings = { + haskell = { + checkProject = false, -- PERF: don't check the entire project on initial load + formattingProvider = "fourmolu", + plugin = { + rename = { + config = { + diff = true, -- (experimental) rename across modules + }, + }, + }, + }, + }, + settings = function(project_root) + local ht = require("haskell-tools") + return ht.lsp.load_hls_settings(project_root, { settings_file_pattern = "hls.json" }) + end, + }, +} diff --git a/.config/nvim/plugin/lsp.lua b/.config/nvim/plugin/lsp.lua index 3d9e1bb1..48b1a88a 100644 --- a/.config/nvim/plugin/lsp.lua +++ b/.config/nvim/plugin/lsp.lua @@ -187,47 +187,6 @@ vim.api.nvim_create_autocmd("FileType", { group = nvim_metals_group, }) --- Haskell -vim.g.haskell_tools = { - tools = { - log = { level = vim.log.levels.OFF }, - hover = { - border = border, - stylize_markdown = true, - }, - }, - hls = { - on_attach = function(client, bufnr) - local ht = require("haskell-tools") - local opts = { buffer = bufnr } - - map("n", "hhe", ht.lsp.buf_eval_all, opts) - map("n", "hhs", ht.hoogle.hoogle_signature, opts) - map("n", "hhr", ht.repl.toggle, opts) - - vim.opt_local.shiftwidth = 2 - mylsp.on_attach(client, bufnr) - end, - default_settings = { - haskell = { - checkProject = false, -- PERF: don't check the entire project on initial load - formattingProvider = "fourmolu", - plugin = { - rename = { - config = { - diff = true, -- (experimental) rename across modules - }, - }, - }, - }, - }, - settings = function(project_root) - local ht = require("haskell-tools") - return ht.lsp.load_hls_settings(project_root, { settings_file_pattern = "hls.json" }) - end, - }, -} - ---------- -- Rust -- ----------