Skip to content

Commit

Permalink
2nd part of the fix for #9500, consider the parent language
Browse files Browse the repository at this point in the history
  • Loading branch information
egamma committed Aug 24, 2016
1 parent 3cce5ed commit 2f2d650
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion src/vs/workbench/parts/emmet/node/editorAccessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,17 @@ import strings = require('vs/base/common/strings');
import snippets = require('vs/editor/contrib/snippet/common/snippet');
import {Range} from 'vs/editor/common/core/range';
import {SnippetController} from 'vs/editor/contrib/snippet/common/snippetController';
import {ExtensionsRegistry} from 'vs/platform/extensions/common/extensionsRegistry';


import emmet = require('emmet');

interface ModeScopeMap {
[key: string]: string;
}

let modeScopesMap: ModeScopeMap = null;

export class EditorAccessor implements emmet.Editor {

editor: ICommonCodeEditor;
Expand Down Expand Up @@ -127,7 +135,7 @@ export class EditorAccessor implements emmet.Editor {
if (profile) {
return profile;
}

if (/\b(razor|handlebars|erb|php|hbs|ejs|twig)\b/.test(syntax)) { // treat like html
return 'html';
}
Expand All @@ -137,6 +145,8 @@ export class EditorAccessor implements emmet.Editor {
if (syntax === 'sass-indented') { // map sass-indented to sass
return 'sass';
}
syntax = this.checkParentMode(syntax);

return syntax;
}

Expand All @@ -147,6 +157,43 @@ export class EditorAccessor implements emmet.Editor {
}
}

private checkParentMode(syntax: string): string {
if (!modeScopesMap) {
modeScopesMap = this.getModeScopeMap();
}
let languageGrammar = modeScopesMap[syntax];
if (!languageGrammar) {
return syntax;
}
let languages = languageGrammar.split('.');
let thisLanguage = languages[languages.length-1];
if (syntax !== thisLanguage || languages.length < 2) {
return syntax;
}
let parentMode = languages[languages.length-2];

This comment has been minimized.

Copy link
@mrmlnc

mrmlnc Aug 24, 2016

Contributor

@egamma,

Are you sure that you correctly get the parent language?

For example, your case with blade extension:

languageGrammar: text.html.php.laravel-blade
languages:       ["text", "html", "php", "laravel-blade"]
thisLanguage:    laravel-blade
parentMode:      php                                      // mayby `html`?

If let parentMode = languages[1]:

languageGrammar: text.html.php.laravel-blade
languages:       ["text", "html", "php", "laravel-blade"]
thisLanguage:    laravel-blade
parentMode:      html                                      // <---- 
if (this.emmetSupportedModes.indexOf(parentMode) !== -1) {
return parentMode;
}
return syntax;
}

private getModeScopeMap(): ModeScopeMap {
let map: ModeScopeMap = {};
ExtensionsRegistry.getAllExtensionDescriptions().forEach((desc) => {
if (desc.contributes) {
let grammars = (<any>desc.contributes).grammars;
if (grammars) {
grammars.forEach((grammar) => {
if (grammar.language && grammar.scopeName) {
map[grammar.language] = grammar.scopeName;
}
});
}
}
});
return map;
}

public getProfileName(): string {
return null;
}
Expand Down

0 comments on commit 2f2d650

Please sign in to comment.