-
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 38895d5
Showing
5 changed files
with
123 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
17 changes: 17 additions & 0 deletions
17
...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,17 @@ | ||
/** | ||
* Copyright (c) 2021 Red Hat Inc. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.lemminx.services.extensions; | ||
|
||
import org.eclipse.lsp4j.DidChangeWorkspaceFoldersParams; | ||
|
||
public interface IWorkspaceServiceParticipant { | ||
|
||
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
70 changes: 70 additions & 0 deletions
70
...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,70 @@ | ||
/******************************************************************************* | ||
* 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 | ||
*********************************************************************************/ | ||
package org.eclipse.lemminx.services.extensions; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertArrayEquals; | ||
|
||
import java.util.Collections; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import org.eclipse.lemminx.XMLLanguageServer; | ||
import org.eclipse.lemminx.customservice.XMLLanguageClientAPI; | ||
import org.eclipse.lsp4j.DidChangeWorkspaceFoldersParams; | ||
import org.eclipse.lsp4j.MessageActionItem; | ||
import org.eclipse.lsp4j.MessageParams; | ||
import org.eclipse.lsp4j.PublishDiagnosticsParams; | ||
import org.eclipse.lsp4j.RegistrationParams; | ||
import org.eclipse.lsp4j.ShowMessageRequestParams; | ||
import org.eclipse.lsp4j.WorkspaceFolder; | ||
import org.eclipse.lsp4j.WorkspaceFoldersChangeEvent; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
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 XMLLanguageServer(); | ||
server.setClient(new XMLLanguageClientAPI() { | ||
@Override public void telemetryEvent(Object object) { } | ||
@Override public CompletableFuture<MessageActionItem> showMessageRequest(ShowMessageRequestParams requestParams) { | ||
return null; | ||
} | ||
@Override public void showMessage(MessageParams messageParams) { } | ||
@Override public void publishDiagnostics(PublishDiagnosticsParams diagnostics) { } | ||
@Override public void logMessage(MessageParams message) { } | ||
@Override public CompletableFuture<Void> registerCapability(RegistrationParams params) { | ||
return null; | ||
} | ||
}); | ||
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)); | ||
} | ||
} |