Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: languages table to specify treesitter highlighing #1612

Merged
merged 1 commit into from
Jul 1, 2022

Conversation

marcelarie
Copy link
Contributor

@marcelarie marcelarie commented Dec 19, 2021

First of all just say that's my first "contribution" to any open source project. I hope with time the contributions are bigger :). This change makes more sense for me that the logic that it's being use now, but maybe not for everyone. Any feedback welcome.

If the languages exists in the config, only the file-types that match with
the ones on the table will be affected by the treesitter boolean.

The config now will look like this:

defaults = {
        preview = {
            treesitter = false,
            languages = { "perl", "javascript" },
        },
},

That will make that only perl and javascript will use regex for the highlight and any other file-type will use treesitter if possible.

@marcelarie
Copy link
Contributor Author

I just realized that there is a bug. I fix it first.

@marcelarie
Copy link
Contributor Author

Done.

@jc00ke
Copy link

jc00ke commented Dec 19, 2021

Congrats on your first (of hopefully many!) open-source PRs! 🎉 🚀 :shipit:

When I look at

defaults = {
        preview = {
            treesitter = false,
            languages = { "perl", "javascript" },
        },
},

I think the opposite of

only perl and javascript will use regex for the highlight and any other file-type will use treesitter if possible.

To me, treesitter = false, languages = {...} reads as

treesitter is disabled for all preview languages except perl and javascript.

Is anyone else confused by this? I'm wondering if it could be made more clear?

@marcelarie
Copy link
Contributor Author

marcelarie commented Dec 19, 2021

Thanks!

Is anyone else confused by this? I'm wondering if it could be made more clear?

Yes maybe you are right. I think having a enable and disable tables will be more clear.

defaults = {
    preview = {
        treesitter = {
			enable = { "..." },
            -- or
			disable = { "..." },
		},
    },
},

and keep the option of treesitter = bool to just enable or disable it in general.

defaults = {
    preview = {
        treesitter = true
    },
},

@ttytm
Copy link
Contributor

ttytm commented Jun 30, 2022

Great, and also neccecry commit!

I think using tables makes it definetely more clear. To further tweak it you could adapt it from treesitters config highlight section.

require'nvim-treesitter.configs'.setup {
  -- A list of parser names, or "all"
  ensure_installed = { "c", "lua", "rust" },

  -- Install parsers synchronously (only applied to `ensure_installed`)
  sync_install = false,

  -- List of parsers to ignore installing (for "all")
  ignore_install = { "javascript" },

  highlight = {
    -- `false` will disable the whole extension
    enable = true,

    -- NOTE: these are the names of the parsers and not the filetype. (for example if you want to
    -- disable highlighting for the `tex` filetype, you need to include `latex` in this list as this is
    -- the name of the parser)
    -- list of language that will be disabled
    disable = { "c", "rust" },

    -- Setting this to true will run `:h syntax` and tree-sitter at the same time.
    -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
    -- Using this option may slow down your editor, and you may see some duplicate highlights.
    -- Instead of true it can also be a list of languages
    additional_vim_regex_highlighting = false,
  },
}

which would translate into something like:

defaults = {
    preview = {
        treesitter = {
           enable = true,
           disable = { "perl", "javascript" },
        },
    },
},

edit: I didn't read your last comment properly, which basically does this and also is a nice implementation using a table OR bool - but is a bit harder logic to implement when having the possibility to define enabled and disabled tables. Do you have the time to update your PR?

@Conni2461
Copy link
Member

Currently in the merge phase. I am going to look at it prior to the dev branch merge tomorrow, see #1938 for more information

Thanks for the PR :)

@marcelarie
Copy link
Contributor Author

edit: I didn't read your last comment properly, which basically does this and also is a nice implementation using a table OR bool - but is a bit harder logic to implement when having the possibility to define enabled and disabled tables. Do you have the time to update your PR?

I will try to update this PR's today.

@Conni2461 Conni2461 changed the base branch from master to dev July 1, 2022 20:48
@Conni2461
Copy link
Member

I took the liberty to finish this since there weren't any updates since dec 19. And we have a feature freeze today. So i am going to merge this now into the current dev branch and after that into the current master.

I also added documentation. So if you want to now how it works, please refer to that or the last commit. Basically the gist is now. that preview.treesitter can be a table with a enable key either a bool or a table of enabled languages, the disable is in this case ignored. If it is just a bool (which defaults to true) you can also set a disable key, a table of languages that are disabled

Thanks for the PR :)

this follows nvim-treesitter more closely but enable can also be a table
of enabled languages

The config now looks like this:
```lua
defaults = {
  preview = {
    treesitter = {
      enable = false,
      -- or
      enable = { "c" },
      -- disable can be set if enable isn't set
      disable = { "perl", "javascript" },
    },
  },
},
```
@Conni2461 Conni2461 merged commit 5dd4b52 into nvim-telescope:dev Jul 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants