From 9175367921454b0e80ed1bf1c5ad30e7838ff3fe Mon Sep 17 00:00:00 2001 From: Sung-Shik Jongmans Date: Wed, 6 Nov 2024 13:30:23 +0100 Subject: [PATCH] Rename `legacyHighlighting` to `specialCaseHighlighting` --- .../parametric/ILanguageContributions.java | 2 +- .../InterpretedLanguageContributions.java | 10 ++++----- .../LanguageContributionsMultiplexer.java | 8 +++---- .../ParametricTextDocumentService.java | 4 ++-- .../parametric/ParserOnlyContribution.java | 2 +- .../lsp/parametric/model/RascalADTs.java | 2 +- .../lsp/rascal/RascalTextDocumentService.java | 4 ++-- .../vscode/lsp/util/SemanticTokenizer.java | 21 +++++++++---------- .../lsp/util/SemanticTokenizerTester.java | 4 ++-- .../rascal/demo/lang/pico/LanguageServer.rsc | 4 ++-- .../rascal/tests/semanticTokenizer/Rascal.rsc | 4 ++-- .../rascal/tests/semanticTokenizer/Util.rsc | 4 ++-- .../src/main/rascal/util/LanguageServer.rsc | 12 +++++------ 13 files changed, 40 insertions(+), 41 deletions(-) diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ILanguageContributions.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ILanguageContributions.java index 8096be72..6ce0b1d3 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ILanguageContributions.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ILanguageContributions.java @@ -73,7 +73,7 @@ public interface ILanguageContributions { public CompletableFuture hasImplementation(); public CompletableFuture hasCodeAction(); - public CompletableFuture legacyHighlighting(); + public CompletableFuture specialCaseHighlighting(); public CompletableFuture getAnalyzerSummaryConfig(); public CompletableFuture getBuilderSummaryConfig(); diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/InterpretedLanguageContributions.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/InterpretedLanguageContributions.java index fe3a9369..fcf2a623 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/InterpretedLanguageContributions.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/InterpretedLanguageContributions.java @@ -100,7 +100,7 @@ public class InterpretedLanguageContributions implements ILanguageContributions private final CompletableFuture hasImplementation; private final CompletableFuture hasCodeAction; - private final CompletableFuture legacyHighlighting; + private final CompletableFuture specialCaseHighlighting; private final CompletableFuture analyzerSummaryConfig; private final CompletableFuture builderSummaryConfig; @@ -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); @@ -401,8 +401,8 @@ public CompletableFuture hasBuild() { } @Override - public CompletableFuture legacyHighlighting() { - return legacyHighlighting; + public CompletableFuture specialCaseHighlighting() { + return specialCaseHighlighting; } @Override diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java index d5167a76..9f0ab7d3 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/LanguageContributionsMultiplexer.java @@ -77,7 +77,7 @@ private static final CompletableFuture failedInitialization() { private volatile CompletableFuture hasImplementation = failedInitialization(); private volatile CompletableFuture hasCodeAction = failedInitialization(); - private volatile CompletableFuture legacyHighlighting = failedInitialization(); + private volatile CompletableFuture specialCaseHighlighting = failedInitialization(); private volatile CompletableFuture analyzerSummaryConfig; private volatile CompletableFuture builderSummaryConfig; @@ -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); @@ -348,8 +348,8 @@ public CompletableFuture hasInlayHint() { } @Override - public CompletableFuture legacyHighlighting() { - return legacyHighlighting; + public CompletableFuture specialCaseHighlighting() { + return specialCaseHighlighting; } @Override diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java index 92e6206d..fc35c310 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java @@ -540,10 +540,10 @@ public void shutdown() { } private CompletableFuture 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) ) diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParserOnlyContribution.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParserOnlyContribution.java index a89e0bb6..2ccec034 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParserOnlyContribution.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParserOnlyContribution.java @@ -229,7 +229,7 @@ public CompletableFuture hasInlayHint() { } @Override - public CompletableFuture legacyHighlighting() { + public CompletableFuture specialCaseHighlighting() { return CompletableFuture.completedFuture(false); } diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/RascalADTs.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/RascalADTs.java index ccf703ae..918e1d46 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/RascalADTs.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/model/RascalADTs.java @@ -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"; diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalTextDocumentService.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalTextDocumentService.java index b18bf1a7..221e37a0 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalTextDocumentService.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalTextDocumentService.java @@ -347,10 +347,10 @@ public void shutdown() { } private CompletableFuture 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()); diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/util/SemanticTokenizer.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/util/SemanticTokenizer.java index 5b603f6f..cbd77f6f 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/util/SemanticTokenizer.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/util/SemanticTokenizer.java @@ -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()); } @@ -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; @@ -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); } } diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/util/SemanticTokenizerTester.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/util/SemanticTokenizerTester.java index 540b9d37..e760af0e 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/util/SemanticTokenizerTester.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/util/SemanticTokenizerTester.java @@ -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]; diff --git a/rascal-lsp/src/main/rascal/demo/lang/pico/LanguageServer.rsc b/rascal-lsp/src/main/rascal/demo/lang/pico/LanguageServer.rsc index fc9bf43c..3c48e659 100644 --- a/rascal-lsp/src/main/rascal/demo/lang/pico/LanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/demo/lang/pico/LanguageServer.rsc @@ -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), @@ -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) }; diff --git a/rascal-lsp/src/main/rascal/lang/rascal/tests/semanticTokenizer/Rascal.rsc b/rascal-lsp/src/main/rascal/lang/rascal/tests/semanticTokenizer/Rascal.rsc index 41d994e3..85e41067 100644 --- a/rascal-lsp/src/main/rascal/lang/rascal/tests/semanticTokenizer/Rascal.rsc +++ b/rascal-lsp/src/main/rascal/lang/rascal/tests/semanticTokenizer/Rascal.rsc @@ -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; @@ -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 ); diff --git a/rascal-lsp/src/main/rascal/lang/rascal/tests/semanticTokenizer/Util.rsc b/rascal-lsp/src/main/rascal/lang/rascal/tests/semanticTokenizer/Util.rsc index 7eaf829f..34abe725 100644 --- a/rascal-lsp/src/main/rascal/lang/rascal/tests/semanticTokenizer/Util.rsc +++ b/rascal-lsp/src/main/rascal/lang/rascal/tests/semanticTokenizer/Util.rsc @@ -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) diff --git a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc index 7ab65c98..f09a916d 100644 --- a/rascal-lsp/src/main/rascal/util/LanguageServer.rsc +++ b/rascal-lsp/src/main/rascal/util/LanguageServer.rsc @@ -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. @@ -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