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:
+50
@@ -172,6 +172,56 @@ class CompilerLanguageServiceBridgeTest {
|
||||
assertTrue(semanticTokens.tokens().stream().anyMatch(token -> token.semanticKey().equals("pbs-builtin-type")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void semanticTokenOverlayReplacesAResolvedUseAndKeepsBrokenText(@TempDir final Path tempDir) throws IOException {
|
||||
final Path projectRoot = tempDir.resolve("app");
|
||||
final Path source = projectRoot.resolve("src").resolve("main.pbs");
|
||||
Files.createDirectories(source.getParent());
|
||||
Files.writeString(projectRoot.resolve("prometeu.json"), """
|
||||
{
|
||||
"name": "app",
|
||||
"version": "1.0.0",
|
||||
"language": "pbs",
|
||||
"stdlib": "1",
|
||||
"target": "Game",
|
||||
"dependencies": []
|
||||
}
|
||||
""");
|
||||
final String text = """
|
||||
fn helper() -> int {
|
||||
return 1;
|
||||
}
|
||||
|
||||
fn main() -> int {
|
||||
return helper;
|
||||
}
|
||||
""";
|
||||
Files.writeString(source, text);
|
||||
Files.writeString(source.getParent().resolve("mod.barrel"), """
|
||||
pub fn helper() -> int;
|
||||
pub fn main() -> int;
|
||||
""");
|
||||
final CompilerLanguageServiceBridge bridge = new CompilerLanguageServiceBridge();
|
||||
final Path realSource = source.toRealPath();
|
||||
final var tokens = bridge.semanticTokens(
|
||||
new LspProjectContext("app", "pbs", projectRoot.toRealPath()),
|
||||
realSource.toUri().toString(),
|
||||
text);
|
||||
final int helperUse = text.indexOf("return helper") + "return ".length();
|
||||
assertTrue(tokens.tokens().stream().anyMatch(token ->
|
||||
token.semanticKey().equals("pbs-function")
|
||||
&& token.line() == new DocumentPositionMapper(text).positionOf(helperUse).line()
|
||||
&& token.startCharacter() == new DocumentPositionMapper(text).positionOf(helperUse).character()));
|
||||
|
||||
final String broken = "fn main( {";
|
||||
final var brokenTokens = bridge.semanticTokens(
|
||||
new LspProjectContext("app", "pbs", projectRoot.toRealPath()),
|
||||
realSource.toUri().toString(),
|
||||
broken);
|
||||
assertTrue(brokenTokens.tokens().stream().anyMatch(token -> token.semanticKey().equals("pbs-keyword")));
|
||||
assertTrue(brokenTokens.tokens().stream().anyMatch(token -> token.semanticKey().equals("pbs-punctuation")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void completionHoverAndSignatureHelpUseCompilerBackedEditorialResolution() {
|
||||
final Path projectRoot = findRepoRoot(Path.of("").toAbsolutePath().normalize())
|
||||
|
||||
Reference in New Issue
Block a user