How do I know if current word being typed is part of some comment?

I am trying to block autocomplete when the user is writing a comment.

My initial guess is to get the css class associated with the current token being typed - and see if the CM language parser has recognized this token as a comment already.

But not sure how I can access this class? Or is there a simpler way to do this?

Thank you.

There’s a utility precisely for that. But the general approach would be to take the syntax tree, resolve the position you’re interested in, and see whether it is inside a comment node (whatever that’s called in the language you’re interested in).

1 Like

Thanks marjin. Reliable as always.

Had to do some work to figure out the values of syntax node names. Don’t think it’s documented anywhere. For anyone reading, ‘Comment’ is the syntax node name to use in this context.