use of org.eclipse.lsp4j.SemanticTokens in project magik-tools by StevenLooman.
the class SemanticTokenProviderTest method testMethodAndSlot.
@Test
void testMethodAndSlot() {
final String code = "_method aaa.bbb .slot _endmethod";
final SemanticTokens semanticTokens = this.getSemanticTokens(code);
assertThat(semanticTokens.getData()).containsExactly(0, 0, "_method".length(), SemanticToken.Type.KEYWORD.getTokenType(), 0, 0, 8, "aaa".length(), SemanticToken.Type.CLASS.getTokenType(), 0, 0, 4, "bbb".length(), SemanticToken.Type.METHOD.getTokenType(), 0, 0, 5, "slot".length(), SemanticToken.Type.PROPERTY.getTokenType(), 0, 0, 5, "_endmethod".length(), SemanticToken.Type.KEYWORD.getTokenType(), 0);
}
use of org.eclipse.lsp4j.SemanticTokens in project magik-tools by StevenLooman.
the class SemanticTokenProviderTest method testString.
@Test
void testString() {
final String code = "\"string\"";
final SemanticTokens semanticTokens = this.getSemanticTokens(code);
assertThat(semanticTokens.getData()).containsExactly(0, 0, "\"string\"".length(), SemanticToken.Type.STRING.getTokenType(), 0);
}
use of org.eclipse.lsp4j.SemanticTokens in project magik-tools by StevenLooman.
the class SemanticTokenProviderTest method testProcedureInvocation.
@Test
void testProcedureInvocation() {
final String code = "a()";
final SemanticTokens semanticTokens = this.getSemanticTokens(code);
assertThat(semanticTokens.getData()).containsExactly(0, 0, "a".length(), SemanticToken.Type.FUNCTION.getTokenType(), // TODO: Why no varGlobalModifier?
0);
}
use of org.eclipse.lsp4j.SemanticTokens in project magik-tools by StevenLooman.
the class SemanticTokenProviderTest method testMethodSyntaxError.
@Test
void testMethodSyntaxError() {
final String code = "_method a.b\n_a\n_endmethod";
final SemanticTokens semanticTokens = this.getSemanticTokens(code);
assertThat(semanticTokens.getData()).containsExactly(0, 0, "_method".length(), SemanticToken.Type.KEYWORD.getTokenType(), 0, 2, 0, "_endmethod".length(), SemanticToken.Type.KEYWORD.getTokenType(), 0);
}
use of org.eclipse.lsp4j.SemanticTokens in project redmatch by aehrc.
the class SemanticTokeniser method tokenise.
public static SemanticTokens tokenise(String text) {
// First we need to get the tokens from the lexer
List<SemanticToken> tokens = new ArrayList<>();
final Lexer lexer = new RedmatchLexer(CharStreams.fromString(text));
for (Token tok : lexer.getAllTokens()) {
// account for 0-index differences
int line = tok.getLine() - 1;
int startChar = tok.getCharPositionInLine();
int length = tok.getText().length();
int tokenType = mapTokenType(tok.getType());
if (tokenType != -1) {
tokens.add(new SemanticToken(line, startChar, length, tokenType));
}
}
// { deltaLine: 2, deltaStartChar: 5, length: 3, tokenType: 0, tokenModifiers: 3 },
if (!tokens.isEmpty()) {
tokens.get(0).deltaLine = tokens.get(0).line;
tokens.get(0).deltaStartChar = tokens.get(0).startChar;
}
for (int i = 1; i < tokens.size(); i++) {
SemanticToken prevToken = tokens.get(i - 1);
SemanticToken token = tokens.get(i);
token.deltaLine = token.line - prevToken.line;
// Now we need to "deltify" the current token
if (prevToken.line == token.line) {
// They are on the same line, so we need to make the start token relative
token.deltaStartChar = token.startChar - prevToken.startChar;
} else {
// There was a change of line so the first token delta start char is the same as the start char
token.deltaStartChar = token.startChar;
}
}
log.info("Encoding " + tokens.size() + " semantic tokens");
// Finally, we transform them into the format expected by the language server protocol
List<Integer> encodedTokens = new ArrayList<>();
for (SemanticToken token : tokens) {
encodedTokens.add(token.deltaLine);
encodedTokens.add(token.deltaStartChar);
encodedTokens.add(token.length);
encodedTokens.add(token.tokenType);
// No modifiers for Redmatch
encodedTokens.add(0);
}
return new SemanticTokens(encodedTokens);
}
Aggregations