Skip to content

Commit 43ef579

Browse files
authored
Revert "Fix language-specific tab expansion and polish (microsoft#157035)" (microsoft#160234)
This reverts commit 9f80085.
1 parent f25d1b8 commit 43ef579

File tree

5 files changed

+36
-42
lines changed

5 files changed

+36
-42
lines changed

extensions/emmet/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"emmet.showAbbreviationSuggestions": {
6666
"type": "boolean",
6767
"default": true,
68-
"scope": "resource",
68+
"scope": "language-overridable",
6969
"markdownDescription": "%emmetShowAbbreviationSuggestions%"
7070
},
7171
"emmet.includeLanguages": {

extensions/emmet/src/abbreviationActions.ts

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -264,47 +264,47 @@ export async function wrapWithAbbreviation(args: any): Promise<boolean> {
264264
}
265265

266266
export function expandEmmetAbbreviation(args: any): Thenable<boolean | undefined> {
267-
if (!validate()) {
268-
return Promise.resolve(undefined);
267+
if (!validate() || !vscode.window.activeTextEditor) {
268+
return fallbackTab();
269269
}
270270

271-
const editor = vscode.window.activeTextEditor!;
272-
273-
args = args || {};
274-
if (!args['language']) {
275-
args['language'] = editor.document.languageId;
276-
} else {
277-
const excludedLanguages = vscode.workspace.getConfiguration('emmet')['excludeLanguages'] ?? [];
278-
if (excludedLanguages.includes(args['language'])) {
279-
return fallbackTab(args['language']);
280-
}
281-
}
282-
const languageId: string = args['language'];
283-
284271
/**
285272
* Short circuit the parsing. If previous character is space, do not expand.
286273
*/
287-
if (editor.selections.length === 1 && editor.selection.isEmpty
274+
if (vscode.window.activeTextEditor.selections.length === 1 &&
275+
vscode.window.activeTextEditor.selection.isEmpty
288276
) {
289-
const anchor = editor.selection.anchor;
277+
const anchor = vscode.window.activeTextEditor.selection.anchor;
290278
if (anchor.character === 0) {
291-
return fallbackTab(languageId);
279+
return fallbackTab();
292280
}
293281

294282
const prevPositionAnchor = anchor.translate(0, -1);
295-
const prevText = editor.document.getText(new vscode.Range(prevPositionAnchor, anchor));
283+
const prevText = vscode.window.activeTextEditor.document.getText(new vscode.Range(prevPositionAnchor, anchor));
296284
if (prevText === ' ' || prevText === '\t') {
297-
return fallbackTab(languageId);
285+
return fallbackTab();
298286
}
299287
}
300288

289+
args = args || {};
290+
if (!args['language']) {
291+
args['language'] = vscode.window.activeTextEditor.document.languageId;
292+
} else {
293+
const excludedLanguages = vscode.workspace.getConfiguration('emmet')['excludeLanguages'] ? vscode.workspace.getConfiguration('emmet')['excludeLanguages'] : [];
294+
if (excludedLanguages.indexOf(vscode.window.activeTextEditor.document.languageId) > -1) {
295+
return fallbackTab();
296+
}
297+
}
301298
const syntax = getSyntaxFromArgs(args);
302299
if (!syntax) {
303-
return fallbackTab(languageId);
300+
return fallbackTab();
304301
}
302+
303+
const editor = vscode.window.activeTextEditor;
304+
305305
// When tabbed on a non empty selection, do not treat it as an emmet abbreviation, and fallback to tab instead
306-
if (vscode.workspace.getConfiguration('emmet', { languageId })['triggerExpansionOnTab'] === true && editor.selections.find(x => !x.isEmpty)) {
307-
return fallbackTab(languageId);
306+
if (vscode.workspace.getConfiguration('emmet')['triggerExpansionOnTab'] === true && editor.selections.find(x => !x.isEmpty)) {
307+
return fallbackTab();
308308
}
309309

310310
const abbreviationList: ExpandAbbreviationInput[] = [];
@@ -325,7 +325,7 @@ export function expandEmmetAbbreviation(args: any): Thenable<boolean | undefined
325325
}
326326

327327
const currentLine = editor.document.lineAt(position.line).text;
328-
const textTillPosition = currentLine.substring(0, position.character);
328+
const textTillPosition = currentLine.substr(0, position.character);
329329

330330
// Expand cases like <div to <div></div> explicitly
331331
// else we will end up with <<div></div>
@@ -415,12 +415,12 @@ export function expandEmmetAbbreviation(args: any): Thenable<boolean | undefined
415415
});
416416

417417
return expandAbbreviationInRange(editor, abbreviationList, allAbbreviationsSame).then(success => {
418-
return success ? Promise.resolve(undefined) : fallbackTab(languageId);
418+
return success ? Promise.resolve(undefined) : fallbackTab();
419419
});
420420
}
421421

422-
function fallbackTab(languageId: string): Thenable<boolean | undefined> {
423-
if (vscode.workspace.getConfiguration('emmet', { languageId })['triggerExpansionOnTab'] === true) {
422+
function fallbackTab(): Thenable<boolean | undefined> {
423+
if (vscode.workspace.getConfiguration('emmet')['triggerExpansionOnTab'] === true) {
424424
return vscode.commands.executeCommand('tab');
425425
}
426426
return Promise.resolve(true);
@@ -470,13 +470,13 @@ export function isValidLocationForEmmetAbbreviation(document: vscode.TextDocumen
470470
&& propertyNode.separator
471471
&& offset >= propertyNode.separatorToken.end
472472
&& offset <= propertyNode.terminatorToken.start
473-
&& !abbreviation.includes(':')) {
473+
&& abbreviation.indexOf(':') === -1) {
474474
return hexColorRegex.test(abbreviation) || abbreviation === '!';
475475
}
476476
if (!propertyNode.terminatorToken
477477
&& propertyNode.separator
478478
&& offset >= propertyNode.separatorToken.end
479-
&& !abbreviation.includes(':')) {
479+
&& abbreviation.indexOf(':') === -1) {
480480
return hexColorRegex.test(abbreviation) || abbreviation === '!';
481481
}
482482
if (hexColorRegex.test(abbreviation) || abbreviation === '!') {
@@ -529,7 +529,7 @@ export function isValidLocationForEmmetAbbreviation(document: vscode.TextDocumen
529529
const typeAttribute = (currentHtmlNode.attributes || []).filter(x => x.name.toString() === 'type')[0];
530530
const typeValue = typeAttribute ? typeAttribute.value.toString() : '';
531531

532-
if (allowedMimeTypesInScriptTag.includes(typeValue)) {
532+
if (allowedMimeTypesInScriptTag.indexOf(typeValue) > -1) {
533533
return true;
534534
}
535535

extensions/emmet/src/defaultCompletionProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class DefaultCompletionItemProvider implements vscode.CompletionItemProvi
3131

3232
if (expandedText.startsWith('<')) {
3333
this.lastCompletionType = 'html';
34-
} else if (expandedText.includes(':') && expandedText.endsWith(';')) {
34+
} else if (expandedText.indexOf(':') > 0 && expandedText.endsWith(';')) {
3535
this.lastCompletionType = 'css';
3636
} else {
3737
this.lastCompletionType = undefined;
@@ -43,7 +43,7 @@ export class DefaultCompletionItemProvider implements vscode.CompletionItemProvi
4343
private provideCompletionItemsInternal(document: vscode.TextDocument, position: vscode.Position, context: vscode.CompletionContext): Thenable<vscode.CompletionList | undefined> | undefined {
4444
const emmetConfig = vscode.workspace.getConfiguration('emmet');
4545
const excludedLanguages = emmetConfig['excludeLanguages'] ? emmetConfig['excludeLanguages'] : [];
46-
if (excludedLanguages.includes(document.languageId)) {
46+
if (excludedLanguages.indexOf(document.languageId) > -1) {
4747
return;
4848
}
4949

extensions/emmet/src/selectItemHTML.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ function getNextAttribute(document: vscode.TextDocument, selectionStart: number,
140140
}
141141

142142
// Fetch the next word in the attr value
143-
if (!attr.value.toString().includes(' ')) {
143+
if (attr.value.toString().indexOf(' ') === -1) {
144144
// attr value does not have space, so no next word to find
145145
continue;
146146
}

src/vs/workbench/contrib/emmet/browser/emmetActions.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { grammarsExtPoint, ITMSyntaxExtensionPoint } from 'vs/workbench/services
88
import { IExtensionService, ExtensionPointContribution } from 'vs/workbench/services/extensions/common/extensions';
99
import { ICommandService } from 'vs/platform/commands/common/commands';
1010
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
11-
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
1211

1312
interface ModeScopeMap {
1413
[key: string]: string;
@@ -71,18 +70,13 @@ export abstract class EmmetEditorAction extends EditorAction {
7170
}
7271

7372
public run(accessor: ServicesAccessor, editor: ICodeEditor): Promise<void> {
74-
const commandService = accessor.get(ICommandService);
75-
const configurationService = accessor.get(IConfigurationService);
7673
const extensionService = accessor.get(IExtensionService);
74+
const commandService = accessor.get(ICommandService);
7775

7876
return this._withGrammarContributions(extensionService).then((grammarContributions) => {
7977

8078
if (this.id === 'editor.emmet.action.expandAbbreviation' && grammarContributions) {
81-
const languageInfo = EmmetEditorAction.getLanguage(editor, grammarContributions);
82-
const languageId = languageInfo?.language;
83-
if (configurationService.getValue('emmet.triggerExpansionOnTab', { overrideIdentifier: languageId }) === true) {
84-
return commandService.executeCommand<void>('emmet.expandAbbreviation', languageInfo);
85-
}
79+
return commandService.executeCommand<void>('emmet.expandAbbreviation', EmmetEditorAction.getLanguage(editor, grammarContributions));
8680
}
8781

8882
return undefined;

0 commit comments

Comments
 (0)