diff options
| author | Elvis Claros Castro <elvis@claros.ar> | 2025-10-30 16:18:36 -0300 |
|---|---|---|
| committer | Elvis Claros Castro <elvis@claros.ar> | 2025-10-30 16:18:36 -0300 |
| commit | d45f8908c35f09ad33e2524fabc8c2dbc9c43d16 (patch) | |
| tree | 870f1dbbc537d34ec33ad2029f54016614dc0b7f /lua | |
| parent | 97811dd201f2f88ff453303d8baa6739616cc9fb (diff) | |
| download | nvim-conf-d45f8908c35f09ad33e2524fabc8c2dbc9c43d16.tar.gz nvim-conf-d45f8908c35f09ad33e2524fabc8c2dbc9c43d16.zip | |
actu
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/config/codecompanion-save.lua | 99 | ||||
| -rw-r--r-- | lua/pi/lsp/servers/asm_lsp.lua | 40 |
2 files changed, 40 insertions, 99 deletions
diff --git a/lua/config/codecompanion-save.lua b/lua/config/codecompanion-save.lua deleted file mode 100644 index 1659b22..0000000 --- a/lua/config/codecompanion-save.lua +++ /dev/null @@ -1,99 +0,0 @@ -local copilot_fn = function() - local copilot_config = { - - schema = { - model = { - default = "claude-3.5-sonnet", - }, - }, - } - return require("codecompanion.adapters").extend("copilot", copilot_config) -end - -local supported_adapters = { - copilot = copilot_fn, -} -local function save_path() - local Path = require("plenary.path") - local p = Path:new(vim.fn.stdpath("data") .. "/cc_saves") - p:mkdir({ parents = true }) - return p -end - ---- Load a saved codecompanion.nvim chat file into a new CodeCompanion chat buffer. ---- Usage: CodeCompanionLoad -vim.api.nvim_create_user_command("CodeCompanionLoad", function() - local fzf = require("fzf-lua") - - local function select_adapter(filepath) - local adapters = vim.tbl_keys(supported_adapters) - - fzf.fzf_exec(adapters, { - prompt = "Select CodeCompanion Adapter> ", - actions = { - ["default"] = function(selected) - local adapter = selected[1] - -- Open new CodeCompanion chat with selected adapter - vim.cmd("CodeCompanionChat " .. adapter) - - -- Read contents of saved chat file - local lines = vim.fn.readfile(filepath) - - -- Get the current buffer (which should be the new CodeCompanion chat) - local current_buf = vim.api.nvim_get_current_buf() - - -- Paste contents into the new chat buffer - vim.api.nvim_buf_set_lines(current_buf, 0, -1, false, lines) - end, - }, - }) - end - - local function start_picker() - local files = vim.fn.glob(save_path() .. "/*", false, true) - - fzf.fzf_exec(files, { - prompt = "Saved CodeCompanion Chats | <c-r>: remove >", - previewer = "builtin", - actions = { - ["default"] = function(selected) - if #selected > 0 then - local filepath = selected[1] - select_adapter(filepath) - end - end, - ["ctrl-r"] = function(selected) - if #selected > 0 then - local filepath = selected[1] - os.remove(filepath) - -- Refresh the picker - start_picker() - end - end, - }, - }) - end - - start_picker() -end, {}) - ---- Save the current codecompanion.nvim chat buffer to a file in the save_folder. ---- Usage: CodeCompanionSave <filename>.md ----@param opts table -vim.api.nvim_create_user_command("CodeCompanionSave", function(opts) - local codecompanion = require("codecompanion") - local success, chat = pcall(function() - return codecompanion.buf_get_chat(0) - end) - if not success or chat == nil then - vim.notify("CodeCompanionSave should only be called from CodeCompanion chat buffers", vim.log.levels.ERROR) - return - end - if #opts.fargs == 0 then - vim.notify("CodeCompanionSave requires at least 1 arg to make a file name", vim.log.levels.ERROR) - end - local save_name = table.concat(opts.fargs, "-") .. ".md" - local save_file = save_path():joinpath(save_name) - local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false) - save_file:write(table.concat(lines, "\n"), "w") -end, { nargs = "*" }) diff --git a/lua/pi/lsp/servers/asm_lsp.lua b/lua/pi/lsp/servers/asm_lsp.lua new file mode 100644 index 0000000..f770b3f --- /dev/null +++ b/lua/pi/lsp/servers/asm_lsp.lua @@ -0,0 +1,40 @@ +local lsp_attach = require "pi.lsp.attach" +local lsp_flags = require "pi.lsp.flags" + +return function(ops) + local capabilities = require("blink.cmp").get_lsp_capabilities(vim.lsp.protocol.make_client_capabilities()) + local config = { + on_attach = function(client, bufnr) + -- Call the default attach function + lsp_attach(client, bufnr) + + -- Disable LSP formatting if asmfmt is available (prefer null-ls formatting) + if vim.fn.executable("asmfmt") == 1 then + client.server_capabilities.documentFormattingProvider = false + client.server_capabilities.documentRangeFormattingProvider = false + end + end, + flags = lsp_flags, + filetypes = { "asm", "s", "S" }, + capabilities = capabilities, + root_dir = function(fname) + local patterns = { "Makefile", "makefile", "GNUmakefile", ".git" } + for _, pattern in ipairs(patterns) do + local found = vim.fs.find(pattern, { + path = fname, + upward = true, + })[1] + if found then + return vim.fs.dirname(found) + end + end + return vim.fn.getcwd() + end, + } + + if vim.fn.executable "asm-lsp" == 1 then + config.cmd = { "asm-lsp" } + end + + return vim.tbl_extend("force", config, ops) +end |