Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LazyNvim #9

Open
Yggdrasill501 opened this issue May 21, 2024 · 6 comments
Open

LazyNvim #9

Yggdrasill501 opened this issue May 21, 2024 · 6 comments

Comments

@Yggdrasill501
Copy link

Yggdrasill501 commented May 21, 2024

Hey I would like to make this work with more package managers for example Lazy, I just wanted to ask if it is welcomed and what are some contributing guideline’s ?

Also I am sorry if it does not belong here but i didn't see anything like forum etc...
Btw amazing implementation. 🫡🥺

@igorgue
Copy link

igorgue commented Sep 13, 2024

@Yggdrasill501 do you have a config?

@sluedecke
Copy link

This is my snippet for lazy.nvim:

require("lazy").setup({

...

  -- Live Coding: sonic-pi music programming
  {
    'magicmonty/sonicpi.nvim',
    config = function()
      require('sonicpi').setup({
        server_dir = '/opt/sonic-pi/app/server',
        lsp_diagnostics = true,
        mappings = {
          { 'n', '<leader>d', ':SonicPiStartDaemon<CR>',                    { desc = 'Sonic Pi: start daemon' } },
          { 'n', '<leader>s', require('sonicpi.remote').stop,               { desc = 'Sonic Pi: stop' } },
          { 'i', '<M-s>',     require('sonicpi.remote').stop,               { desc = 'Sonic Pi: stop' } },
          { 'n', '<leader>r', require('sonicpi.remote').run_current_buffer, { desc = 'Sonic Pi: run' } },
          { 'i', '<M-r>',     require('sonicpi.remote').run_current_buffer, { desc = 'Sonic Pi: run' } },
          { 'n', '<leader>R', ':SonicPiSendBuffer<CR>',                     { desc = 'Sonic Pi: send buffer' } },
          { 'i', '<M-R>',     ':SonicPiSendBuffer<CR>',                     { desc = 'Sonic Pi: send buffer' } },
        },
        single_file = true,
      })
    end,
    dependencies = {
      'hrsh7th/nvim-cmp',
      'kyazdani42/nvim-web-devicons'
    },
  },

...

})

HTH

@igorgue
Copy link

igorgue commented Oct 30, 2024

@sluedecke I don't think the server_dir = '/opt/sonic-pi/app/server', should be implied... This is mine: /run/current-system/sw/bin/sonic-pi NixOS, other distros might not put software in /opt

@igorgue
Copy link

igorgue commented Oct 30, 2024

@sluedecke this is what I did for sonic-pi and LazyVim:

local function get_server_path()
  local exepath = vim.fn.exepath("sonic-pi")
  ---@diagnostic disable-next-line: undefined-field
  local realpath = vim.loop.fs_realpath(exepath)
  local pkg_root = vim.fn.fnamemodify(realpath, ":h:h")
  return pkg_root .. "/app/server"
end

local server_path = get_server_path()

require("lazyvim.util").lsp.on_attach(function(client, _)
  if client.name == "solargraph" then
    require("sonicpi").lsp_on_init(client, { server_dir = server_path })
  end
end)

vim.api.nvim_create_autocmd({ "BufWritePost" }, {
  pattern = { "*.sonicpi" },
  callback = function()
    if require("sonicpi.opts").remote.lifecycle.daemon_started == 1 then
      vim.cmd("SonicPiSendBuffer")
    end
  end,
})

return {
  {
    "nvim-treesitter/nvim-treesitter",
    ft = { "sonicpi" },
    optional = true,
    opts = function(_, opts)
      vim.treesitter.language.register("ruby", "sonicpi")

      opts.indent = {
        enable = true,
        disable = false,
      }
      opts.highlight.additional_vim_regex_highlighting = true

      return opts
    end,
  },
  {
    "stevearc/conform.nvim",
    ft = { "sonicpi" },
    optional = true,
    opts = {
      formatters_by_ft = {
        sonicpi = { "rubocop" },
      },
    },
  },
  {
    "neovim/nvim-lspconfig",
    opts = {
      servers = {
        ruby_lsp = {
          filetypes = { "ruby", "sonicpi" },
          single_file_support = true,
        },
        solargraph = {
          enabled = true,
          filetypes = { "ruby", "sonicpi" },
          diagnostics = true,
          single_file_support = true,
        },
        rubocop = {
          enabled = true,
          filetypes = { "ruby", "sonicpi" },
          single_file_support = true,
        },
      },
    },
  },
  {
    "magicmonty/sonicpi.nvim",
    -- dir = "~/Code/sonicpi.nvim",
    ft = { "sonicpi" },
    dependencies = {
      "kyazdani42/nvim-web-devicons",
      "nvim-lua/plenary.nvim",
    },
    config = function(_, opts)
      local wk = require("which-key")

      local mappings = {
        { "n", "<M-s>", require("sonicpi.remote").stop, { desc = "Sonic Pi Stop" } },
        { "i", "<M-s>", require("sonicpi.remote").stop, { desc = "Sonic Pi Stop" } },
        { "n", "<M-r>", require("sonicpi.remote").run_current_buffer, { desc = "Sonic Pi Run" } },
        { "i", "<M-r>", require("sonicpi.remote").run_current_buffer, { desc = "Sonic Pi Run" } },
      }
      opts = vim.tbl_extend("force", opts, { mappings = mappings })

      require("sonicpi").setup(opts)
      require("luasnip").filetype_extend("sonicpi", { "ruby" })

      wk.add({
        { "<leader>S", group = "sonicpi", icon = { icon = "", color = "cyan" } },
      })
    end,
    opts = {
      server_dir = server_path,
      single_file = true,
      lsp_diagnostics = true,
    },
    keys = {
      { "<cr>", "<cmd>SonicPiSendBuffer<CR>", desc = "Sonic Pi send buffer", ft = "sonicpi" },
      {
        "<s-cr>",
        function()
          require("sonicpi.remote").stop()
        end,
        desc = "Sonic Pi stop clock",
        ft = "sonicpi",
      },
      { "<leader>Ss", "<cmd>SonicPiStartDaemon<CR>", desc = "Sonic Pi start daemon", ft = "sonicpi" },
      { "<leader>SS", "<cmd>SonicPiStopDaemon<CR>", desc = "Sonic Pi stop daemon", ft = "sonicpi" },
      {
        "<leader>;",
        function()
          require("sonicpi.remote").stop()
          require("sonicpi.remote").run_current_buffer()
        end,
        desc = "Sonic Pi restart clock",
        ft = "sonicpi",
      },
    },
  },
}

@igorgue
Copy link

igorgue commented Oct 30, 2024

@sluedecke
Copy link

sluedecke commented Oct 30, 2024

@igorgue nice stuff, thanks for sharing!

And you are right, I do not need to specify the server_dir, sonicpi.nvim already searches a list of known paths:

local known_paths = {
'/opt/sonic-pi/app/server',
'/usr/lib/sonic-pi/app/server',
'/usr/lib/sonicpi/app/server',
'/usr/share/sonic-pi/app/server',
'/usr/share/sonicpi/app/server',
}

I too use treesitter and lsp and it took me a while to get solargraph working correctly with mason, but it works fine now.

** Some more snippets: setting up solargraph (which has been installed using the :Mason command as Ruby LSP):**

local lspconfig = require('lspconfig')

-- from :h mason-lspconfig-automatic-server-setup
require('mason-lspconfig').setup_handlers({
  function(server_name) -- default handler (optional)

    -- 2024-10-29 Solargraph shall handle ruby AND sonicpi files, add on_init according to documentation
    if server_name == "solargraph" then
      lspconfig[server_name].setup {
        config = {
          on_init = function(client)
            require('sonicpi').lsp_on_init(client, {})
          end
        },
        filetypes = { 'ruby', 'sonicpi' },
      }
    end

    ....

  end
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants