From 67dafbaf6c3a24268182d4c614c2bc7b56d68177 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sascha=20L=C3=BCdecke?= Date: Wed, 30 Oct 2024 20:40:56 +0100 Subject: [PATCH] Sonic-Pi send visual selection and integration, luasnip TAB jumps insert positions --- init.lua | 1 + lua/config/nvim-cmp.lua | 2 ++ lua/functions.lua | 15 +++++++++++++++ lua/lsp.lua | 2 +- lua/plugins.lua | 12 +++++++----- 5 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 lua/functions.lua diff --git a/init.lua b/init.lua index 4f24273..0f12221 100644 --- a/init.lua +++ b/init.lua @@ -1,5 +1,6 @@ -- load configurations files from lua/* require('options') +require('functions') require('plugins') require('colorscheme') require('lsp') diff --git a/lua/config/nvim-cmp.lua b/lua/config/nvim-cmp.lua index c740300..6d2014e 100644 --- a/lua/config/nvim-cmp.lua +++ b/lua/config/nvim-cmp.lua @@ -33,6 +33,8 @@ cmp.setup({ -- Hint: if the completion menu is visible select next one if cmp.visible() then cmp.select_next_item() + elseif luasnip.jumpable(1) then + luasnip.jump(1) elseif has_words_before() then cmp.complete() else diff --git a/lua/functions.lua b/lua/functions.lua new file mode 100644 index 0000000..9342e82 --- /dev/null +++ b/lua/functions.lua @@ -0,0 +1,15 @@ +-- custom defined functions + +-- Return the currently, visually selected text range +function SL_get_visual_selection() + vim.cmd([[ execute "normal! \" ]]) + local s_start = vim.fn.getcharpos("'<") + local s_end = vim.fn.getcharpos("'>") + vim.cmd([[ execute "normal! gv" ]]) + + local current_buffer = vim.api.nvim_get_current_buf() + local r = vim.api.nvim_buf_get_text(current_buffer, s_start[2] - 1, s_start[3] - 1, + s_end[2] - 1, s_end[3], {}) + -- print("region might be", current_buffer, s_start[2], s_start[3], s_end[2], s_end[3]) + return table.concat(r, "\n") +end diff --git a/lua/lsp.lua b/lua/lsp.lua index 6d7cbeb..9d47a40 100644 --- a/lua/lsp.lua +++ b/lua/lsp.lua @@ -90,7 +90,7 @@ require('mason-lspconfig').setup_handlers({ on_attach = on_attach, config = { on_init = function(client) - require('sonicpi').lsp_on_init(client, { server_dir = '/opt/sonic-pi/app/server' }) + require('sonicpi').lsp_on_init(client, {}) end }, filetypes = { 'ruby', 'sonicpi' }, diff --git a/lua/plugins.lua b/lua/plugins.lua index 22daadf..b963bd5 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -447,13 +447,12 @@ require("lazy").setup({ end, }, - -- -- Live Coding: sonic-pi music programming + -- Live Coding: sonic-pi music programming { 'magicmonty/sonicpi.nvim', - -- broken if used here, setup called further below config = function() require('sonicpi').setup({ - server_dir = '/opt/sonic-pi/app/server', + -- server_dir = '/opt/sonic-pi/app/server', lsp_diagnostics = true, mappings = { { 'n', 'd', ':SonicPiStartDaemon', { desc = 'Sonic Pi: start daemon' } }, @@ -463,8 +462,11 @@ require("lazy").setup({ { 'i', '', require('sonicpi.remote').run_current_buffer, { desc = 'Sonic Pi: run' } }, { 'n', 'R', ':SonicPiSendBuffer', { desc = 'Sonic Pi: send buffer' } }, { 'i', '', ':SonicPiSendBuffer', { desc = 'Sonic Pi: send buffer' } }, - -- // TODO.2024-10-29 implement sending of tree-sitter node - { 'n', '', function() end, { desc = 'Sonic Pi: send current' } }, + { 'v', 's', require('sonicpi.remote').stop, { desc = 'Sonic Pi: stop' } }, + { 'v', 'v', + function() + require('sonicpi.remote').run_code(SL_get_visual_selection()) + end, { desc = 'Sonic Pi: send visual range' } } }, single_file = true, })