I get syntax highlighting for javascript but no autocomplete. Any idea what could be going wrong here? I could post the grammar for the templateParser if needed.
I don’t have your grammar, but when I change that code to use the @lezer/html parser and target the UnquotedAttributeValue nodes instead, JavaScript completion works inside of those.
Also running into this highly specific issue 2 hours after the post was made? That’s quite a coincidence. Or, in case you’re a coworker of the OP ‘bumping’ this or a spam account trying to build up post count, please don’t — it’s annoying.
Thanks for the prompt response Marjin. Would the grammar/tokenizer have any impact on how support extensions for nested parsers are run? The HTML example works well for me, so wondering what the difference could be.
import { ExternalTokenizer } from "@lezer/lr";
import { CloseExpression, javascriptText } from "./parser.terms";
const closeTemplate = 125;
function expressionTokenizer() {
return new ExternalTokenizer((input) => {
let i = 0;
let state = 0;
let javascriptTextLength = 0;
while (true) {
if (input.next < 0) {
if (i) input.acceptToken(javascriptText);
break;
}
// first close template
if (state == 0 && input.next == closeTemplate) {
state++;
}
// second close template
else if (state == 1 && input.next == closeTemplate) {
// if we have javascriptTextLength then accept that token
if (javascriptTextLength) {
input.acceptToken(javascriptText, -javascriptTextLength);
} else {
input.acceptToken(CloseExpression, 1);
}
break;
} else {
// reset
javascriptTextLength++;
state = 0;
}
input.advance();
}
});
}
export const scriptTokens = expressionTokenizer();
With the following string: {{asdf}} being parsed here are the nodes:
Node TemplateString from 0 to 8
Node Expression from 0 to 8
Node OpenExpression from 0 to 2
Node JavaScriptText from 2 to 6
Node CloseExpression from 6 to 8
which seems like I should be able to just run the javascript parser on JavaScriptText and get the appropriate support extensions
Although interestingly, this suggests that my mixed language parsing isn’t exactly correct as i shouldn’t need to modify the javascript language extensions…
Now I also need to parse like text {{ var a = Date.now() }} text content, the whole content is plain text, but content between {{ and }} parsed as javascript.