-
Notifications
You must be signed in to change notification settings - Fork 758
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41756 from nipunayf/fix-cyclic-ls
Generate notifications for cyclic dependencies to the LS client
- Loading branch information
Showing
13 changed files
with
171 additions
and
21 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
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
90 changes: 90 additions & 0 deletions
90
...r-core/src/test/java/org/ballerinalang/langserver/diagnostics/CyclicDependenciesTest.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,90 @@ | ||
/* | ||
* Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com) All Rights Reserved. | ||
* | ||
* WSO2 LLC. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.ballerinalang.langserver.diagnostics; | ||
|
||
import org.ballerinalang.langserver.LSContextOperation; | ||
import org.ballerinalang.langserver.commons.DocumentServiceContext; | ||
import org.ballerinalang.langserver.commons.LanguageServerContext; | ||
import org.ballerinalang.langserver.commons.client.ExtendedLanguageClient; | ||
import org.ballerinalang.langserver.commons.eventsync.exceptions.EventSyncException; | ||
import org.ballerinalang.langserver.commons.workspace.WorkspaceDocumentException; | ||
import org.ballerinalang.langserver.contexts.ContextBuilder; | ||
import org.ballerinalang.langserver.contexts.LanguageServerContextImpl; | ||
import org.ballerinalang.langserver.diagnostic.DiagnosticsHelper; | ||
import org.ballerinalang.langserver.util.FileUtils; | ||
import org.ballerinalang.langserver.workspace.BallerinaWorkspaceManager; | ||
import org.eclipse.lsp4j.MessageParams; | ||
import org.eclipse.lsp4j.MessageType; | ||
import org.mockito.Mockito; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Test; | ||
|
||
import java.nio.file.Path; | ||
import java.util.List; | ||
|
||
/** | ||
* Diagnostic tests related to cyclic dependencies. | ||
* | ||
* @since 2201.9.0 | ||
*/ | ||
public class CyclicDependenciesTest { | ||
|
||
private final Path projectRoot = FileUtils.RES_DIR.resolve("diagnostics").resolve("sources"); | ||
private final LanguageServerContext serverContext = new LanguageServerContextImpl(); | ||
private final BallerinaWorkspaceManager workspaceManager = new BallerinaWorkspaceManager(serverContext); | ||
|
||
@Test(dataProvider = "cyclic-package-provider") | ||
public void testCyclicDependenciesOnOpen(String packageName, List<String> expectedMessages) | ||
throws WorkspaceDocumentException, EventSyncException, | ||
InterruptedException { | ||
Path projectPath = projectRoot.resolve(packageName); | ||
ExtendedLanguageClient mockClient = Mockito.mock(ExtendedLanguageClient.class); | ||
|
||
DocumentServiceContext serviceContext = | ||
ContextBuilder.buildDocumentServiceContext(projectPath.toUri().toString(), | ||
this.workspaceManager, | ||
LSContextOperation.TXT_DID_OPEN, | ||
this.serverContext); | ||
|
||
this.workspaceManager.loadProject(projectPath); | ||
DiagnosticsHelper diagnosticsHelper = DiagnosticsHelper.getInstance(this.serverContext); | ||
diagnosticsHelper.schedulePublishDiagnostics(mockClient, serviceContext); | ||
Thread.sleep(2000); | ||
|
||
Mockito.verify(mockClient, Mockito.times(expectedMessages.size())).showMessage(Mockito.any()); | ||
expectedMessages.forEach(expectedMessage -> Mockito.verify(mockClient) | ||
.showMessage(new MessageParams(MessageType.Error, expectedMessage))); | ||
} | ||
|
||
@DataProvider(name = "cyclic-package-provider") | ||
public Object[][] cyclicDataProvider() { | ||
return new Object[][]{ | ||
{"cyclic_simple", | ||
List.of("cyclic module imports detected 'lsorg/cyclic.mod1:0.1.0 -> lsorg/cyclic.mod2:0.1.0" + | ||
" -> lsorg/cyclic.mod1:0.1.0'")}, | ||
{"cyclic_multi", | ||
List.of("cyclic module imports detected 'lsorg/cyclic_multi.abc:0.1.0 -> lsorg/cyclic_multi" + | ||
".def:0.1.0 -> lsorg/cyclic_multi.ghi:0.1.0 -> lsorg/cyclic_multi.jkl:0.1.0 " + | ||
"-> lsorg/cyclic_multi.abc:0.1.0'", | ||
"cyclic module imports detected 'lsorg/cyclic_multi.def:0.1.0 -> lsorg/cyclic_multi" + | ||
".ghi:0.1.0 -> lsorg/cyclic_multi.def:0.1.0'", | ||
"cyclic module imports detected 'lsorg/cyclic_multi.abc:0.1.0 -> lsorg/cyclic_multi" + | ||
".def:0.1.0 -> lsorg/cyclic_multi.ghi:0.1.0 -> lsorg/cyclic_multi.abc:0.1.0'")} | ||
}; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...odules/langserver-core/src/test/resources/diagnostics/sources/cyclic_multi/Ballerina.toml
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,4 @@ | ||
[package] | ||
org = "lsorg" | ||
name = "cyclic_multi" | ||
version = "0.1.0" |
7 changes: 7 additions & 0 deletions
7
.../langserver-core/src/test/resources/diagnostics/sources/cyclic_multi/modules/abc/main.bal
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,7 @@ | ||
import cyclic_multi.def as _; | ||
import cyclic_multi.mno as _; | ||
import cyclic_multi.pqr as _; | ||
|
||
function test() { | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
.../langserver-core/src/test/resources/diagnostics/sources/cyclic_multi/modules/def/main.bal
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,5 @@ | ||
import cyclic_multi.ghi as _; | ||
|
||
function test() { | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
.../langserver-core/src/test/resources/diagnostics/sources/cyclic_multi/modules/ghi/main.bal
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,7 @@ | ||
import cyclic_multi.def as _; | ||
import cyclic_multi.abc as _; | ||
import cyclic_multi.jkl as _; | ||
|
||
function test() { | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
.../langserver-core/src/test/resources/diagnostics/sources/cyclic_multi/modules/jkl/main.bal
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,5 @@ | ||
import cyclic_multi.abc as _; | ||
|
||
function test() { | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
.../langserver-core/src/test/resources/diagnostics/sources/cyclic_multi/modules/mno/main.bal
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,5 @@ | ||
import cyclic_multi.pqr as _; | ||
|
||
function test() { | ||
|
||
} |
3 changes: 3 additions & 0 deletions
3
.../langserver-core/src/test/resources/diagnostics/sources/cyclic_multi/modules/pqr/main.bal
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,3 @@ | ||
function test() { | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
...dules/langserver-core/src/test/resources/diagnostics/sources/cyclic_simple/Ballerina.toml
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,4 @@ | ||
[package] | ||
org = "lsorg" | ||
name = "cyclic" | ||
version = "0.1.0" |
9 changes: 9 additions & 0 deletions
9
...angserver-core/src/test/resources/diagnostics/sources/cyclic_simple/modules/mod1/mod1.bal
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,9 @@ | ||
import cyclic.mod2; | ||
|
||
public function hello(string name) returns string { | ||
_ = mod2:hello("A"); | ||
if name !is "" { | ||
return "Hello, " + name; | ||
} | ||
return "Hello, World!"; | ||
} |
9 changes: 9 additions & 0 deletions
9
...angserver-core/src/test/resources/diagnostics/sources/cyclic_simple/modules/mod2/mod2.bal
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,9 @@ | ||
import cyclic.mod1; | ||
|
||
public function hello(string name) returns string { | ||
_ = mod1:hello("A"); | ||
if name !is "" { | ||
return "Hello, " + name; | ||
} | ||
return "Hello, World!"; | ||
} |