Skip to content

Commit

Permalink
Rename legacyHighlighting to specialCaseHighlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
sungshik committed Nov 6, 2024
1 parent 29e222f commit 9175367
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public interface ILanguageContributions {
public CompletableFuture<Boolean> hasImplementation();
public CompletableFuture<Boolean> hasCodeAction();

public CompletableFuture<Boolean> legacyHighlighting();
public CompletableFuture<Boolean> specialCaseHighlighting();

public CompletableFuture<SummaryConfig> getAnalyzerSummaryConfig();
public CompletableFuture<SummaryConfig> getBuilderSummaryConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public class InterpretedLanguageContributions implements ILanguageContributions
private final CompletableFuture<Boolean> hasImplementation;
private final CompletableFuture<Boolean> hasCodeAction;

private final CompletableFuture<Boolean> legacyHighlighting;
private final CompletableFuture<Boolean> specialCaseHighlighting;

private final CompletableFuture<SummaryConfig> analyzerSummaryConfig;
private final CompletableFuture<SummaryConfig> builderSummaryConfig;
Expand Down Expand Up @@ -153,9 +153,9 @@ public InterpretedLanguageContributions(LanguageParameter lang, IBaseTextDocumen
this.hasImplementation = nonNull(this.implementation);
this.hasCodeAction = nonNull(this.codeAction);

this.legacyHighlighting = getContributionParameter(contributions,
this.specialCaseHighlighting = getContributionParameter(contributions,
LanguageContributions.PARSING,
LanguageContributions.Parameters.USES_LEGACY_HIGHLIGHTING);
LanguageContributions.Parameters.USES_SPECIAL_CASE_HIGHLIGHTING);

this.analyzerSummaryConfig = scheduledSummaryConfig(contributions, LanguageContributions.ANALYSIS);
this.builderSummaryConfig = scheduledSummaryConfig(contributions, LanguageContributions.BUILD);
Expand Down Expand Up @@ -401,8 +401,8 @@ public CompletableFuture<Boolean> hasBuild() {
}

@Override
public CompletableFuture<Boolean> legacyHighlighting() {
return legacyHighlighting;
public CompletableFuture<Boolean> specialCaseHighlighting() {
return specialCaseHighlighting;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private static final <T> CompletableFuture<T> failedInitialization() {
private volatile CompletableFuture<Boolean> hasImplementation = failedInitialization();
private volatile CompletableFuture<Boolean> hasCodeAction = failedInitialization();

private volatile CompletableFuture<Boolean> legacyHighlighting = failedInitialization();
private volatile CompletableFuture<Boolean> specialCaseHighlighting = failedInitialization();

private volatile CompletableFuture<SummaryConfig> analyzerSummaryConfig;
private volatile CompletableFuture<SummaryConfig> builderSummaryConfig;
Expand Down Expand Up @@ -161,7 +161,7 @@ private synchronized void calculateRouting() {
hasReferences = anyTrue(ILanguageContributions::hasReferences);
hasImplementation = anyTrue(ILanguageContributions::hasImplementation);

legacyHighlighting = anyTrue(ILanguageContributions::legacyHighlighting);
specialCaseHighlighting = anyTrue(ILanguageContributions::specialCaseHighlighting);

analyzerSummaryConfig = anyTrue(ILanguageContributions::getAnalyzerSummaryConfig, SummaryConfig.FALSY, SummaryConfig::or);
builderSummaryConfig = anyTrue(ILanguageContributions::getBuilderSummaryConfig, SummaryConfig.FALSY, SummaryConfig::or);
Expand Down Expand Up @@ -348,8 +348,8 @@ public CompletableFuture<Boolean> hasInlayHint() {
}

@Override
public CompletableFuture<Boolean> legacyHighlighting() {
return legacyHighlighting;
public CompletableFuture<Boolean> specialCaseHighlighting() {
return specialCaseHighlighting;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,10 +540,10 @@ public void shutdown() {
}

private CompletableFuture<SemanticTokens> getSemanticTokens(TextDocumentIdentifier doc) {
var legacyHighlighting = contributions(doc).legacyHighlighting();
var specialCaseHighlighting = contributions(doc).specialCaseHighlighting();
return recoverExceptions(getFile(doc).getCurrentTreeAsync()
.thenApply(Versioned::get)
.thenCombineAsync(legacyHighlighting, tokenizer::semanticTokensFull, ownExecuter)
.thenCombineAsync(specialCaseHighlighting, tokenizer::semanticTokensFull, ownExecuter)
.whenComplete((r, e) ->
logger.trace("Semantic tokens success, reporting {} tokens back", r == null ? 0 : r.getData().size() / 5)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public CompletableFuture<Boolean> hasInlayHint() {
}

@Override
public CompletableFuture<Boolean> legacyHighlighting() {
public CompletableFuture<Boolean> specialCaseHighlighting() {
return CompletableFuture.completedFuture(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private LanguageContributions () {}
public static class Parameters {
private Parameters() {}

public static final String USES_LEGACY_HIGHLIGHTING = "usesLegacyHighlighting";
public static final String USES_SPECIAL_CASE_HIGHLIGHTING = "usesSpecialCaseHighlighting";

public static final String PROVIDES_HOVERS = "providesHovers";
public static final String PROVIDES_DEFINITIONS = "providesDefinitions";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,10 @@ public void shutdown() {
}

private CompletableFuture<SemanticTokens> getSemanticTokens(TextDocumentIdentifier doc) {
var legacyHighlighting = CompletableFuture.completedFuture(false);
var specialCaseHighlighting = CompletableFuture.completedFuture(false);
return getFile(doc).getCurrentTreeAsync()
.thenApply(Versioned::get)
.thenCombineAsync(legacyHighlighting, tokenizer::semanticTokensFull, ownExecuter)
.thenCombineAsync(specialCaseHighlighting, tokenizer::semanticTokensFull, ownExecuter)
.exceptionally(e -> {
logger.error("Tokenization failed", e);
return new SemanticTokens(Collections.emptyList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ public SemanticTokenizer(boolean rascal) {
this.patch = rascal ? new RascalCategoryPatch() : new DefaultCategoryPatch();
}

public SemanticTokens semanticTokensFull(ITree tree, boolean legacyHighlighting) {
public SemanticTokens semanticTokensFull(ITree tree, boolean specialCaseHighlighting) {
TokenList tokens = new TokenList();
new TokenCollector(tokens, legacyHighlighting, patch).collect(tree);
new TokenCollector(tokens, specialCaseHighlighting, patch).collect(tree);
return new SemanticTokens(tokens.getTheList());
}

Expand Down Expand Up @@ -382,12 +382,12 @@ private static class TokenCollector {
private final boolean showAmb = false;

private final TokenList tokens;
private final boolean legacyHighlighting;
private final boolean specialCaseHighlighting;
private final CategoryPatch patch;

public TokenCollector(TokenList tokens, boolean legacyHighlighting, CategoryPatch patch) {
public TokenCollector(TokenList tokens, boolean specialCaseHighlighting, CategoryPatch patch) {
this.tokens = tokens;
this.legacyHighlighting = legacyHighlighting;
this.specialCaseHighlighting = specialCaseHighlighting;
this.patch = patch;

line = 0;
Expand Down Expand Up @@ -444,12 +444,11 @@ private void collectAppl(ITree tree, @Nullable String parentCategory) {
for (IValue child : TreeAdapter.getArgs(tree)) {
//Propagate current category to child unless currently in a syntax nonterminal
//*AND* the current child is a syntax nonterminal too
if (legacyHighlighting && !TreeAdapter.isChar((ITree) child) && ProductionAdapter.isSort(prod) &&
ProductionAdapter.isSort(TreeAdapter.getProduction((ITree) child))) {
collect((ITree) child, null);
} else {
collect((ITree) child, category);
}
var specialCase = specialCaseHighlighting &&
!TreeAdapter.isChar((ITree) child) && ProductionAdapter.isSort(prod) &&
ProductionAdapter.isSort(TreeAdapter.getProduction((ITree) child));

collect((ITree) child, specialCase ? null : category);
}
}

Expand Down
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 useLegacyHighlighting, IBool applyRascalCategoryPatch) {
public IValue toTokens(IConstructor tree, IBool useSpecialCaseHighlighting, IBool applyRascalCategoryPatch) {
var tokenizer = new SemanticTokenizer(applyRascalCategoryPatch.getValue());
var encoded = tokenizer.semanticTokensFull((ITree) tree, useLegacyHighlighting.getValue()).getData();
var encoded = tokenizer.semanticTokensFull((ITree) tree, useSpecialCaseHighlighting.getValue()).getData();

var values = IRascalValueFactory.getInstance();
var tokens = new IValue[encoded.size() / 5];
Expand Down
4 changes: 2 additions & 2 deletions rascal-lsp/src/main/rascal/demo/lang/pico/LanguageServer.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Here we group all services such that the LSP server can link them
with the ((Language)) definition later.
}
set[LanguageService] picoLanguageServer() = {
parsing(parser(#start[Program]), usesLegacyHighlighting = false),
parsing(parser(#start[Program]), usesSpecialCaseHighlighting = false),
documentSymbol(picoDocumentSymbolService),
codeLens(picoCodeLenseService),
execution(picoExecutionService),
Expand All @@ -62,7 +62,7 @@ such that quicky loaded features can be made available while slower to load
tools come in later.
}
set[LanguageService] picoLanguageServerSlowSummary() = {
parsing(parser(#start[Program]), usesLegacyHighlighting = false),
parsing(parser(#start[Program]), usesSpecialCaseHighlighting = false),
analysis(picoAnalysisService, providesImplementations = false),
build(picoBuildService)
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ test bool testUnicode() = testTokenizer(#Declaration,
applyRascalCategoryPatch = true
);

test bool testInnerOverOuterLegacy() = testTokenizer(#Declaration,
test bool testSpecialCaseHighlighting() = testTokenizer(#Declaration,

"void f() {
int i = 3;
Expand All @@ -124,6 +124,6 @@ test bool testInnerOverOuterLegacy() = testTokenizer(#Declaration,
expectFirst("3", "uncategorized"), // Instead of `number`
expectFirst("|unknown:///|", "uncategorized"), // Instead of `string`

useLegacyHighlighting = true,
useSpecialCaseHighlighting = true,
applyRascalCategoryPatch = true
);
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ import String;
// functions in this module are auxiliary (and private).
bool testTokenizer(type[&T<:Tree] begin, str input, Expect expects...,
bool printActuals = false,
bool useLegacyHighlighting = false,
bool useSpecialCaseHighlighting = 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, useLegacyHighlighting, applyRascalCategoryPatch);
list[SemanticToken] tokens = toTokens(tree, useSpecialCaseHighlighting, 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
12 changes: 6 additions & 6 deletions rascal-lsp/src/main/rascal/util/LanguageServer.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ interpreter lock will make the editor services less responsive.
* and if `n` has a `syntax` non-terminal node `m` as a child,
* then the category of `n` is ignored in the subtree rooted at `m`
(regardless of whether a category is declared as part of `m`).
This special case is deprecated: it continues to exist only for historical
reasons, but it will be removed in a future release. In anticipation of the
removal, users that rely on this special case for syntax highlighting can
update their grammars and explicitly opt-out of the special case by passing
`usesLegacyHighlighting = false` when registering the ((parsing)) service.
This special case is deprecated and will be removed in a future release. In
anticipation of the removal, users that rely on this special case for
syntax highlighting can update their grammars and explicitly opt-out of the
special case by passing `usesSpecialCaseHighlighting = false` when
registering the ((parsing)) service.
* The ((analysis)) service indexes a file as a ((Summary)), offering precomputed relations for looking up
hover documentation, definition with uses, references to declarations, implementations of types and compiler errors and warnings.
* ((analysis)) focuses on their own file, but may reuse cached or stored indices from other files.
Expand Down Expand Up @@ -246,7 +246,7 @@ typical programming language concepts. Since these are all just `rel[loc, loc]`
}
data LanguageService
= parsing(Tree (str _input, loc _origin) parsingService
, bool usesLegacyHighlighting = true)
, bool usesSpecialCaseHighlighting = true)
| analysis(Summary (loc _origin, Tree _input) analysisService
, bool providesDocumentation = true
, bool providesHovers = providesDocumentation
Expand Down

0 comments on commit 9175367

Please sign in to comment.