TextMate grammar bundle documentation

Answered

Has JetBrains published any TextMate grammar bundle documentation?

I have multiple questions:

Does IDEA support Semantic Highlighting, like VS Code? Does that, or does any other IDEA extension to TextMate bundles, allow users to navigate from a function call to the definition of the called function?

Is there any inspector that shows the contexts applied to different parts of a file? That shows / logs matching patterns as & where they're matched? etc.

I've empirically determined that the first listed regex in the current "context" to match text gets applied, but is that guaranteed to be the case, or is that just an implementation detail, not part of the spec?

When I apply a scope name from a begin/end rule, I can't seem to override the scope name applied by that rule for text between the begin & end patterns that matches patterns in that rule's "patterns" list. e.g., say I want a double-quoted string's characters to be green, except I want interpolated variables (e.g., using $…) & code (e.g., using […]) to have different colors. Right now, if I apply "name": "string.quoted.double.language" in the rule, none of the names applied by rules in the "patterns": […] list overrides that, so all the characters are green. How can I fix that? If I don't apply the name, non-interpolated characters won't be green (but the characters matching the other rules do get their correct colors).

What TextMate scope names are supported by IDEA? Is there a list anywhere? How are these mapped to editor code formatting settings? Can I add in my own mappings for additional custom TextMate scope names?

How is auto text highlighting supposed to work?

Some braces / other paired bookends don't properly highlight matching pairs: either they fail to match, or they match with other bookends, but not with the correct one.

Sometimes a whole section is background highlighted (not for text selection, it just looks like matched pair highlighting, but for the whole section, not just for the paired bookends) when my cursor is in it, but I don't know why.

etc.

Thanks.

0
8 comments
Hi,

Please kindly refer to the answers:

> Is there any inspector that shows the contexts applied to different parts of a file? That shows / logs matching patterns as & where they're matched? etc.

IntelliJ interprets them but doesn't provide any tools for developing them. For supporting languages, we recommend generating a proper lexer and parser instead of using TextMate grammar: https://plugins.jetbrains.com/docs/intellij/custom-language-support-tutorial.html

> What happens if 2 active patterns both match input text. Is only the first or last pattern listed that matches the text applied? Do all matching patterns apply?

All patterns are matched against input. Patterns may have a priority (R: or L: prefixes). If the priorities are the same, the one with less offset is taken

> What TextMate names / contexts are supported by IDEA? Is there a list anywhere?

Sorry, I don't understand the question. What do you mean by supporting names/contexts?

> How are these mapped to editor code formatting settings? Can I add in my own mappings for additional TextMate names / contexts?

They don't, IntelliJ doesn't do formatting in files supported by TextMate.

> How is auto text highlighting supposed to work?

Could you elaborate on what you mean by auto-text highlighting?

> Some braces / other paired bookends don't properly highlight matching pairs: either they fail to match, or they match with other bookends, but not with the correct one.
> Sometimes a whole section is background highlighted (not for text selection, it just looks like matched pair highlighting, but for the whole section, not just for the paired bookends) when my cursor is in it, but I don't know why.

It might be a bug. You're very welcome to report particular examples at https://youtrack.jetbrains.com (https://youtrack.jetbrains.com/)
0

You can specify scope names (like string.quoted.double, or comment.line.number-sign) for text regions in TextMate language grammars (in .tmLanguage.json files, or other .tmLanguage formats like a .tmLanguage plist).

Any text can be used for scope names, but IDEA recognizes some of them (like the 2 aforementioned ones), then formats the scoped text appropriately. e.g., IDEA colors green all text scoped as string.quoted.double by my .tmLanguage.json. It colors grey all text scoped as comment.line.number-sign. etc. I want to know what scope names IDEA recognizes, and also how to change the formatting for recognized scopes (maybe I want string.quoted.double scoped text to be blue instead of green). I also want to know if IDEA only recognizes scopes from a predetermined list, or if I can add mappings from scopes to formatting for any custom scopes that I want.

See the following pages for info about scope names:

https://www.sublimetext.com/docs/scope_naming.html

https://macromates.com/manual/en/language_grammars#naming_conventions

0

Also, multiple scope names can be applied to the same text. Can IDEA use multiple scopes to map to formatting, or does it only use one scope? If only one, how is that determined? Is it the first scope that was applied? The most specific scope? If the first selected scope doesn't map to any formatting, does IDEA then try the second scope, and so on? Or, if text is scoped as A & B, can I have specialized formatting for the pair that's different than the formatting for A & B singularly? Or is it like CSS, where all formatting field values are applied in a cascading manner, with a more specific match overriding less specific matches?

0
> Also, multiple scope names can be applied to the same text. Can IDEA use multiple scopes to map to formatting, or does it only use one scope? 

> If only one, how is that determined? Is it the first scope that was applied? The most specific scope? 

Scopes are composite. Matching is performed according to the spec https://macromates.com/manual/en/scope_selectors#ranking_matches. The spec is quite incomplete. The implementation is publicly available, though. See `weigh` method of nodes: https://github.com/JetBrains/intellij-community/blob/master/plugins/textmate/core/src/org/jetbrains/plugins/textmate/language/syntax/selector/TextMateSelectorParser.java#L141

> I also want to know if IDEA only recognizes scopes from a predetermined list, or if I can add mappings from scopes to formatting for any custom scopes that I want.

There is a mapping between matching selector and IntelliJ color scheme key: https://github.com/JetBrains/intellij-community/blob/master/plugins/textmate/src/org/jetbrains/plugins/textmate/language/syntax/highlighting/TextMateDefaultColorsProvider.java#L29. + https://github.com/JetBrains/intellij-community/blob/master/plugins/textmate/src/org/jetbrains/plugins/textmate/language/syntax/highlighting/TextMateTheme.java#L18 Every scope is matched against that list. The highlighting is chosen accordingly. `string.quoted.double` will be matched to `DefaultLanguageHighlighterColors.STRING`, `comment.line.number-sign` – to `DefaultLanguageHighlighterColors.LINE_COMMENT`.
0

Thanks for the info. I’ll look it all over and get back with any additional questions.

It looks like some of my questions got lost in the shuffle. e.g.,:

Does IDEA support Semantic Highlighting, like VS Code? Does that, or does any other IDEA extension to TextMate bundles, allow users to navigate from a function call to the definition of the called function?

(FYI, VS semantic highlighting is documented at https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide)

If there are any other extant unanswered questions, I’d be interested in info about those, too

New question: does IDEA support any other language definition formats besides TextMate & IDEA plugin? Like SublimeText .sublime-syntax?

https://www.sublimetext.com/docs/syntax.html

0

Ross,

Does IDEA support Semantic Highlighting, like VS Code? 

 
Sure: https://plugins.jetbrains.com/docs/intellij/syntax-highlighting-and-error-highlighting.html#semantic-highlighting
 

Does that, or does any other IDEA extension to TextMate bundles, allow users to navigate from a function call to the definition of the called function?

No, as I mentioned above, textmate bundles support provides only the syntax highlighting and should be considered as a kick-off for language support but the real full-featured support is supposed to rely on IJ parser: https://plugins.jetbrains.com/docs/intellij/custom-language-support.html
 

Like SublimeText .sublime-syntax?

No, yaml is not supported as a source for TextMate Bundles

0

Thanks. When I asked about semantic highlighting, I meant with TextMate bundles, not with a custom language plugin. I’m looking into writing a plugin, but I’m having issues with the bnf file. I’ve already asked questions about that elsewhere, so I’ll proceed with a plug-in once I get those answers. Thanks again.

0

Ross,

Once a TextMate bundle is added, IDE provides syntax highlighting for the file types registered with the bundle

0

Please sign in to leave a comment.