use of org.eclipse.lsp4j.ApplyWorkspaceEditParams in project ballerina by ballerina-lang.
the class CommandExecutor method applyWorkspaceEdit.
private static void applyWorkspaceEdit(List<TextDocumentEdit> textDocumentEdits, LanguageClient client) {
WorkspaceEdit workspaceEdit = new WorkspaceEdit();
workspaceEdit.setDocumentChanges(textDocumentEdits);
ApplyWorkspaceEditParams applyWorkspaceEditParams = new ApplyWorkspaceEditParams(workspaceEdit);
client.applyEdit(applyWorkspaceEditParams);
}
use of org.eclipse.lsp4j.ApplyWorkspaceEditParams in project sts4 by spring-projects.
the class LanguageServerHarness method intialize.
public InitializeResult intialize(File workspaceRoot) throws Exception {
server = factory.call();
int parentPid = random.nextInt(40000) + 1000;
InitializeParams initParams = new InitializeParams();
if (workspaceRoot != null) {
initParams.setRootPath(workspaceRoot.toString());
initParams.setRootUri(UriUtil.toUri(workspaceRoot).toString());
}
initParams.setProcessId(parentPid);
ClientCapabilities clientCap = new ClientCapabilities();
TextDocumentClientCapabilities textCap = new TextDocumentClientCapabilities();
CompletionCapabilities completionCap = new CompletionCapabilities(new CompletionItemCapabilities(true));
textCap.setCompletion(completionCap);
clientCap.setTextDocument(textCap);
WorkspaceClientCapabilities workspaceCap = new WorkspaceClientCapabilities();
workspaceCap.setApplyEdit(true);
ExecuteCommandCapabilities exeCap = new ExecuteCommandCapabilities();
exeCap.setDynamicRegistration(true);
workspaceCap.setExecuteCommand(exeCap);
clientCap.setWorkspace(workspaceCap);
initParams.setCapabilities(clientCap);
initResult = getServer().initialize(initParams).get();
if (getServer() instanceof LanguageClientAware) {
((LanguageClientAware) getServer()).connect(new STS4LanguageClient() {
@Override
public void telemetryEvent(Object object) {
// TODO Auto-generated method stub
}
@Override
public CompletableFuture<MessageActionItem> showMessageRequest(ShowMessageRequestParams requestParams) {
// TODO Auto-generated method stub
return CompletableFuture.completedFuture(new MessageActionItem("Some Message Request Answer"));
}
@Override
public void showMessage(MessageParams messageParams) {
// TODO Auto-generated method stub
}
@Override
public void publishDiagnostics(PublishDiagnosticsParams diagnostics) {
receiveDiagnostics(diagnostics);
}
@Override
public void highlight(HighlightParams highlights) {
receiveHighlights(highlights);
}
@Override
public void logMessage(MessageParams message) {
// TODO Auto-generated method stub
}
@Override
public CompletableFuture<ApplyWorkspaceEditResponse> applyEdit(ApplyWorkspaceEditParams params) {
return Mono.fromCallable(() -> {
perform(params.getEdit());
return new ApplyWorkspaceEditResponse(true);
}).toFuture();
}
@Override
public CompletableFuture<Void> registerCapability(RegistrationParams params) {
return CompletableFuture.completedFuture(null);
}
@Override
public void progress(ProgressParams progressEvent) {
// TODO Auto-generated method stub
}
@Override
public CompletableFuture<Object> moveCursor(CursorMovement cursorMovement) {
for (Editor editor : activeEditors) {
if (editor.getUri().equals(cursorMovement.getUri())) {
editor.setCursor(cursorMovement.getPosition());
return CompletableFuture.completedFuture(new ApplyWorkspaceEditResponse(true));
}
}
return CompletableFuture.completedFuture(new ApplyWorkspaceEditResponse(false));
}
@Override
public CompletableFuture<ProjectResponse> project(String uri) {
return CompletableFuture.completedFuture(null);
}
@Override
public CompletableFuture<Object> addClasspathListener(ClasspathListenerParams params) {
return CompletableFuture.completedFuture("ok");
}
@Override
public CompletableFuture<Object> removeClasspathListener(ClasspathListenerParams classpathListenerParams) {
return CompletableFuture.completedFuture("ok");
}
});
}
getServer().initialized();
return initResult;
}
use of org.eclipse.lsp4j.ApplyWorkspaceEditParams in project eclipse.jdt.ls by eclipse.
the class JavaClientConnection method applyWorkspaceEdit.
/**
* Sends a message to client to apply the given workspace edit.
* This is available since LSP v3.0 should be used
* only by checking the ClientCapabilities.
*
* @param edit
*/
public boolean applyWorkspaceEdit(WorkspaceEdit edit) {
ApplyWorkspaceEditParams $ = new ApplyWorkspaceEditParams();
$.setEdit(edit);
ApplyWorkspaceEditResponse response = client.applyEdit($).join();
return response.getApplied().booleanValue();
}
use of org.eclipse.lsp4j.ApplyWorkspaceEditParams in project ballerina by ballerina-lang.
the class CommandExecutor method applySingleTextEdit.
private static void applySingleTextEdit(String editText, Range range, VersionedTextDocumentIdentifier identifier, LanguageClient client) {
WorkspaceEdit workspaceEdit = new WorkspaceEdit();
ApplyWorkspaceEditParams applyWorkspaceEditParams = new ApplyWorkspaceEditParams();
TextEdit textEdit = new TextEdit(range, editText);
TextDocumentEdit textDocumentEdit = new TextDocumentEdit(identifier, Collections.singletonList(textEdit));
workspaceEdit.setDocumentChanges(Collections.singletonList(textDocumentEdit));
applyWorkspaceEditParams.setEdit(workspaceEdit);
client.applyEdit(applyWorkspaceEditParams);
}
use of org.eclipse.lsp4j.ApplyWorkspaceEditParams in project sts4 by spring-projects.
the class SimpleLanguageServer method executeCommand.
protected CompletableFuture<Object> executeCommand(ExecuteCommandParams params) {
ExecuteCommandHandler handler = commands.get(params.getCommand());
if (handler != null) {
return handler.handle(params);
}
if (CODE_ACTION_COMMAND_ID.equals(params.getCommand())) {
Assert.isLegal(params.getArguments().size() == 2);
QuickfixResolveParams quickfixParams = new QuickfixResolveParams((String) params.getArguments().get(0), params.getArguments().get(1));
return quickfixResolve(quickfixParams).flatMap((QuickfixEdit edit) -> {
Mono<ApplyWorkspaceEditResponse> applyEdit = Mono.fromFuture(client.applyEdit(new ApplyWorkspaceEditParams(edit.workspaceEdit)));
Mono<Object> moveCursor = edit.cursorMovement == null ? Mono.just(new ApplyWorkspaceEditResponse(true)) : Mono.fromFuture(client.moveCursor(edit.cursorMovement));
return applyEdit.flatMap(r -> r.getApplied() ? moveCursor : Mono.just(new ApplyWorkspaceEditResponse(true)));
}).toFuture();
}
Log.warn("Unknown command ignored: " + params.getCommand());
return CompletableFuture.completedFuture(false);
}
Aggregations