tree-sitter-supercollider icon indicating copy to clipboard operation
tree-sitter-supercollider copied to clipboard

Indentation does not work

Open salkin-mada opened this issue 4 years ago • 8 comments

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: scrn-2021-02-17-20-21-41

the same block of code yanked and pasted into another buffer indents to: scrn-2021-02-17-20-22-02

salkin-mada avatar Feb 17 '21 19:02 salkin-mada

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: scrn-2021-02-17-23-13-55

but becomes: scrn-2021-02-17-23-14-04

salkin-mada avatar Feb 17 '21 22:02 salkin-mada

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",
			},
		},
	}

madskjeldgaard avatar Feb 18 '21 16:02 madskjeldgaard

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.

salkin-mada avatar Mar 02 '21 12:03 salkin-mada

I still have no clue about indentation and tree-sitter. If anyone would like to enlighten me/us, feel free

madskjeldgaard avatar May 16 '21 19:05 madskjeldgaard

If anyone feels like helping out with understanding how indentation is supposed to work, please let me know.

madskjeldgaard avatar Jan 12 '22 23:01 madskjeldgaard

Possible inspiration: https://github.com/nvim-treesitter/nvim-treesitter/blob/master/queries/ecma/indents.scm

madskjeldgaard avatar Jan 13 '22 23:01 madskjeldgaard

And tiny bit of documentation here https://github.com/nvim-treesitter/nvim-treesitter/blob/master/CONTRIBUTING.md#indents

madskjeldgaard avatar Jan 13 '22 23:01 madskjeldgaard

The indentation queries have been updated and improved somewhat but still not good enough

madskjeldgaard avatar Jan 20 '22 18:01 madskjeldgaard