-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
Stylesheet partial parse #46376
Conversation
@@ -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); |
There was a problem hiding this comment.
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
extensions/emmet/src/util.ts
Outdated
stream.pos = position; | ||
let openBracesRemaining = 1; | ||
let unindentedRulesFound = 0; | ||
while (openBracesRemaining > 0 && !(stream.pos.line === 0 && stream.pos.character === 0)) { |
There was a problem hiding this comment.
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
extensions/emmet/src/util.ts
Outdated
if (ch === openBrace) { | ||
openBracesRemaining--; | ||
// Heuristic to not parse the whole document. | ||
if (unindentedRulesFound >= 10) { |
There was a problem hiding this comment.
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.
99d0653
to
dea5096
Compare
extensions/emmet/src/util.ts
Outdated
if (ch === openBrace) { | ||
openBracesRemaining--; | ||
} else if (ch === closeBrace) { | ||
if (document.languageId !== 'css') { |
There was a problem hiding this comment.
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
extensions/emmet/src/util.ts
Outdated
openBracesRemaining++; | ||
} | ||
if (position.line - stream.pos.line > 1000) { | ||
return parseStylesheet(new DocumentStreamReader(document, new vscode.Position(0, 0))); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
extensions/emmet/src/util.ts
Outdated
// 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) { |
There was a problem hiding this comment.
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
extensions/emmet/src/util.ts
Outdated
// Go forward until we found a closing brace. | ||
let stream = new DocumentStreamReader(document, position); | ||
while (!stream.eof()) { | ||
if (stream.eat(closeBrace)) { |
There was a problem hiding this comment.
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))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we can
extensions/emmet/src/util.ts
Outdated
stream.pos = position; | ||
let openBracesRemaining = 1; | ||
let currentLine = position.line; | ||
let isCSS = document.languageId === 'css'; |
There was a problem hiding this comment.
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
extensions/emmet/src/util.ts
Outdated
openBracesRemaining++; | ||
} else if (ch === slash) { | ||
stream.backUp(1); | ||
if (!stream.eat(char => { return char !== star; })) { |
There was a problem hiding this comment.
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)
?
There was a problem hiding this comment.
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.
Added support for partial parsing of Stylesheet documents to provide Emmet completions where needed.