Allow dynamic location of textmate grammar
See original GitHub issueRef: 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
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:
- Created 5 years ago
- Reactions:10
- Comments:10 (3 by maintainers)
Top GitHub Comments
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:
Both Vim and Sublime Text 3 editors support dynamic syntax generation; this mechanism is widely used in Vim by parenthesis highlighting extensions.
any chance semantic highlighting could hackily cover this? https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide