Skip to content

Commit

Permalink
Update the semantic tokenizer tests for useLegacyHighlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
sungshik committed Nov 5, 2024
1 parent 75e8b30 commit 161d638
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@

public class SemanticTokenizerTester {

public IValue toTokens(IConstructor tree, IBool applyRascalCategoryPatch) {
public IValue toTokens(IConstructor tree, IBool useLegacyHighlighting, IBool applyRascalCategoryPatch) {
var tokenizer = new SemanticTokenizer(applyRascalCategoryPatch.getValue());
var encoded = tokenizer.semanticTokensFull((ITree) tree).getData();
var encoded = tokenizer.semanticTokensFull((ITree) tree, useLegacyHighlighting.getValue()).getData();

var values = IRascalValueFactory.getInstance();
var tokens = new IValue[encoded.size() / 5];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,7 @@ test bool testInterface() = testTokenizer(#Interface,
// This test demonstrates that, sometimes, arguably the "natural" way to
// write a grammar (e.g., "An interface name is just any class name, but
// prefixed with an I") requires outer-over-inner semantic tokenization.
// The following test shows the effect of overriding the default from
// inner-over-outer to outer-over-inner. Further reading:
// This is currently not supported (i.e., the only "solution" right now is
// to rewrite the grammar). Further reading:
// https://github.com/usethesource/rascal-language-servers/issues/456
);

test bool testInterfaceOuterOverInner() = testTokenizer(#InterfaceOuterOverInner,

"IFoo",

expectFirst("I", "interface"),
expectFirst("Foo", "interface"),
expectFirst("IFoo", "interface") // Outer over inner
);
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,6 @@ test bool testInnerOverOuterLegacy() = testTokenizer(#Declaration,
expectFirst("3", "uncategorized"), // Instead of `number`
expectFirst("|unknown:///|", "uncategorized"), // Instead of `string`

applyRascalCategoryPatch = false // Use legacy mode instead of strict mode
useLegacyHighlighting = true,
applyRascalCategoryPatch = true
);
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ import String;
// This is the main utility function to test the semantic tokenizer. All other
// functions in this module are auxiliary (and private).
bool testTokenizer(type[&T<:Tree] begin, str input, Expect expects...,
bool printActuals = false, bool applyRascalCategoryPatch = false) {
bool printActuals = false,
bool useLegacyHighlighting = false,
bool applyRascalCategoryPatch = false) {

// First, compute the tokens by calling the semantic tokenizer (in Java)
Tree tree = parse(begin, input);
list[SemanticToken] tokens = toTokens(tree, applyRascalCategoryPatch);
list[SemanticToken] tokens = toTokens(tree, useLegacyHighlighting, applyRascalCategoryPatch);

// Next, compute the absolute location of each token (i.e., the position of
// each token in `tokens` is represented *relative to* its predecessor)
Expand Down Expand Up @@ -90,7 +92,7 @@ alias SemanticToken = tuple[
str tokenModifier];

@javaClass{org.rascalmpl.vscode.lsp.util.SemanticTokenizerTester}
java list[SemanticToken] toTokens(Tree _, bool _);
java list[SemanticToken] toTokens(Tree _, bool _, bool _);

//
// Length conversion: Characters are counted as 16-bit units in LSP, whereas
Expand Down

0 comments on commit 161d638

Please sign in to comment.