diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/AddIsolatedQualifierCodeAction.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/AddIsolatedQualifierCodeAction.java index 29de44aded60..0ffd9aec7f65 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/AddIsolatedQualifierCodeAction.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/AddIsolatedQualifierCodeAction.java @@ -87,8 +87,8 @@ public List getCodeActions(Diagnostic diagnostic, } // Check if there are multiple diagnostics of the considered category - List diagnostics = context.diagnostics(context.filePath()); - if (diagnostics.size() > 1 && hasMultipleDiagnostics(nonTerminalNode, diagnostic, diagnostics)) { + if (CommonUtil.hasMultipleDiagnostics(context, nonTerminalNode, diagnostic, DIAGNOSTIC_CODES, + DIAGNOSTIC_CODE_3961)) { return Collections.emptyList(); } @@ -170,14 +170,6 @@ private static List getCodeAction(LineRange lineRange, String expres CodeActionUtil.createCodeAction(commandTitle, List.of(textEdit), filePath, CodeActionKind.QuickFix)); } - private static boolean hasMultipleDiagnostics(NonTerminalNode node, Diagnostic currentDiagnostic, - List diagnostics) { - return diagnostics.stream().anyMatch(diagnostic -> !currentDiagnostic.equals(diagnostic) && - DIAGNOSTIC_CODES.contains(diagnostic.diagnosticInfo().code()) && - PositionUtil.isWithinLineRange(diagnostic.location().lineRange(), node.lineRange())) && - currentDiagnostic.diagnosticInfo().code().equals(DIAGNOSTIC_CODE_3961); - } - @Override public String getName() { return NAME; diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/AddReadonlyCodeAction.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/AddReadonlyCodeAction.java index 04471cff6e02..b425b341fc20 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/AddReadonlyCodeAction.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/AddReadonlyCodeAction.java @@ -30,6 +30,7 @@ import org.ballerinalang.langserver.codeaction.CodeActionNodeValidator; import org.ballerinalang.langserver.codeaction.CodeActionUtil; import org.ballerinalang.langserver.common.constants.CommandConstants; +import org.ballerinalang.langserver.common.utils.CommonUtil; import org.ballerinalang.langserver.common.utils.PositionUtil; import org.ballerinalang.langserver.commons.CodeActionContext; import org.ballerinalang.langserver.commons.codeaction.spi.DiagBasedPositionDetails; @@ -43,6 +44,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Set; /** * Code action to add readonly to the type. @@ -53,12 +55,13 @@ public class AddReadonlyCodeAction implements DiagnosticBasedCodeActionProvider { private static final String NAME = "Add readonly to the type"; - private static final String DIAGNOSTIC_CODE = "BCE3959"; + private static final String DIAGNOSTIC_CODE_3959 = "BCE3959"; + private static final Set DIAGNOSTIC_CODES = Set.of(DIAGNOSTIC_CODE_3959, "BCE3960"); @Override public boolean validate(Diagnostic diagnostic, DiagBasedPositionDetails positionDetails, CodeActionContext context) { - return DIAGNOSTIC_CODE.equals(diagnostic.diagnosticInfo().code()) + return DIAGNOSTIC_CODES.contains(diagnostic.diagnosticInfo().code()) && CodeActionNodeValidator.validate(context.nodeAtRange()); } @@ -71,6 +74,12 @@ public List getCodeActions(Diagnostic diagnostic, DiagBasedPositionD TypeSymbol typeSymbol = semanticModel.typeOf(node).orElseThrow(); Location location = typeSymbol.getLocation().orElseThrow(); + // Check if there are multiple diagnostics of the considered category + if (CommonUtil.hasMultipleDiagnostics(context, node, diagnostic, DIAGNOSTIC_CODES, + DIAGNOSTIC_CODE_3959)) { + return Collections.emptyList(); + } + // Skip if a type reference, as the symbol does not contain the location of the variable initialization. if (typeSymbol.typeKind() == TypeDescKind.TYPE_REFERENCE) { return Collections.emptyList(); diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/CloneValueCodeAction.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/CloneValueCodeAction.java index 1fb7abf0d032..c23710a42bce 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/CloneValueCodeAction.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/CloneValueCodeAction.java @@ -26,6 +26,7 @@ import org.ballerinalang.langserver.codeaction.CodeActionNodeValidator; import org.ballerinalang.langserver.codeaction.CodeActionUtil; import org.ballerinalang.langserver.common.constants.CommandConstants; +import org.ballerinalang.langserver.common.utils.CommonUtil; import org.ballerinalang.langserver.common.utils.PositionUtil; import org.ballerinalang.langserver.commons.CodeActionContext; import org.ballerinalang.langserver.commons.codeaction.spi.DiagBasedPositionDetails; @@ -39,6 +40,7 @@ import java.util.Collections; import java.util.List; import java.util.Optional; +import java.util.Set; /** * Code action to clone the value or clone it as a readonly value. @@ -49,14 +51,15 @@ public class CloneValueCodeAction implements DiagnosticBasedCodeActionProvider { private static final String NAME = "Clone the value"; - private static final String DIAGNOSTIC_CODE = "BCE3959"; + private static final String DIAGNOSTIC_CODE_3959 = "BCE3959"; + private static final Set DIAGNOSTIC_CODES = Set.of(DIAGNOSTIC_CODE_3959, "BCE3960"); private static final String CLONE_METHOD = ".clone()"; private static final String CLONE_READONLY_METHOD = ".cloneReadOnly()"; @Override public boolean validate(Diagnostic diagnostic, DiagBasedPositionDetails positionDetails, CodeActionContext context) { - return DIAGNOSTIC_CODE.equals(diagnostic.diagnosticInfo().code()) + return DIAGNOSTIC_CODES.contains(diagnostic.diagnosticInfo().code()) && CodeActionNodeValidator.validate(context.nodeAtRange()); } @@ -65,6 +68,12 @@ public List getCodeActions(Diagnostic diagnostic, DiagBasedPositionD CodeActionContext context) { NonTerminalNode matchedNode = positionDetails.matchedNode(); + // Check if there are multiple diagnostics of the considered category + if (CommonUtil.hasMultipleDiagnostics(context, matchedNode, diagnostic, DIAGNOSTIC_CODES, + DIAGNOSTIC_CODE_3959)) { + return Collections.emptyList(); + } + // Obtain the type symbol of the matched node. Optional optTypeSymbol = context.currentSemanticModel() .flatMap(semanticModel -> semanticModel.typeOf(positionDetails.matchedNode())); diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/utils/CommonUtil.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/utils/CommonUtil.java index b2c5d2c0ddc4..a0007ecca57a 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/utils/CommonUtil.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/utils/CommonUtil.java @@ -45,6 +45,7 @@ import io.ballerina.compiler.syntax.tree.SyntaxTree; import io.ballerina.compiler.syntax.tree.Token; import io.ballerina.projects.Package; +import io.ballerina.tools.diagnostics.Diagnostic; import io.ballerina.tools.text.LinePosition; import io.ballerina.tools.text.LineRange; import io.ballerina.tools.text.TextDocument; @@ -52,6 +53,7 @@ import org.apache.commons.lang3.SystemUtils; import org.ballerinalang.langserver.LSPackageLoader; import org.ballerinalang.langserver.commons.BallerinaCompletionContext; +import org.ballerinalang.langserver.commons.CodeActionContext; import org.ballerinalang.langserver.commons.DocumentServiceContext; import org.ballerinalang.langserver.commons.completion.LSCompletionItem; import org.ballerinalang.langserver.completions.SymbolCompletionItem; @@ -756,6 +758,28 @@ public static Optional getLastQualifier(BallerinaCompletionContext contex return Optional.of(qualifiers.get(qualifiers.size() - 1)); } + /** + * Checks if there are multiple diagnostics for the considered code action. + * + * @param context The code action context + * @param node The non-terminal node around which the diagnostics are being checked + * @param currentDiagnostic The current diagnostic being evaluated + * @param diagnostics The diagnostics relevant to the code action + * @param prioritizedDiagnostic The prioritized diagnostic that won't being ignored. + * @return {@code true} if there are multiple diagnostics for the relevant code action. + */ + public static boolean hasMultipleDiagnostics(CodeActionContext context, NonTerminalNode node, + Diagnostic currentDiagnostic, + Set diagnostics, + String prioritizedDiagnostic) { + List projectDiagnostics = context.diagnostics(context.filePath()); + return projectDiagnostics.size() > 1 && + projectDiagnostics.stream().anyMatch(diagnostic -> !currentDiagnostic.equals(diagnostic) && + diagnostics.contains(diagnostic.diagnosticInfo().code()) && + PositionUtil.isWithinLineRange(diagnostic.location().lineRange(), node.lineRange())) && + currentDiagnostic.diagnosticInfo().code().equals(prioritizedDiagnostic); + } + /** * Returns the matching node for a given node. * diff --git a/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/codeaction/AddReadonlyCodeActionTest.java b/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/codeaction/AddReadonlyCodeActionTest.java index 8f4ae7ed70cc..608b256c67fe 100644 --- a/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/codeaction/AddReadonlyCodeActionTest.java +++ b/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/codeaction/AddReadonlyCodeActionTest.java @@ -65,6 +65,30 @@ public Object[][] dataProvider() { {"add_readonly_config22.json"}, {"add_readonly_config23.json"}, {"add_readonly_config24.json"}, + {"add_readonly_config25.json"}, + {"add_readonly_config26.json"}, + {"add_readonly_config27.json"}, + {"add_readonly_config28.json"}, + {"add_readonly_config29.json"}, + {"add_readonly_config30.json"}, + {"add_readonly_config31.json"}, + {"add_readonly_config32.json"}, + {"add_readonly_config33.json"}, + {"add_readonly_config34.json"}, + {"add_readonly_config35.json"}, + {"add_readonly_config36.json"}, + {"add_readonly_config37.json"}, + {"add_readonly_config38.json"}, + {"add_readonly_config39.json"}, + {"add_readonly_config40.json"}, + {"add_readonly_config41.json"}, + {"add_readonly_config42.json"}, + {"add_readonly_config43.json"}, + {"add_readonly_config44.json"}, + {"add_readonly_config45.json"}, + {"add_readonly_config46.json"}, + {"add_readonly_config47.json"}, + {"add_readonly_config48.json"} }; } diff --git a/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/codeaction/CloneValueCodeActionTest.java b/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/codeaction/CloneValueCodeActionTest.java index 67bc7894b3ad..9df20e2032af 100644 --- a/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/codeaction/CloneValueCodeActionTest.java +++ b/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/codeaction/CloneValueCodeActionTest.java @@ -68,7 +68,34 @@ public Object[][] dataProvider() { {"clone_value_config25.json"}, {"clone_value_config26.json"}, {"clone_value_config27.json"}, - {"clone_value_config28.json"} + {"clone_value_config28.json"}, + {"clone_value_config29.json"}, + {"clone_value_config30.json"}, + {"clone_value_config31.json"}, + {"clone_value_config32.json"}, + {"clone_value_config33.json"}, + {"clone_value_config34.json"}, + {"clone_value_config35.json"}, + {"clone_value_config36.json"}, + {"clone_value_config37.json"}, + {"clone_value_config38.json"}, + {"clone_value_config39.json"}, + {"clone_value_config40.json"}, + {"clone_value_config41.json"}, + {"clone_value_config42.json"}, + {"clone_value_config43.json"}, + {"clone_value_config44.json"}, + {"clone_value_config45.json"}, + {"clone_value_config46.json"}, + {"clone_value_config47.json"}, + {"clone_value_config48.json"}, + {"clone_value_config49.json"}, + {"clone_value_config50.json"}, + {"clone_value_config51.json"}, + {"clone_value_config52.json"}, + {"clone_value_config53.json"}, + {"clone_value_config54.json"}, + {"clone_value_config55.json"} }; } diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config25.json b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config25.json new file mode 100644 index 000000000000..5684ebe61e55 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config25.json @@ -0,0 +1,30 @@ +{ + "position": { + "line": 7, + "character": 15 + }, + "source": "add_readonly7.bal", + "description": "Add readonly to a map value", + "expected": [ + { + "title": "Add readonly to 'map'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 5, + "character": 33 + }, + "end": { + "line": 5, + "character": 33 + } + }, + "newText": " & readonly" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config26.json b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config26.json new file mode 100644 index 000000000000..87e26f27ac6f --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config26.json @@ -0,0 +1,30 @@ +{ + "position": { + "line": 13, + "character": 15 + }, + "source": "add_readonly7.bal", + "description": "Add readonly to a map value", + "expected": [ + { + "title": "Add readonly to 'map'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 11, + "character": 37 + }, + "end": { + "line": 11, + "character": 37 + } + }, + "newText": " & readonly" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config27.json b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config27.json new file mode 100644 index 000000000000..7e0f6c839703 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config27.json @@ -0,0 +1,30 @@ +{ + "position": { + "line": 19, + "character": 15 + }, + "source": "add_readonly7.bal", + "description": "Add readonly to a map value", + "expected": [ + { + "title": "Add readonly to 'map>'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 17, + "character": 38 + }, + "end": { + "line": 17, + "character": 38 + } + }, + "newText": " & readonly" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config28.json b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config28.json new file mode 100644 index 000000000000..97b215e1ef3a --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config28.json @@ -0,0 +1,30 @@ +{ + "position": { + "line": 25, + "character": 20 + }, + "source": "add_readonly7.bal", + "description": "Add readonly to a map value", + "expected": [ + { + "title": "Add readonly to 'map'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 23, + "character": 33 + }, + "end": { + "line": 23, + "character": 33 + } + }, + "newText": " & readonly" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config29.json b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config29.json new file mode 100644 index 000000000000..b680fe8fb1ba --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config29.json @@ -0,0 +1,30 @@ +{ + "position": { + "line": 31, + "character": 30 + }, + "source": "add_readonly7.bal", + "description": "Add readonly to a map value", + "expected": [ + { + "title": "Add readonly to 'map'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 29, + "character": 35 + }, + "end": { + "line": 29, + "character": 35 + } + }, + "newText": " & readonly" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config30.json b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config30.json new file mode 100644 index 000000000000..17285a884cc5 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config30.json @@ -0,0 +1,30 @@ +{ + "position": { + "line": 37, + "character": 35 + }, + "source": "add_readonly7.bal", + "description": "Add readonly to a map value", + "expected": [ + { + "title": "Add readonly to 'string[]'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 35, + "character": 30 + }, + "end": { + "line": 35, + "character": 30 + } + }, + "newText": " & readonly" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config31.json b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config31.json new file mode 100644 index 000000000000..d453a19e3fda --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config31.json @@ -0,0 +1,30 @@ +{ + "position": { + "line": 8, + "character": 16 + }, + "source": "add_readonly8.bal", + "description": "Add readonly to a array value", + "expected": [ + { + "title": "Add readonly to 'int[]'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 6, + "character": 18 + }, + "end": { + "line": 6, + "character": 18 + } + }, + "newText": " & readonly" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config32.json b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config32.json new file mode 100644 index 000000000000..59835c7a998d --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config32.json @@ -0,0 +1,30 @@ +{ + "position": { + "line": 14, + "character": 16 + }, + "source": "add_readonly8.bal", + "description": "Add readonly to a array value", + "expected": [ + { + "title": "Add readonly to '(string|int)[]'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 12, + "character": 27 + }, + "end": { + "line": 12, + "character": 27 + } + }, + "newText": " & readonly" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config33.json b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config33.json new file mode 100644 index 000000000000..59cde2327bdb --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config33.json @@ -0,0 +1,30 @@ +{ + "position": { + "line": 20, + "character": 19 + }, + "source": "add_readonly8.bal", + "description": "Add readonly to a array value", + "expected": [ + { + "title": "Add readonly to 'int[][]'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 18, + "character": 20 + }, + "end": { + "line": 18, + "character": 20 + } + }, + "newText": " & readonly" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config34.json b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config34.json new file mode 100644 index 000000000000..1436b05773b5 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config34.json @@ -0,0 +1,30 @@ +{ + "position": { + "line": 26, + "character": 22 + }, + "source": "add_readonly8.bal", + "description": "Add readonly to a array value", + "expected": [ + { + "title": "Add readonly to 'int[]'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 24, + "character": 18 + }, + "end": { + "line": 24, + "character": 18 + } + }, + "newText": " & readonly" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config35.json b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config35.json new file mode 100644 index 000000000000..3f34972b6467 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config35.json @@ -0,0 +1,30 @@ +{ + "position": { + "line": 32, + "character": 16 + }, + "source": "add_readonly8.bal", + "description": "Add readonly to a array value", + "expected": [ + { + "title": "Add readonly to '[int, string]'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 30, + "character": 26 + }, + "end": { + "line": 30, + "character": 26 + } + }, + "newText": " & readonly" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config36.json b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config36.json new file mode 100644 index 000000000000..5f7ff47104ea --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config36.json @@ -0,0 +1,30 @@ +{ + "position": { + "line": 38, + "character": 25 + }, + "source": "add_readonly8.bal", + "description": "Add readonly to a array value", + "expected": [ + { + "title": "Add readonly to 'int[]'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 36, + "character": 18 + }, + "end": { + "line": 36, + "character": 18 + } + }, + "newText": " & readonly" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config37.json b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config37.json new file mode 100644 index 000000000000..bff46f0ad4c6 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config37.json @@ -0,0 +1,30 @@ +{ + "position": { + "line": 44, + "character": 22 + }, + "source": "add_readonly8.bal", + "description": "Add readonly to a array value", + "expected": [ + { + "title": "Add readonly to 'map[]'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 42, + "character": 26 + }, + "end": { + "line": 42, + "character": 26 + } + }, + "newText": " & readonly" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config38.json b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config38.json new file mode 100644 index 000000000000..7369531e0fa2 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config38.json @@ -0,0 +1,30 @@ +{ + "position": { + "line": 14, + "character": 20 + }, + "source": "add_readonly9.bal", + "description": "Add readonly to a record value", + "expected": [ + { + "title": "Add readonly to 'record {|anydata...;|}'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 12, + "character": 31 + }, + "end": { + "line": 12, + "character": 31 + } + }, + "newText": " & readonly" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config39.json b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config39.json new file mode 100644 index 000000000000..ac17767b84ba --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config39.json @@ -0,0 +1,30 @@ +{ + "position": { + "line": 20, + "character": 19 + }, + "source": "add_readonly9.bal", + "description": "Add readonly to a record value", + "expected": [ + { + "title": "Add readonly to 'map'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 18, + "character": 24 + }, + "end": { + "line": 18, + "character": 24 + } + }, + "newText": " & readonly" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config40.json b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config40.json new file mode 100644 index 000000000000..ac17767b84ba --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config40.json @@ -0,0 +1,30 @@ +{ + "position": { + "line": 20, + "character": 19 + }, + "source": "add_readonly9.bal", + "description": "Add readonly to a record value", + "expected": [ + { + "title": "Add readonly to 'map'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 18, + "character": 24 + }, + "end": { + "line": 18, + "character": 24 + } + }, + "newText": " & readonly" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config41.json b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config41.json new file mode 100644 index 000000000000..f6d7d57d1bdb --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config41.json @@ -0,0 +1,30 @@ +{ + "position": { + "line": 26, + "character": 26 + }, + "source": "add_readonly9.bal", + "description": "Add readonly to a record value", + "expected": [ + { + "title": "Add readonly to 'map'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 24, + "character": 24 + }, + "end": { + "line": 24, + "character": 24 + } + }, + "newText": " & readonly" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config42.json b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config42.json new file mode 100644 index 000000000000..a3109b7b565f --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config42.json @@ -0,0 +1,30 @@ +{ + "position": { + "line": 10, + "character": 15 + }, + "source": "add_readonly10.bal", + "description": "Add readonly to a table value", + "expected": [ + { + "title": "Add readonly to 'table'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 8, + "character": 23 + }, + "end": { + "line": 8, + "character": 23 + } + }, + "newText": " & readonly" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config43.json b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config43.json new file mode 100644 index 000000000000..e9b78e097866 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config43.json @@ -0,0 +1,30 @@ +{ + "position": { + "line": 5, + "character": 27 + }, + "source": "add_readonly11.bal", + "description": "Add readonly to a class variable value", + "expected": [ + { + "title": "Add readonly to 'map'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 3, + "character": 24 + }, + "end": { + "line": 3, + "character": 24 + } + }, + "newText": " & readonly" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config44.json b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config44.json new file mode 100644 index 000000000000..3584b5f4b9e0 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config44.json @@ -0,0 +1,30 @@ +{ + "position": { + "line": 15, + "character": 28 + }, + "source": "add_readonly11.bal", + "description": "Add readonly to a class variable value", + "expected": [ + { + "title": "Add readonly to 'map'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 13, + "character": 36 + }, + "end": { + "line": 13, + "character": 36 + } + }, + "newText": " & readonly" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config45.json b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config45.json new file mode 100644 index 000000000000..e7bc6d7774ca --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config45.json @@ -0,0 +1,30 @@ +{ + "position": { + "line": 21, + "character": 33 + }, + "source": "add_readonly11.bal", + "description": "Add readonly to a class variable value", + "expected": [ + { + "title": "Add readonly to 'string[]'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 19, + "character": 44 + }, + "end": { + "line": 19, + "character": 44 + } + }, + "newText": " & readonly" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config46.json b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config46.json new file mode 100644 index 000000000000..e2422e2a350c --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config46.json @@ -0,0 +1,43 @@ +{ + "position": { + "line": 6, + "character": 16 + }, + "source": "add_readonly12.bal", + "description": "Add readonly to an union value", + "expected": [ + { + "title": "Add readonly to 'map|int[]'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 4, + "character": 13 + }, + "end": { + "line": 4, + "character": 13 + } + }, + "newText": "(" + }, + { + "range": { + "start": { + "line": 4, + "character": 30 + }, + "end": { + "line": 4, + "character": 30 + } + }, + "newText": ") & readonly" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config47.json b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config47.json new file mode 100644 index 000000000000..a1df9d523ab6 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config47.json @@ -0,0 +1,43 @@ +{ + "position": { + "line": 12, + "character": 16 + }, + "source": "add_readonly12.bal", + "description": "Add readonly to an union value", + "expected": [ + { + "title": "Add readonly to 'int[]|int'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 10, + "character": 13 + }, + "end": { + "line": 10, + "character": 13 + } + }, + "newText": "(" + }, + { + "range": { + "start": { + "line": 10, + "character": 22 + }, + "end": { + "line": 10, + "character": 22 + } + }, + "newText": ") & readonly" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config48.json b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config48.json new file mode 100644 index 000000000000..663ce9c56416 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/config/add_readonly_config48.json @@ -0,0 +1,43 @@ +{ + "position": { + "line": 18, + "character": 16 + }, + "source": "add_readonly12.bal", + "description": "Add readonly to an union value", + "expected": [ + { + "title": "Add readonly to 'map|int[]|boolean'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 16, + "character": 13 + }, + "end": { + "line": 16, + "character": 13 + } + }, + "newText": "(" + }, + { + "range": { + "start": { + "line": 16, + "character": 38 + }, + "end": { + "line": 16, + "character": 38 + } + }, + "newText": ") & readonly" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/source/add_readonly10.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/source/add_readonly10.bal new file mode 100644 index 000000000000..4dcdef35bf3e --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/source/add_readonly10.bal @@ -0,0 +1,13 @@ +type Row record {| + readonly int id; + string value; + [int, string][] values; +|}; + +isolated table tbl = table []; + +function fn1(table a) { + lock { + tbl = a; + } +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/source/add_readonly11.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/source/add_readonly11.bal new file mode 100644 index 000000000000..8a575a3d00b6 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/source/add_readonly11.bal @@ -0,0 +1,25 @@ +isolated class MyClass { + private map[] arr = []; + + function fn(map a) { + lock { + self.arr[0] = a; + } + } +} + +isolated client class MyClient { + private map> mp = {}; + + remote function fn(map a) { + lock { + self.mp["a"] = a; + } + } + + resource function accessor path(string[] a) { + lock { + self.mp["a"]["b"] = a; + } + } +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/source/add_readonly12.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/source/add_readonly12.bal new file mode 100644 index 000000000000..05ae25f944e6 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/source/add_readonly12.bal @@ -0,0 +1,21 @@ +isolated map|int[] val1 = []; +isolated int[]|int val2 = []; +isolated map|int[]|boolean val3 = []; + +function fn1(map|int[] a) { + lock { + val1 = a; + } +} + +function fn2(int[]|int a) { + lock { + val2 = a; + } +} + +function fn3(map|int[]|boolean a) { + lock { + val3 = a; + } +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/source/add_readonly7.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/source/add_readonly7.bal new file mode 100644 index 000000000000..c8c491c81d2a --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/source/add_readonly7.bal @@ -0,0 +1,40 @@ +isolated map mp1 = {}; +isolated map mp2 = {}; +isolated map> mp3 = {}; +isolated map>>> mp4 = {}; + +isolated function fn1(map a) { + lock { + mp1 = a; + } +} + +isolated function fn2(map a) { + lock { + mp2 = a; + } +} + +isolated function fn3(map> a) { + lock { + mp3 = a; + } +} + +isolated function fn4(map a) { + lock { + mp3["a"] = a; + } +} + +isolated function fn5(map a) { + lock { + mp4["a"]["b"]["c"] = a; + } +} + +isolated function fn6(string[] a) { + lock { + mp4["a"]["b"]["c"]["d"] = a; + } +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/source/add_readonly8.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/source/add_readonly8.bal new file mode 100644 index 000000000000..a5b20ae772b7 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/source/add_readonly8.bal @@ -0,0 +1,47 @@ +isolated int[] arr1 = []; +isolated (string|int)[] arr2 = []; +isolated int[][][] arr3 = []; +isolated [int, string] arr4 = []; +isolated [int[][][], map[][]] arr5 = []; + +function fn1(int[] a) { + lock { + arr1 = a; + } +} + +function fn2((string|int)[] a) { + lock { + arr2 = a; + } +} + +function fn3(int[][] a) { + lock { + arr3[0] = a; + } +} + +function fn4(int[] a) { + lock { + arr3[0][1] = a; + } +} + +function fn5([int, string] a) { + lock { + arr4 = a; + } +} + +function fn6(int[] a) { + lock { + arr5[0][0][1] = a; + } +} + +function fn7(map[] a) { + lock { + arr5[1][0] = a; + } +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/source/add_readonly9.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/source/add_readonly9.bal new file mode 100644 index 000000000000..cd78e6b88796 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/add-readonly/source/add_readonly9.bal @@ -0,0 +1,35 @@ +type Rec record {| + map mp; + int i; +|}; + +isolated record {|record {} rec;|} rec1 = {rec: {}}; +isolated Rec rec2 = {mp: {}, i: 0}; +isolated record {|Rec field1; record {|int id; Rec value;|} field2;|} rec3 = { + field1: {mp: {}, i: 0}, + field2: {id: 0, value: {mp: {}, i: 0}} +}; + +isolated function fn1(record {} a) { + lock { + rec1.rec = a; + } +} + +function fn2(map a) { + lock { + rec2.mp = a; + } +} + +function fn3(map a) { + lock { + rec3.field1.mp = a; + } +} + +function fn4(map a) { + lock { + rec3.field2.value.mp = a; + } +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config29.json b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config29.json new file mode 100644 index 000000000000..0d93fcc1ec31 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config29.json @@ -0,0 +1,50 @@ +{ + "position": { + "line": 7, + "character": 15 + }, + "source": "clone_value10.bal", + "description": "Clone a array value", + "expected": [ + { + "title": "Clone the value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 7, + "character": 16 + }, + "end": { + "line": 7, + "character": 16 + } + }, + "newText": ".clone()" + } + ], + "resolvable": false + }, + { + "title": "Clone as a readonly value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 7, + "character": 16 + }, + "end": { + "line": 7, + "character": 16 + } + }, + "newText": ".cloneReadOnly()" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config30.json b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config30.json new file mode 100644 index 000000000000..5f5c20bb4d13 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config30.json @@ -0,0 +1,50 @@ +{ + "position": { + "line": 13, + "character": 19 + }, + "source": "clone_value10.bal", + "description": "Clone a array value", + "expected": [ + { + "title": "Clone the value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 13, + "character": 19 + }, + "end": { + "line": 13, + "character": 19 + } + }, + "newText": ".clone()" + } + ], + "resolvable": false + }, + { + "title": "Clone as a readonly value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 13, + "character": 19 + }, + "end": { + "line": 13, + "character": 19 + } + }, + "newText": ".cloneReadOnly()" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config31.json b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config31.json new file mode 100644 index 000000000000..c335d60c865b --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config31.json @@ -0,0 +1,50 @@ +{ + "position": { + "line": 19, + "character": 19 + }, + "source": "clone_value10.bal", + "description": "Clone a array value", + "expected": [ + { + "title": "Clone the value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 19, + "character": 19 + }, + "end": { + "line": 19, + "character": 19 + } + }, + "newText": ".clone()" + } + ], + "resolvable": false + }, + { + "title": "Clone as a readonly value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 19, + "character": 19 + }, + "end": { + "line": 19, + "character": 19 + } + }, + "newText": ".cloneReadOnly()" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config32.json b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config32.json new file mode 100644 index 000000000000..0cf69f5fd971 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config32.json @@ -0,0 +1,50 @@ +{ + "position": { + "line": 25, + "character": 22 + }, + "source": "clone_value10.bal", + "description": "Clone a array value", + "expected": [ + { + "title": "Clone the value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 25, + "character": 22 + }, + "end": { + "line": 25, + "character": 22 + } + }, + "newText": ".clone()" + } + ], + "resolvable": false + }, + { + "title": "Clone as a readonly value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 25, + "character": 22 + }, + "end": { + "line": 25, + "character": 22 + } + }, + "newText": ".cloneReadOnly()" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config33.json b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config33.json new file mode 100644 index 000000000000..d14802b9e254 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config33.json @@ -0,0 +1,50 @@ +{ + "position": { + "line": 6, + "character": 15 + }, + "source": "clone_value11.bal", + "description": "Clone a map value", + "expected": [ + { + "title": "Clone the value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 6, + "character": 15 + }, + "end": { + "line": 6, + "character": 15 + } + }, + "newText": ".clone()" + } + ], + "resolvable": false + }, + { + "title": "Clone as a readonly value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 6, + "character": 15 + }, + "end": { + "line": 6, + "character": 15 + } + }, + "newText": ".cloneReadOnly()" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config34.json b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config34.json new file mode 100644 index 000000000000..e8e0df312e85 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config34.json @@ -0,0 +1,50 @@ +{ + "position": { + "line": 12, + "character": 24 + }, + "source": "clone_value11.bal", + "description": "Clone a map value", + "expected": [ + { + "title": "Clone the value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 12, + "character": 25 + }, + "end": { + "line": 12, + "character": 25 + } + }, + "newText": ".clone()" + } + ], + "resolvable": false + }, + { + "title": "Clone as a readonly value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 12, + "character": 25 + }, + "end": { + "line": 12, + "character": 25 + } + }, + "newText": ".cloneReadOnly()" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config35.json b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config35.json new file mode 100644 index 000000000000..5741457c38c1 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config35.json @@ -0,0 +1,50 @@ +{ + "position": { + "line": 18, + "character": 25 + }, + "source": "clone_value11.bal", + "description": "Clone a map value", + "expected": [ + { + "title": "Clone the value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 18, + "character": 25 + }, + "end": { + "line": 18, + "character": 25 + } + }, + "newText": ".clone()" + } + ], + "resolvable": false + }, + { + "title": "Clone as a readonly value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 18, + "character": 25 + }, + "end": { + "line": 18, + "character": 25 + } + }, + "newText": ".cloneReadOnly()" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config36.json b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config36.json new file mode 100644 index 000000000000..311ea75d8e3c --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config36.json @@ -0,0 +1,50 @@ +{ + "position": { + "line": 14, + "character": 20 + }, + "source": "clone_value12.bal", + "description": "Clone a record value", + "expected": [ + { + "title": "Clone the value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 14, + "character": 20 + }, + "end": { + "line": 14, + "character": 20 + } + }, + "newText": ".clone()" + } + ], + "resolvable": false + }, + { + "title": "Clone as a readonly value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 14, + "character": 20 + }, + "end": { + "line": 14, + "character": 20 + } + }, + "newText": ".cloneReadOnly()" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config37.json b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config37.json new file mode 100644 index 000000000000..73f2470eab46 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config37.json @@ -0,0 +1,50 @@ +{ + "position": { + "line": 20, + "character": 19 + }, + "source": "clone_value12.bal", + "description": "Clone a record value", + "expected": [ + { + "title": "Clone the value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 20, + "character": 19 + }, + "end": { + "line": 20, + "character": 19 + } + }, + "newText": ".clone()" + } + ], + "resolvable": false + }, + { + "title": "Clone as a readonly value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 20, + "character": 19 + }, + "end": { + "line": 20, + "character": 19 + } + }, + "newText": ".cloneReadOnly()" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config38.json b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config38.json new file mode 100644 index 000000000000..55f200bfb40c --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config38.json @@ -0,0 +1,50 @@ +{ + "position": { + "line": 26, + "character": 25 + }, + "source": "clone_value12.bal", + "description": "Clone a record value", + "expected": [ + { + "title": "Clone the value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 26, + "character": 26 + }, + "end": { + "line": 26, + "character": 26 + } + }, + "newText": ".clone()" + } + ], + "resolvable": false + }, + { + "title": "Clone as a readonly value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 26, + "character": 26 + }, + "end": { + "line": 26, + "character": 26 + } + }, + "newText": ".cloneReadOnly()" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config39.json b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config39.json new file mode 100644 index 000000000000..8355c4414b9a --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config39.json @@ -0,0 +1,50 @@ +{ + "position": { + "line": 32, + "character": 31 + }, + "source": "clone_value12.bal", + "description": "Clone a record value", + "expected": [ + { + "title": "Clone the value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 32, + "character": 32 + }, + "end": { + "line": 32, + "character": 32 + } + }, + "newText": ".clone()" + } + ], + "resolvable": false + }, + { + "title": "Clone as a readonly value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 32, + "character": 32 + }, + "end": { + "line": 32, + "character": 32 + } + }, + "newText": ".cloneReadOnly()" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config40.json b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config40.json new file mode 100644 index 000000000000..609af8c6dfb3 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config40.json @@ -0,0 +1,50 @@ +{ + "position": { + "line": 38, + "character": 16 + }, + "source": "clone_value12.bal", + "description": "Clone a record value", + "expected": [ + { + "title": "Clone the value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 38, + "character": 16 + }, + "end": { + "line": 38, + "character": 16 + } + }, + "newText": ".clone()" + } + ], + "resolvable": false + }, + { + "title": "Clone as a readonly value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 38, + "character": 16 + }, + "end": { + "line": 38, + "character": 16 + } + }, + "newText": ".cloneReadOnly()" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config41.json b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config41.json new file mode 100644 index 000000000000..240d828a4fa6 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config41.json @@ -0,0 +1,50 @@ +{ + "position": { + "line": 6, + "character": 16 + }, + "source": "clone_value13.bal", + "description": "Clone a tuple value", + "expected": [ + { + "title": "Clone the value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 6, + "character": 16 + }, + "end": { + "line": 6, + "character": 16 + } + }, + "newText": ".clone()" + } + ], + "resolvable": false + }, + { + "title": "Clone as a readonly value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 6, + "character": 16 + }, + "end": { + "line": 6, + "character": 16 + } + }, + "newText": ".cloneReadOnly()" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config42.json b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config42.json new file mode 100644 index 000000000000..d5f83e378264 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config42.json @@ -0,0 +1,50 @@ +{ + "position": { + "line": 12, + "character": 19 + }, + "source": "clone_value13.bal", + "description": "Clone a tuple value", + "expected": [ + { + "title": "Clone the value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 12, + "character": 19 + }, + "end": { + "line": 12, + "character": 19 + } + }, + "newText": ".clone()" + } + ], + "resolvable": false + }, + { + "title": "Clone as a readonly value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 12, + "character": 19 + }, + "end": { + "line": 12, + "character": 19 + } + }, + "newText": ".cloneReadOnly()" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config43.json b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config43.json new file mode 100644 index 000000000000..a50c06b4d06e --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config43.json @@ -0,0 +1,50 @@ +{ + "position": { + "line": 18, + "character": 25 + }, + "source": "clone_value13.bal", + "description": "Clone a tuple value", + "expected": [ + { + "title": "Clone the value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 18, + "character": 25 + }, + "end": { + "line": 18, + "character": 25 + } + }, + "newText": ".clone()" + } + ], + "resolvable": false + }, + { + "title": "Clone as a readonly value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 18, + "character": 25 + }, + "end": { + "line": 18, + "character": 25 + } + }, + "newText": ".cloneReadOnly()" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config44.json b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config44.json new file mode 100644 index 000000000000..5e524f3b8fae --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config44.json @@ -0,0 +1,50 @@ +{ + "position": { + "line": 10, + "character": 16 + }, + "source": "clone_value14.bal", + "description": "Clone a table value", + "expected": [ + { + "title": "Clone the value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 10, + "character": 16 + }, + "end": { + "line": 10, + "character": 16 + } + }, + "newText": ".clone()" + } + ], + "resolvable": false + }, + { + "title": "Clone as a readonly value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 10, + "character": 16 + }, + "end": { + "line": 10, + "character": 16 + } + }, + "newText": ".cloneReadOnly()" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config45.json b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config45.json new file mode 100644 index 000000000000..27e70c60667b --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config45.json @@ -0,0 +1,50 @@ +{ + "position": { + "line": 9, + "character": 20 + }, + "source": "clone_value15.bal", + "description": "Clone a json value", + "expected": [ + { + "title": "Clone the value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 9, + "character": 20 + }, + "end": { + "line": 9, + "character": 20 + } + }, + "newText": ".clone()" + } + ], + "resolvable": false + }, + { + "title": "Clone as a readonly value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 9, + "character": 20 + }, + "end": { + "line": 9, + "character": 20 + } + }, + "newText": ".cloneReadOnly()" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config46.json b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config46.json new file mode 100644 index 000000000000..f48b82909479 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config46.json @@ -0,0 +1,50 @@ +{ + "position": { + "line": 15, + "character": 20 + }, + "source": "clone_value15.bal", + "description": "Clone a json value", + "expected": [ + { + "title": "Clone the value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 15, + "character": 20 + }, + "end": { + "line": 15, + "character": 20 + } + }, + "newText": ".clone()" + } + ], + "resolvable": false + }, + { + "title": "Clone as a readonly value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 15, + "character": 20 + }, + "end": { + "line": 15, + "character": 20 + } + }, + "newText": ".cloneReadOnly()" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config47.json b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config47.json new file mode 100644 index 000000000000..fee325e4d016 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config47.json @@ -0,0 +1,50 @@ +{ + "position": { + "line": 21, + "character": 19 + }, + "source": "clone_value15.bal", + "description": "Clone a json value", + "expected": [ + { + "title": "Clone the value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 21, + "character": 19 + }, + "end": { + "line": 21, + "character": 19 + } + }, + "newText": ".clone()" + } + ], + "resolvable": false + }, + { + "title": "Clone as a readonly value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 21, + "character": 19 + }, + "end": { + "line": 21, + "character": 19 + } + }, + "newText": ".cloneReadOnly()" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config48.json b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config48.json new file mode 100644 index 000000000000..82d9b15ec323 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config48.json @@ -0,0 +1,50 @@ +{ + "position": { + "line": 27, + "character": 19 + }, + "source": "clone_value15.bal", + "description": "Clone a json value", + "expected": [ + { + "title": "Clone the value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 27, + "character": 19 + }, + "end": { + "line": 27, + "character": 19 + } + }, + "newText": ".clone()" + } + ], + "resolvable": false + }, + { + "title": "Clone as a readonly value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 27, + "character": 19 + }, + "end": { + "line": 27, + "character": 19 + } + }, + "newText": ".cloneReadOnly()" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config49.json b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config49.json new file mode 100644 index 000000000000..56f3954c96b6 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config49.json @@ -0,0 +1,50 @@ +{ + "position": { + "line": 33, + "character": 19 + }, + "source": "clone_value15.bal", + "description": "Clone a json value", + "expected": [ + { + "title": "Clone the value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 33, + "character": 19 + }, + "end": { + "line": 33, + "character": 19 + } + }, + "newText": ".clone()" + } + ], + "resolvable": false + }, + { + "title": "Clone as a readonly value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 33, + "character": 19 + }, + "end": { + "line": 33, + "character": 19 + } + }, + "newText": ".cloneReadOnly()" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config50.json b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config50.json new file mode 100644 index 000000000000..f0ced5838850 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config50.json @@ -0,0 +1,50 @@ +{ + "position": { + "line": 5, + "character": 27 + }, + "source": "clone_value16.bal", + "description": "Clone a value in a class", + "expected": [ + { + "title": "Clone the value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 5, + "character": 27 + }, + "end": { + "line": 5, + "character": 27 + } + }, + "newText": ".clone()" + } + ], + "resolvable": false + }, + { + "title": "Clone as a readonly value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 5, + "character": 27 + }, + "end": { + "line": 5, + "character": 27 + } + }, + "newText": ".cloneReadOnly()" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config51.json b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config51.json new file mode 100644 index 000000000000..650df9b0efb9 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config51.json @@ -0,0 +1,50 @@ +{ + "position": { + "line": 15, + "character": 28 + }, + "source": "clone_value16.bal", + "description": "Clone a value in a class", + "expected": [ + { + "title": "Clone the value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 15, + "character": 28 + }, + "end": { + "line": 15, + "character": 28 + } + }, + "newText": ".clone()" + } + ], + "resolvable": false + }, + { + "title": "Clone as a readonly value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 15, + "character": 28 + }, + "end": { + "line": 15, + "character": 28 + } + }, + "newText": ".cloneReadOnly()" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config52.json b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config52.json new file mode 100644 index 000000000000..4204452d5925 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config52.json @@ -0,0 +1,50 @@ +{ + "position": { + "line": 21, + "character": 33 + }, + "source": "clone_value16.bal", + "description": "Clone a value in a class", + "expected": [ + { + "title": "Clone the value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 21, + "character": 33 + }, + "end": { + "line": 21, + "character": 33 + } + }, + "newText": ".clone()" + } + ], + "resolvable": false + }, + { + "title": "Clone as a readonly value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 21, + "character": 33 + }, + "end": { + "line": 21, + "character": 33 + } + }, + "newText": ".cloneReadOnly()" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config53.json b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config53.json new file mode 100644 index 000000000000..59e543564739 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config53.json @@ -0,0 +1,50 @@ +{ + "position": { + "line": 6, + "character": 16 + }, + "source": "clone_value17.bal", + "description": "Clone a union value", + "expected": [ + { + "title": "Clone the value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 6, + "character": 16 + }, + "end": { + "line": 6, + "character": 16 + } + }, + "newText": ".clone()" + } + ], + "resolvable": false + }, + { + "title": "Clone as a readonly value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 6, + "character": 16 + }, + "end": { + "line": 6, + "character": 16 + } + }, + "newText": ".cloneReadOnly()" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config54.json b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config54.json new file mode 100644 index 000000000000..ccbf255f7c18 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config54.json @@ -0,0 +1,50 @@ +{ + "position": { + "line": 12, + "character": 16 + }, + "source": "clone_value17.bal", + "description": "Clone a union value", + "expected": [ + { + "title": "Clone the value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 12, + "character": 16 + }, + "end": { + "line": 12, + "character": 16 + } + }, + "newText": ".clone()" + } + ], + "resolvable": false + }, + { + "title": "Clone as a readonly value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 12, + "character": 16 + }, + "end": { + "line": 12, + "character": 16 + } + }, + "newText": ".cloneReadOnly()" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config55.json b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config55.json new file mode 100644 index 000000000000..224c704718c6 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/config/clone_value_config55.json @@ -0,0 +1,50 @@ +{ + "position": { + "line": 18, + "character": 16 + }, + "source": "clone_value17.bal", + "description": "Clone a union value", + "expected": [ + { + "title": "Clone the value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 18, + "character": 16 + }, + "end": { + "line": 18, + "character": 16 + } + }, + "newText": ".clone()" + } + ], + "resolvable": false + }, + { + "title": "Clone as a readonly value", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 18, + "character": 16 + }, + "end": { + "line": 18, + "character": 16 + } + }, + "newText": ".cloneReadOnly()" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/source/clone_value10.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/source/clone_value10.bal new file mode 100644 index 000000000000..f27a97eb8f86 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/source/clone_value10.bal @@ -0,0 +1,28 @@ +isolated int[] arr1 = []; +isolated int[][] arr2 = []; +isolated map[] arr3 = []; +isolated int[][][] arr4 = []; + +isolated function fn1(int[] a) { + lock { + arr1 = a; + } +} + +function fn2(int[] a) { + lock { + arr2[0] = a; + } +} + +function fn3(map a) { + lock { + arr3[0] = a; + } +} + +function fn4(int[] a) { + lock { + arr4[0][0] = a; + } +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/source/clone_value11.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/source/clone_value11.bal new file mode 100644 index 000000000000..efe4ca3e13a3 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/source/clone_value11.bal @@ -0,0 +1,21 @@ +isolated map mp1 = {}; +isolated map>> mp2 = {}; +isolated map> mp3 = {}; + +function fn1(map a) { + lock { + mp1 = a; + } +} + +function fn2(map a) { + lock { + mp2["a"]["a"] = a; + } +} + +function fn3(int[] a) { + lock { + mp3["a"]["b"] = a; + } +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/source/clone_value12.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/source/clone_value12.bal new file mode 100644 index 000000000000..5b0928467b73 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/source/clone_value12.bal @@ -0,0 +1,41 @@ +type Rec record {| + map mp; + int i; +|}; + +isolated record {|record {} rec;|} rec1 = {rec: {}}; +isolated Rec rec2 = {mp: {}, i: 0}; +isolated record {|Rec field1; record {|int id; Rec value;|} field2;|} rec3 = { + field1: {mp: {}, i: 0}, + field2: {id: 0, value: {mp: {}, i: 0}} +}; + +isolated function fn1(record {} a) { + lock { + rec1.rec = a; + } +} + +function fn2(map a) { + lock { + rec2.mp = a; + } +} + +function fn3(map a) { + lock { + rec3.field1.mp = a; + } +} + +function fn4(map a) { + lock { + rec3.field2.value.mp = a; + } +} + +function fn5(Rec a) { + lock { + rec2 = a; + } +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/source/clone_value13.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/source/clone_value13.bal new file mode 100644 index 000000000000..524e29c4c98d --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/source/clone_value13.bal @@ -0,0 +1,21 @@ +isolated [int, int] tup1 = [1, 2]; +isolated [[int, string], int] tup2 = [[1, "a"], 2]; +isolated [[[boolean, record {int id;}, int], string]] tup3 = [[[true, {id: 1}, 2], "a"]]; + +function fn1([int, int] a) { + lock { + tup1 = a; + } +} + +function fn2([int, string] a) { + lock { + tup2[0] = a; + } +} + +function fn3(record {int id;} a) { + lock { + tup3[0][0][1] = a; + } +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/source/clone_value14.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/source/clone_value14.bal new file mode 100644 index 000000000000..84a489a48971 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/source/clone_value14.bal @@ -0,0 +1,13 @@ +type Row record {| + readonly int id; + string value; + [int, string][] values; +|}; + +isolated table tbl = table []; + +function fn1(table a) { + lock { + tbl = a; + } +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/source/clone_value15.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/source/clone_value15.bal new file mode 100644 index 000000000000..d1a6dd8cb2c3 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/source/clone_value15.bal @@ -0,0 +1,36 @@ +isolated json jsonVal1 = {"a": [1, 2]}; +isolated json jsonVal2 = "a"; +isolated anydata anyVal1 = {"a": [1, 2]}; +isolated anydata anyVal2 = false; +const NUM = 1; +isolated anydata anyVal3 = NUM; + +function fn1(json a) { + lock { + jsonVal1 = a; + } +} + +function fn2(json a) { + lock { + jsonVal2 = a; + } +} + +function fn3(anydata a) { + lock { + anyVal1 = a; + } +} + +function fn4(anydata a) { + lock { + anyVal2 = a; + } +} + +function fn5(anydata a) { + lock { + anyVal3 = a; + } +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/source/clone_value16.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/source/clone_value16.bal new file mode 100644 index 000000000000..8a575a3d00b6 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/source/clone_value16.bal @@ -0,0 +1,25 @@ +isolated class MyClass { + private map[] arr = []; + + function fn(map a) { + lock { + self.arr[0] = a; + } + } +} + +isolated client class MyClient { + private map> mp = {}; + + remote function fn(map a) { + lock { + self.mp["a"] = a; + } + } + + resource function accessor path(string[] a) { + lock { + self.mp["a"]["b"] = a; + } + } +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/source/clone_value17.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/source/clone_value17.bal new file mode 100644 index 000000000000..05ae25f944e6 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/clone-value/source/clone_value17.bal @@ -0,0 +1,21 @@ +isolated map|int[] val1 = []; +isolated int[]|int val2 = []; +isolated map|int[]|boolean val3 = []; + +function fn1(map|int[] a) { + lock { + val1 = a; + } +} + +function fn2(int[]|int a) { + lock { + val2 = a; + } +} + +function fn3(map|int[]|boolean a) { + lock { + val3 = a; + } +}