-
Notifications
You must be signed in to change notification settings - Fork 13
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
Add code to the context
#11
Comments
Yeah, that's what I suspected when I first raised the possibility of previewing the code. |
Ping @SassDoc/owners. |
I propose the following: You match the function declaration (only the name and arguments) with a regex, like before. Then, assuming you have the whole code buffer in a var start = cursor; // Remember the start position
cursor++; // Pass the first brace
var depth = 1;
var length = buffer.length;
for (; cursor < length && depth > 0; cursor++) {
switch (buffer[cursor]) {
case '{':
depth++;
break;
case '}':
depth--;
break;
}
}
// Now `cursor` is at the last matching brace
var code = buffer.substring(start, cursor); This is not tested, but I think there's not much to tweak to make it work in your parser. Note this is totally ignoring the eventual braces in strings and comments. |
What if there are several functions/mixins in the same file? You have to stop whenever you find a new function/mixin declaration. |
It stops when the matching brace is found. If you don't nest mixins/functions, that's okay. And even if it can be nested, the result will be consistent. |
@valeriangalliat We could possibly extend the detection of quotes and comments. Thanks for the initial version. Will work form there. |
It looks pretty nice. If you build a pre-release, we can try it out. |
Fixed in version |
Currently the extracted code is usesless. see
We need to take into account that it is possible to have "{" and "}" inside the code snipped.
The text was updated successfully, but these errors were encountered: