-
-
Notifications
You must be signed in to change notification settings - Fork 198
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
feat: folding range support #2169
Conversation
…nto folding-range
…nto folding-range
…nto folding-range
…nto folding-range
pug syntax are mostly text to html parser so rely on html ls should be good enough
cc97056
to
3b509b9
Compare
3b509b9
to
4ae9999
Compare
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.
Damn, impressive work!
General thought: We're using various getText()
operations like indexOf
, split(/\n\r?/)
etc in many places - maybe it's worth having some of these operations move into the document in a more performant manner (for example, keeping the splitted lines cached etc).
case 'postcss': | ||
case 'sass': | ||
case 'stylus': | ||
case 'styl': |
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.
style?
#1704 #1120
This adds the syntactic folding range support instead of the VSCode's default indentation-based and regex-based folding. For embedded languages like Pug and Sass, I added a simplified version of indentation folding. The indentation folding is also a fallback for svelte blocks if there is a parser error.
For users who prefer the speed of the indent-based folding, You can still roll back with the following config.
Implementation
The commits might be messy because I started this nearly a year ago and have done part of this every few months 😆. The process is "the TypeScript result is good enough that's used it for HTML and svelte block as well" to "the TypeScrip result has a lot of weird cases, that's use HTML language service and svelte ast instead".
Now, the TypeScript folding handles everything inside the script tags and any folding ranges that are one-to-one in the generated code, i.e. it's untouched or only being moved around. Component tag and HTML tag are handled by HTML language service. Svelte blocks like each, if and await are extracted from Svelte AST. And folded from the end of the start tag to the start of the end tag. For example,
VSCode only supports line folding, so it'll start at line 0 and end at line 1, leaving line 2 visible after fold.