implements PLN-0111

This commit is contained in:
2026-07-15 11:22:38 +01:00
parent 3ee0da3c0a
commit b1e75973f9
19 changed files with 1154 additions and 45 deletions
@@ -0,0 +1,33 @@
package p.studio.compiler.services;
import java.util.Objects;
public record FrontendCompletionCandidate(
String label,
FrontendSymbolKind kind,
String detail,
String documentation,
String origin) {
public FrontendCompletionCandidate {
label = requireText(label, "label");
kind = Objects.requireNonNull(kind, "kind");
detail = normalize(detail);
documentation = normalize(documentation);
origin = normalize(origin);
}
private static String normalize(final String value) {
return value == null ? "" : value.trim();
}
private static String requireText(
final String value,
final String field) {
final String candidate = Objects.requireNonNull(value, field).trim();
if (candidate.isEmpty()) {
throw new IllegalArgumentException(field + " must not be blank");
}
return candidate;
}
}
@@ -0,0 +1,22 @@
package p.studio.compiler.services;
import java.nio.file.Path;
import java.util.Objects;
public record FrontendDocumentRequest(
Path projectRoot,
Path documentPath,
String documentText) {
public FrontendDocumentRequest {
projectRoot = normalizePath(projectRoot, "projectRoot");
documentPath = normalizePath(documentPath, "documentPath");
documentText = documentText == null ? "" : documentText;
}
private static Path normalizePath(
final Path path,
final String field) {
return Objects.requireNonNull(path, field).toAbsolutePath().normalize();
}
}
@@ -0,0 +1,21 @@
package p.studio.compiler.services;
import java.util.Objects;
public record FrontendDocumentation(
FrontendDocumentationFormat format,
String text) {
public FrontendDocumentation {
format = Objects.requireNonNull(format, "format");
text = text == null ? "" : text;
}
public boolean isBlank() {
return text.isBlank();
}
public static FrontendDocumentation markdown(final String text) {
return new FrontendDocumentation(FrontendDocumentationFormat.MARKDOWN, text);
}
}
@@ -0,0 +1,6 @@
package p.studio.compiler.services;
public enum FrontendDocumentationFormat {
MARKDOWN,
PLAINTEXT
}
@@ -0,0 +1,38 @@
package p.studio.compiler.services;
import java.util.List;
import java.util.Objects;
public record FrontendHover(
String displayName,
FrontendSymbolKind kind,
String detail,
String origin,
List<FrontendSignature> signatures,
FrontendDocumentation documentation) {
public FrontendHover {
displayName = requireText(displayName, "displayName");
kind = Objects.requireNonNull(kind, "kind");
detail = normalize(detail);
origin = normalize(origin);
signatures = signatures == null ? List.of() : List.copyOf(signatures);
documentation = documentation == null
? FrontendDocumentation.markdown("")
: documentation;
}
private static String normalize(final String value) {
return value == null ? "" : value.trim();
}
private static String requireText(
final String value,
final String field) {
final String candidate = Objects.requireNonNull(value, field).trim();
if (candidate.isEmpty()) {
throw new IllegalArgumentException(field + " must not be blank");
}
return candidate;
}
}
@@ -1,7 +1,33 @@
package p.studio.compiler.services;
import p.studio.compiler.models.FrontendSemanticToken;
import java.util.List;
import java.util.Optional;
/**
* Marker contract for optional frontend-owned editor services.
* Optional frontend-owned editor services.
*/
public interface FrontendLanguageService {
default List<FrontendSemanticToken> semanticTokens(final FrontendDocumentRequest request) {
return List.of();
}
default List<FrontendCompletionCandidate> completion(
final FrontendDocumentRequest request,
final int offset) {
return List.of();
}
default Optional<FrontendHover> hover(
final FrontendDocumentRequest request,
final int offset) {
return Optional.empty();
}
default FrontendSignatureHelp signatureHelp(
final FrontendDocumentRequest request,
final int offset) {
return FrontendSignatureHelp.empty();
}
}
@@ -0,0 +1,28 @@
package p.studio.compiler.services;
import java.util.List;
import java.util.Objects;
public record FrontendSignature(
String label,
List<String> parameterLabels,
String documentation) {
public FrontendSignature {
label = requireText(label, "label");
parameterLabels = parameterLabels == null ? List.of() : parameterLabels.stream()
.map(parameterLabel -> requireText(parameterLabel, "parameterLabel"))
.toList();
documentation = documentation == null ? "" : documentation.trim();
}
private static String requireText(
final String value,
final String field) {
final String candidate = Objects.requireNonNull(value, field).trim();
if (candidate.isEmpty()) {
throw new IllegalArgumentException(field + " must not be blank");
}
return candidate;
}
}
@@ -0,0 +1,23 @@
package p.studio.compiler.services;
import java.util.List;
public record FrontendSignatureHelp(
List<FrontendSignature> signatures,
int activeSignature,
int activeParameter) {
public FrontendSignatureHelp {
signatures = signatures == null ? List.of() : List.copyOf(signatures);
if (activeSignature < 0) {
throw new IllegalArgumentException("activeSignature must be >= 0");
}
if (activeParameter < 0) {
throw new IllegalArgumentException("activeParameter must be >= 0");
}
}
public static FrontendSignatureHelp empty() {
return new FrontendSignatureHelp(List.of(), 0, 0);
}
}
@@ -0,0 +1,21 @@
package p.studio.compiler.services;
public enum FrontendSymbolKind {
KEYWORD,
LOCAL,
PARAMETER,
FIELD,
FUNCTION,
METHOD,
CONSTRUCTOR,
STRUCT,
BUILTIN_TYPE,
SERVICE,
HOST,
CONTRACT,
CALLBACK,
ENUM,
ERROR,
GLOBAL,
CONST
}