Skip to content

Commit

Permalink
Issue eclipse-lsp4j#132: Proposal for workspaceFolders
Browse files Browse the repository at this point in the history
Signed-off-by: Mickael Istria <mistria@redhat.com>
  • Loading branch information
mickaelistria committed Nov 20, 2017
1 parent a9bbfbd commit 4ae0ab3
Show file tree
Hide file tree
Showing 12 changed files with 711 additions and 7 deletions.
92 changes: 92 additions & 0 deletions org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/Protocol.xtend
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.eclipse.lsp4j.generator.JsonRpcData
import org.eclipse.lsp4j.jsonrpc.messages.Either
import org.eclipse.lsp4j.jsonrpc.messages.Either3
import org.eclipse.lsp4j.jsonrpc.validation.NonNull
import com.google.common.annotations.Beta

@JsonRpcData
class DynamicRegistrationCapabilities {
Expand Down Expand Up @@ -121,6 +122,13 @@ class WorkspaceClientCapabilities {
* Capabilities specific to the `workspace/executeCommand` request.
*/
ExecuteCommandCapabilities executeCommand

/**
* Capabilities specific to the `workspace/didChangeWorkspaceFolders` notification.
*
* This API is a <b>proposal</b> from LSP and may change.
*/
@Beta Boolean workspaceFolders
}

@JsonRpcData
Expand Down Expand Up @@ -1901,6 +1909,30 @@ class ServerCapabilities {
* Experimental server capabilities.
*/
Object experimental

/**
* Capabilities of the server regarding workspace.
*
* This is an LSP <b>proposal</b>.
*/
@Beta WorkspaceServerCapabilities workspace

}

/**
* Capabilities of the server regarding workspace.
*
* This is an LSP <b>proposal</b>.
*/
@Beta
@JsonRpcData
class WorkspaceServerCapabilities {
/**
* Capabilities specific to the `workspace/didChangeWorkspaceFolders` notification.
*
* This is an LSP <b>proposal</b>.
*/
@Beta WorkspaceFoldersOptions workspaceFolders
}

/**
Expand Down Expand Up @@ -2674,3 +2706,63 @@ class ApplyWorkspaceEditResponse {
this.applied = applied
}
}

@Beta
@JsonRpcData
class WorkspaceFoldersOptions {
/**
* The server has support for workspace folders
*/
Boolean supported

/**
* Whether the server wants to receive workspace folder
* change notifications.
*
* If a strings is provided the string is treated as a ID
* under which the notification is registed on the client
* side. The ID can be used to unregister for these events
* using the `client/unregisterCapability` request.
*/
Either<String, Boolean> changeNotifications;
}

@Beta
@JsonRpcData
class WorkspaceFolder {
/**
* The associated URI for this workspace folder.
*/
@NonNull String uri

/**
* The name of the workspace folder. Defaults to the uri's basename.
*/
String name
}

@Beta
@JsonRpcData
class WorkspaceFoldersChangeEvent {
/**
* The array of added workspace folders
*/
@NonNull
List<WorkspaceFolder> added = new ArrayList

/**
* The array of the removed workspace folders
*/
@NonNull
List<WorkspaceFolder> removed = new ArrayList
}

@Beta
@JsonRpcData
class DidChangeWorkspaceFoldersParams {
/**
* The actual workspace folder change event.
*/
@NonNull
WorkspaceFoldersChangeEvent event
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*******************************************************************************/
package org.eclipse.lsp4j.services;

import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;

import org.eclipse.lsp4j.ApplyWorkspaceEditParams;
Expand All @@ -17,10 +19,13 @@
import org.eclipse.lsp4j.RegistrationParams;
import org.eclipse.lsp4j.ShowMessageRequestParams;
import org.eclipse.lsp4j.UnregistrationParams;
import org.eclipse.lsp4j.WorkspaceFolder;
import org.eclipse.lsp4j.jsonrpc.services.JsonNotification;
import org.eclipse.lsp4j.jsonrpc.services.JsonRequest;

public interface LanguageClient {
import com.google.common.annotations.Beta;

public interface LanguageClient {
/**
* The workspace/applyEdit request is sent from the server to the client to modify resource on the client side.
*/
Expand All @@ -39,9 +44,9 @@ default CompletableFuture<ApplyWorkspaceEditResponse> applyEdit(ApplyWorkspaceEd
default CompletableFuture<Void> registerCapability(RegistrationParams params) {
throw new UnsupportedOperationException();
}

/**
* The client/unregisterCapability request is sent from the server to the client
* The client/unregisterCapability request is sent from the server to the client
* to unregister a previously register capability.
*/
@JsonRequest("client/unregisterCapability")
Expand Down Expand Up @@ -85,4 +90,20 @@ default CompletableFuture<Void> unregisterCapability(UnregistrationParams params
*/
@JsonNotification("window/logMessage")
void logMessage(MessageParams message);

/**
* The workspace/workspaceFolders request is sent from the server to the client
* to fetch the current open list of workspace folders.
*
* This API is a <b>proposal</b> from LSP and may change.
*
* @return null in the response if only a single file is open in the tool,
* an empty array if a workspace is open but no folders are configured,
* the workspace folders otherwise.
*/
@Beta
@JsonRequest("workspace/workspaceFolders")
default CompletableFuture<List<WorkspaceFolder>> workspaceFolders() {
return CompletableFuture.completedFuture(Collections.emptyList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@

import org.eclipse.lsp4j.DidChangeConfigurationParams;
import org.eclipse.lsp4j.DidChangeWatchedFilesParams;
import org.eclipse.lsp4j.DidChangeWorkspaceFoldersParams;
import org.eclipse.lsp4j.ExecuteCommandParams;
import org.eclipse.lsp4j.SymbolInformation;
import org.eclipse.lsp4j.WorkspaceSymbolParams;
import org.eclipse.lsp4j.jsonrpc.services.JsonNotification;
import org.eclipse.lsp4j.jsonrpc.services.JsonRequest;
import org.eclipse.lsp4j.jsonrpc.services.JsonSegment;

import com.google.common.annotations.Beta;

@JsonSegment("workspace")
public interface WorkspaceService {
/**
Expand All @@ -27,7 +30,7 @@ public interface WorkspaceService {
* server creates a WorkspaceEdit structure and applies the changes to the
* workspace using the request workspace/applyEdit which is sent from the
* server to the client.
*
*
* Registration Options: ExecuteCommandRegistrationOptions
*/
@JsonRequest
Expand All @@ -38,7 +41,7 @@ default CompletableFuture<Object> executeCommand(ExecuteCommandParams params) {
/**
* The workspace symbol request is sent from the client to the server to
* list project-wide symbols matching the query string.
*
*
* Registration Options: void
*/
@JsonRequest
Expand All @@ -57,4 +60,17 @@ default CompletableFuture<Object> executeCommand(ExecuteCommandParams params) {
*/
@JsonNotification
void didChangeWatchedFiles(DidChangeWatchedFilesParams params);

/**
* The workspace/didChangeWorkspaceFolders notification is sent from the client
* to the server to inform the server about workspace folder configuration changes.
* The notification is sent by default if both ServerCapabilities/workspaceFolders
* and ClientCapabilities/workspace/workspaceFolders are true; or if the server has
* registered to receive this notification it first.
*
* This API is a <b>proposal</b> from LSP and may change.
*/
@JsonNotification
@Beta
default void didChangeWorkspaceFolders(DidChangeWorkspaceFoldersParams params) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.lsp4j;

import com.google.common.annotations.Beta;
import org.eclipse.lsp4j.WorkspaceFoldersChangeEvent;
import org.eclipse.lsp4j.jsonrpc.validation.NonNull;
import org.eclipse.xtext.xbase.lib.Pure;
import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;

@Beta
@SuppressWarnings("all")
public class DidChangeWorkspaceFoldersParams {
/**
* The actual workspace folder change event.
*/
@NonNull
private WorkspaceFoldersChangeEvent event;

/**
* The actual workspace folder change event.
*/
@Pure
@NonNull
public WorkspaceFoldersChangeEvent getEvent() {
return this.event;
}

/**
* The actual workspace folder change event.
*/
public void setEvent(@NonNull final WorkspaceFoldersChangeEvent event) {
this.event = event;
}

@Override
@Pure
public String toString() {
ToStringBuilder b = new ToStringBuilder(this);
b.add("event", this.event);
return b.toString();
}

@Override
@Pure
public boolean equals(final Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
DidChangeWorkspaceFoldersParams other = (DidChangeWorkspaceFoldersParams) obj;
if (this.event == null) {
if (other.event != null)
return false;
} else if (!this.event.equals(other.event))
return false;
return true;
}

@Override
@Pure
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.event== null) ? 0 : this.event.hashCode());
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
package org.eclipse.lsp4j;

import com.google.common.annotations.Beta;
import org.eclipse.lsp4j.CodeLensOptions;
import org.eclipse.lsp4j.CompletionOptions;
import org.eclipse.lsp4j.DocumentLinkOptions;
Expand All @@ -15,6 +16,7 @@
import org.eclipse.lsp4j.SignatureHelpOptions;
import org.eclipse.lsp4j.TextDocumentSyncKind;
import org.eclipse.lsp4j.TextDocumentSyncOptions;
import org.eclipse.lsp4j.WorkspaceServerCapabilities;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.eclipse.xtext.xbase.lib.Pure;
import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;
Expand Down Expand Up @@ -112,6 +114,14 @@ public class ServerCapabilities {
*/
private Object experimental;

/**
* Capabilities of the server regarding workspace.
*
* This is an LSP <b>proposal</b>.
*/
@Beta
private WorkspaceServerCapabilities workspace;

/**
* Defines how text documents are synced. Is either a detailed structure defining each notification or
* for backwards compatibility the TextDocumentSyncKind number.
Expand Down Expand Up @@ -392,6 +402,25 @@ public void setExperimental(final Object experimental) {
this.experimental = experimental;
}

/**
* Capabilities of the server regarding workspace.
*
* This is an LSP <b>proposal</b>.
*/
@Pure
public WorkspaceServerCapabilities getWorkspace() {
return this.workspace;
}

/**
* Capabilities of the server regarding workspace.
*
* This is an LSP <b>proposal</b>.
*/
public void setWorkspace(final WorkspaceServerCapabilities workspace) {
this.workspace = workspace;
}

@Override
@Pure
public String toString() {
Expand All @@ -414,6 +443,7 @@ public String toString() {
b.add("documentLinkProvider", this.documentLinkProvider);
b.add("executeCommandProvider", this.executeCommandProvider);
b.add("experimental", this.experimental);
b.add("workspace", this.workspace);
return b.toString();
}

Expand Down Expand Up @@ -517,6 +547,11 @@ public boolean equals(final Object obj) {
return false;
} else if (!this.experimental.equals(other.experimental))
return false;
if (this.workspace == null) {
if (other.workspace != null)
return false;
} else if (!this.workspace.equals(other.workspace))
return false;
return true;
}

Expand All @@ -543,6 +578,7 @@ public int hashCode() {
result = prime * result + ((this.documentLinkProvider== null) ? 0 : this.documentLinkProvider.hashCode());
result = prime * result + ((this.executeCommandProvider== null) ? 0 : this.executeCommandProvider.hashCode());
result = prime * result + ((this.experimental== null) ? 0 : this.experimental.hashCode());
result = prime * result + ((this.workspace== null) ? 0 : this.workspace.hashCode());
return result;
}
}
Loading

0 comments on commit 4ae0ab3

Please sign in to comment.