-
Notifications
You must be signed in to change notification settings - Fork 29.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: Enable emmet for other file extensions. #9500
Comments
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 |
I did an ugly hack to force it enable:
Everything seems fine for now. |
@mrmlnc what would be a good way to expose this that is consistent with emmet. Now that VS Code exposes emmet preferences and profiles? |
@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 I see several ways to solve this problem. Very simple wayExpand the list of language identifiers use Editor settings {
"emmet.syntaxProfiles": {
// force HTML profile for Nunjucks syntax
"nunjucks": "html"
}
}
// Supported by Emmet languages
const baseEmmetLanguages = ['html', 'css', 'xml', 'svg', 'xsl', 'haml', 'jade', 'jsx', 'slim', 'scss', 'sass', 'less', 'stylus', 'styl'];
public getSyntax(): string {
let position = this.editor.getSelection().getStartPosition();
let modeId = this.editor.getModel().getModeIdAtPosition(position.lineNumber, position.column);
let syntax = modeId.split('.').pop();
// Pseudo code
let syntaxProfilesLanguages = editor.settings.emmet.syntaxProfiles;
if (syntaxProfilesLanguages[syntax] && typeof syntaxProfilesLanguages[syntax] === 'string') {
return syntaxProfilesLanguages[syntax];
}
// Default checks for `typescriptreact`, `sass-indented` and other IDs
// ...
return syntax;
} Pros
Cons
Best way
Each language has a chain of heritage in
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: // Supported by Emmet languages
const baseEmmetLanguages = ['html', 'css', 'xml', 'svg', 'xsl', 'haml', 'jade', 'jsx', 'slim', 'scss', 'sass', 'less', 'stylus', 'styl'];
public isEmmetEnabledMode(): boolean {
let syntax = this.getSyntax();
return Boolean(syntax);
}
public getSyntax(): string {
// Pseudo code
let scopeName = getDocumentSyntaxScopeName();
// scope[0] -> source or text
// scope[1] -> parent syntax
// ...
// scope[n] -> current syntax
let scopes = 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.net
let currentSyntax = 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 -> false
if (baseEmmetLanguages.indexOf(currentSyntax) !== -1) {
return currentSyntax;
}
let parentSyntax = 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 -> false
if (baseEmmetLanguages.indexOf(parentSyntax) !== -1) {
return parentSyntax;
}
// Default checks for `typescriptreact`, `sass-indented` and other IDs
//
// Handlebars (hbs), erb, ejs, twig with extension?
if (/\b(razor)\b/.test(syntax)) { // treat like html
return 'html';
}
if (/\b(typescriptreact|javascriptreact)\b/.test(syntax)) { // treat like tsx like jsx
return 'jsx';
}
if (syntax === 'sass-indented') { // map sass-indented to sass
return 'sass';
}
// [3] Java -> source.java -> return null -> drop Emmet
// [5] ASP vb.NET -> source.asp.vb.net -> return null -> drop Emmet
return ''; // may be null or false ?
} Pros
Cons
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 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 |
@mrmlnc great analysis thanks. What is obvious is now that we support the syntaxProfiles setting the hard coded behaviour in I've added this on the plan for August since we are just wrapping up the July update. |
@mrmlnc starting to implement this. I think we need both solutions that you described above:
|
@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. |
@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? |
@egamma the official documentation not contain a list of available profiles. It can be found in the
As array: ['html', 'xhtml', 'css', 'xml', 'xsl', 'haml', 'jade', 'jsx', 'slim', 'scss', 'sass', 'less', 'stylus', 'styl'] |
@egamma, small question: First, see 2f2d650#commitcomment-18768402 Also maybe add a condition for those languages that are already present in the list? It seems to me there is no point in checking the parent languages for CSS or HTML. public getSyntax(): string {
...
// user can overwrite the syntax using the emmet syntaxProfiles setting
let profile = this.getSyntaxProfile(syntax);
if (profile) {
return profile;
}
+ if (this.emmetSupportedModes.indexOf(syntax) !== -1) {
+ return syntax;
+ }
if (/\b(razor|handlebars|erb|php|hbs|ejs|twig)\b/.test(syntax)) { // treat like html IMO, you can replace PR ? 😸 |
@mrmlnc thanks for the code review.
No, I wasn't aware of this case "... first is either text or source and the second is the name of the language or document type." However, it is really time for some unit tests for the getSyntax() code. I'll start on it.
👍
💯 , I wasn't sure of the official supported list. So a PR would be much appreciated. |
@egamma, Sadly, TextMate does not limit the nesting of languages (but recommends use As I understand from the documentation, What do you think about replacing the last condition on cycle? It's completely cover private checkParentMode(syntax: string): string {
...
- let parentMode = languages[languages.length-2];
- if (this.emmetSupportedModes.indexOf(parentMode) !== -1) {
- return parentMode;
- }
return syntax;
} for (let i = 1; i < languages.length; i++) {
const language = languages[languages.length - i];
if (this.emmetSupportedModes.indexOf(language) !== -1) {
return language;
}
} |
@mrmlnc 👍 on this change, it makes the core more robust and removes an assumption. BTW, I'm refactoring the editorAccessor code a bit to make it easier testable. So if you plan to make a PR, please wait until I'm done with this refactoring and we can have unit tests for all this logic. |
Yes, thanks for the warning. I'll wait your changes. |
@mrmlnc |
@egamma, done. |
Hello folks!
Also tried |
@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-a this could be related to #18434 |
@iamandrewluca What is the language mode that appears in the bottom right corner of the status bar when you have this Set the language mode for this file to html and you should be good to go |
@ramya-rao-a I am doing but, What is the consequences of that? What happen if the |
@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? |
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 ( I had to disable useNewEmmet for it to work. |
@hogdogthegod In the new emmet model, we are using "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/ 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 |
You can simple use this: "emmet.includeLanguages": {
"erb": "html"
} |
Steps to Reproduce:
Nunjucks
plugin.p
and press tab.\t
was inserted.Expected Result:
p
expanded to<p></p>
.I was looking for the setting to enable
emmet
, but it seems hard-coded in the source (src/vs/workbench/parts/emmet/node/editorAccessor.ts#L20).Can we modify this value through preference?
Thanks.
The text was updated successfully, but these errors were encountered: