You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Feature Request: Enable emmet for other file extensions. #9500
I think thats an issue that comes up not the first time (#4962 or #4700 for example) but was always phrased as "support emmet in filetype x". I think implementing an option to turn emmet on for filetypes or if some people want it everywhere (thats how I have it in vim) would be nice and could solve this one and for all.
# sed -i.bak 's/emmetSupportedModes=\["html",/emmetSupportedModes=\["nunjucks","html",/' /usr/share/code/resources/app/out/vs/workbench/workbench.main.js
Denis Malinochkin (@mrmlnc) what would be a good way to expose this that is consistent with emmet. Now that VS Code exposes emmet preferences and profiles?
The main problem is that we have a list of language identifiers that cannot be edited and supplemented. This imposes on us the responsibility to resolve issues such as this.
Now our main problem is the isEmmetEnabledMode function.
I see several ways to solve this problem.
Very simple way
Expand the list of language identifiers use emmet.syntaxProfiles property. For example:
Editor settings
{
"emmet.syntaxProfiles": {
// force HTML profile for Nunjucks syntax"nunjucks": "html"
}
}
getSyntax function
// Supported by Emmet languagesconstbaseEmmetLanguages=['html','css','xml','svg','xsl','haml','jade','jsx','slim','scss','sass','less','stylus','styl'];publicgetSyntax(): string {letposition=this.editor.getSelection().getStartPosition();letmodeId=this.editor.getModel().getModeIdAtPosition(position.lineNumber,position.column);letsyntax=modeId.split('.').pop();// Pseudo codeletsyntaxProfilesLanguages=editor.settings.emmet.syntaxProfiles;if(syntaxProfilesLanguages[syntax]&&typeofsyntaxProfilesLanguages[syntax]==='string'){returnsyntaxProfilesLanguages[syntax];}// Default checks for `typescriptreact`, `sass-indented` and other IDs// ...returnsyntax;}
Pros
We don't need to do anything.
Looks decent.
Cons
Full responsibility rests with the end user, not the creator of the plugin.
Removed settings - write again.
We still need to have conditions for certain syntaxes. (typescriptreact, sass-indented and etc).
Best way
This method solves the problem fundamentally.
Each language has a chain of heritage in tmLanguage or language.json. Also the scope is specified in the package.json file in each language extension (contributes.grammars.scopeName). This parameter is stored in the scopeName field.
scopeName (line 1) — this should be a unique name for the grammar, following the convention of being a dot-separated name where each new (left-most) part specializes the name. Normally it would be a two-part name where the first is either text or source and the second is the name of the language or document type. But if you are specializing an existing type, you probably want to derive the name from the type you are specializing. For example Markdown is text.html.markdown and Ruby on Rails (rhtml files) is text.html.rails. The advantage of deriving it from (in this case) text.html is that everything which works in the text.html scope will also work in the text.html.«something» scope (but with a lower precedence than something specifically targeting text.html.«something»).
For example, this method is used in Atom. Thus we can 100% be sure that Emmet works for all languages, that he can support.
Warning
Unfortunately, some languages do not have this field. See code example below (razor).
For example with pesudo code:
// Supported by Emmet languagesconstbaseEmmetLanguages=['html','css','xml','svg','xsl','haml','jade','jsx','slim','scss','sass','less','stylus','styl'];publicisEmmetEnabledMode(): boolean {letsyntax=this.getSyntax();returnBoolean(syntax);}publicgetSyntax(): string {// Pseudo codeletscopeName=getDocumentSyntaxScopeName();// scope[0] -> source or text// scope[1] -> parent syntax// ...// scope[n] -> current syntaxletscopes=scopeName.split('.')// For example://// [1] Less -> source.css.less// [2] CSS -> source.css// [3] Java -> source.java// [4] PHP -> text.html.php// [5] ASP vb.NET -> source.asp.vb.netletcurrentSyntax=scopes[scopes.length];// [1] Less -> source.css.less -> less -> true -> return `less`// [2] CSS -> source.css -> css -> true -> return `css`// [3] Java -> source.java -> java -> false// [4] PHP -> text.html.php -> php -> false// [5] ASP vb.NET -> source.asp.vb.net -> net -> falseif(baseEmmetLanguages.indexOf(currentSyntax)!==-1){returncurrentSyntax;}letparentSyntax=scopes[1];// [3] Java -> source.java -> java -> false// [4] PHP -> text.html.php -> html -> true -> return `html`// [5] ASP vb.NET -> source.asp.vb.net -> asp -> falseif(baseEmmetLanguages.indexOf(parentSyntax)!==-1){returnparentSyntax;}// Default checks for `typescriptreact`, `sass-indented` and other IDs//// Handlebars (hbs), erb, ejs, twig with extension?if(/\b(razor)\b/.test(syntax)){// treat like htmlreturn'html';}if(/\b(typescriptreact|javascriptreact)\b/.test(syntax)){// treat like tsx like jsxreturn'jsx';}if(syntax==='sass-indented'){// map sass-indented to sassreturn'sass';}// [3] Java -> source.java -> return null -> drop Emmet// [5] ASP vb.NET -> source.asp.vb.net -> return null -> drop Emmetreturn'';// may be null or false ?}
Pros
All languages automatically have support Emmet.
The end user must not do anything except install the extension.
Cons
A lot of code.
We still need to have conditions for certain syntaxes. (typescriptreact, sass-indented and etc).
Not a problem, but need to optimize language checking. In the above code checks only the current and parent syntax. But in the real case, a set of syntaxes can be unlimited (see ASP vb.NET source.asp.vb.net).
Denis Malinochkin (@mrmlnc) great analysis thanks. What is obvious is now that we support the syntaxProfiles setting the hard coded behaviour in isEmmetEnabledMode function must be removed.
I've added this on the plan for August since we are just wrapping up the July update.
Reacted by Mathis Wiehl, KwanLam Chan, Denis Malinochkin, Mihai Vilcu and Sayth
Denis Malinochkin (@mrmlnc) starting to implement this. I think we need both solutions that you described above:
we should honor when the user defines a different profile for an existing language
it should be possible to contribute a language to vscode that gets emmet support without that the user needs to configure emmet support in the settings.
Erich Gamma (@egamma), on one hand I have nothing against current solution (partial fix). But on the other hand, when I install extension (for example, HAML), I want to support Emmet out of the box. Also users must now have additional settings. And we still have a list of available languages.
And to make matters worse, users should be aware of the existing profiles Emmet, that are not described in the documentation.
Denis Malinochkin (@mrmlnc) I fully agree with you. This is why I didn't close the issue yet. I'm about to check in the 2nd part of the fix which covers the NunJucks scenario.
And to make matters worse, users should be aware of the existing profiles Emmet, that are not described in the documentation.
I've filed this issue to track the documentation gap microsoft/vscode-docs#541. Is there some emmet documentation we can refer to?
@iamandrewluca What is the language mode that appears in the bottom right corner of the status bar when you have this myFile.html.erb file open? My guess is that it would be plain text. I don't believe erb or eruby is one of the valid language modes in VS Code out of the box.
Set the language mode for this file to html and you should be good to go
Hog Dog (@hogdogthegod) In the new emmet model, we are using emmet.includeLanguages for mapping new language modes to an existing language that has emmet support.
Activity
fahrradflucht commentedon Jul 19, 2016
I think thats an issue that comes up not the first time (#4962 or #4700 for example) but was always phrased as "support emmet in filetype x". I think implementing an option to turn emmet on for filetypes or if some people want it everywhere (thats how I have it in vim) would be nice and could solve this one and for all.
This option should be triggerable by plugins implementing new filetypes as well. Otherwise it would not be possible to fix issues like https://github.com/mat-mcloughlin/vscode-elixir/issues/11 since you can't just associate
.eexwithhtmlor would it?jixunmoe commentedon Jul 19, 2016
I did an ugly hack to force it enable:
Everything seems fine for now.
egamma commentedon Jul 26, 2016
Denis Malinochkin (@mrmlnc) what would be a good way to expose this that is consistent with emmet. Now that VS Code exposes emmet preferences and profiles?
mrmlnc commentedon Jul 27, 2016
Erich Gamma (@egamma), now it is difficult to say something.
The main problem is that we have a list of language identifiers that cannot be edited and supplemented. This imposes on us the responsibility to resolve issues such as this.
Now our main problem is the
isEmmetEnabledModefunction.I see several ways to solve this problem.
Very simple way
Expand the list of language identifiers use
emmet.syntaxProfilesproperty. For example:Editor settings
{ "emmet.syntaxProfiles": { // force HTML profile for Nunjucks syntax "nunjucks": "html" } }getSyntaxfunctionPros
Cons
typescriptreact,sass-indentedand etc).Best way
Each language has a chain of heritage in
tmLanguageorlanguage.json. Also the scope is specified in thepackage.jsonfile in each language extension (contributes.grammars.scopeName). This parameter is stored in thescopeNamefield.For example, this method is used in Atom. Thus we can 100% be sure that Emmet works for all languages, that he can support.
For example with pesudo code:
Pros
Cons
typescriptreact,sass-indentedand etc).Not a problem, but need to optimize language checking. In the above code checks only the current and parent syntax. But in the real case, a set of syntaxes can be unlimited (see ASP vb.NET
source.asp.vb.net).For example, Atom, checks first only the current and parent syntax and, if not, then begins to check the entire chain: https://github.com/emmetio/emmet-atom/blob/master/lib/editor-proxy.coffee#L207-L223
egamma commentedon Jul 27, 2016
Denis Malinochkin (@mrmlnc) great analysis thanks. What is obvious is now that we support the syntaxProfiles setting the hard coded behaviour in
isEmmetEnabledModefunction must be removed.I've added this on the plan for August since we are just wrapping up the July update.
egamma commentedon Aug 24, 2016
Denis Malinochkin (@mrmlnc) starting to implement this. I think we need both solutions that you described above:
Partial fix for #9500
mrmlnc commentedon Aug 24, 2016
Erich Gamma (@egamma), on one hand I have nothing against current solution (partial fix). But on the other hand, when I install extension (for example, HAML), I want to support Emmet out of the box. Also users must now have additional settings. And we still have a list of available languages.
And to make matters worse, users should be aware of the existing profiles Emmet, that are not described in the documentation.
egamma commentedon Aug 24, 2016
Denis Malinochkin (@mrmlnc) I fully agree with you. This is why I didn't close the issue yet. I'm about to check in the 2nd part of the fix which covers the NunJucks scenario.
I've filed this issue to track the documentation gap microsoft/vscode-docs#541. Is there some emmet documentation we can refer to?
2nd part of the fix for #9500, consider the parent language
mrmlnc commentedon Aug 24, 2016
Erich Gamma (@egamma) the official documentation not contain a list of available profiles. It can be found in the
lib/snippets.jsonfile. Also see http://docs.emmet.io/abbreviations/types/#element-typescsshtmlxhtml- hardcode (the same as html, but outputs empty elements with closed slash:<br />.)xml(emmet v1.4.0+ we have 1.3.1)svgxslhamljadejsxslimscsssasslessstylusstyl=stylusAs array:
5 remaining items
mrmlnc commentedon Aug 25, 2016
Erich Gamma (@egamma),
Yes, thanks for the warning. I'll wait your changes.
egamma commentedon Aug 25, 2016
Denis Malinochkin (@mrmlnc)
I've checked in unit test for the EditorAccessor, please review them and add more as needed.
mrmlnc commentedon Aug 26, 2016
Erich Gamma (@egamma), done.
unrevised6419 commentedon Dec 27, 2016
Hello folks!
I have a eRuby file
myFile.html.erband it seems that emmet does not work.I also tried to add this to settings but no chance.
Also tried
erbno chance.How can I fix this?
Thanks in advance!
egamma commentedon Jan 17, 2017
@iamandrewluca commenting on a closed issue can easily be overlooked. Please file a new issue for the problem you mention in #9500 (comment)
fyi Ramya Rao (@ramya-rao-a) this could be related to #18434
ramya-rao-a commentedon Jan 23, 2017
@iamandrewluca What is the language mode that appears in the bottom right corner of the status bar when you have this
myFile.html.erbfile open? My guess is that it would be plain text. I don't believeerborerubyis one of the valid language modes in VS Code out of the box.Set the language mode for this file to html and you should be good to go
yordis commentedon Jul 5, 2017
Ramya Rao (@ramya-rao-a) I am doing
.vuefiles and I know switching tohtmlin theLanguage Modewill actually fix my issuebut,
What is the consequences of that? What happen if the
.vueextension have multiple processing like emmet itself have?ramya-rao-a commentedon Jul 6, 2017
Yordis Prieto (@yordis) I don't understand what you mean by "multiple processing like emmet".
Did you try using emmet.syntaxProfiles setting to map vue to html?
hogdogthegod commentedon Jul 22, 2017
I was also having trouble getting emmet to run on erb files. The language was mode was being recognized as erb after installing [vscode-ruby-erb](https://github.com/vortizhe/vscode-ruby-erb, and I had emmet.syntaxProfiles set to associate erb with html (
"emmet.syntaxProfiles": { "erb": "html" }).I had to disable useNewEmmet for it to work.
ramya-rao-a commentedon Jul 22, 2017
Hog Dog (@hogdogthegod) In the new emmet model, we are using
emmet.includeLanguagesfor mapping new language modes to an existing language that has emmet support."syntaxProfiles" in emmet was meant to configure the output profile eg: casing control on attribute name or single/double quotes for attributes etc. You can read more here: https://docs.emmet.io/customization/syntax-profiles/
So we are moving away from hijacking "syntaxProfiles" for mapping new languages
Please read https://code.visualstudio.com/updates/v1_13#_emmet-abbreviation-expansion-in-suggestion-list and https://code.visualstudio.com/updates/v1_14#_emmet-abbreviation-improvements for more information on the new emmet model
abnersajr commentedon Oct 26, 2017
You can simple use this: