implements PLN-0137 (5/7) semantic-token-overlay

Keep the lexical token provider as the baseline. When hover resolution
names a symbol and an existing semantic key matches it, replace the
weaker identifier token. A failed resolution, a broken file, or a
symbol without an existing key keeps the provider token. No new
semantic key is added.
This commit is contained in:
2026-09-22 09:09:43 +01:00
parent 7629a73e0a
commit 202c785f94
7 changed files with 297 additions and 2 deletions
@@ -2,6 +2,7 @@ package p.studio.lsp.services.compiler;
import org.apache.commons.lang3.StringUtils;
import p.studio.compiler.FrontendRegistryService;
import p.studio.compiler.exceptions.BuildException;
import p.studio.compiler.messages.*;
import p.studio.compiler.models.*;
import p.studio.compiler.services.FrontendCodeAction;
@@ -628,7 +629,7 @@ public final class CompilerLanguageServiceBridge implements LanguageServiceBridg
documentPath,
effectiveText);
final List<FrontendSemanticToken> tokens = provider.languageService()
.map(languageService -> languageService.semanticTokens(request))
.map(languageService -> semanticTokens(languageService, context, documentUri, documentPath, request))
.orElseGet(List::of);
final var positionMapper = new DocumentPositionMapper(effectiveText);
final var semanticTokens = new ArrayList<BaselineSemanticToken>();
@@ -647,6 +648,26 @@ public final class CompilerLanguageServiceBridge implements LanguageServiceBridg
return new BaselineSemanticTokens(presentation.semanticKeys(), semanticTokens);
}
private List<FrontendSemanticToken> semanticTokens(
final FrontendLanguageService languageService,
final LspProjectContext context,
final String documentUri,
final Path documentPath,
final FrontendDocumentRequest request) {
try {
return editorialDocument(context, documentUri, request.documentText())
.map(document -> languageService.semanticTokens(
new FrontendDocumentRequest(
context.projectRoot(),
documentPath,
document.text()),
document.editorialContext()))
.orElseGet(() -> languageService.semanticTokens(request));
} catch (final BuildException ignored) {
return languageService.semanticTokens(request);
}
}
@Override
public String onSave(
final LspProjectContext context,