Skip to content

Commit

Permalink
Merge pull request #41053 from LakshanWeerasinghe/fix-#40294
Browse files Browse the repository at this point in the history
Fix fill record field code action and fill record filed completions
  • Loading branch information
LakshanWeerasinghe authored Aug 14, 2023
2 parents 006e427 + cc5e506 commit 4381741
Show file tree
Hide file tree
Showing 16 changed files with 443 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,13 @@ public static void populateStructureFields(Types types, SymbolTable symTable,
fieldType = origField.type;
}

Name origFieldName = origField.name;
Name origFieldName = origField.symbol.originalName;
Name fieldName = origField.name;
BVarSymbol fieldSymbol;
BType referredType = Types.getReferredType(fieldType);
if (referredType.tag == TypeTags.INVOKABLE && referredType.tsymbol != null) {
fieldSymbol = new BInvokableSymbol(origField.symbol.tag, origField.symbol.flags | flag,
origFieldName, pkgID, fieldType,
fieldName, origFieldName, pkgID, fieldType,
structureSymbol, origField.symbol.pos, SOURCE);
BInvokableTypeSymbol tsymbol = (BInvokableTypeSymbol) referredType.tsymbol;
BInvokableSymbol invokableSymbol = (BInvokableSymbol) fieldSymbol;
Expand All @@ -347,16 +348,16 @@ public static void populateStructureFields(Types types, SymbolTable symTable,
} else if (fieldType == symTable.semanticError) {
// Can only happen for records.
fieldSymbol = new BVarSymbol(origField.symbol.flags | flag | Flags.OPTIONAL,
origFieldName, pkgID, symTable.neverType,
fieldName, origFieldName, pkgID, symTable.neverType,
structureSymbol, origField.symbol.pos, SOURCE);
} else {
fieldSymbol = new BVarSymbol(origField.symbol.flags | flag, origFieldName, pkgID,
fieldSymbol = new BVarSymbol(origField.symbol.flags | flag, fieldName, origFieldName, pkgID,
fieldType, structureSymbol,
origField.symbol.pos, SOURCE);
}
String nameString = origFieldName.value;
fields.put(nameString, new BField(origFieldName, null, fieldSymbol));
structureSymbol.scope.define(origFieldName, fieldSymbol);
String nameString = fieldName.value;
fields.put(nameString, new BField(fieldName, null, fieldSymbol));
structureSymbol.scope.define(fieldName, fieldSymbol);
}
structureType.fields = fields;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public static String getFillAllRecordFieldInsertText(Map<String, RecordFieldSymb
public static Map<String, RecordFieldSymbol> getRecordFields(RawTypeSymbolWrapper<RecordTypeSymbol> wrapper,
List<String> existingFields) {
return wrapper.getRawType().fieldDescriptors().entrySet().stream()
.filter(e -> !existingFields.contains(e.getKey()))
.filter(e -> !existingFields.contains(e.getValue().getName().get()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ public Object[][] dataProvider() {
{"fill_record_fields_config15.json"},
{"fill_record_fields_config16.json"},
{"fill_record_fields_config17.json"},
{"fill_record_fields_config18.json"}
{"fill_record_fields_config18.json"},
{"fill_record_fields_config19.json"},
{"fill_record_fields_config20.json"},
{"fill_record_fields_config21.json"},
{"fill_record_fields_config22.json"},
{"fill_record_fields_config23.json"}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"position": {
"line": 16,
"character": 27
},
"source": "fill_record_fields_source16.bal",
"description": "Fill record fields in object field",
"expected": [
{
"title": "Fill 'Foo' required fields",
"kind": "quickfix",
"edits": [
{
"range": {
"start": {
"line": 16,
"character": 27
},
"end": {
"line": 16,
"character": 27
}
},
"newText": ",id: 0"
}
],
"resolvable": false
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"position": {
"line": 18,
"character": 27
},
"source": "fill_record_fields_source16.bal",
"description": "Fill record fields in object field",
"expected": [
{
"title": "Fill 'Bar' required fields",
"kind": "quickfix",
"edits": [
{
"range": {
"start": {
"line": 18,
"character": 27
},
"end": {
"line": 18,
"character": 27
}
},
"newText": ",id: 0"
}
],
"resolvable": false
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"position": {
"line": 20,
"character": 27
},
"source": "fill_record_fields_source16.bal",
"description": "Fill record fields in object field",
"expected": [
{
"title": "Fill 'Baz' required fields",
"kind": "quickfix",
"edits": [
{
"range": {
"start": {
"line": 20,
"character": 27
},
"end": {
"line": 20,
"character": 27
}
},
"newText": ",id: 0"
}
],
"resolvable": false
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"position": {
"line": 22,
"character": 46
},
"source": "fill_record_fields_source16.bal",
"description": "Fill record fields in object field",
"expected": [
{
"title": "Fill 'record {|readonly string 'type; readonly int id; anydata & readonly...;|}' required fields",
"kind": "quickfix",
"edits": [
{
"range": {
"start": {
"line": 22,
"character": 46
},
"end": {
"line": 22,
"character": 46
}
},
"newText": ",id: 0"
}
],
"resolvable": false
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"position": {
"line": 27,
"character": 45
},
"source": "fill_record_fields_source16.bal",
"description": "Fill record fields in object field",
"expected": [
{
"title": "Fill 'record {|readonly string 'type; readonly int id; anydata & readonly...;|}' required fields",
"kind": "quickfix",
"edits": [
{
"range": {
"start": {
"line": 27,
"character": 45
},
"end": {
"line": 27,
"character": 45
}
},
"newText": ",id: 0"
}
],
"resolvable": false
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
type Foo record {
string 'type;
int id;
};

type Bar readonly & record {
string 'type;
int id;
};

type Baz record {
readonly string 'type;
int id;
};

function testFillRecordFields() {
Foo foo = {'type: "foo"};

Bar bar = {'type: "bar"};

Baz baz = {'type: "baz"};

Foo & readonly fooReadonly = {'type: "foo"};

record {
string 'type;
int id;
} & readonly fooReadonly2 = {'type: "foo"};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"position": {
"line": 20,
"character": 28
},
"source": "expression_context/source/mapping_constructor_expr_ctx_source8.bal",
"description": "",
"items": [
{
"label": "readonly",
"kind": "Keyword",
"detail": "Keyword",
"sortText": "U",
"filterText": "readonly",
"insertText": "readonly ",
"insertTextFormat": "Snippet"
},
{
"label": "Fill Bar Required Fields",
"kind": "Property",
"detail": "Bar",
"sortText": "R",
"filterText": "fill",
"insertText": "id: ${1:0}",
"insertTextFormat": "Snippet"
},
{
"label": "id",
"kind": "Field",
"detail": "Bar.id",
"sortText": "K",
"insertText": "id: ${1:0}",
"insertTextFormat": "Snippet"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"position": {
"line": 22,
"character": 28
},
"source": "expression_context/source/mapping_constructor_expr_ctx_source8.bal",
"description": "",
"items": [
{
"label": "readonly",
"kind": "Keyword",
"detail": "Keyword",
"sortText": "U",
"filterText": "readonly",
"insertText": "readonly ",
"insertTextFormat": "Snippet"
},
{
"label": "Fill Baz Required Fields",
"kind": "Property",
"detail": "Baz",
"sortText": "R",
"filterText": "fill",
"insertText": "id: ${1:0}",
"insertTextFormat": "Snippet"
},
{
"label": "id",
"kind": "Field",
"detail": "Baz.id",
"sortText": "K",
"insertText": "id: ${1:0}",
"insertTextFormat": "Snippet"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"position": {
"line": 24,
"character": 47
},
"source": "expression_context/source/mapping_constructor_expr_ctx_source8.bal",
"description": "",
"items": [
{
"label": "readonly",
"kind": "Keyword",
"detail": "Keyword",
"sortText": "U",
"filterText": "readonly",
"insertText": "readonly ",
"insertTextFormat": "Snippet"
},
{
"label": "Fill record {|readonly string 'type; readonly int id; anydata & readonly...;|} Required Fields",
"kind": "Property",
"detail": "record {|readonly string 'type; readonly int id; anydata & readonly...;|}",
"sortText": "R",
"filterText": "fill",
"insertText": "id: ${1:0}",
"insertTextFormat": "Snippet"
},
{
"label": "id",
"kind": "Field",
"detail": "(record {|readonly string 'type; readonly int id; anydata & readonly...;|}).id",
"sortText": "K",
"insertText": "id: ${1:0}",
"insertTextFormat": "Snippet"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"position": {
"line": 29,
"character": 46
},
"source": "expression_context/source/mapping_constructor_expr_ctx_source8.bal",
"description": "",
"items": [
{
"label": "readonly",
"kind": "Keyword",
"detail": "Keyword",
"sortText": "U",
"filterText": "readonly",
"insertText": "readonly ",
"insertTextFormat": "Snippet"
},
{
"label": "Fill record {|readonly string 'type; readonly int id; anydata & readonly...;|} Required Fields",
"kind": "Property",
"detail": "record {|readonly string 'type; readonly int id; anydata & readonly...;|}",
"sortText": "R",
"filterText": "fill",
"insertText": "id: ${1:0}",
"insertTextFormat": "Snippet"
},
{
"label": "id",
"kind": "Field",
"detail": "(record {|readonly string 'type; readonly int id; anydata & readonly...;|}).id",
"sortText": "K",
"insertText": "id: ${1:0}",
"insertTextFormat": "Snippet"
}
]
}
Loading

0 comments on commit 4381741

Please sign in to comment.