Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to instruct the client to save a document. #6848

Merged
merged 1 commit into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,8 @@ public CompletableFuture<Void> configurationUpdate(UpdateConfigParams params) {
return remote.configurationUpdate(params);
}

@Override
public CompletableFuture<Boolean> requestDocumentSave(SaveDocumentRequestParams documentUris) {
return remote.requestDocumentSave(documentUris);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,7 @@ public default boolean isRequestDispatcherThread() {
@JsonRequest("config/update")
public CompletableFuture<Void> configurationUpdate(@NonNull UpdateConfigParams params);

@JsonRequest("window/documentSave")
public CompletableFuture<Boolean> requestDocumentSave(@NonNull SaveDocumentRequestParams documentUri);

}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,12 @@ public CompletableFuture<Void> configurationUpdate(UpdateConfigParams params) {
logWarning(params);
return CompletableFuture.completedFuture(null);
}

@Override
public CompletableFuture<Boolean> requestDocumentSave(SaveDocumentRequestParams documentUris) {
logWarning(Arrays.asList(documentUris));
return CompletableFuture.completedFuture(false);
}
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
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;
Expand Down Expand Up @@ -155,4 +156,8 @@ public CompletableFuture<Void> configurationUpdate(UpdateConfigParams params) {
throw new UnsupportedOperationException();
}

@Override
public CompletableFuture<Boolean> requestDocumentSave(SaveDocumentRequestParams documentUris) {
return CompletableFuture.completedFuture(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
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;
Expand Down Expand Up @@ -278,6 +279,11 @@ public void clearChanges() {
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
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;
Expand Down Expand Up @@ -221,6 +222,5 @@ public void notifyNodeChange(NodeChangedParams params) {
public CompletableFuture<Void> configurationUpdate(UpdateConfigParams params) {
return CompletableFuture.completedFuture(null);
}

}
}
10 changes: 9 additions & 1 deletion java/java.lsp.server/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 });
});
Expand Down
8 changes: 8 additions & 0 deletions java/java.lsp.server/vscode/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down