tree-sitter-supercollider
tree-sitter-supercollider copied to clipboard
Indentation does not work
not really sure if this is a sc treesitter issue or some neovim v0.5 nightly buggy behavior.
For auto indenting an entire buffer I use variations of mzgg=G`zzz in my mappings.
the following block written out by hand in a fresh buffer:
(
Pdef('default',
Pbind(
\instrument, 'default',
\scale, Scale.yu,
\degree, Pseq([12, 5, 5, 5, 7, 7, 8, 7, 2, 11, 9, 11, 9, 7, 11, 12, 2, 2, 4, 5, 12, 12], inf),
\legato, Pxrand([3/6, 12/8, 13/7, 5/7, 14/11, 16/9], inf) * 2.2,
\octave, Pseq([4, 5, 3, 4, 5, 3, 3, 4], inf),
\dur, Pseq([2/9, 12/9, 2/11, 2/4, 13/11, 16/11, 14/16, 6/6, Pwhite(10/14, 9/1, 1)*Rest()], inf),
)
).play
)
indents with mzgg... to:

the same block of code yanked and pasted into another buffer indents to:

further example:
TempoClock.tempo = 90 / 120;
Pdef('swing',
Ppar([
Pseq([
Pchain(
~swingify,
Pbind(
\instrument, 'default',
\out, ~bus_1,
\dur, Pwhite(0.1),
\legato, 1.0,
\degree, Pseq((0..12), inf),
\octave, Pseq([3,4,5,4,5], inf),
\scale, Scale.yu,
\pan, Pwhite(-1) * 1/4,
\amp, Pwhite(0.6,0.7),
),
(swingBase: 0.25, swingAmount: 0.1)
),
Pfuncn({ q.stop; Event.silent(0) }, 1)
])
])
).play(quant: 1/8);
should be:

but becomes:

I honestly don't understand how treesitter is supposed to do indenting. Trying with more established grammars like the cpp grammar yields equalling confusing results IMO.
I have personally disabled indenting via treesitter until I understand it better. See below how indent is disabled in neovim
require'nvim-treesitter.configs'.setup {
rainbow = {
enable = true
},
indent = {
enable = disable
},
ensure_installed = "maintained", -- one of "all", "maintained" (parsers with maintainers), or a list of languages
highlight = {
enable = true, -- false will disable the whole extension
-- disable = { "c", "rust", "lua", "cpp", "html" , "python", "bash"}, -- list of language that will be disabled
},
fold = {
enable = true
},
incremental_selection = {
enable = true,
keymaps = {
init_selection = "gnn",
node_incremental = "grn",
scope_incremental = "grc",
node_decremental = "grm",
},
},
}
it also works with the indent key in the config as it does with the highlight key - enable but disable some.
indent = {
enable = true,
disable = { "supercollider" },
}
disables sc - keeps the indent on for other langs.
I still have no clue about indentation and tree-sitter. If anyone would like to enlighten me/us, feel free
If anyone feels like helping out with understanding how indentation is supposed to work, please let me know.
Possible inspiration: https://github.com/nvim-treesitter/nvim-treesitter/blob/master/queries/ecma/indents.scm
And tiny bit of documentation here https://github.com/nvim-treesitter/nvim-treesitter/blob/master/CONTRIBUTING.md#indents
The indentation queries have been updated and improved somewhat but still not good enough