SCNVim - A NeoVim frontend for SuperCollider

Hi Mads, this is really cool. I think all scide Document class with all the nuances now can be rewrited into nvim version (thanks to this!). While thinking about it, I checked the classlib and one question come to my mind. There exists EmacsDocument, ScelDocument, why scnvim called its class just Document and not NvimDocument ?

The Document help file mentions that subclassing is due to historical reasons: Document | SuperCollider 3.12.2 Help

The classes that are used specifically by scnvim are only compiled when starting sclang with the -i scide_scnvim command line flag, so there will be no conflicts with duplicate class (e.g. Document) implementations.

1 Like

When I’m writing: SinOsc.ar(

and then press TAB, I get the arguments (freq etc) listed, but I can’t select them, so the arguments are filled in with the default values?

Are you expanding a snippet when pressing <Tab>? If you are using the function signature helper (g:scnvim_echo_args) then no arguments will be filled in, it only displays the arguments as a way of remembering their order.

2 Likes

I’ve been working on a large refactor of the scnvim code base in the last couple of weeks. The biggest changes from a user perspective are:

  • Neovim version 0.7 or above will be required
  • All configuration options has moved to lua
  • The vim script API has been removed

You can follow the development in this PR, and feel free to start trying it out if you’d like! Please post any questions that you might have about the new configuration system either here or on the scnvim issue tracker and I’ll try to answer.

I’ve also added a new page to the wiki an example configuration example.

Cheers!

9 Likes

Whenever I open an .sc file, I always need to manually type :setf supercollider
If I don’t do this, :set filetype returns filetype=scala

I already tried brew uninstall neovim and deleted anything nvim from ~/.config and ~/.local

What I want is the correct filetype directly after opening nvim. It worked once automatically, but only until I restarted my system. Any idea what might have gone wrong?

Edit: Other filetypes such as *.cpp are recognized correctly.

I found a solution, but I am not sure if I destroy anything by doing this workaround:
in

/usr/local/Cellar/neovim/0.7.0/share/nvim/runtime/filetype.vim

I changed:

au BufNewFile,BufRead *.sc			call dist#ft#FTsc()

to

au BufNewFile,BufRead *.sc			setf supercollider

Is that bad?

Edit: @davidgranstrom this is so cool! Thanks a million for building this!

Hi,

I’m happy to announce that the scnvim rewrite is complete and is now merged to the main branch.

Here follows a summary of the most important changes and new features.

Cheers!

New features

  • New mapping system
  • Be able to pre-process text before being sent to sclang
  • Post window can be displayed as a “floating” window
  • New “fade” eval highlight effect
  • (Regular) Post window remember its last size
  • More fine grained user configuration (and hopefully easier to configure)
  • No post-install hooks for SCNvim (SuperCollider) classes
  • Bug fixes
  • Extensions

Developer features

  • Code base formatted with stylua
  • Auto generated and hosted API documentation
  • Unit tests
  • CI (lint/style, unit tests)
  • Extensions API

Breaking changes

  • Neovim version 0.7 or higher is now required
  • No public viml API with the exception of scnvim#statusline#server_status which still is convenient to use for configuring the status line.
  • SCNvimTags has been renamed to SCNvimGenerateAssets
  • No default keymaps are defined
7 Likes

how can i define a keymap? i got:
-INFO no keymaps defined
when running :checkhealth scnvim …

trying a minimal install here to learn :slight_smile:
i just added to my init.lua

local scnvim = require 'scnvim'
local map = scnvim.map
local map_expr = scnvim.map_expr
scnvim.setup {
  ensure_installed = true,
  keymaps = {
    ['<CR>'] = map('postwin.toggle')
  },
}

no errors loading and i can run :SCNvimStart … :thinking:

The example you posted looks correct to me. Note that the default mode for map is “normal mode” so the mapping will only work from this mode. If you run:

:lua print(vim.inspect(require'scnvim.config'))

You will see the resolved config and the expanded value of the keymap (in this case <CR>).

so i did

:lua print(vim.inspect(require'scnvim.config'))

and got

{
  config = {
    documentation = {
      args = { "$1", "--from", "html", "--to", "plain", "-o", "$2" },
      direction = "top",
      horizontal = true,
      keymaps = true
    },
    editor = {
      force_ft_supercollider = true,
      highlight = {
        color = "TermCursor",
        fade = {
          duration = 375
        },
        flash = {
          duration = 100,
          repeats = 2
        },
        type = "flash"
      },
      signature = {
        auto = true,
        config = {},
        float = true
      }
    },
    ensure_installed = true,
    extensions = {},
    keymaps = {},
    postwin = {
      auto_toggle_error = true,
      direction = "right",
      float = {
        callback = <function 1>,
        col = <function 2>,
        config = {
          border = "single"
        },
        enabled = false,
        height = 14,
        row = 0,
        width = 64
      },
      highlight = true,
      horizontal = false,
      scrollback = 5000
    },
    sclang = {
      args = {}
    },
    snippet = {
      engine = {
        name = "luasnip",
        options = {
          descriptions = true
        }
      }
    },
    statusline = {
      poll_interval = 1
    }
  },
  resolve = <function 3>,
  <metatable> = {
    __index = <function 4>
  }
}

i think there’s no keymaps or mention to <CR> on this file… :thinking:

Hmm, that is strange indeed! Are you calling scnvim.setup at some later place in your config and perhaps (unintentionally) overwriting the keymaps? Also, is it possible to view your config online somewhere or would you mind attaching it here as a .zip or send it to me via email? You can find my address on my github profile.

sorry bad typing error here. working now, with statusline! \o/
(next step install & learn to use snippets)
thx david! :smiley:

1 Like

i found snippets and autocomplete to be the most complex and time consuming thing to set up - so much so, that i just gave up - there are so many snippet and autocomplete packages in various states of newbie friendliness

I’ve been using nvim-cmp for quite some time, can recommend it if you haven’t tried it out yet. Together with the tags source it works pretty well for SC.

Here’s the configuration I’m using:

2 Likes

Hi @igormpc, what exactly was your typo? I have the same problem here :slight_smile: thanx

EDIT: I’ve found that when I’ve commented the code below from packer block, all problems solved. I am not good at lua and nvim stuff, so I don’t understand why.
(My scnvim setup code is in a separate file)

use {
	'davidgranstrom/scnvim',
	-- config = function()
		-- require('scnvim').setup()
	-- end
}
1 Like

Just tried this - this combination works nicely. Thank you

I’m using neovim 0.8.0 with scnvim. As the following has worked fine in the past, I am wondering if anyone else has this problem.

Simply, if I type Synth( to test a synth, neovim freezes sometimes with and sometimes without the tooltip describing the Synth function.

Any ideas? Thank you very much in advance.