magicmonty / sonicpi.nvim

A neovim Plugin for [Sonic Pi](https://sonic-pi.net)
41 stars 7 forks source link
neovim-plugin nvim-cmp sonic-pi

sonicpi.nvim

This is a neovim plugin for Sonic Pi

Screenshot

Features

This plugin is inspired by sonicpi.vim.

But

Installation

You will need at least version 0.6 of neovim with lua support and nvim-cmp. Use your preferred package/plugin manager to install this plugin. With packer.nvim, this looks like:

use({
  'magicmonty/sonicpi.nvim',
  config = function()
    require('sonicpi').setup()
  end,
  requires = {¬
    'hrsh7th/nvim-cmp',
    'kyazdani42/nvim-web-devicons'
  }
})

You have to set the directory to the Sonic Pi server, so that the plugin can read the documentation and language arguments for the completion engine.

Configuration

The default configuration is as follows, you can override it with your own settings if you wish

require('sonicpi').setup({
  server_dir = "", -- It will try to find the SonicPi server
  lsp_diagnostics = false -- enable LSP diagnostics
  mappings = {
    { 'n', '<leader>s', require('sonicpi.remote').stop, default_mapping_opts },
    { 'i', '<M-s>', require('sonicpi.remote').stop, default_mapping_opts },
    { 'n', '<leader>r', require('sonicpi.remote').run_current_buffer, default_mapping_opts },
    { 'i', '<M-r>', require('sonicpi.remote').run_current_buffer, default_mapping_opts },
  },
})

LSP setup

If you want to use the LSP, then install solargraph correctly and add the following to the on_init callback of your lsp config:

local function on_init(client)
  ...

  require('sonicpi').lsp_on_init(client, { server_dir = '/opt/sonic-pi/app/server' })
end

also you need to configure solargraph to accept single files with

single_file = true

in the solargraph settings for your LSP setup

CMP setup

If you want to use the completion engine, then you have to add the sonicpi source to your config:

require('cmp').setup({
  ...

  sources = {
    ...
    { name = 'sonicpi' }
    ...
  },
})

Luasnip

This plugin has support for Luasnip. If you have luasnip istalled, then a selection of predefined snippets will be available.

Currently the following snippets are available:

Usage

You need to create a new file with a .sonicpi extension and open it in neovim. Then you can use the LSP and completion engine including the snippets.

Commands

Default Mappings

Mode Key binding Description
n <leader>r Run current buffer
n <leader>s Stop execution
i <M-r> Run current buffer
i <M-s> Stop execution