editor with write capability
This commit is contained in:
@@ -104,11 +104,12 @@ public final class SemanticIndex {
|
||||
final List<PbsToken> tokens,
|
||||
final Map<String, LspSymbolKind> visibleKindsByName) {
|
||||
final List<LspHighlightSpanDTO> highlights = new ArrayList<>();
|
||||
for (final PbsToken token : tokens) {
|
||||
for (int index = 0; index < tokens.size(); index++) {
|
||||
final PbsToken token = tokens.get(index);
|
||||
if (token.kind() == PbsTokenKind.EOF) {
|
||||
continue;
|
||||
}
|
||||
final String semanticKey = semanticKey(token, visibleKindsByName);
|
||||
final String semanticKey = semanticKey(tokens, index, visibleKindsByName);
|
||||
if (semanticKey == null || semanticKey.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
@@ -120,14 +121,50 @@ public final class SemanticIndex {
|
||||
}
|
||||
|
||||
private String semanticKey(
|
||||
final PbsToken token,
|
||||
final List<PbsToken> tokens,
|
||||
final int tokenIndex,
|
||||
final Map<String, LspSymbolKind> visibleKindsByName) {
|
||||
final PbsToken token = tokens.get(tokenIndex);
|
||||
if (isLifecycleAttributeToken(tokens, tokenIndex)) {
|
||||
return PbsSemanticKind.LIFECYCLE.semanticKey();
|
||||
}
|
||||
final PbsSemanticKind semanticKind = token.kind() == p.studio.compiler.pbs.lexer.PbsTokenKind.IDENTIFIER
|
||||
? semanticKindForIdentifier(token.lexeme(), visibleKindsByName)
|
||||
: PbsSemanticKind.forToken(token);
|
||||
return semanticKind == null ? null : semanticKind.semanticKey();
|
||||
}
|
||||
|
||||
private boolean isLifecycleAttributeToken(final List<PbsToken> tokens, final int tokenIndex) {
|
||||
if (tokenIndex < 0 || tokenIndex >= tokens.size()) {
|
||||
return false;
|
||||
}
|
||||
final PbsToken token = tokens.get(tokenIndex);
|
||||
return switch (token.kind()) {
|
||||
case LEFT_BRACKET -> hasLifecycleAttributeWindow(tokens, tokenIndex, tokenIndex + 1, tokenIndex + 2);
|
||||
case IDENTIFIER -> hasLifecycleAttributeWindow(tokens, tokenIndex - 1, tokenIndex, tokenIndex + 1);
|
||||
case RIGHT_BRACKET -> hasLifecycleAttributeWindow(tokens, tokenIndex - 2, tokenIndex - 1, tokenIndex);
|
||||
default -> false;
|
||||
};
|
||||
}
|
||||
|
||||
private boolean hasLifecycleAttributeWindow(
|
||||
final List<PbsToken> tokens,
|
||||
final int leftBracketIndex,
|
||||
final int identifierIndex,
|
||||
final int rightBracketIndex) {
|
||||
if (leftBracketIndex < 0 || rightBracketIndex >= tokens.size()) {
|
||||
return false;
|
||||
}
|
||||
return tokens.get(leftBracketIndex).kind() == PbsTokenKind.LEFT_BRACKET
|
||||
&& tokens.get(identifierIndex).kind() == PbsTokenKind.IDENTIFIER
|
||||
&& isLifecycleAttributeName(tokens.get(identifierIndex).lexeme())
|
||||
&& tokens.get(rightBracketIndex).kind() == PbsTokenKind.RIGHT_BRACKET;
|
||||
}
|
||||
|
||||
private boolean isLifecycleAttributeName(final String lexeme) {
|
||||
return "Init".equals(lexeme) || "Frame".equals(lexeme);
|
||||
}
|
||||
|
||||
private PbsSemanticKind semanticKindForIdentifier(
|
||||
final String lexeme,
|
||||
final Map<String, LspSymbolKind> visibleKindsByName) {
|
||||
|
||||
Reference in New Issue
Block a user