Giter VIP home page Giter VIP logo

Comments (30)

clason avatar clason commented on May 24, 2024 31

You need to install the comment parser to get highlighting inside comments.

from nvim-treesitter.

stsewd avatar stsewd commented on May 24, 2024 14

I'll try to send a PR tomorrow or next week

todos

from nvim-treesitter.

vigoux avatar vigoux commented on May 24, 2024 10

Hi and thanks for reporting this ! What you are aiming for here is what we call language injection, that is we want to treat certain parts of the program (the comments) differently.
We will build a comment (doc and codetags) later and use it together with language injection later. Unfortunately language injection is a bit tougher than expected.

from nvim-treesitter.

stsewd avatar stsewd commented on May 24, 2024 7

but maybe this something we can add by default? don't know how common is to use just TODO something instead of TODO: something

from nvim-treesitter.

vigoux avatar vigoux commented on May 24, 2024 4

Language injection is on by default now, only thing missing is creating the codetag parser, and setting things up for each language.
We are (still) missing some other things like a strip directive, that we will try to hack into here.

from nvim-treesitter.

stsewd avatar stsewd commented on May 24, 2024 4

@joellidin you need the @text.note highlight group.

from nvim-treesitter.

yashLadha avatar yashLadha commented on May 24, 2024 3

Are there some examples present to achieve this currently with treesitter? @vigoux

from nvim-treesitter.

caheredia avatar caheredia commented on May 24, 2024 3

@caheredia the syntax is TODO: something, you can highlight tokens that don't have : if you want with a custom query like

@stsewd according to python docs, https://www.python.org/dev/peps/pep-0350/#id25 it looks like Codetags should be followed by a colon. Although in the wild, I've seen more "TODO"s without the colon. Either way thanks for the custom query, I'll add that to my conifgs

from nvim-treesitter.

pabuisson avatar pabuisson commented on May 24, 2024 2

Damn, I didn't understand this πŸ€¦β€β™‚οΈ Maybe it'll also help other people someday.
Sorry for the noise and thanks a lot for the help!

from nvim-treesitter.

joellidin avatar joellidin commented on May 24, 2024 1

I am sorry to yet again bring this up. But for python it still does not highlight the todo comments for me.
image
The healtcheck seems fine:

nvim-treesitter: require("nvim-treesitter.health").check()
========================================================================
## Installation
  - WARNING: `tree-sitter` executable not found (parser generator, only needed for :TSInstallFromGrammar, not required for :TSInstall)
  - OK: `node` found v14.20.0 (only needed for :TSInstallFromGrammar)
  - OK: `git` executable found.
  - OK: `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
    Version: cc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
  - OK: Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI.

## Parser/Features H L F I J
  - go             βœ“ βœ“ βœ“ βœ“ βœ“
  - bash           βœ“ βœ“ βœ“ . βœ“
  - cpp            βœ“ βœ“ βœ“ βœ“ βœ“
  - cuda           βœ“ βœ“ βœ“ βœ“ βœ“
  - regex          βœ“ . . . .
  - graphql        βœ“ . . βœ“ βœ“
  - markdown       βœ“ . βœ“ . βœ“
  - make           βœ“ . βœ“ . βœ“
  - python         βœ“ βœ“ βœ“ βœ“ βœ“
  - rust           βœ“ βœ“ βœ“ βœ“ βœ“
  - sql            βœ“ . . . βœ“
  - typescript     βœ“ βœ“ βœ“ βœ“ βœ“
  - json           βœ“ βœ“ βœ“ βœ“ .
  - comment        βœ“ . . . .
  - lua            βœ“ βœ“ βœ“ βœ“ βœ“
  - dockerfile     βœ“ . . . βœ“
  - c              βœ“ βœ“ βœ“ βœ“ βœ“
  - scss           βœ“ . . βœ“ .
  - vim            βœ“ βœ“ βœ“ . βœ“
  - toml           βœ“ βœ“ βœ“ βœ“ βœ“
  - yaml           βœ“ βœ“ βœ“ βœ“ βœ“
  - javascript     βœ“ βœ“ βœ“ βœ“ βœ“
  - bibtex         βœ“ . βœ“ βœ“ .
  - css            βœ“ . βœ“ βœ“ βœ“
  - latex          βœ“ . βœ“ . βœ“
  - help           βœ“ . . . .

from nvim-treesitter.

runebone avatar runebone commented on May 24, 2024 1

For those who still haven't figured out how to do that, just add the following to your lua config:
vim.api.nvim_set_hl(0, "@text.note", { link = "Search" })

Or you can use any word from :hi instead of "Search".

from nvim-treesitter.

dominiklohmann avatar dominiklohmann commented on May 24, 2024

Glad to hear it's on your roadmap already. This is in no way urgent, and I like that you're looking to do this in a generic fashion (which ultimately is what makes treesitter highlighting superior).

from nvim-treesitter.

vigoux avatar vigoux commented on May 24, 2024

Okay, language injection is here now ! Now what we need is a little parser to highlight such code tags, maybe a little code tag parser could be good !

from nvim-treesitter.

dominiklohmann avatar dominiklohmann commented on May 24, 2024

Sounds great. I regularly use the following:

  • FIXME:, FIXME(username): (must be addressed)
  • TODO:, TODO(username): (should be addressed)
  • NYI: (not yet implemented)

from nvim-treesitter.

vigoux avatar vigoux commented on May 24, 2024

Awesome, it sounds like there was a PEP too specifying that a bit, maybe we can use that as a reference : https://www.python.org/dev/peps/pep-0350/

There is still some things to do to : for each language we'd have to set up injection, and use the strip!operator.

The problem is that the strip operator is not yet implemented and wouldn't word for now, so we need to find a proper way of doing so.

from nvim-treesitter.

theHamsta avatar theHamsta commented on May 24, 2024

I planned to do that with #590 So you could trim node ranges in the queries to get subranges of them.

from nvim-treesitter.

caheredia avatar caheredia commented on May 24, 2024

Likewise the lack of python TODO is a pain point for me as well. Glad it's on the roadmap.

from nvim-treesitter.

vigoux avatar vigoux commented on May 24, 2024

So, together with @steelsojka we've been discussing a bit.
There is some upstream issues that might block language injection a bit, and that we need to fix before going forward.

While this work is being done, I'll be working on the todo parser, and if anyone wants to contribute, I'll be really grateful.

from nvim-treesitter.

caheredia avatar caheredia commented on May 24, 2024

@vigoux I mostly code in python, but happy to help in any way I can

from nvim-treesitter.

vigoux avatar vigoux commented on May 24, 2024

@steelsojka did a a set of two PRs (neovim/neovim#13207, and #627) to be able to inject in a better way.

from nvim-treesitter.

talbergs avatar talbergs commented on May 24, 2024

An absolute MUST feature. See this PR neovim/neovim#13252

I work with files that are php -> js and php -> html -> js I could determine which of these parser chains to use based on filename. Have a spectacular syntax highlighting!

from nvim-treesitter.

rakin406 avatar rakin406 commented on May 24, 2024

Yes plssss

from nvim-treesitter.

caheredia avatar caheredia commented on May 24, 2024

I see this issue was recently closed, but TODO still isn't working for me in python

Screen Shot 2021-03-12 at 8 40 00 PM

``` health#nvim_treesitter#check ======================================================================== ## Installation
  • OK: tree-sitter found 0.19.3(parser generator, used for :TSInstallFromGrammar)

  • OK: git executable found.

  • OK: cc executable found.

Parser/Features H L F I

  • scala . . . .
  • python βœ“ βœ“ βœ“ βœ“
  • supercollider βœ“ βœ“ βœ“ βœ“
  • go βœ“ βœ“ βœ“ βœ“
  • haskell . . . .
  • toml x x x x
  • glimmer βœ“ . . .
  • ruby βœ“ βœ“ . βœ“
  • bash βœ“ βœ“ βœ“ .
  • vue βœ“ . βœ“ .
  • php βœ“ x βœ“ .
  • java βœ“ βœ“ . βœ“
  • svelte βœ“ . βœ“ βœ“
  • yaml βœ“ βœ“ βœ“ βœ“
  • kotlin βœ“ . . .
  • nix βœ“ βœ“ βœ“ .
  • devicetree βœ“ βœ“ βœ“ βœ“
  • html βœ“ βœ“ βœ“ βœ“
  • dart x βœ“ . βœ“
  • julia βœ“ βœ“ . .
  • turtle βœ“ βœ“ βœ“ βœ“
  • rst βœ“ βœ“ . .
  • json βœ“ βœ“ βœ“ βœ“
  • fennel x βœ“ . .
  • css x . βœ“ βœ“
  • teal βœ“ βœ“ βœ“ βœ“
  • erlang . . . .
  • ocaml_interfacex βœ“ βœ“ .
  • ql βœ“ x . .
  • javascript βœ“ x βœ“ βœ“
  • graphql βœ“ . . βœ“
  • ocaml x βœ“ βœ“ .
  • query βœ“ βœ“ βœ“ βœ“
  • elm . . . .
  • comment x . . .
  • regex βœ“ . . .
  • c βœ“ βœ“ x x
  • verilog x x x .
  • jsdoc x . . .
  • ocamllex x . . .
  • jsonc x x x x
  • swift . . . .
  • sparql x x x x
  • c_sharp x . . .
  • cpp x x x x
  • gdscript x x . .
  • clojure x x . .
  • typescript x x x x
  • lua x x x x
  • rust x x x x
  • tsx x x x x
  • ledger x . x x

from nvim-treesitter.

stsewd avatar stsewd commented on May 24, 2024

@caheredia the syntax is TODO: something, you can highlight tokens that don't have : if you want with a custom query like

("text" @text.warning
 (#match? @text.warning "^(TODO|HACK|WARNING)$"))

from nvim-treesitter.

luc-tielen avatar luc-tielen commented on May 24, 2024

I would highlight it without the : as well.

from nvim-treesitter.

pabuisson avatar pabuisson commented on May 24, 2024

Sorry to reactivate an old issue, but I never got my TODOs and FIXMEs highlighted in my neovim. Currently running 0.6.1, and I'm having the problem in two different languages, ruby and javascript. It's been like this for a while for me, and I was even surprised to find that it was supposed to work.

Capture d’écran 2022-03-03 aΜ€ 18 34 21

Healthcheck seems OK:

nvim_treesitter: health#nvim_treesitter#check
========================================================================
## Installation
  - OK: `tree-sitter` found 0.20.4 (parser generator, only needed for :TSInstallFromGrammar)
  - OK: `node` found v16.13.1 (only needed for :TSInstallFromGrammar)
  - OK: `git` executable found.
  - OK: `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
    Version: Apple clang version 12.0.5 (clang-1205.0.22.11)
  - OK: Neovim was compiled with tree-sitter runtime ABI version 13 (required >=13). Parsers must be compatible with runtime ABI.

## Parser/Features H L F I J
  - javascript     βœ“ βœ“ βœ“ βœ“ βœ“ 
  - ruby           βœ“ βœ“ βœ“ βœ“ βœ“ 

  Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
         +) multiple parsers found, only one will be used
         x) errors found in the query, try to run :TSUpdate {lang}

I don't know if color scheme can have an impact (like a non-implemented highlight group?), so I tried to switch and get the same result with nord, onedark, palenight, everforest and basically all decent color schemes I could think of.

Anything I may be missing? At this point I don't know how to investigate any further.

from nvim-treesitter.

diegoulloao avatar diegoulloao commented on May 24, 2024

You need to install the comment parser to get highlighting inside comments.

How I do that?

from nvim-treesitter.

diegoulloao avatar diegoulloao commented on May 24, 2024

Now I realized, I just added comment inside the ensure_installed list in my treesitter configuration.
Anyway, I think there are better solutions for this purpose: https://github.com/folke/todo-comments.nvim

from nvim-treesitter.

stsewd avatar stsewd commented on May 24, 2024

@joellidin I see that the : are highlighted, so this is probably your colorscheme missing highlighting the @text.* captures, see #2293 (comment)

from nvim-treesitter.

joellidin avatar joellidin commented on May 24, 2024

@joellidin I see that the : are highlighted, so this is probably your colorscheme missing highlighting the @text.* captures, see #2293 (comment)

@stsewd Thank you for the response. I looked and it seems that my colorscheme should have it. See picture below when I checked :hi. Worth noting maybe is that the todo comments get highlighted when I disable TS hightlighting. Is it anything obvious I am missing maybe?
image

from nvim-treesitter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.