question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow dynamic location of textmate grammar

See original GitHub issue

Ref: https://github.com/vuejs/vetur/issues/210

In Vue files you can have <template>, <style> and <script> tag.

However, certain libraries can add top-level custom blocks that uses another language. For example:

<template></template>
<script></script>
<style></style>

<docs>
# This might be markdown or json, depending on user's build configuration
</docs>

Our approach was:

  • Give a setting vetur.grammar.customBlocks
  • Register a command to recompile the TextMate grammar with the custom blocks
  • Write the file to extension directory, the same path as the one specified in package.json

vetur

This has been working, but I’m worried extension integrity check might kick in and ask for reinstall. Also @sandy081 mentioned updates remove the old folder, so it’s bad to keep states in extension directory.

What I need is a path that I can:

  • Statically determine in write-time (as the path is specified in package.json)
  • Have write permission

So the paths in ExtensionContext wouldn’t work for me.

After checking with @sandy081, we think offering an API like languages.setGrammar would be best. We considered allowing path interpolations like ${globalStoragePath}/grammars/vue.json in package.json, but that means the best Vetur can do is to write to that path on first activation, so no coloring before first activation/reload.

However, I’m not sure we should provide an API tied to TextMate grammar. Also the API means the dynamically generated TextMate grammar wouldn’t be loaded until extension activation.

@alexandrudima What do you think?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:10
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
mechatronercommented, Oct 2, 2020

I wanted to open a new ticket, but found the existing one! I also have a strong need for dynamic grammar generation. As a developer of Rainbow CSV I need this API to implement the following features:

  • Support comments in CSV files (depending on user selection of a comment prefix Rainbow CSV would be able to generate an appropriate TextMate grammar)
  • Support all possible single-character and multi-character CSV delimiters (just the ASCII character set has over 30 non-alphanumeric characters that can be used as CSV separators, so providing 30 pre-generated static syntax files is not feasible, and there are also use-cases for multi-character separators) There are multiple issues in my project which are blocked by the lack of this mechanism in VSCode: mechatroner/vscode_rainbow_csv#14, mechatroner/vscode_rainbow_csv#1, mechatroner/vscode_rainbow_csv#31, mechatroner/vscode_rainbow_csv#70, mechatroner/vscode_rainbow_csv#58, mechatroner/vscode_rainbow_csv#33

Both Vim and Sublime Text 3 editors support dynamic syntax generation; this mechanism is widely used in Vim by parenthesis highlighting extensions.

1reaction
jquensecommented, Jul 28, 2020

any chance semantic highlighting could hackily cover this? https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide

Read more comments on GitHub >

github_iconTop Results From Across the Web

Language Grammars — TextMate 1.x Manual
You can create a new language grammar by opening the bundle editor (Window → Show Bundle Editor) and select “New Language” from the...
Read more >
Is it possible to dynamically add "keywords" in VS Code syntax ...
I've been playing around with syntax highlighting in VS Code and have so far been able to get a pretty good result using...
Read more >
TextMate Grammar support plugin should be optional
The plugin to support TextMate Grammars is automatically installed without an option to omit it. It can be uninstalled after installation, so there...
Read more >
[vim/vim] [proposal] Can we introduce TextMate grammar ...
For example, a constant variable name can be rendered using constant highlighting throughout the project, not just at the place of its declaration....
Read more >
Ace - The High Performance Code Editor for the Web
Learn how to embed this in your own site ... Syntax highlighting for over 110 languages (TextMate/Sublime Text.tmlanguage files can be imported) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found