Skip to content

Commit

Permalink
Partial fix for #9500
Browse files Browse the repository at this point in the history
  • Loading branch information
egamma committed Aug 24, 2016
1 parent 673d75e commit 67bbb46
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
22 changes: 19 additions & 3 deletions src/vs/workbench/parts/emmet/node/editorAccessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,20 @@ import emmet = require('emmet');
export class EditorAccessor implements emmet.Editor {

editor: ICommonCodeEditor;
syntaxProfiles: any;

private _hasMadeEdits: boolean;

emmetSupportedModes = ['html', 'razor', 'css', 'less', 'sass', 'scss', 'stylus', 'xml', 'xsl', 'jade', 'handlebars', 'ejs', 'hbs', 'jsx', 'tsx', 'erb', 'php', 'twig'];

constructor(editor: ICommonCodeEditor) {
constructor(editor: ICommonCodeEditor, syntaxProfiles: any) {
this.editor = editor;
this.syntaxProfiles = syntaxProfiles;
this._hasMadeEdits = false;
}

public isEmmetEnabledMode(): boolean {
let syntax = this.getSyntax();
return (this.emmetSupportedModes.indexOf(syntax) !== -1);
return this.emmetSupportedModes.indexOf(this.getSyntax()) !== -1;
}

public getSelectionRange(): emmet.Range {
Expand Down Expand Up @@ -119,6 +121,13 @@ export class EditorAccessor implements emmet.Editor {
let position = this.editor.getSelection().getStartPosition();
let modeId = this.editor.getModel().getModeIdAtPosition(position.lineNumber, position.column);
let syntax = modeId.split('.').pop();

// user can overwrite the syntax using the emmet syntaxProfiles setting
let profile = this.getSyntaxProfile(syntax);
if (profile) {
return profile;
}

if (/\b(razor|handlebars|erb|php|hbs|ejs|twig)\b/.test(syntax)) { // treat like html
return 'html';
}
Expand All @@ -131,6 +140,13 @@ export class EditorAccessor implements emmet.Editor {
return syntax;
}

private getSyntaxProfile(syntax: string): string {
const profile = this.syntaxProfiles[syntax];
if (profile && typeof profile === 'string') {
return profile;
}
}

public getProfileName(): string {
return null;
}
Expand Down
6 changes: 3 additions & 3 deletions src/vs/workbench/parts/emmet/node/emmetActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ class LazyEmmet {
_emmet.preferences.define(key, preferences[key]);
}
}
let syntaxProfile = configurationService.getConfiguration<IEmmetConfiguration>().emmet.syntaxProfiles;
let syntaxProfiles = configurationService.getConfiguration<IEmmetConfiguration>().emmet.syntaxProfiles;
_emmet.profile.reset();
_emmet.loadProfiles(syntaxProfile);
_emmet.loadProfiles(syntaxProfiles);
}

private resetEmmetPreferences(configurationService:IConfigurationService, _emmet: typeof emmet) {
Expand Down Expand Up @@ -110,7 +110,7 @@ export abstract class EmmetEditorAction extends EditorAction {
const configurationService = accessor.get(IConfigurationService);
const instantiationService = accessor.get(IInstantiationService);

let editorAccessor = new EditorAccessor(editor);
let editorAccessor = new EditorAccessor(editor, configurationService.getConfiguration<IEmmetConfiguration>().emmet.syntaxProfiles);
if (!editorAccessor.isEmmetEnabledMode()) {
this.noExpansionOccurred(editor);
return ;
Expand Down

0 comments on commit 67bbb46

Please sign in to comment.