JoosepAlviste / nvim-ts-context-commentstring

Neovim treesitter plugin for setting the commentstring based on the cursor location in a file.
MIT License
1.14k stars 34 forks source link

Custom commentstring not working with Prolog #36

Closed motorto closed 2 years ago

motorto commented 2 years ago
use {'JoosepAlviste/nvim-ts-context-commentstring',
    config = function()
        require'nvim-treesitter.configs'.setup {
            context_commentstring = {
                enable = true,
                config = {
                    prolog = {
                        __default = "%% %s",
                    },
                    vue = {
                        __default = "/* %s  */",
                        html = "<!-- %s -->",
                        javascript = "// %s",
                        script = "// %s",
                        css = "/* %s */",
                        comment = "<!-- %s -->",
                    },
                }
            }
        }
    end 
}

So I have an autocmd that changes all *.pl file to be prolog, but my custom commentstring is not applied am I doing something wrong ?

echo &commentstring = #%s

Edit: It seems to be setting the commenstring but as soon as I press gcc it changes to the commentstring ... (see video)

motorto commented 2 years ago

https://user-images.githubusercontent.com/52639805/158804427-b99c5024-f13f-459b-ac36-f045b3ac25bd.mp4

JoosepAlviste commented 2 years ago

Hey @motorto! Does Prolog have a treesitter parses that you're using? I didn't see any in the nvim-treesitter supported languages: https://github.com/nvim-treesitter/nvim-treesitter/#supported-languages

I don't think that this plugin should be doing anything if treesitter is not active for the buffer. Maybe there's something else that's changing your commentstring for some reason?

Could you show the output of :TSModuleInfo context_commentstring? It should show prolog or something if it's enabled (or maybe perl if you have the perl parser installed?). Or maybe you could show the treesitter tree with https://github.com/nvim-treesitter/playground by running :TSPlaygroundToggle?

I tried out by adding an autocmd to set the filetype to prolog and it seems to work correctly for me. Also, the commentstring is correctly set and treesitter is not active in the buffer (using regex highlighting as far as I can tell).

motorto commented 2 years ago

Thanks for the detailed answer !

It seems that the issue is with the perl treessiter parser, by uninstalling (the perl treesitter) it works fine. Shouldn't treesitter respect the filetype and only be called when inside a perl program ?

Unfortunately there isn't a prolog parser as far as I am concerned.

Maybe I should open an issue in the treessiter repo right ?

JoosepAlviste commented 2 years ago

Hmm yeah, it seems weird that treesitter does not respect the filetype. I guess if you don't need to write perl code, then the solution of uninstalling the parser is good enough.

But yeah, I think that this is more of an issue of nvim-treesitter so I'll close this one for now. Let me know if anything else comes up!