drccrd commented on code in PR #3717:
URL:
https://github.com/apache/incubator-kie-tools/pull/3717#discussion_r3803071391
##########
packages/drools-lsp/drools-lsp-server/src/main/java/org/drools/lsp/server/DroolsLspServer.java:
##########
@@ -263,6 +296,166 @@ public CompletableFuture<InitializeResult>
initialize(InitializeParams params) {
return CompletableFuture.supplyAsync(() -> initializeResult);
}
+ /**
+ * Returns the workspace's DRL file groups, keyed by name, so a client can
+ * show which group the open file is in and offer the rest.
+ *
+ * <p>The client asks rather than reading the config files itself: the
server
+ * already resolves kmodule descriptors, config files and adopted
manifests,
+ * and a second implementation of that in the client is a second place for
it
+ * to be wrong.
+ */
+ @JsonRequest("drools/fileGroups")
+ public CompletableFuture<Map<String, FileGroupingProtocol.FileGroup>>
fileGroups() {
+ return CompletableFuture.supplyAsync(() -> {
+ Map<String, FileGroupingProtocol.FileGroup> groups = new
LinkedHashMap<>();
+
WorkspaceSiblingResolvers.active().resolveAllGroups().forEach((name, group) -> {
+ List<String> uris = new ArrayList<>(group.files().size());
+ for (Path file : group.files()) {
+ uris.add(file.toUri().toString());
+ }
+ Path declaredIn = group.declaredIn();
+ groups.put(name, new FileGroupingProtocol.FileGroup(uris,
group.kind(),
+ declaredIn == null ? null :
declaredIn.toUri().toString()));
+ });
+ return groups;
+ });
+ }
+
+ /**
+ * Pins a document to a named group, overriding what the configuration
+ * resolves it to. A file can belong to several groups, so this is how the
+ * user settles which one the editor works in.
+ */
+ @JsonNotification("drools/setFileGroup")
+ public void setFileGroup(FileGroupingProtocol.FileGroupParams params) {
+ if (params == null || params.getUri() == null) {
+ return;
+ }
+ try {
+ WorkspaceSiblingResolvers.active()
+ .setGroupOverride(Paths.get(URI.create(params.getUri())),
params.getGroup());
+ // Pinning changes what is in scope, and diagnostics here are
pulled
+ // rather than pushed, so nothing would re-ask on its own.
+ refreshDiagnostics();
+ } catch (Exception e) {
+ logger.log(Level.WARNING, "Failed to pin " + params.getUri() + "
to a DRL file group", e);
+ }
+ }
+
+ /** Re-reads the workspace's grouping configuration after a config file
changes. */
+ @JsonNotification("drools/reloadFileGroups")
+ public void reloadFileGroups() {
+ WorkspaceSiblingResolvers.active().reload();
+ notifyFileGroupsChanged();
+ }
+
+ /**
+ * Replaces the grouping declared in the editor's settings, so a user
editing
+ * {@code drools.lsp.grouping} sees the effect without restarting the
server.
+ */
+ @JsonNotification("drools/setGroupingConfig")
+ public void setGroupingConfig(FileGroupingProtocol.GroupingConfigParams
params) {
+ JsonObject config = (params == null) ? null : params.getConfig();
+ WorkspaceSiblingResolvers.active().setSettingsConfig(config == null ?
null : config.toString());
+ notifyFileGroupsChanged();
+ }
+
+ /**
+ * Tells the client the group map changed, so it can re-read it.
+ *
+ * <p>Sent through the raw endpoint because this is a custom method the
+ * {@link LanguageClient} interface does not declare. A client that is not
an
+ * lsp4j proxy — a test double, say — simply does not get told.
+ */
+ private void notifyFileGroupsChanged() {
+ if (client instanceof Endpoint endpoint) {
+ endpoint.notify("drools/fileGroupsChanged", null);
+ }
Review Comment:
I don't think this is true, I'm not sure what is meant here by "the real
server" but it works as-is in a prod-package installed in VS code...
I added a unit test to ensure this stays true. Claude says:
lsp4j builds the remote proxy over both the service interface and `Endpoint`
— `ServiceEndpoints.toServiceObject` constructs `new Class[]{interface_,
Endpoint.class}` before `Proxy.newProxyInstance`. So `client instanceof
Endpoint` is true for the launcher's proxy and the notification is sent. Added
`LauncherTest#remoteClientProxyIsAlsoAnEndpoint` asserting it, so the
assumption is now enforced rather than implicit.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]