microsoft / vscode-textmate

A library that helps tokenize text using Text Mate grammars.
MIT License
562 stars 108 forks source link

Matching multiline text #211

Open Nv7-GitHub opened 9 months ago

Nv7-GitHub commented 9 months ago

My language has syntax that is structured as follows:

<Group 1>
<Group 2>
<Group 2>

<Group 1>
<Group 2>
<Group 2>
<Group 2>

...

There are sets of one "Group 1" followed by any number of "Group 2" before a blank line, after which another set starts. I want Group 1 highlighted differently than Group 2. There are no identifying features within the line, just its place within the file. I tried using newlines in a regex to capture these but it didn't work, and it seems that VSCode only goes one line at a time for the regex.

I can't use a language server since this needs to work in VSCode web, how can I achieve this highlighting?

jeff-hykin commented 9 months ago

(I'm just a random guy that does a lot of highlighting not a VS Code contributor btw)

how can I achieve this highlighting

There's only two tools in Textmate parsers (VS Code and many editors use Textmate grammars for highlighting).

Thats it.

So you could get creative, use a pattern range, have it start with group 1, have it end when it sees a blank line, and then restrict what patterns are allowed inside of the pattern range.

Here's some code snippets to show a little bit of what I mean.

"What if the start-trigger/start-pattern requires multiple lines to be identified?"

Well then you're straight outta luck. Textmate parsers are hacky, very-limited things. Its actually more amazing that they work at all. Stuff like the C++ pre-processor just straight up break it with no good workaround. Its sad but that's how it is. One day (maybe) VS Code will switch to the Tree Sitter Parser and these problems won't exist.

alexdima commented 9 months ago

I can't use a language server since this needs to work in VSCode web, how can I achieve this highlighting?

You could try using semantic tokens. There you can look at the entire file contents when creating them, not just one line at a time, looking for patterns. You can create an extension that uses a nodejs language server and our libraries for that. They are fit for running in a web worker, and creating a new worker on the web or a new nodejs process on the desktop. In our codebase, you can take a look at css.