implements PLN-0027 frontend semantic presentation contract and lsp descriptor
This commit is contained in:
@@ -22,6 +22,13 @@ final class LspServiceImplTest {
|
||||
@TempDir
|
||||
Path tempDir;
|
||||
|
||||
private static final String OVERLAY_SOURCE = """
|
||||
fn helper_call() -> void
|
||||
{
|
||||
helper();
|
||||
}
|
||||
""";
|
||||
|
||||
@Test
|
||||
void analyzeDocumentUsesVfsOverlayForRequestedDocumentAndFilesystemFallbackForClosedFiles() throws Exception {
|
||||
final Path projectRoot = createProject();
|
||||
@@ -31,18 +38,17 @@ final class LspServiceImplTest {
|
||||
Files.writeString(helperFile, "fn helper() -> void {}\n");
|
||||
|
||||
final VfsProjectDocument delegate = new FilesystemProjectDocumentVfsFactory().open(projectContext(projectRoot));
|
||||
final String overlaySource = """
|
||||
fn helper_call() -> void
|
||||
{
|
||||
helper();
|
||||
}
|
||||
""";
|
||||
final LspService service = new LspServiceImpl(
|
||||
new LspProjectContext("Example", "pbs", projectRoot),
|
||||
new OverlayVfsProjectDocument(delegate, mainFile, overlaySource));
|
||||
new OverlayVfsProjectDocument(delegate, mainFile, OVERLAY_SOURCE));
|
||||
|
||||
final var analysis = service.analyzeDocument(new LspAnalyzeDocumentRequest(mainFile));
|
||||
|
||||
assertEquals("pbs-function", semanticKeyForLexeme(analysis, OVERLAY_SOURCE, "helper_call"));
|
||||
assertEquals("pbs-function", semanticKeyForLexeme(analysis, OVERLAY_SOURCE, "helper"));
|
||||
assertEquals(List.of("/themes/pbs/semantic-highlighting.css"), analysis.semanticPresentation().resources());
|
||||
assertTrue(analysis.semanticPresentation().semanticKeys().contains("pbs-function"));
|
||||
|
||||
assertTrue(
|
||||
analysis.documentSymbols().stream().anyMatch(symbol -> symbol.name().equals("helper_call")),
|
||||
analysis.toString());
|
||||
@@ -51,7 +57,7 @@ final class LspServiceImplTest {
|
||||
symbol.name().equals("helper") && symbol.documentPath().equals(normalize(helperFile))),
|
||||
analysis.toString());
|
||||
|
||||
final int offset = overlaySource.indexOf("helper();");
|
||||
final int offset = OVERLAY_SOURCE.indexOf("helper();");
|
||||
final var definition = service.definition(new LspDefinitionRequest(mainFile, offset));
|
||||
final List<LspDefinitionTargetDTO> targets = definition.targets();
|
||||
|
||||
@@ -110,6 +116,27 @@ final class LspServiceImplTest {
|
||||
}
|
||||
}
|
||||
|
||||
private static String semanticKeyForLexeme(
|
||||
final p.studio.lsp.messages.LspAnalyzeDocumentResult analysis,
|
||||
final String source,
|
||||
final String lexeme) {
|
||||
return analysis.semanticHighlights().stream()
|
||||
.filter(highlight -> lexeme.equals(spanContent(source, highlight.range().startOffset(), highlight.range().endOffset())))
|
||||
.map(p.studio.lsp.dtos.LspHighlightSpanDTO::semanticKey)
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
}
|
||||
|
||||
private static String spanContent(
|
||||
final String source,
|
||||
final int start,
|
||||
final int end) {
|
||||
if (start < 0 || end > source.length() || start >= end) {
|
||||
return "";
|
||||
}
|
||||
return source.substring(start, end);
|
||||
}
|
||||
|
||||
private static final class OverlayVfsProjectDocument implements VfsProjectDocument {
|
||||
private final VfsProjectDocument delegate;
|
||||
private final Path overlayPath;
|
||||
|
||||
Reference in New Issue
Block a user