Skip to content

Commit

Permalink
Addressing feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustavo Martin Hurovich committed Mar 23, 2018
1 parent 8f796cb commit dea5096
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
4 changes: 2 additions & 2 deletions extensions/emmet/src/defaultCompletionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import * as vscode from 'vscode';
import { Node } from 'EmmetNode';
import { isValidLocationForEmmetAbbreviation } from './abbreviationActions';
import { getEmmetHelper, getNode, getMappingForIncludedLanguages, parsePartialStylesheet, getEmmetConfiguration, getEmmetMode, isStyleSheet } from './util';
import { getEmmetHelper, getNode, getMappingForIncludedLanguages, parsePartialStylesheet, getEmmetConfiguration, getEmmetMode, isStyleSheet, parseDocument } from './util';

export class DefaultCompletionItemProvider implements vscode.CompletionItemProvider {

Expand Down Expand Up @@ -38,7 +38,7 @@ export class DefaultCompletionItemProvider implements vscode.CompletionItemProvi

// If document can be css parsed, get currentNode
if (isStyleSheet(document.languageId)) {
const rootNode = parsePartialStylesheet(document, position);
const rootNode = document.lineCount > 1000 ? parsePartialStylesheet(document, position) : parseDocument(document, false);
if (!rootNode) {
return;
}
Expand Down
15 changes: 6 additions & 9 deletions extensions/emmet/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,17 @@ export function parsePartialStylesheet(document: vscode.TextDocument, position:
// Go back until we found an opening brace. If we find a closing one, we first find its opening brace and then we continue.
stream.pos = position;
let openBracesRemaining = 1;
let unindentedRulesFound = 0;
while (openBracesRemaining > 0 && !(stream.pos.line === 0 && stream.pos.character === 0)) {
while (openBracesRemaining > 0 && !stream.sof()) {
let ch = stream.backUp(1);
if (ch === openBrace) {
openBracesRemaining--;
// Heuristic to not parse the whole document.
if (unindentedRulesFound >= 10) {
break;
}
} else if (ch === closeBrace) {
if (stream.pos.character === 0) {
unindentedRulesFound++;
if (document.languageId !== 'css') {
openBracesRemaining++;
}
if (position.line - stream.pos.line > 1000) {
return parseStylesheet(new DocumentStreamReader(document, new vscode.Position(0, 0)));
}
openBracesRemaining++;
}
}
// We are at an opening brace. We need to include its selector
Expand Down

0 comments on commit dea5096

Please sign in to comment.