-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow extensions to contribute to WorkspaceService
Currently supports didChangeWorkspaceFolders Signed-off-by: Mickael Istria <[email protected]>
- Loading branch information
1 parent
5488280
commit 2b4e570
Showing
5 changed files
with
124 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...x/src/main/java/org/eclipse/lemminx/services/extensions/IWorkspaceServiceParticipant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021 Red Hat Inc. and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.lemminx.services.extensions; | ||
|
||
import org.eclipse.lsp4j.DidChangeWorkspaceFoldersParams; | ||
import org.eclipse.lsp4j.services.WorkspaceService; | ||
|
||
/** | ||
* Workspace Service participant API. | ||
* @since 0.14.2 | ||
*/ | ||
public interface IWorkspaceServiceParticipant { | ||
|
||
/** | ||
* Receive and handle notification about workspace folder changing on client side. | ||
* @param params the workspace folders change description | ||
* @see WorkspaceService#didChangeWorkspaceFolders(DidChangeWorkspaceFoldersParams) | ||
*/ | ||
public void didChangeWorkspaceFolders(DidChangeWorkspaceFoldersParams params); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...rc/test/java/org/eclipse/lemminx/services/extensions/WorkspaceServiceParticipantTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021 Red Hat Inc. and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.lemminx.services.extensions; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertArrayEquals; | ||
|
||
import java.util.Collections; | ||
|
||
import org.eclipse.lemminx.MockXMLLanguageServer; | ||
import org.eclipse.lemminx.XMLLanguageServer; | ||
import org.eclipse.lsp4j.DidChangeWorkspaceFoldersParams; | ||
import org.eclipse.lsp4j.WorkspaceFolder; | ||
import org.eclipse.lsp4j.WorkspaceFoldersChangeEvent; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Tests for {@link IWorkspaceServiceParticipant} | ||
*/ | ||
public class WorkspaceServiceParticipantTest { | ||
|
||
private static class CaptureWokspaceServiceCalls implements IWorkspaceServiceParticipant { | ||
|
||
public DidChangeWorkspaceFoldersParams didChangeWorkspaceFolders; | ||
|
||
@Override | ||
public void didChangeWorkspaceFolders(DidChangeWorkspaceFoldersParams params) { | ||
this.didChangeWorkspaceFolders = params; | ||
} | ||
} | ||
|
||
private CaptureWokspaceServiceCalls workspaceServiceParticipant; | ||
private XMLLanguageServer server; | ||
|
||
@BeforeEach | ||
public void initializeLanguageService() { | ||
this.server = new MockXMLLanguageServer(); | ||
this.workspaceServiceParticipant = new CaptureWokspaceServiceCalls(); | ||
server.getXMLLanguageService().registerWorkspaceServiceParticipant(this.workspaceServiceParticipant); | ||
} | ||
|
||
@Test | ||
public void testWorkspaceFolders() { | ||
DidChangeWorkspaceFoldersParams params = new DidChangeWorkspaceFoldersParams(new WorkspaceFoldersChangeEvent(Collections.singletonList(new WorkspaceFolder("added")), Collections.singletonList(new WorkspaceFolder("removed")))); | ||
server.getWorkspaceService().didChangeWorkspaceFolders(params); | ||
assertArrayEquals(new String[] { "added" }, workspaceServiceParticipant.didChangeWorkspaceFolders.getEvent().getAdded().stream().map(WorkspaceFolder::getUri).toArray(String[]::new)); | ||
assertArrayEquals(new String[] { "removed" }, workspaceServiceParticipant.didChangeWorkspaceFolders.getEvent().getRemoved().stream().map(WorkspaceFolder::getUri).toArray(String[]::new)); | ||
} | ||
} |