implements PLN-0063

This commit is contained in:
2026-05-05 11:14:45 +01:00
parent cebef90118
commit 1f85be3721
59 changed files with 9 additions and 3046 deletions
@@ -1,21 +0,0 @@
package p.studio.lsp;
import p.studio.lsp.dtos.LspSessionStateDTO;
import p.studio.lsp.messages.*;
import p.studio.vfs.VfsProjectDocument;
public interface LspService extends AutoCloseable {
LspProjectContext projectContext();
VfsProjectDocument projectDocumentVfs();
LspSessionStateDTO snapshot();
LspAnalyzeDocumentResult analyzeDocument(LspAnalyzeDocumentRequest request);
LspDefinitionResult definition(LspDefinitionRequest request);
@Override
default void close() {
}
}
@@ -1,8 +0,0 @@
package p.studio.lsp;
import p.studio.lsp.messages.LspProjectContext;
import p.studio.vfs.VfsProjectDocument;
public interface LspServiceFactory {
LspService open(LspProjectContext projectContext, VfsProjectDocument vfsProjectDocument);
}
@@ -1,16 +0,0 @@
package p.studio.lsp.dtos;
import java.nio.file.Path;
import java.util.Objects;
public record LspDefinitionTargetDTO(
String name,
Path documentPath,
LspRangeDTO range) {
public LspDefinitionTargetDTO {
name = Objects.requireNonNull(name, "name");
documentPath = Objects.requireNonNull(documentPath, "documentPath").toAbsolutePath().normalize();
range = Objects.requireNonNull(range, "range");
}
}
@@ -1,24 +0,0 @@
package p.studio.lsp.dtos;
import p.studio.lsp.messages.LspDiagnosticSeverity;
import java.nio.file.Path;
import java.util.Objects;
public record LspDiagnosticDTO(
Path documentPath,
LspRangeDTO range,
LspDiagnosticSeverity severity,
String phase,
String code,
String message) {
public LspDiagnosticDTO {
documentPath = Objects.requireNonNull(documentPath, "documentPath").toAbsolutePath().normalize();
range = Objects.requireNonNull(range, "range");
severity = Objects.requireNonNull(severity, "severity");
phase = phase == null ? "" : phase;
code = code == null ? "" : code;
message = Objects.requireNonNull(message, "message");
}
}
@@ -1,13 +0,0 @@
package p.studio.lsp.dtos;
import java.util.Objects;
public record LspHighlightSpanDTO(
LspRangeDTO range,
String semanticKey) {
public LspHighlightSpanDTO {
range = Objects.requireNonNull(range, "range");
semanticKey = Objects.requireNonNull(semanticKey, "semanticKey");
}
}
@@ -1,18 +0,0 @@
package p.studio.lsp.dtos;
import java.util.Objects;
public record LspInlineHintDTO(
LspRangeDTO anchor,
String label,
String category) {
public LspInlineHintDTO {
anchor = Objects.requireNonNull(anchor, "anchor");
label = Objects.requireNonNull(label, "label").trim();
category = Objects.requireNonNull(category, "category").trim();
if (label.isBlank()) {
throw new IllegalArgumentException("label cannot be blank");
}
}
}
@@ -1,15 +0,0 @@
package p.studio.lsp.dtos;
public record LspRangeDTO(
int startOffset,
int endOffset) {
public LspRangeDTO {
startOffset = Math.max(0, startOffset);
endOffset = Math.max(startOffset, endOffset);
}
public boolean contains(final int offset) {
return startOffset <= offset && offset < endOffset;
}
}
@@ -1,14 +0,0 @@
package p.studio.lsp.dtos;
import java.util.List;
import java.util.Objects;
public record LspSemanticPresentationDTO(
List<String> semanticKeys,
List<String> resources) {
public LspSemanticPresentationDTO {
semanticKeys = List.copyOf(Objects.requireNonNull(semanticKeys, "semanticKeys"));
resources = List.copyOf(Objects.requireNonNull(resources, "resources"));
}
}
@@ -1,13 +0,0 @@
package p.studio.lsp.dtos;
import java.util.List;
import java.util.Objects;
public record LspSessionStateDTO(
boolean semanticReadReady,
List<String> declaredCapabilities) {
public LspSessionStateDTO {
declaredCapabilities = List.copyOf(Objects.requireNonNull(declaredCapabilities, "declaredCapabilities"));
}
}
@@ -1,18 +0,0 @@
package p.studio.lsp.dtos;
import java.util.List;
import java.util.Objects;
public record LspStructuralAnchorDTO(
LspRangeDTO range,
LspRangeDTO startAnchor,
LspRangeDTO endAnchor,
List<LspStructuralAnchorDTO> children) {
public LspStructuralAnchorDTO {
range = Objects.requireNonNull(range, "range");
startAnchor = Objects.requireNonNull(startAnchor, "startAnchor");
endAnchor = Objects.requireNonNull(endAnchor, "endAnchor");
children = List.copyOf(Objects.requireNonNull(children, "children"));
}
}
@@ -1,23 +0,0 @@
package p.studio.lsp.dtos;
import p.studio.lsp.messages.LspSymbolKind;
import java.nio.file.Path;
import java.util.List;
import java.util.Objects;
public record LspSymbolDTO(
String name,
LspSymbolKind kind,
Path documentPath,
LspRangeDTO range,
List<LspSymbolDTO> children) {
public LspSymbolDTO {
name = Objects.requireNonNull(name, "name");
kind = Objects.requireNonNull(kind, "kind");
documentPath = Objects.requireNonNull(documentPath, "documentPath").toAbsolutePath().normalize();
range = Objects.requireNonNull(range, "range");
children = List.copyOf(Objects.requireNonNull(children, "children"));
}
}
@@ -1,13 +0,0 @@
package p.studio.lsp.events;
import java.util.Objects;
public record LspEvent(
LspEventKind kind,
String message) {
public LspEvent {
Objects.requireNonNull(kind, "kind");
Objects.requireNonNull(message, "message");
}
}
@@ -1,5 +0,0 @@
package p.studio.lsp.events;
public enum LspEventKind {
SESSION_READY
}
@@ -1,5 +0,0 @@
package p.studio.lsp.events;
public interface LspEventSink {
void publish(LspEvent event);
}
@@ -1,12 +0,0 @@
package p.studio.lsp.messages;
import java.nio.file.Path;
import java.util.Objects;
public record LspAnalyzeDocumentRequest(
Path documentPath) {
public LspAnalyzeDocumentRequest {
documentPath = Objects.requireNonNull(documentPath, "documentPath").toAbsolutePath().normalize();
}
}
@@ -1,34 +0,0 @@
package p.studio.lsp.messages;
import p.studio.lsp.dtos.LspDiagnosticDTO;
import p.studio.lsp.dtos.LspHighlightSpanDTO;
import p.studio.lsp.dtos.LspInlineHintDTO;
import p.studio.lsp.dtos.LspSemanticPresentationDTO;
import p.studio.lsp.dtos.LspSessionStateDTO;
import p.studio.lsp.dtos.LspStructuralAnchorDTO;
import p.studio.lsp.dtos.LspSymbolDTO;
import java.util.List;
import java.util.Objects;
public record LspAnalyzeDocumentResult(
LspSessionStateDTO sessionState,
LspSemanticPresentationDTO semanticPresentation,
List<LspDiagnosticDTO> diagnostics,
List<LspHighlightSpanDTO> semanticHighlights,
List<LspInlineHintDTO> inlineHints,
List<LspSymbolDTO> documentSymbols,
List<LspStructuralAnchorDTO> structuralAnchors,
List<LspSymbolDTO> workspaceSymbols) {
public LspAnalyzeDocumentResult {
Objects.requireNonNull(sessionState, "sessionState");
Objects.requireNonNull(semanticPresentation, "semanticPresentation");
diagnostics = List.copyOf(Objects.requireNonNull(diagnostics, "diagnostics"));
semanticHighlights = List.copyOf(Objects.requireNonNull(semanticHighlights, "semanticHighlights"));
inlineHints = List.copyOf(Objects.requireNonNull(inlineHints, "inlineHints"));
documentSymbols = List.copyOf(Objects.requireNonNull(documentSymbols, "documentSymbols"));
structuralAnchors = List.copyOf(Objects.requireNonNull(structuralAnchors, "structuralAnchors"));
workspaceSymbols = List.copyOf(Objects.requireNonNull(workspaceSymbols, "workspaceSymbols"));
}
}
@@ -1,14 +0,0 @@
package p.studio.lsp.messages;
import java.nio.file.Path;
import java.util.Objects;
public record LspDefinitionRequest(
Path documentPath,
int offset) {
public LspDefinitionRequest {
documentPath = Objects.requireNonNull(documentPath, "documentPath").toAbsolutePath().normalize();
offset = Math.max(0, offset);
}
}
@@ -1,19 +0,0 @@
package p.studio.lsp.messages;
import p.studio.lsp.dtos.LspDefinitionTargetDTO;
import java.nio.file.Path;
import java.util.List;
import java.util.Objects;
public record LspDefinitionResult(
Path documentPath,
int offset,
List<LspDefinitionTargetDTO> targets) {
public LspDefinitionResult {
documentPath = Objects.requireNonNull(documentPath, "documentPath").toAbsolutePath().normalize();
offset = Math.max(0, offset);
targets = List.copyOf(Objects.requireNonNull(targets, "targets"));
}
}
@@ -1,6 +0,0 @@
package p.studio.lsp.messages;
public enum LspDiagnosticSeverity {
ERROR,
WARNING
}
@@ -1,16 +0,0 @@
package p.studio.lsp.messages;
import java.nio.file.Path;
import java.util.Objects;
public record LspProjectContext(
String projectName,
String languageId,
Path rootPath) {
public LspProjectContext {
Objects.requireNonNull(projectName, "projectName");
Objects.requireNonNull(languageId, "languageId");
rootPath = Objects.requireNonNull(rootPath, "rootPath").toAbsolutePath().normalize();
}
}
@@ -1,24 +0,0 @@
package p.studio.lsp.messages;
public enum LspSymbolKind {
FUNCTION,
METHOD,
CONSTRUCTOR,
IF,
SWITCH,
FOR,
WHILE,
HANDLE,
GLOBAL,
CONST,
STRUCT,
CONTRACT,
HOST,
BUILTIN_TYPE,
SERVICE,
ERROR,
ENUM,
CALLBACK,
IMPLEMENTS,
UNKNOWN
}