implements PLN-0135
Intrepid/Prometeu/Studio/pipeline/pr-master Build started...
JaCoCo Coverage #### Project Overview
No changes detected, that affect the code coverage.
* Line Coverage: 63.56% (19159/30145)
* Branch Coverage: 54.14% (7612/14060)
* Lines of Code: 30145
* Cyclomatic Complexity: 12214
#### Quality Gates Summary
Output truncated.
Test / Build skipped: 15, passed: 678
Intrepid/Prometeu/Studio/pipeline/head This commit looks good
Intrepid/Prometeu/Studio/pipeline/pr-master Build started...
JaCoCo Coverage #### Project Overview
No changes detected, that affect the code coverage.
* Line Coverage: 63.56% (19159/30145)
* Branch Coverage: 54.14% (7612/14060)
* Lines of Code: 30145
* Cyclomatic Complexity: 12214
#### Quality Gates Summary
Output truncated.
Test / Build skipped: 15, passed: 678
Intrepid/Prometeu/Studio/pipeline/head This commit looks good
Add PBS rename as a validated WorkspaceEdit of physical identifier sites on FrontendLanguageService. Identity is definition; locals and params rename from their name span. Refuse aliases, virtual stdlib, builtins, error labels, keywords, and collisions. Advertise renameProvider with prepareProvider; refused cursors are LSP errors, not empty success. Housekeep DSC-0043 with LSN-0072.
This commit is contained in:
+8
@@ -8,6 +8,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class PbsLexerTest {
|
||||
@@ -34,6 +35,13 @@ class PbsLexerTest {
|
||||
.kind());
|
||||
assertEquals(PbsTokenKind.EOF, tokens.getLast().kind());
|
||||
assertTrue(diagnostics.isEmpty(), "Lexer should not report diagnostics for valid input");
|
||||
assertTrue(PbsLexer.isKeyword("fn"));
|
||||
assertTrue(PbsLexer.isKeyword("step"));
|
||||
assertTrue(PbsLexer.isIdentifierLexeme("helper"));
|
||||
assertTrue(PbsLexer.isIdentifierLexeme("_value"));
|
||||
assertFalse(PbsLexer.isIdentifierLexeme("fn"));
|
||||
assertFalse(PbsLexer.isIdentifierLexeme("1ab"));
|
||||
assertFalse(PbsLexer.isIdentifierLexeme(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+126
@@ -606,6 +606,132 @@ final class PbsEditorialSupportServiceTest {
|
||||
assertEquals(List.of("r", "pack"), names(symbols.get(1).children()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void renameRewritesPhysicalFunctionSitesAndSkipsCommentsStringsAndCollisions() {
|
||||
final var source = """
|
||||
fn helper() -> int { return 1; }
|
||||
|
||||
fn helper(value: int) -> int { return value; }
|
||||
|
||||
fn frame() -> void {
|
||||
helper();
|
||||
helper(2);
|
||||
// helper
|
||||
let text = "helper";
|
||||
}
|
||||
""";
|
||||
final var ast = parseOrdinary(source);
|
||||
final var renamed = service.rename(source, ast, ReadOnlyList.empty(), source.indexOf("helper();"), "aid");
|
||||
assertTrue(renamed.allowed(), renamed.refusal());
|
||||
assertEquals(4, renamed.sites().size(), renamed.sites().toString());
|
||||
assertTrue(service.prepareRename(source, ast, ReadOnlyList.empty(), source.indexOf("helper();")).isPresent());
|
||||
|
||||
final var keyword = service.rename(source, ast, ReadOnlyList.empty(), source.indexOf("helper();"), "fn");
|
||||
assertFalse(keyword.allowed());
|
||||
assertEquals("invalid identifier", keyword.refusal());
|
||||
|
||||
final var collision = service.rename(source, ast, ReadOnlyList.empty(), source.indexOf("helper();"), "frame");
|
||||
assertFalse(collision.allowed());
|
||||
assertEquals("name collision", collision.refusal());
|
||||
}
|
||||
|
||||
@Test
|
||||
void renameAllowsLocalNameSpanAndRefusesAliasBuiltinAndErrorLabel() {
|
||||
final var source = """
|
||||
import { Log as Logger } from @sdk:log;
|
||||
|
||||
declare error Boom {
|
||||
Missing;
|
||||
}
|
||||
|
||||
fn frame() -> void {
|
||||
let total = 1;
|
||||
Logger.info("x");
|
||||
let n: int = total;
|
||||
n;
|
||||
}
|
||||
""";
|
||||
final var ast = parseOrdinary(source);
|
||||
final var supplemental = supplementalTopDecls("""
|
||||
declare service Log {
|
||||
fn info(message: str) -> void {
|
||||
return;
|
||||
}
|
||||
}
|
||||
""");
|
||||
|
||||
final var local = service.rename(
|
||||
source,
|
||||
ast,
|
||||
supplemental,
|
||||
source.indexOf("total ="),
|
||||
"sum");
|
||||
assertTrue(local.allowed(), local.refusal());
|
||||
assertEquals(2, local.sites().size(), local.sites().toString());
|
||||
|
||||
final var alias = service.prepareRename(
|
||||
source,
|
||||
ast,
|
||||
supplemental,
|
||||
source.indexOf("Logger.info"));
|
||||
assertTrue(alias.isEmpty());
|
||||
|
||||
final var builtin = service.prepareRename(
|
||||
source,
|
||||
ast,
|
||||
supplemental,
|
||||
source.indexOf("int = total"));
|
||||
assertTrue(builtin.isEmpty());
|
||||
|
||||
final var errorLabel = service.prepareRename(
|
||||
source,
|
||||
ast,
|
||||
supplemental,
|
||||
source.indexOf("Missing"));
|
||||
assertTrue(errorLabel.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void renameOfExportDoesNotRewriteDifferingAlias() {
|
||||
final var exporter = """
|
||||
fn helper() -> int { return 1; }
|
||||
""";
|
||||
final var importer = """
|
||||
import { helper as aid } from @sdk:log;
|
||||
|
||||
fn frame() -> void {
|
||||
aid();
|
||||
}
|
||||
""";
|
||||
final var exporterAst = parse(exporter, new FileId(1), PbsParser.ParseMode.ORDINARY);
|
||||
final var importerAst = parseOrdinary(importer);
|
||||
final var exporterDoc = new PbsEditorialSupportService.EditorialDocument(
|
||||
exporter,
|
||||
exporterAst,
|
||||
ReadOnlyList.empty(),
|
||||
p.studio.compiler.messages.FESurfaceContext.empty());
|
||||
final var importerDoc = new PbsEditorialSupportService.EditorialDocument(
|
||||
importer,
|
||||
importerAst,
|
||||
exporterAst.topDecls(),
|
||||
p.studio.compiler.messages.FESurfaceContext.empty());
|
||||
final var renamed = service.rename(
|
||||
exporterDoc,
|
||||
exporter.indexOf("helper"),
|
||||
"renamed",
|
||||
List.of(exporterDoc, importerDoc));
|
||||
assertTrue(renamed.allowed(), renamed.refusal());
|
||||
assertEquals(2, renamed.sites().size(), renamed.sites().toString());
|
||||
assertTrue(renamed.sites().stream().anyMatch(site ->
|
||||
site.span().getFileId().equals(exporterAst.span().getFileId())));
|
||||
assertTrue(renamed.sites().stream().anyMatch(site ->
|
||||
site.span().getFileId().equals(importerAst.span().getFileId())));
|
||||
final int aliasUse = importer.indexOf("aid();");
|
||||
assertTrue(renamed.sites().stream().noneMatch(site ->
|
||||
site.span().getFileId().equals(importerAst.span().getFileId())
|
||||
&& site.span().getStart() == aliasUse));
|
||||
}
|
||||
|
||||
private PbsEditorialResolvedSymbol requireHover(
|
||||
final String source,
|
||||
final PbsAst.File ast,
|
||||
|
||||
Reference in New Issue
Block a user