From 7db92a3485281caa70d72fe5b31d442d6d75ec6e Mon Sep 17 00:00:00 2001 From: Dane Sabo Date: Wed, 19 Feb 2025 20:13:14 -0500 Subject: [PATCH] updates --- lua/custom/chadrc.lua | 2 +- lua/custom/configs/lspconfig.lua | 18 +++++++- lua/custom/init.lua | 2 +- .../language_specific_commands/matlab.lua | 43 +++++++++++++++++++ lua/custom/mappings.lua | 2 + lua/custom/plugins.lua | 2 + lua/plugins/configs/treesitter.lua | 2 +- 7 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 lua/custom/language_specific_commands/matlab.lua diff --git a/lua/custom/chadrc.lua b/lua/custom/chadrc.lua index 7031f55..8903a5f 100644 --- a/lua/custom/chadrc.lua +++ b/lua/custom/chadrc.lua @@ -1,7 +1,7 @@ ---@type ChadrcConfig local M = {} -M.ui = { theme = 'melange' } +M.ui = { theme = 'oceanic-light' } M.plugins = 'custom.plugins' M.mappings = require "custom.mappings" return M diff --git a/lua/custom/configs/lspconfig.lua b/lua/custom/configs/lspconfig.lua index f5fa3aa..f025bb3 100644 --- a/lua/custom/configs/lspconfig.lua +++ b/lua/custom/configs/lspconfig.lua @@ -2,7 +2,7 @@ local config = require("plugins.configs.lspconfig") local on_attach = function(client, bufnr) config.on_attach(client, bufnr) - + -- Keybinding to show hover documentation vim.api.nvim_buf_set_keymap(bufnr, 'n', 'h', 'lua vim.lsp.buf.hover()', { noremap = true, silent = true }) @@ -19,7 +19,7 @@ local lspconfig = require("lspconfig") local servers = { "pyright", - "ruff_lsp", + "ruff_lsp" } for _, lsp in ipairs(servers) do @@ -38,6 +38,20 @@ for _, lsp in ipairs(servers) do }) end +lspconfig.hls.setup{ + on_attach = on_attach, + capabilities = capabilities, + filetypes = {'haskell', 'lhaskell', 'cabal'} +} + + + +lspconfig.matlab_ls.setup{ + on_attach = on_attach, + capabilities = capabilities, + filetypes = {'matlab'} +} + -- Function to show diagnostics on hover vim.api.nvim_create_autocmd("CursorHold", { callback = function() diff --git a/lua/custom/init.lua b/lua/custom/init.lua index 05416e6..749d7f1 100644 --- a/lua/custom/init.lua +++ b/lua/custom/init.lua @@ -1,2 +1,2 @@ vim.g.dap_virtual_text = false - +vim.env.PATH = vim.env.PATH .. ":/home/danesabo/.ghcup/bin" diff --git a/lua/custom/language_specific_commands/matlab.lua b/lua/custom/language_specific_commands/matlab.lua new file mode 100644 index 0000000..f8cf44a --- /dev/null +++ b/lua/custom/language_specific_commands/matlab.lua @@ -0,0 +1,43 @@ +-- Global variables to store the MATLAB terminal buffer and job ID +local matlab_term_buf = nil +local matlab_term_job = nil + +-- Create the "RunMatlab" user command +vim.api.nvim_create_user_command("RunMatlab", function() + -- Get the absolute path of the current file + local file = vim.fn.expand("%:p") + -- Escape single quotes by doubling them for MATLAB's string literal. + local matlab_file = file:gsub("'", "''") + -- Construct the command to run MATLAB in batch mode, executing the current file. + local cmd = 'matlab -batch "run(\'' .. matlab_file .. '\')"' + + -- If we already have a MATLAB terminal and it's valid, reuse it. + if matlab_term_buf and vim.api.nvim_buf_is_valid(matlab_term_buf) and matlab_term_job then + -- Check if the terminal buffer is visible in any window. + local wins = vim.fn.win_findbuf(matlab_term_buf) + if #wins == 0 then + -- If not visible, open it in a vertical split. + vim.cmd("split") + vim.cmd("buffer " .. matlab_term_buf) + else + -- Otherwise, switch focus to that window. + vim.api.nvim_set_current_win(wins[1]) + end + -- Send the MATLAB command to the terminal. (You can add a clear command here if desired.) + vim.api.nvim_chan_send(matlab_term_job, cmd .. "\n") + else + -- If the MATLAB terminal doesn't exist, open a new vertical split terminal. + vim.cmd("split") + vim.cmd("terminal") + -- Store the terminal buffer and job ID for future reuse. + matlab_term_buf = vim.api.nvim_get_current_buf() + matlab_term_job = vim.b.terminal_job_id + -- Optionally, rename the terminal buffer for clarity. + vim.api.nvim_buf_set_name(matlab_term_buf, "MATLAB Output") + -- Send the MATLAB command to run the current file. + vim.api.nvim_chan_send(matlab_term_job, cmd .. "\n") + end +end, {}) + +-- Map +r+m (i.e. rm) to run the MATLAB code +vim.keymap.set("n", "rm", ":RunMatlab", { noremap = true, silent = true }) diff --git a/lua/custom/mappings.lua b/lua/custom/mappings.lua index e2acf4b..b4876cd 100644 --- a/lua/custom/mappings.lua +++ b/lua/custom/mappings.lua @@ -27,4 +27,6 @@ M.crates = { } } +require("custom.language_specific_commands.matlab") + return M diff --git a/lua/custom/plugins.lua b/lua/custom/plugins.lua index cc23f7b..b529284 100644 --- a/lua/custom/plugins.lua +++ b/lua/custom/plugins.lua @@ -6,6 +6,8 @@ local plugins = { opts = { ensure_installed = { "rust-analyzer", + "haskell-language-server", + "matlab-language-server", }, }, }, diff --git a/lua/plugins/configs/treesitter.lua b/lua/plugins/configs/treesitter.lua index 1da6a99..1514f7c 100644 --- a/lua/plugins/configs/treesitter.lua +++ b/lua/plugins/configs/treesitter.lua @@ -1,5 +1,5 @@ local options = { - ensure_installed = { "lua", "vim", "vimdoc","c","rust"}, + ensure_installed = { "lua", "vim", "vimdoc","c","rust","haskell", "matlab", "tlaplus"}, highlight = { enable = true,