SCNVim - A NeoVim frontend for SuperCollider

Straightforward with lazy: GitHub - Saghen/blink.nvim: Set of simple, performant neovim plugins you want blink-cmp although the other modules are nice too!

1 Like

Thanks wil give it a try once more :wink:

It is basically working but I struggle with getting the classes, snippets and the tags loaded which are in ~/.cache/nvim/scnvim. Should I define the paths in the blink_cmp.lua file or somewhere else?

return{
{
  'saghen/blink.cmp',
  -- optional: provides snippets for the snippet source
  dependencies = { 'rafamadriz/friendly-snippets' },

  -- use a release tag to download pre-built binaries
  version = '1.*',
  -- AND/OR build from source, requires nightly: https://rust-lang.github.io/rustup/concepts/channels.html#working-with-nightly-rust
  -- build = 'cargo build --release',
  -- If you use nix, you can build from source using latest nightly rust with:
  -- build = 'nix run .#build-plugin',

  ---@module 'blink.cmp'
  ---@type blink.cmp.Config
  opts = {
    -- 'default' (recommended) for mappings similar to built-in completions (C-y to accept)
    -- 'super-tab' for mappings similar to vscode (tab to accept)
    -- 'enter' for enter to accept
    -- 'none' for no mappings
    --
    -- All presets have the following mappings:
    -- C-space: Open menu or open docs if already open
    -- C-n/C-p or Up/Down: Select next/previous item
    -- C-e: Hide menu
    -- C-k: Toggle signature help (if signature.enabled = true)
    --
    -- See :h blink-cmp-config-keymap for defining your own keymap
    keymap = { preset = 'default' },

    appearance = {
      -- 'mono' (default) for 'Nerd Font Mono' or 'normal' for 'Nerd Font'
      -- Adjusts spacing to ensure icons are aligned
      nerd_font_variant = 'mono'
    },

    -- (Default) Only show the documentation popup when manually triggered
    completion = { documentation = { auto_show = false } },

    -- Default list of enabled providers defined so that you can extend it
    -- elsewhere in your config, without redefining it, due to `opts_extend`
    sources = {
      default = { 'lsp', 'path', 'snippets', 'buffer' },
    },

    -- (Default) Rust fuzzy matcher for typo resistance and significantly better performance
    -- You may use a lua implementation instead by using `implementation = "lua"` or fallback to the lua implementation,
    -- when the Rust fuzzy matcher is not available, by using `implementation = "prefer_rust"`
    --
    -- See the fuzzy documentation for more information
    fuzzy = { implementation = "prefer_rust_with_warning" }
  },
  opts_extend = { "sources.default" }
}
}

Im away from the computer rn but I believe you need to add the snippets in your luasnip.lua ! I’ll check when I see my machine!

1 Like

Ok, thanks. No problem. I give up for today.

try

require("luasnip").add_snippets("supercollider", require("scnvim/utils").get_snippets())

in your luasnip config!

1 Like

Oh that was you, sorry. I’ll give it a try. I’m just fiddling with it.

I gave up an will open a separate thread tomorrow. Really want to get this running.

Maybe I´m confusing things. When thinking about autocompletion I mainly mean things like Pulse, SinOsc.ar, EnvGen, etc.

I guess snippets are smaller blocks of code and EnvGen,etc. is not handled by luasnippets, right? How do I get simple autocompletion like in scIDE running? Is it sufficient just to install blink.cmp which I did.

Nvim is aware of the SC classes as e.g. SinOsc, and Pulse have a different color compared to e.g. House or Car. But I don´t get suggestions of e.g. Pulse when hitting TAB. Words present in the buffer are suggested though.

EnvGen should have a snippet and will autocomplete

this is what I see using blink when I type ‘Env’:

Blink also has “frecency” meaning that terms you type often or recently will be available to autocomplete.

you have to make sure that luasnip is selected in blink config - in opts:

		sources = {
			default = { ''path', 'snippets', 'buffer' }, --you can change the order here or add/remove other sources
		},
		snippets = { preset = 'luasnip' },

and you need to be sure luasnip knows where to look for supercolliders snippets (see post above)

If you want *only the classname" to be autocompleted (ie no args) then you want to use nvim-cmp and add a tags source GitHub - quangnguyen30192/cmp-nvim-tags: tags sources for nvim-cmp

1 Like

Thanks a lot!! This was missing and now I get more or less what I expect:

Next I want to remove the symbols at the beginning of each entry and then I need to figure out how the keybindings work. At the moment I immediately get the list (not on TAB).

When pressing Ctrl + SPACE after “Pulse” I get this

I looks quite usable now:

The nerd icons I replaced with simple letters in the the blink-cmp configuration file with ChatGPT.
Then I installed the status line according to: Neovim as a SuperCollider IDE | Mads Kjeldgaard

Again ChatGPT was a help here. It however completely failed in getting the lua snippets right.
I will now use this over the weekend and get used to vim. Nice side effect is that I hopefully learn a bit lua which then I can use for Reaper and maybe Renoise as well.

return {
  'saghen/blink.cmp',
  dependencies = { 'rafamadriz/friendly-snippets' },
  version = '1.*',

  ---@module 'blink.cmp'
  ---@type blink.cmp.Config
  opts = {
    -- Key mappings
    keymap = { preset = 'default' },

    -- Appearance
    appearance = {
      nerd_font_variant = 'none',  -- disables Nerd Font spacing
      kind_icons = {               -- remove all icons (ASCII-only)
        Text = 'T',
        Method = 'M',
        Function = 'F',
        Constructor = 'c',
        Field = 'F',
        Variable = 'V',
        Class = 'C',
        Interface = 'I',
        Module = 'm',
        Property = 'P',
        Unit = 'U',
        Value = '',
        Enum = '',
        Keyword = '',
        Snippet = 'S',
        Color = '',
        File = '',
        Reference = '',
        Folder = '',
        EnumMember = '',
        Constant = '',
        Struct = '',
        Event = '',
        Operator = '',
        TypeParameter = '',
      },
    },

    -- Completion menu settings
    completion = { documentation = { auto_show = false } },

    -- Completion sources
    sources = { default = { 'lsp', 'path', 'snippets', 'buffer' } },

    -- Snippets
    snippets = { preset = 'luasnip' },

    -- Fuzzy matcher
    fuzzy = { implementation = "prefer_rust_with_warning" },
  },

  -- Optional: extend default sources without redefining
  opts_extend = { "sources.default" }
}


Shouldn’t it be possible in nvim to execute a block with C-e ?

Form the config:

 keymaps = {
    ['<M-e>'] = map('editor.send_line', {'i', 'n'}),
    ['<C-e>'] = {
      map('editor.send_block', {'i', 'n'}),
      map('editor.send_selection', 'x'),

So when I’ m somewhere in these three lines it should be possible to play the sound with C-e, but it’s not working here:

(
{SinOsc.ar(440, 1)}.play
)

yes that should work! in nvim try :map <C-e> to see if another mapping is stealing the key. In my config luasnip is using . Also be sure to try in a clean file because if you have unmatched parens above scnvim cant find the block.

Thanks it works. I think I was hitting the Alt key. :sweat_smile:

I method autocompletion working for you? E.g. .exprange ?

that is a ittle tricky! Folks here have been working on getting scztts LanguageServer.quark to work with nvim which takes care of that nicely but otherwise one approach is to use tags - I added these to Lazy (and then “tags” to the sources). You may also have to set the tags file (:set tags=~/.cache/nvim/scnvim) I don’t get argument suggestions for these though sadly.

"quangnguyen30192/cmp-nvim-tags",
 "Saghen/blink.compat",
1 Like

I somehow never noticed this, but when I run sclang from scnvim, the startup file doesn’t get read… but the same sclang (i.e., the exact same executable in the same path) reads it just fine when started from the scide. What could be going on here?

EDIT: nvm, figured it out. for posterity: On mac (haven’t checked other platforms), common/SC_filesystem_macos.cpp checks for XDG_CONFIG_HOME and if it exists, sets that as userConfigDir. I guess XDG isn’t set when you open scide, so it defaults to the mac Application Support/SuperCollider folder… whereas the shell from which I run nvim does set the XDG directories, which means that sclang makes that one its userConfigdir
Not sure how I would change that behavior, but it’s actually nice to have separate startup files anyhow.

EDIT2: Silly little workaround, as an extension to the SCNvim class:

+ SCNvim {
    *initClass {
        StartUp.add {
            if( thisProcess.platform.isKindOf(OSXPlatform)
                and: File.exists(Platform.userAppSupportDir ++ "/startup.scd")
                and: Platform.userConfigDir != Platform.userAppSupportDir
            ) {
                thisProcess.interpreter.executeFile(Platform.userAppSupportDir ++ "/startup.scd")
            }
        }
    }
}

Seems you really can’t change the UserConfigDir and the startup file path derived from it, but you can of course just add arbitrary stuff via StartUp.add (gets executed after the actual startup file).