Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Sherman <bentshermann@gmail.com>
  • Loading branch information
bentsherman committed Jan 10, 2025
1 parent 0f09447 commit 47b0c3f
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ public static <T extends ASTNode> T ast(T astNode, ASTNode start, ASTNode stop)
return astNode;
}

/**
* Get the zero-based start position (line, character) of a token.
*
* @param ctx
*/
public static TokenPosition tokenPosition(ParserRuleContext ctx) {
var token = ctx.getStart();
return new TokenPosition(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public CompletableFuture<InitializeResult> initialize(InitializeParams params) {
var semanticTokensOptions = new SemanticTokensWithRegistrationOptions(
new SemanticTokensLegend(
SemanticTokensVisitor.TOKEN_TYPES,
List.of()
Collections.emptyList()
),
true,
false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public SemanticTokens getTokens() {
0
))
.collect(Collectors.toList());

return new SemanticTokens(data);
}

Expand Down Expand Up @@ -186,19 +186,17 @@ public void visitGStringExpression(GStringExpression node) {
inGString = igs;
}

}

private static record SemanticToken(
Position position,
int length,
String type
) {}

record SemanticToken(
Position position,
int length,
String type
) {}
private static record SemanticTokenDelta(
int deltaLine,
int deltaStartChar,
int length,
String type
) {}


record SemanticTokenDelta(
int deltaLine,
int deltaStartChar,
int length,
String type
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,43 +61,43 @@ public SemanticTokens semanticTokensFull(TextDocumentIdentifier textDocument) {
}

private static class Visitor extends ConfigVisitorSupport {

private SourceUnit sourceUnit;

private SemanticTokensVisitor tok;

public Visitor(SourceUnit sourceUnit) {
this.sourceUnit = sourceUnit;
this.tok = new SemanticTokensVisitor();
}

@Override
protected SourceUnit getSourceUnit() {
return sourceUnit;
}

public void visit() {
var moduleNode = sourceUnit.getAST();
if( moduleNode instanceof ConfigNode cn )
super.visit(cn);
}

public SemanticTokens getTokens() {
return tok.getTokens();
}

// config statements

@Override
public void visitConfigAssign(ConfigAssignNode node) {
tok.visit(node.value);
}

@Override
public void visitConfigInclude(ConfigIncludeNode node) {
tok.visit(node.source);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -75,36 +75,36 @@ public SemanticTokens semanticTokensFull(TextDocumentIdentifier textDocument) {
}

private static class Visitor extends ScriptVisitorSupport {

private SourceUnit sourceUnit;

private SemanticTokensVisitor tok;

public Visitor(SourceUnit sourceUnit) {
this.sourceUnit = sourceUnit;
this.tok = new SemanticTokensVisitor();
}

@Override
protected SourceUnit getSourceUnit() {
return sourceUnit;
}

public void visit() {
var moduleNode = sourceUnit.getAST();
if( moduleNode instanceof ScriptNode sn )
visit(sn);
}

public SemanticTokens getTokens() {
return tok.getTokens();
}

@Override
public void visitFeatureFlag(FeatureFlagNode node) {
tok.visit(node.value);
}

@Override
public void visitInclude(IncludeNode node) {
for( var module : node.modules ) {
Expand All @@ -113,33 +113,33 @@ public void visitInclude(IncludeNode node) {
tok.append(module.getNodeMetaData("_START_ALIAS"), module.alias, SemanticTokenTypes.Function);
}
}

@Override
public void visitParam(ParamNode node) {
tok.visit(node.target);
tok.visit(node.value);
}

@Override
public void visitWorkflow(WorkflowNode node) {
if( node.takes instanceof BlockStatement block )
visitWorkflowTakes(block.getStatements());

tok.visit(node.main);

if( node.emits instanceof BlockStatement block )
visitWorkflowEmits(block.getStatements());

tok.visit(node.publishers);
}

protected void visitWorkflowTakes(List<Statement> takes) {
for( var stmt : takes ) {
var ve = (VariableExpression) asVarX(stmt);
tok.append(ve, SemanticTokenTypes.Parameter);
}
}

protected void visitWorkflowEmits(List<Statement> emits) {
for( var stmt : emits ) {
var es = (ExpressionStatement)stmt;
Expand All @@ -160,7 +160,7 @@ else if( emit instanceof VariableExpression ve ) {
}
}
}

@Override
public void visitProcess(ProcessNode node) {
tok.visit(node.directives);
Expand All @@ -170,38 +170,38 @@ public void visitProcess(ProcessNode node) {
tok.visit(node.exec);
tok.visit(node.stub);
}

@Override
public void visitFunction(FunctionNode node) {
tok.visitParameters(node.getParameters());
tok.visit(node.getCode());
}

@Override
public void visitEnum(ClassNode node) {
for( var fn : node.getFields() )
tok.append(fn, SemanticTokenTypes.EnumMember);
}

@Override
public void visitOutput(OutputNode node) {
visitOutputBody(node.body);
}

protected void visitOutputBody(Statement body) {
asBlockStatements(body).forEach((stmt) -> {
var call = asMethodCallX(stmt);
if( call == null )
return;

var code = asDslBlock(call, 1);
if( code != null ) {
tok.append(call.getMethod(), SemanticTokenTypes.Parameter);
tok.visit(code);
}
});
}

}

}

0 comments on commit 47b0c3f

Please sign in to comment.