From 8f691f357548334d26f8c6dd882e1c3a8d24c9a5 Mon Sep 17 00:00:00 2001 From: aboyko Date: Wed, 8 May 2024 22:56:06 -0400 Subject: [PATCH] Return `null` semantic tokens by default rather than empty list --- .../semantic/tokens/SemanticTokensHandler.java | 6 +++--- .../ide/vscode/boot/java/JdtSemanticTokensHandler.java | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/headless-services/commons/commons-language-server/src/main/java/org/springframework/ide/vscode/commons/languageserver/semantic/tokens/SemanticTokensHandler.java b/headless-services/commons/commons-language-server/src/main/java/org/springframework/ide/vscode/commons/languageserver/semantic/tokens/SemanticTokensHandler.java index 759f62c97c..f54c3c19d1 100644 --- a/headless-services/commons/commons-language-server/src/main/java/org/springframework/ide/vscode/commons/languageserver/semantic/tokens/SemanticTokensHandler.java +++ b/headless-services/commons/commons-language-server/src/main/java/org/springframework/ide/vscode/commons/languageserver/semantic/tokens/SemanticTokensHandler.java @@ -24,15 +24,15 @@ public interface SemanticTokensHandler { SemanticTokensWithRegistrationOptions getCapability(); default SemanticTokens semanticTokensFull(SemanticTokensParams params, CancelChecker cancelChecker) { - return new SemanticTokens(); + return null; } default Either semanticTokensFullDelta(SemanticTokensDeltaParams params, CancelChecker cancelChecker) { - return Either.forLeft(new SemanticTokens()); + return null; } default SemanticTokens semanticTokensRange(SemanticTokensRangeParams params, CancelChecker cancelChecker) { - return new SemanticTokens(); + return null; } } diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/JdtSemanticTokensHandler.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/JdtSemanticTokensHandler.java index f4484124c1..4feea31a17 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/JdtSemanticTokensHandler.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/JdtSemanticTokensHandler.java @@ -69,15 +69,16 @@ public SemanticTokens semanticTokensFull(SemanticTokensParams params, CancelChec return cuCache.withCompilationUnit(jp, URI.create(params.getTextDocument().getUri()), cu -> computeTokens(applicableTokenProviders, jp, cu)); } } - return new SemanticTokens(); + return null; } private SemanticTokens computeTokens(List applicableTokenProviders, IJavaProject jp, CompilationUnit cu) { if (cu == null) { - return new SemanticTokens(); + return null; } List tokensData = applicableTokenProviders.stream().map(tp -> tp.computeTokens(jp, cu)).flatMap(t -> t.stream()).collect(Collectors.toList()); - return new SemanticTokens(SemanticTokensUtils.mapTokensDataToLsp(tokensData, legend, offset -> cu.getLineNumber(offset) - 1, cu::getColumnNumber)); + List toLsp = SemanticTokensUtils.mapTokensDataToLsp(tokensData, legend, offset -> cu.getLineNumber(offset) - 1, cu::getColumnNumber); + return toLsp.isEmpty() ? null : new SemanticTokens(toLsp); } }