Skip to content

Commit b530c2d

Browse files
authored
Merge pull request #133 from mickaelistria/132-workspaceFolders
Issue #132: Proposal for workspaceFolders
2 parents 9bd814b + 4ae0ab3 commit b530c2d

File tree

12 files changed

+711
-7
lines changed

12 files changed

+711
-7
lines changed

org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/Protocol.xtend

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import org.eclipse.lsp4j.generator.JsonRpcData
1515
import org.eclipse.lsp4j.jsonrpc.messages.Either
1616
import org.eclipse.lsp4j.jsonrpc.messages.Either3
1717
import org.eclipse.lsp4j.jsonrpc.validation.NonNull
18+
import com.google.common.annotations.Beta
1819

1920
@JsonRpcData
2021
class DynamicRegistrationCapabilities {
@@ -121,6 +122,13 @@ class WorkspaceClientCapabilities {
121122
* Capabilities specific to the `workspace/executeCommand` request.
122123
*/
123124
ExecuteCommandCapabilities executeCommand
125+
126+
/**
127+
* Capabilities specific to the `workspace/didChangeWorkspaceFolders` notification.
128+
*
129+
* This API is a <b>proposal</b> from LSP and may change.
130+
*/
131+
@Beta Boolean workspaceFolders
124132
}
125133

126134
@JsonRpcData
@@ -1901,6 +1909,30 @@ class ServerCapabilities {
19011909
* Experimental server capabilities.
19021910
*/
19031911
Object experimental
1912+
1913+
/**
1914+
* Capabilities of the server regarding workspace.
1915+
*
1916+
* This is an LSP <b>proposal</b>.
1917+
*/
1918+
@Beta WorkspaceServerCapabilities workspace
1919+
1920+
}
1921+
1922+
/**
1923+
* Capabilities of the server regarding workspace.
1924+
*
1925+
* This is an LSP <b>proposal</b>.
1926+
*/
1927+
@Beta
1928+
@JsonRpcData
1929+
class WorkspaceServerCapabilities {
1930+
/**
1931+
* Capabilities specific to the `workspace/didChangeWorkspaceFolders` notification.
1932+
*
1933+
* This is an LSP <b>proposal</b>.
1934+
*/
1935+
@Beta WorkspaceFoldersOptions workspaceFolders
19041936
}
19051937

19061938
/**
@@ -2674,3 +2706,63 @@ class ApplyWorkspaceEditResponse {
26742706
this.applied = applied
26752707
}
26762708
}
2709+
2710+
@Beta
2711+
@JsonRpcData
2712+
class WorkspaceFoldersOptions {
2713+
/**
2714+
* The server has support for workspace folders
2715+
*/
2716+
Boolean supported
2717+
2718+
/**
2719+
* Whether the server wants to receive workspace folder
2720+
* change notifications.
2721+
*
2722+
* If a strings is provided the string is treated as a ID
2723+
* under which the notification is registed on the client
2724+
* side. The ID can be used to unregister for these events
2725+
* using the `client/unregisterCapability` request.
2726+
*/
2727+
Either<String, Boolean> changeNotifications;
2728+
}
2729+
2730+
@Beta
2731+
@JsonRpcData
2732+
class WorkspaceFolder {
2733+
/**
2734+
* The associated URI for this workspace folder.
2735+
*/
2736+
@NonNull String uri
2737+
2738+
/**
2739+
* The name of the workspace folder. Defaults to the uri's basename.
2740+
*/
2741+
String name
2742+
}
2743+
2744+
@Beta
2745+
@JsonRpcData
2746+
class WorkspaceFoldersChangeEvent {
2747+
/**
2748+
* The array of added workspace folders
2749+
*/
2750+
@NonNull
2751+
List<WorkspaceFolder> added = new ArrayList
2752+
2753+
/**
2754+
* The array of the removed workspace folders
2755+
*/
2756+
@NonNull
2757+
List<WorkspaceFolder> removed = new ArrayList
2758+
}
2759+
2760+
@Beta
2761+
@JsonRpcData
2762+
class DidChangeWorkspaceFoldersParams {
2763+
/**
2764+
* The actual workspace folder change event.
2765+
*/
2766+
@NonNull
2767+
WorkspaceFoldersChangeEvent event
2768+
}

org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/services/LanguageClient.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
*******************************************************************************/
88
package org.eclipse.lsp4j.services;
99

10+
import java.util.Collections;
11+
import java.util.List;
1012
import java.util.concurrent.CompletableFuture;
1113

1214
import org.eclipse.lsp4j.ApplyWorkspaceEditParams;
@@ -17,10 +19,13 @@
1719
import org.eclipse.lsp4j.RegistrationParams;
1820
import org.eclipse.lsp4j.ShowMessageRequestParams;
1921
import org.eclipse.lsp4j.UnregistrationParams;
22+
import org.eclipse.lsp4j.WorkspaceFolder;
2023
import org.eclipse.lsp4j.jsonrpc.services.JsonNotification;
2124
import org.eclipse.lsp4j.jsonrpc.services.JsonRequest;
2225

23-
public interface LanguageClient {
26+
import com.google.common.annotations.Beta;
27+
28+
public interface LanguageClient {
2429
/**
2530
* The workspace/applyEdit request is sent from the server to the client to modify resource on the client side.
2631
*/
@@ -39,9 +44,9 @@ default CompletableFuture<ApplyWorkspaceEditResponse> applyEdit(ApplyWorkspaceEd
3944
default CompletableFuture<Void> registerCapability(RegistrationParams params) {
4045
throw new UnsupportedOperationException();
4146
}
42-
47+
4348
/**
44-
* The client/unregisterCapability request is sent from the server to the client
49+
* The client/unregisterCapability request is sent from the server to the client
4550
* to unregister a previously register capability.
4651
*/
4752
@JsonRequest("client/unregisterCapability")
@@ -85,4 +90,20 @@ default CompletableFuture<Void> unregisterCapability(UnregistrationParams params
8590
*/
8691
@JsonNotification("window/logMessage")
8792
void logMessage(MessageParams message);
93+
94+
/**
95+
* The workspace/workspaceFolders request is sent from the server to the client
96+
* to fetch the current open list of workspace folders.
97+
*
98+
* This API is a <b>proposal</b> from LSP and may change.
99+
*
100+
* @return null in the response if only a single file is open in the tool,
101+
* an empty array if a workspace is open but no folders are configured,
102+
* the workspace folders otherwise.
103+
*/
104+
@Beta
105+
@JsonRequest("workspace/workspaceFolders")
106+
default CompletableFuture<List<WorkspaceFolder>> workspaceFolders() {
107+
return CompletableFuture.completedFuture(Collections.emptyList());
108+
}
88109
}

org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/services/WorkspaceService.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@
1212

1313
import org.eclipse.lsp4j.DidChangeConfigurationParams;
1414
import org.eclipse.lsp4j.DidChangeWatchedFilesParams;
15+
import org.eclipse.lsp4j.DidChangeWorkspaceFoldersParams;
1516
import org.eclipse.lsp4j.ExecuteCommandParams;
1617
import org.eclipse.lsp4j.SymbolInformation;
1718
import org.eclipse.lsp4j.WorkspaceSymbolParams;
1819
import org.eclipse.lsp4j.jsonrpc.services.JsonNotification;
1920
import org.eclipse.lsp4j.jsonrpc.services.JsonRequest;
2021
import org.eclipse.lsp4j.jsonrpc.services.JsonSegment;
2122

23+
import com.google.common.annotations.Beta;
24+
2225
@JsonSegment("workspace")
2326
public interface WorkspaceService {
2427
/**
@@ -27,7 +30,7 @@ public interface WorkspaceService {
2730
* server creates a WorkspaceEdit structure and applies the changes to the
2831
* workspace using the request workspace/applyEdit which is sent from the
2932
* server to the client.
30-
*
33+
*
3134
* Registration Options: ExecuteCommandRegistrationOptions
3235
*/
3336
@JsonRequest
@@ -38,7 +41,7 @@ default CompletableFuture<Object> executeCommand(ExecuteCommandParams params) {
3841
/**
3942
* The workspace symbol request is sent from the client to the server to
4043
* list project-wide symbols matching the query string.
41-
*
44+
*
4245
* Registration Options: void
4346
*/
4447
@JsonRequest
@@ -57,4 +60,17 @@ default CompletableFuture<Object> executeCommand(ExecuteCommandParams params) {
5760
*/
5861
@JsonNotification
5962
void didChangeWatchedFiles(DidChangeWatchedFilesParams params);
63+
64+
/**
65+
* The workspace/didChangeWorkspaceFolders notification is sent from the client
66+
* to the server to inform the server about workspace folder configuration changes.
67+
* The notification is sent by default if both ServerCapabilities/workspaceFolders
68+
* and ClientCapabilities/workspace/workspaceFolders are true; or if the server has
69+
* registered to receive this notification it first.
70+
*
71+
* This API is a <b>proposal</b> from LSP and may change.
72+
*/
73+
@JsonNotification
74+
@Beta
75+
default void didChangeWorkspaceFolders(DidChangeWorkspaceFoldersParams params) {}
6076
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/**
2+
* Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*/
8+
package org.eclipse.lsp4j;
9+
10+
import com.google.common.annotations.Beta;
11+
import org.eclipse.lsp4j.WorkspaceFoldersChangeEvent;
12+
import org.eclipse.lsp4j.jsonrpc.validation.NonNull;
13+
import org.eclipse.xtext.xbase.lib.Pure;
14+
import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;
15+
16+
@Beta
17+
@SuppressWarnings("all")
18+
public class DidChangeWorkspaceFoldersParams {
19+
/**
20+
* The actual workspace folder change event.
21+
*/
22+
@NonNull
23+
private WorkspaceFoldersChangeEvent event;
24+
25+
/**
26+
* The actual workspace folder change event.
27+
*/
28+
@Pure
29+
@NonNull
30+
public WorkspaceFoldersChangeEvent getEvent() {
31+
return this.event;
32+
}
33+
34+
/**
35+
* The actual workspace folder change event.
36+
*/
37+
public void setEvent(@NonNull final WorkspaceFoldersChangeEvent event) {
38+
this.event = event;
39+
}
40+
41+
@Override
42+
@Pure
43+
public String toString() {
44+
ToStringBuilder b = new ToStringBuilder(this);
45+
b.add("event", this.event);
46+
return b.toString();
47+
}
48+
49+
@Override
50+
@Pure
51+
public boolean equals(final Object obj) {
52+
if (this == obj)
53+
return true;
54+
if (obj == null)
55+
return false;
56+
if (getClass() != obj.getClass())
57+
return false;
58+
DidChangeWorkspaceFoldersParams other = (DidChangeWorkspaceFoldersParams) obj;
59+
if (this.event == null) {
60+
if (other.event != null)
61+
return false;
62+
} else if (!this.event.equals(other.event))
63+
return false;
64+
return true;
65+
}
66+
67+
@Override
68+
@Pure
69+
public int hashCode() {
70+
final int prime = 31;
71+
int result = 1;
72+
result = prime * result + ((this.event== null) ? 0 : this.event.hashCode());
73+
return result;
74+
}
75+
}

org.eclipse.lsp4j/src/main/xtend-gen/org/eclipse/lsp4j/ServerCapabilities.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88
package org.eclipse.lsp4j;
99

10+
import com.google.common.annotations.Beta;
1011
import org.eclipse.lsp4j.CodeLensOptions;
1112
import org.eclipse.lsp4j.CompletionOptions;
1213
import org.eclipse.lsp4j.DocumentLinkOptions;
@@ -15,6 +16,7 @@
1516
import org.eclipse.lsp4j.SignatureHelpOptions;
1617
import org.eclipse.lsp4j.TextDocumentSyncKind;
1718
import org.eclipse.lsp4j.TextDocumentSyncOptions;
19+
import org.eclipse.lsp4j.WorkspaceServerCapabilities;
1820
import org.eclipse.lsp4j.jsonrpc.messages.Either;
1921
import org.eclipse.xtext.xbase.lib.Pure;
2022
import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;
@@ -112,6 +114,14 @@ public class ServerCapabilities {
112114
*/
113115
private Object experimental;
114116

117+
/**
118+
* Capabilities of the server regarding workspace.
119+
*
120+
* This is an LSP <b>proposal</b>.
121+
*/
122+
@Beta
123+
private WorkspaceServerCapabilities workspace;
124+
115125
/**
116126
* Defines how text documents are synced. Is either a detailed structure defining each notification or
117127
* for backwards compatibility the TextDocumentSyncKind number.
@@ -392,6 +402,25 @@ public void setExperimental(final Object experimental) {
392402
this.experimental = experimental;
393403
}
394404

405+
/**
406+
* Capabilities of the server regarding workspace.
407+
*
408+
* This is an LSP <b>proposal</b>.
409+
*/
410+
@Pure
411+
public WorkspaceServerCapabilities getWorkspace() {
412+
return this.workspace;
413+
}
414+
415+
/**
416+
* Capabilities of the server regarding workspace.
417+
*
418+
* This is an LSP <b>proposal</b>.
419+
*/
420+
public void setWorkspace(final WorkspaceServerCapabilities workspace) {
421+
this.workspace = workspace;
422+
}
423+
395424
@Override
396425
@Pure
397426
public String toString() {
@@ -414,6 +443,7 @@ public String toString() {
414443
b.add("documentLinkProvider", this.documentLinkProvider);
415444
b.add("executeCommandProvider", this.executeCommandProvider);
416445
b.add("experimental", this.experimental);
446+
b.add("workspace", this.workspace);
417447
return b.toString();
418448
}
419449

@@ -517,6 +547,11 @@ public boolean equals(final Object obj) {
517547
return false;
518548
} else if (!this.experimental.equals(other.experimental))
519549
return false;
550+
if (this.workspace == null) {
551+
if (other.workspace != null)
552+
return false;
553+
} else if (!this.workspace.equals(other.workspace))
554+
return false;
520555
return true;
521556
}
522557

@@ -543,6 +578,7 @@ public int hashCode() {
543578
result = prime * result + ((this.documentLinkProvider== null) ? 0 : this.documentLinkProvider.hashCode());
544579
result = prime * result + ((this.executeCommandProvider== null) ? 0 : this.executeCommandProvider.hashCode());
545580
result = prime * result + ((this.experimental== null) ? 0 : this.experimental.hashCode());
581+
result = prime * result + ((this.workspace== null) ? 0 : this.workspace.hashCode());
546582
return result;
547583
}
548584
}

0 commit comments

Comments
 (0)