implements PLN-0108
This commit is contained in:
+62
@@ -0,0 +1,62 @@
|
||||
package p.studio.compiler;
|
||||
|
||||
import p.studio.compiler.messages.FESurfaceContext;
|
||||
import p.studio.compiler.models.FrontendSemanticToken;
|
||||
import p.studio.compiler.pbs.ast.PbsAst;
|
||||
import p.studio.compiler.pbs.semantics.PbsEditorialCompletionCandidate;
|
||||
import p.studio.compiler.pbs.semantics.PbsEditorialResolvedSymbol;
|
||||
import p.studio.compiler.pbs.semantics.PbsEditorialSignatureHelp;
|
||||
import p.studio.compiler.pbs.semantics.PbsEditorialSupportService;
|
||||
import p.studio.compiler.services.FrontendLanguageService;
|
||||
import p.studio.utilities.structures.ReadOnlyList;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
public final class PBSFrontendLanguageService implements FrontendLanguageService {
|
||||
private final PbsEditorialSupportService editorialSupportService;
|
||||
private final PBSSemanticTokenProvider semanticTokenProvider;
|
||||
|
||||
public PBSFrontendLanguageService() {
|
||||
this(new PbsEditorialSupportService(), new PBSSemanticTokenProvider());
|
||||
}
|
||||
|
||||
PBSFrontendLanguageService(
|
||||
final PbsEditorialSupportService editorialSupportService,
|
||||
final PBSSemanticTokenProvider semanticTokenProvider) {
|
||||
this.editorialSupportService = Objects.requireNonNull(editorialSupportService, "editorialSupportService");
|
||||
this.semanticTokenProvider = Objects.requireNonNull(semanticTokenProvider, "semanticTokenProvider");
|
||||
}
|
||||
|
||||
public List<PbsEditorialCompletionCandidate> completion(
|
||||
final String sourceText,
|
||||
final PbsAst.File ast,
|
||||
final ReadOnlyList<PbsAst.TopDecl> supplementalTopDecls,
|
||||
final FESurfaceContext feSurfaceContext,
|
||||
final int offset) {
|
||||
return editorialSupportService.completion(sourceText, ast, supplementalTopDecls, feSurfaceContext, offset);
|
||||
}
|
||||
|
||||
public Optional<PbsEditorialResolvedSymbol> hover(
|
||||
final String sourceText,
|
||||
final PbsAst.File ast,
|
||||
final ReadOnlyList<PbsAst.TopDecl> supplementalTopDecls,
|
||||
final FESurfaceContext feSurfaceContext,
|
||||
final int offset) {
|
||||
return editorialSupportService.hover(sourceText, ast, supplementalTopDecls, feSurfaceContext, offset);
|
||||
}
|
||||
|
||||
public Optional<PbsEditorialSignatureHelp> signatureHelp(
|
||||
final String sourceText,
|
||||
final PbsAst.File ast,
|
||||
final ReadOnlyList<PbsAst.TopDecl> supplementalTopDecls,
|
||||
final FESurfaceContext feSurfaceContext,
|
||||
final int offset) {
|
||||
return editorialSupportService.signatureHelp(sourceText, ast, supplementalTopDecls, feSurfaceContext, offset);
|
||||
}
|
||||
|
||||
public List<FrontendSemanticToken> semanticTokens(final String documentText) {
|
||||
return semanticTokenProvider.tokenize(documentText == null ? "" : documentText);
|
||||
}
|
||||
}
|
||||
+17
-1
@@ -1,19 +1,30 @@
|
||||
package p.studio.compiler;
|
||||
|
||||
import p.studio.compiler.models.FrontendSpec;
|
||||
import p.studio.compiler.services.FrontendLanguageService;
|
||||
import p.studio.compiler.services.FrontendPhaseService;
|
||||
import p.studio.compiler.services.FrontendProvider;
|
||||
import p.studio.compiler.services.PBSFrontendPhaseService;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public final class PBSFrontendProvider implements FrontendProvider {
|
||||
private final FrontendPhaseService compiler;
|
||||
private final PBSFrontendLanguageService languageService;
|
||||
|
||||
public PBSFrontendProvider() {
|
||||
this(new PBSFrontendPhaseService());
|
||||
this(new PBSFrontendPhaseService(), new PBSFrontendLanguageService());
|
||||
}
|
||||
|
||||
PBSFrontendProvider(final FrontendPhaseService compiler) {
|
||||
this(compiler, new PBSFrontendLanguageService());
|
||||
}
|
||||
|
||||
PBSFrontendProvider(
|
||||
final FrontendPhaseService compiler,
|
||||
final PBSFrontendLanguageService languageService) {
|
||||
this.compiler = compiler;
|
||||
this.languageService = languageService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -25,4 +36,9 @@ public final class PBSFrontendProvider implements FrontendProvider {
|
||||
public FrontendPhaseService compiler() {
|
||||
return compiler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<FrontendLanguageService> languageService() {
|
||||
return Optional.of(languageService);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -4,8 +4,8 @@ import org.junit.jupiter.api.Test;
|
||||
import p.studio.compiler.services.PBSFrontendPhaseService;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class PBSFrontendProviderTest {
|
||||
|
||||
@@ -15,6 +15,7 @@ class PBSFrontendProviderTest {
|
||||
|
||||
assertEquals(PBSDefinitions.PBS.getLanguageId(), provider.specification().getLanguageId());
|
||||
assertInstanceOf(PBSFrontendPhaseService.class, provider.compiler());
|
||||
assertFalse(provider.languageService().isPresent());
|
||||
assertTrue(provider.languageService().isPresent());
|
||||
assertInstanceOf(PBSFrontendLanguageService.class, provider.languageService().orElseThrow());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user