This is an automated email from the ASF dual-hosted git repository.

sdedic pushed a commit to branch sdedic/feature/project-dependency-add_base
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to 
refs/heads/sdedic/feature/project-dependency-add_base by this push:
     new 53d7daeb46 Allow to instruct the client to save a document.
53d7daeb46 is described below

commit 53d7daeb46210b4a5a406dae8eb12201b06363fa
Author: Svata Dedic <[email protected]>
AuthorDate: Thu Dec 14 20:13:35 2023 +0100

    Allow to instruct the client to save a document.
---
 .../lsp/server/protocol/NbCodeClientWrapper.java   |  4 ++
 .../lsp/server/protocol/NbCodeLanguageClient.java  |  3 ++
 .../server/protocol/SaveDocumentRequestParams.java | 46 ++++++++++++++++++++++
 .../modules/java/lsp/server/protocol/Server.java   |  6 +++
 .../java/lsp/server/TestCodeLanguageClient.java    |  5 +++
 .../java/lsp/server/explorer/ProjectViewTest.java  |  6 +++
 .../server/progress/TestProgressHandlerTest.java   |  2 +-
 java/java.lsp.server/vscode/src/extension.ts       | 10 ++++-
 java/java.lsp.server/vscode/src/protocol.ts        |  9 +++++
 9 files changed, 89 insertions(+), 2 deletions(-)

diff --git 
a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/NbCodeClientWrapper.java
 
b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/NbCodeClientWrapper.java
index 7cef6cec02..7f633df675 100644
--- 
a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/NbCodeClientWrapper.java
+++ 
b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/NbCodeClientWrapper.java
@@ -219,4 +219,8 @@ class NbCodeClientWrapper implements NbCodeLanguageClient {
         return remote.configurationUpdate(params);
     }
     
+    @Override
+    public CompletableFuture<Boolean> 
requestDocumentSave(SaveDocumentRequestParams documentUris) {
+        return remote.requestDocumentSave(documentUris);
+    }
 }
diff --git 
a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/NbCodeLanguageClient.java
 
b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/NbCodeLanguageClient.java
index 42fd4e5328..1c44d56fa5 100644
--- 
a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/NbCodeLanguageClient.java
+++ 
b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/NbCodeLanguageClient.java
@@ -151,4 +151,7 @@ public interface NbCodeLanguageClient extends 
LanguageClient {
     @JsonRequest("config/update")
     public CompletableFuture<Void> configurationUpdate(@NonNull 
UpdateConfigParams params);
     
+    @JsonRequest("window/documentSave")
+    public CompletableFuture<Boolean> requestDocumentSave(@NonNull 
SaveDocumentRequestParams documentUri);
+    
 }
diff --git 
a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/SaveDocumentRequestParams.java
 
b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/SaveDocumentRequestParams.java
new file mode 100644
index 0000000000..0941008616
--- /dev/null
+++ 
b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/SaveDocumentRequestParams.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.lsp.server.protocol;
+
+import java.util.List;
+import org.eclipse.xtext.xbase.lib.Pure;
+
+/**
+ *
+ * @author sdedic
+ */
+public class SaveDocumentRequestParams {
+    private List<String> documents;
+
+    public SaveDocumentRequestParams() {
+    }
+
+    public SaveDocumentRequestParams(List<String> documents) {
+        this.documents = documents;
+    }
+
+    @Pure
+    public List<String> getDocuments() {
+        return documents;
+    }
+
+    public void setDocuments(List<String> documents) {
+        this.documents = documents;
+    }
+}
diff --git 
a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java
 
b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java
index 17147a04ab..42d4d6a813 100644
--- 
a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java
+++ 
b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java
@@ -1252,6 +1252,12 @@ public final class Server {
             logWarning(params);
             return CompletableFuture.completedFuture(null);
         }
+
+        @Override
+        public CompletableFuture<Boolean> 
requestDocumentSave(SaveDocumentRequestParams documentUris) {
+            logWarning(Arrays.asList(documentUris));
+            return CompletableFuture.completedFuture(false);
+        }
     };
 
 
diff --git 
a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/TestCodeLanguageClient.java
 
b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/TestCodeLanguageClient.java
index d26ba5d8a6..ba5588804f 100644
--- 
a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/TestCodeLanguageClient.java
+++ 
b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/TestCodeLanguageClient.java
@@ -43,6 +43,7 @@ import 
org.netbeans.modules.java.lsp.server.protocol.SetTextEditorDecorationPara
 import org.netbeans.modules.java.lsp.server.input.ShowInputBoxParams;
 import org.netbeans.modules.java.lsp.server.input.ShowMutliStepInputParams;
 import org.netbeans.modules.java.lsp.server.input.ShowQuickPickParams;
+import org.netbeans.modules.java.lsp.server.protocol.SaveDocumentRequestParams;
 import org.netbeans.modules.java.lsp.server.protocol.ShowStatusMessageParams;
 import org.netbeans.modules.java.lsp.server.protocol.TestProgressParams;
 import org.netbeans.modules.java.lsp.server.protocol.UpdateConfigParams;
@@ -155,4 +156,8 @@ public abstract class TestCodeLanguageClient implements 
NbCodeLanguageClient {
         throw new UnsupportedOperationException();
     }
     
+    @Override
+    public CompletableFuture<Boolean> 
requestDocumentSave(SaveDocumentRequestParams documentUris) {
+        return CompletableFuture.completedFuture(false);
+    }
 }
diff --git 
a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/explorer/ProjectViewTest.java
 
b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/explorer/ProjectViewTest.java
index 14a57b2cf1..ea6dcf3427 100644
--- 
a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/explorer/ProjectViewTest.java
+++ 
b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/explorer/ProjectViewTest.java
@@ -76,6 +76,7 @@ import 
org.netbeans.modules.java.lsp.server.input.QuickPickItem;
 import org.netbeans.modules.java.lsp.server.input.ShowInputBoxParams;
 import org.netbeans.modules.java.lsp.server.input.ShowMutliStepInputParams;
 import org.netbeans.modules.java.lsp.server.input.ShowQuickPickParams;
+import org.netbeans.modules.java.lsp.server.protocol.SaveDocumentRequestParams;
 import 
org.netbeans.modules.java.lsp.server.protocol.SetTextEditorDecorationParams;
 import org.netbeans.modules.java.lsp.server.protocol.ShowStatusMessageParams;
 import org.netbeans.modules.java.lsp.server.protocol.TestProgressParams;
@@ -278,6 +279,11 @@ public class ProjectViewTest extends NbTestCase {
         public CompletableFuture<Void> configurationUpdate(UpdateConfigParams 
params) {
             return CompletableFuture.completedFuture(null);
         }
+
+        @Override
+        public CompletableFuture<Boolean> 
requestDocumentSave(SaveDocumentRequestParams documentUris) {
+            return CompletableFuture.completedFuture(false);
+        }
     }
 
     private static Launcher<NbLanguageServer> 
createLauncher(NbCodeLanguageClient client, InputStream in, OutputStream out,
diff --git 
a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/progress/TestProgressHandlerTest.java
 
b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/progress/TestProgressHandlerTest.java
index 00b12fca07..84a0ac8f51 100644
--- 
a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/progress/TestProgressHandlerTest.java
+++ 
b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/progress/TestProgressHandlerTest.java
@@ -46,6 +46,7 @@ import 
org.netbeans.modules.java.lsp.server.input.QuickPickItem;
 import 
org.netbeans.modules.java.lsp.server.protocol.SetTextEditorDecorationParams;
 import org.netbeans.modules.java.lsp.server.input.ShowInputBoxParams;
 import org.netbeans.modules.java.lsp.server.input.ShowQuickPickParams;
+import org.netbeans.modules.java.lsp.server.protocol.SaveDocumentRequestParams;
 import org.netbeans.modules.java.lsp.server.protocol.ShowStatusMessageParams;
 import org.netbeans.modules.java.lsp.server.protocol.TestProgressParams;
 import org.netbeans.modules.java.lsp.server.protocol.TestSuiteInfo;
@@ -221,6 +222,5 @@ public class TestProgressHandlerTest extends NbTestCase {
         public CompletableFuture<Void> configurationUpdate(UpdateConfigParams 
params) {
             return CompletableFuture.completedFuture(null);
         }
-
     }
 }
diff --git a/java/java.lsp.server/vscode/src/extension.ts 
b/java/java.lsp.server/vscode/src/extension.ts
index 0b6fdd891e..2938ce4df6 100644
--- a/java/java.lsp.server/vscode/src/extension.ts
+++ b/java/java.lsp.server/vscode/src/extension.ts
@@ -51,7 +51,7 @@ import * as launcher from './nbcode';
 import {NbTestAdapter} from './testAdapter';
 import { asRanges, StatusMessageRequest, ShowStatusMessageParams, 
QuickPickRequest, InputBoxRequest, MutliStepInputRequest, 
TestProgressNotification, DebugConnector,
          TextEditorDecorationCreateRequest, 
TextEditorDecorationSetNotification, TextEditorDecorationDisposeNotification, 
HtmlPageRequest, HtmlPageParams,
-         ExecInHtmlPageRequest, SetTextEditorDecorationParams, 
ProjectActionParams, UpdateConfigurationRequest, QuickPickStep, InputBoxStep
+         ExecInHtmlPageRequest, SetTextEditorDecorationParams, 
ProjectActionParams, UpdateConfigurationRequest, QuickPickStep, InputBoxStep, 
SaveDocumentsRequest, SaveDocumentRequestParams
 } from './protocol';
 import * as launchConfigurations from './launchConfigurations';
 import { createTreeViewService, TreeViewService, TreeItemDecorator, 
Visualizer, CustomizableTreeDataProvider } from './explorer';
@@ -1053,6 +1053,14 @@ function doActivateWithJDK(specifiedJDK: string | null, 
context: ExtensionContex
                 await 
vscode.workspace.getConfiguration(param.section).update(param.key, param.value);
                 runConfigurationUpdateAll();
             });
+            c.onRequest(SaveDocumentsRequest.type, async (request : 
SaveDocumentRequestParams) => {
+                for (let ed of window.visibleTextEditors) {
+                    if 
(request.documents.includes(ed.document.uri.toString())) {
+                        await 
vscode.commands.executeCommand('workbench.action.files.save', ed.document.uri);
+                    }
+                }
+                return true;
+            });
             c.onRequest(InputBoxRequest.type, async param => {
                 return await window.showInputBox({ title: param.title, prompt: 
param.prompt, value: param.value, password: param.password });
             });
diff --git a/java/java.lsp.server/vscode/src/protocol.ts 
b/java/java.lsp.server/vscode/src/protocol.ts
index ac76ed9c20..70a27998a4 100644
--- a/java/java.lsp.server/vscode/src/protocol.ts
+++ b/java/java.lsp.server/vscode/src/protocol.ts
@@ -204,6 +204,14 @@ export namespace TextEditorDecorationDisposeNotification {
     export const type = new ProtocolNotificationType<string, 
void>('window/disposeTextEditorDecoration');
 }
 
+export interface SaveDocumentRequestParams {
+    documents: string[];
+}
+
+export namespace SaveDocumentsRequest {
+    export const type = new ProtocolRequestType<SaveDocumentRequestParams, 
boolean, never, void, void>('window/documentSave');
+}
+
 export interface NodeChangedParams {
     rootId : number;
     nodeId : number | null;
@@ -292,6 +300,7 @@ export namespace NodeInfoRequest {
     }
 };
 
+
 export function asPosition(value: undefined | null): undefined;
 export function asPosition(value: Position): vscode.Position;
 export function asPosition(value: Position | undefined | null): 
vscode.Position | undefined;


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to