Skip to content

[POM-leading for DSLs] Routing to dedicated remote language servers#1069

Open
toinehartman wants to merge 69 commits into
feature/1010-pom-leading-for-dsls/finalfrom
feature/1010-pom-leading-for-dsls/remote-routing
Open

[POM-leading for DSLs] Routing to dedicated remote language servers#1069
toinehartman wants to merge 69 commits into
feature/1010-pom-leading-for-dsls/finalfrom
feature/1010-pom-leading-for-dsls/remote-routing

Conversation

@toinehartman
Copy link
Copy Markdown
Member

@toinehartman toinehartman commented Apr 28, 2026

This PR is the first of a series. gradually implementing POM-leading behavior in DSLs/the parametric server.
This PR introduces a routing language server, which delegates incoming LSP requests to the appropriate parametric language server, dedicated to a single language. A dedicated server is started upon initial language registration.

Closes #1076

@toinehartman toinehartman self-assigned this Apr 28, 2026
@toinehartman toinehartman added the enhancement New feature or request label Apr 28, 2026
@toinehartman toinehartman changed the base branch from main to feature/1010-pom-leading-for-dsls/final April 28, 2026 16:23
@toinehartman toinehartman force-pushed the feature/1010-pom-leading-for-dsls/remote-routing branch from 7bf6060 to 017ab39 Compare May 5, 2026 09:30
@toinehartman toinehartman force-pushed the feature/1010-pom-leading-for-dsls/remote-routing branch from 683fef2 to 6ee7eca Compare May 5, 2026 15:55
@toinehartman toinehartman force-pushed the feature/1010-pom-leading-for-dsls/remote-routing branch from 8e1ed67 to b434ff4 Compare May 11, 2026 12:43
}

public SemanticTokensWithRegistrationOptions options() {
public static SemanticTokensWithRegistrationOptions options() {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change allows us to make ParametricTextDocumentService::setStaticServerCapabilities static as well and re-use it in the new RoutingTextDocumentService


RascalWorkspaceService(ExecutorService exec, IBaseTextDocumentService documentService) {
super(exec, documentService);
RascalWorkspaceService(ExecutorService exec) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This argument is replaced by a pair function

@toinehartman toinehartman force-pushed the feature/1010-pom-leading-for-dsls/remote-routing branch from b434ff4 to 6f475fe Compare May 11, 2026 14:57
@toinehartman toinehartman force-pushed the feature/1010-pom-leading-for-dsls/remote-routing branch from 600df56 to 3ed29d4 Compare May 12, 2026 11:51
@toinehartman toinehartman force-pushed the feature/1010-pom-leading-for-dsls/remote-routing branch from 3ed29d4 to 2b01979 Compare May 12, 2026 11:59
@sonarqubecloud
Copy link
Copy Markdown

@toinehartman toinehartman marked this pull request as ready for review May 12, 2026 12:22
@toinehartman toinehartman linked an issue May 12, 2026 that may be closed by this pull request
, "-cp", classPath
, "org.rascalmpl.vscode.lsp.parametric.ParametricLanguageServer"
, "--exitWhenEmpty"
// , new GsonBuilder().create().toJson(lang, LanguageParameter.class).replace("\"", "\\\"") // escape JSON string on command line
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice you use the dedicated language feature of the parametric LSP here, but then we should also probably swallow the registerLanguage call that triggered this, as otherwise, we are registering twice and wasting resources.

Copy link
Copy Markdown
Member

@DavyLandman DavyLandman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is heading in the right direction. But it's not ready yet.

private final Map<String, String> languagesByExtension = new ConcurrentHashMap<>();
// NOTE
// 1. This map should only contains running server processes.
// 2. Upon removal from this map, the process should be killed to avoid resource leaks.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should also register a shutdown hook to always close our child processes.

}

public CompletableFuture<IBaseLanguageServerExtensions> route(String extension) {
return safeLanguage(extension).map(this::languageByName).orElseThrow(() -> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this exception is thrown in the context of route not in the context of the completable future, so that might be not so nice.

Same is true for the safeLanguage exception.

}

private static String classPath(LanguageParameter lang) {
var separator = System.getProperty("path.separator");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use File.pathSeparator instead. (this maybe negates the need for this).

} catch (IOException e) {
logger.error("Error while parsing path config {}", lang.getPathConfig(), e);
logger.warn("Could not compute class path for {}; falling back to class path of routing server", lang.getName());
return System.getProperty("java.class.path");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we should have a fallback like this. It can lead to all kinds of down stream errors that a user didn't suspect, all because of like some parse error in the pom.xml that wasn't reported to the user as a breaking error.

// Check if we are in Rascal-LSP
var classPath = new StringBuilder();
if (isRascalLspProject(rootProject)) {
classPath.append(separator);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should collect all entries in a list, and then at the end join them with the path sep as element seperator?

so that he final substring can also be skipped.

Comment on lines +121 to +122
@SuppressWarnings("unused")
private final ExecutorService exec;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why keep it around if we don't use it?

this.parentServer = server;
}

private ActualRoutingLanguageServer availableServer() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this extra edge, why do we need to loop back to the server? I've had this same question when reading this PR, I don't like all these cycles, so can we do without?

.thenCompose(s -> s.getWorkspaceService().executeCommand(commandParams));
}

return CompletableFutureUtils.completedFuture(commandParams.getCommand() + " was ignored.", getExecutor());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we say why it was ignored?

Comment on lines +68 to +69
@JsonDelegate
IBaseTextDocumentService getIBaseTextDocumentService();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this extension? can we add a comment? I don't see how the IBaseTextDocumentService could ever be serialized over json?

try {
root = resolveLocation(|project://rascal-lsp|);
} catch SchemeNotSupported(_): {
root = resolveLocation(|cwd:///../../../rascal-lsp|);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add a comment to explain why we're doing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parametric routing layer with dedicated servers

2 participants