Skip to content
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

Stylesheet partial parse #46376

Merged
merged 13 commits into from
Mar 27, 2018
Merged

Stylesheet partial parse #46376

merged 13 commits into from
Mar 27, 2018

Conversation

gushuro
Copy link
Contributor

@gushuro gushuro commented Mar 22, 2018

Added support for partial parsing of Stylesheet documents to provide Emmet completions where needed.

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

// If document can be css parsed, get currentNode
if (isStyleSheet(document.languageId)) {
const rootNode = parseDocument(document, false);
const rootNode = parsePartialStylesheet(document, position);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets partial parse only if document.lineCount > 1000. Adjust the number after running tests on stable

stream.pos = position;
let openBracesRemaining = 1;
let unindentedRulesFound = 0;
while (openBracesRemaining > 0 && !(stream.pos.line === 0 && stream.pos.character === 0)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stream.sof() will tell if you if have reached start of file. But you need to rebase from master for that

if (ch === openBrace) {
openBracesRemaining--;
// Heuristic to not parse the whole document.
if (unindentedRulesFound >= 10) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of unindentedRulesFound lets use # of lines we parse as a heuristic.

@gushuro gushuro force-pushed the css-partial-parse branch from 99d0653 to dea5096 Compare March 23, 2018 00:39
if (ch === openBrace) {
openBracesRemaining--;
} else if (ch === closeBrace) {
if (document.languageId !== 'css') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is css, then we can set startPosition and return from here

openBracesRemaining++;
}
if (position.line - stream.pos.line > 1000) {
return parseStylesheet(new DocumentStreamReader(document, new vscode.Position(0, 0)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing the range to be passed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, move this code to the beginning of the while loop. No reason to have it inside the if/else correct?

// We are at an opening brace. We need to include its selector
while (stream.pos.character > 0) {
let ch = stream.backUp(1);
if (ch === closeBrace || ch === openBrace) {
Copy link
Contributor

@ramya-rao-a ramya-rao-a Mar 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't really need the whole selector, we can stop when we find a non whitespace as well

// Go forward until we found a closing brace.
let stream = new DocumentStreamReader(document, position);
while (!stream.eof()) {
if (stream.eat(closeBrace)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we combine this if with the while?
while (!stream.eof() && !stream.eat(closeBrace))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we can

stream.pos = position;
let openBracesRemaining = 1;
let currentLine = position.line;
let isCSS = document.languageId === 'css';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be pulled up as it can be used when determining the single line comments above

openBracesRemaining++;
} else if (ch === slash) {
stream.backUp(1);
if (!stream.eat(char => { return char !== star; })) {
Copy link
Contributor

@ramya-rao-a ramya-rao-a Mar 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not stream.eat(star)?

Copy link
Contributor Author

@gushuro gushuro Mar 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is emulating a stream.eatback(star).
I changed it so that is easier to read and understand.

@microsoft microsoft deleted a comment from gushuro Mar 26, 2018
@microsoft microsoft deleted a comment from gushuro Mar 26, 2018
@microsoft microsoft deleted a comment from gushuro Mar 27, 2018
@ramya-rao-a ramya-rao-a merged commit 91416ff into master Mar 27, 2018
@gushuro gushuro deleted the css-partial-parse branch March 27, 2018 22:23
@github-actions github-actions bot locked and limited conversation to collaborators Mar 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants