Open dansullivan86 opened 7 years ago
It's possible by modding the js grammar that comes with VSCode, so it embeds html grammar.
I'll look into that a bit later. One question: is there anyway to tell whether the js file is a vue component? For react support in VSCode, VSCode uses jsx/tsx to denote support for jsx literal.
Unfortunately Vue components are exported as standard js objects in standard js files.
Could this be opt in for all js files?
Thanks
Even if it's opt-in, I can't just mark everything in backtick as html, right?
Template literals can contain plain strings, variables wrapped in ${} and html; https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Template_literals
I don't know anything about how the VSCode grammar stuff works to answer whether that would cause an issue.
How to know stuff between backstick is html but not plain string? If there is no way to check, I can't blindly mark everything between backstick as html.
Since HTML itself supports plain strings I'm not sure I see the issue?
If it helps Vue components are required to have a single root element so ignoring whitespace they would always start and finish with a tag e.g <div></div>
This will take a lot of time to get right. I'll take a look after #26.
Taking my words back -- this seems to be an interesting addition, and can be reused for other framework support, like how people in React is doing inlining CSS with string literals.
I'll try to have it by May for 1.0 release.
Alright, I thought angular already have this so I was bookmarking their LS. Turns out they have neither syntax highlighting nor intelligent completion for inline html template.
This is a hard feature to support.
We can hard code
/template:\s*`/
as the start of template literal. So only specific string literal is highlighted.
Angular has implemented template completion by Angular Language Service as a tsserver plugin. While it is doable, I don't think it is easy to implement well, if it worth implementing at all.
hey guys, when will we get this feature? @HerringtonDarkholme @octref I just want highlight
That's blocked by an upstream issue: https://github.com/Microsoft/vscode/issues/44056
I modified a sample vscode plugin and made it look for the template:
property so that I could get highlighting on my Vue templates:
"html-tagged-template": {
"begin": "(?<=template: `)", "end": "(?=`)",
"contentName": "meta.embedded.html",
"patterns": [
{
"include": "#html-template-body"
}
]
}
It's a quick-and-dirty solution that probably doesn't address every edge case, but I've been pretty happy with it so far.
I have this working in javascript files using commenting.. either through https://github.com/mjbvz/vscode-comment-tagged-templates or (this is a bit more specific to lit-html) https://github.com/mjbvz/vscode-lit-html
Both require marking up your template literal.. which honestly I think makes sense. You could have template literals not meant to be HTML for sure.. but the notion of placing a comment in front of the backtick to denote the intended syntax is (to me) a reasonable standard:
const template = /* html */`
<div class="template"></div>
`
I just added the first plugin (comment-tagged-templates) but found it doesn't work in Vue files... but wondered if there's a way to configure it to work through Vetur.
@segphault how did you set your "workingness" up exactly? Was it a matter of forking/cloning that repo and editing it specifically with the options you posted and then installing it as a VSCode plugin?
I'm very keen to get this working in Sublime- has anyone had success?
It's common in GraphQL-land to hint tooling by tagging the literals. Perhaps Something like:
export default {
template: vue`...`
}
May need to import a lib that defines the vue
tag to make this work, but I'd be happy to add that to my components. I already do it for my GraphQL files.
@Patcher56 Would you be interested in taking this issue?
I'm very busy atm but I am very interested. If I have more time, I will do that for sure!
Any other news on this issue? One use case for this feature is writing Vue stories in Storybook. Tried using es6-string-html but it has no autocompletion, not even for basic html tags. styled-components has an extension for CSS rules with highlighting and intellisense, maybe it can be used as inspiration.
A workaround for people which are still interested could be to use the vscode extension https://marketplace.visualstudio.com/items?itemName=plievone.vscode-template-literal-editor. You can select the template literal, press ctrl + enter and a second editor opens. In this window you have syntax highlighting and autocompletion.
Remarks: I'm not the author of this extension nor affiliated.
Is it possible to add syntax highlighting support to template literals when not using .vue files.