-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support 'window/workDoneProgress/cancel' lsp event
Signed-off-by: Aman Prashant <aman.prashant@broadcom.com>
- Loading branch information
Showing
8 changed files
with
165 additions
and
11 deletions.
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
36 changes: 36 additions & 0 deletions
36
.../main/java/org/eclipse/lsp/cobol/lsp/events/notifications/CancelProgressNotification.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,36 @@ | ||
/* | ||
* Copyright (c) 2024 Broadcom. | ||
* The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Broadcom, Inc. - initial API and implementation | ||
* | ||
*/ | ||
package org.eclipse.lsp.cobol.lsp.events.notifications; | ||
|
||
import lombok.SneakyThrows; | ||
import org.eclipse.lsp.cobol.lsp.LspNotification; | ||
import org.eclipse.lsp.cobol.lsp.handlers.server.CancelProgressHandler; | ||
|
||
/** `window/workDoneProgress/cancel` language server event */ | ||
public class CancelProgressNotification implements LspNotification { | ||
private final String uri; | ||
private final CancelProgressHandler cancelProgressHandler; | ||
|
||
public CancelProgressNotification(String uri, CancelProgressHandler cancelProgressHandler) { | ||
this.uri = uri; | ||
this.cancelProgressHandler = cancelProgressHandler; | ||
} | ||
|
||
@SneakyThrows | ||
@Override | ||
public void execute() { | ||
this.cancelProgressHandler.cancel(uri); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...engine/src/main/java/org/eclipse/lsp/cobol/lsp/handlers/server/CancelProgressHandler.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,37 @@ | ||
/* | ||
* Copyright (c) 2024 Broadcom. | ||
* The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Broadcom, Inc. - initial API and implementation | ||
* | ||
*/ | ||
package org.eclipse.lsp.cobol.lsp.handlers.server; | ||
|
||
import com.google.inject.Inject; | ||
import org.eclipse.lsp.cobol.lsp.analysis.AsyncAnalysisService; | ||
|
||
/** LSP `window/workDoneProgress/cancel` Handler */ | ||
public class CancelProgressHandler { | ||
private final AsyncAnalysisService asyncAnalysisService; | ||
|
||
@Inject | ||
public CancelProgressHandler(AsyncAnalysisService asyncAnalysisService) { | ||
this.asyncAnalysisService = asyncAnalysisService; | ||
} | ||
|
||
/** | ||
* Cancel analysis for the passed uri | ||
* @param uri | ||
* @throws InterruptedException | ||
*/ | ||
public void cancel(String uri) throws InterruptedException { | ||
asyncAnalysisService.cancelAnalysis(uri); | ||
} | ||
} |
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
32 changes: 32 additions & 0 deletions
32
...t/java/org/eclipse/lsp/cobol/lsp/events/notifications/CancelProgressNotificationTest.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,32 @@ | ||
/* | ||
* Copyright (c) 2024 Broadcom. | ||
* The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Broadcom, Inc. - initial API and implementation | ||
* | ||
*/ | ||
package org.eclipse.lsp.cobol.lsp.events.notifications; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import org.eclipse.lsp.cobol.lsp.handlers.server.CancelProgressHandler; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** Test {@link CancelProgressNotification} */ | ||
class CancelProgressNotificationTest { | ||
@Test | ||
void test() throws InterruptedException { | ||
CancelProgressHandler handler = mock(CancelProgressHandler.class); | ||
CancelProgressNotification notification = new CancelProgressNotification("uri", handler); | ||
notification.execute(); | ||
verify(handler).cancel("uri"); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...ne/src/test/java/org/eclipse/lsp/cobol/lsp/handlers/server/CancelProgressHandlerTest.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,33 @@ | ||
/* | ||
* Copyright (c) 2024 Broadcom. | ||
* The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Broadcom, Inc. - initial API and implementation | ||
* | ||
*/ | ||
package org.eclipse.lsp.cobol.lsp.handlers.server; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import org.eclipse.lsp.cobol.lsp.analysis.AsyncAnalysisService; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** Test {@link CancelProgressHandler} */ | ||
class CancelProgressHandlerTest { | ||
|
||
@Test | ||
void whenCancelIsCalled_properMethodIsInvoked() throws InterruptedException { | ||
AsyncAnalysisService asyncAnalysisService = mock(AsyncAnalysisService.class); | ||
CancelProgressHandler handler = new CancelProgressHandler(asyncAnalysisService); | ||
handler.cancel("test-uri"); | ||
verify(asyncAnalysisService).cancelAnalysis("test-uri"); | ||
} | ||
} |
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