Skip to content

Commit

Permalink
Merge pull request #41161 from KavinduZoysa/fix-issue-33862
Browse files Browse the repository at this point in the history
Suggest clauses after type test
  • Loading branch information
KavinduZoysa authored Aug 7, 2023
2 parents 444b24c + 1d3cc35 commit b8b78ca
Show file tree
Hide file tree
Showing 11 changed files with 1,174 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
import io.ballerina.compiler.api.symbols.TypeReferenceTypeSymbol;
import io.ballerina.compiler.api.symbols.TypeSymbol;
import io.ballerina.compiler.api.symbols.UnionTypeSymbol;
import io.ballerina.compiler.syntax.tree.Node;
import io.ballerina.compiler.syntax.tree.QualifiedNameReferenceNode;
import io.ballerina.compiler.syntax.tree.SimpleNameReferenceNode;
import io.ballerina.compiler.syntax.tree.SyntaxKind;
import io.ballerina.compiler.syntax.tree.Token;
import io.ballerina.compiler.syntax.tree.TypeTestExpressionNode;
import io.ballerina.projects.Module;
Expand All @@ -38,6 +41,7 @@
import org.ballerinalang.langserver.completions.TypeCompletionItem;
import org.ballerinalang.langserver.completions.builder.TypeCompletionItemBuilder;
import org.ballerinalang.langserver.completions.providers.AbstractCompletionProvider;
import org.ballerinalang.langserver.completions.util.CompletionUtil;
import org.ballerinalang.langserver.completions.util.QNameRefCompletionUtil;
import org.ballerinalang.langserver.completions.util.SortingUtil;

Expand Down Expand Up @@ -68,6 +72,9 @@ public List<LSCompletionItem> getCompletions(BallerinaCompletionContext context,
QualifiedNameReferenceNode qNameRef = (QualifiedNameReferenceNode) context.getNodeAtCursor();
List<Symbol> typesInModule = QNameRefCompletionUtil.getTypesInModule(context, qNameRef);
completionItems.addAll(this.getCompletionItemList(typesInModule, context));
} else if (isValidTypeName(node.typeDescriptor()) &&
context.getCursorPosition().getCharacter() > node.typeDescriptor().lineRange().endLine().offset()) {
return CompletionUtil.route(context, node.parent());
} else {
completionItems.addAll(this.getTypeDescContextItems(context));
completionItems.addAll(getModuleTypeDescCompletionsForExpression(context, node));
Expand All @@ -76,6 +83,13 @@ public List<LSCompletionItem> getCompletions(BallerinaCompletionContext context,

return completionItems;
}

private boolean isValidTypeName(Node node) {
if (node.kind() == SyntaxKind.SIMPLE_NAME_REFERENCE) {
return !((SimpleNameReferenceNode) node).name().text().isEmpty();
}
return true;
}

private List<LSCompletionItem> getModuleTypeDescCompletionsForExpression(BallerinaCompletionContext context,
TypeTestExpressionNode node) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
{
"position": {
"line": 3,
"character": 26
},
"source": "query_expression/source/query_expr_ctx_source32.bal",
"description": "",
"items": [
{
"label": "where",
"kind": "Keyword",
"detail": "Keyword",
"sortText": "BQ",
"filterText": "where",
"insertText": "where ",
"insertTextFormat": "Snippet"
},
{
"label": "let",
"kind": "Keyword",
"detail": "Keyword",
"sortText": "BQ",
"filterText": "let",
"insertText": "let",
"insertTextFormat": "Snippet"
},
{
"label": "let clause",
"kind": "Snippet",
"detail": "Snippet",
"sortText": "BP",
"filterText": "let",
"insertText": "let ${1:var} ${2:varName} = ${3}",
"insertTextFormat": "Snippet"
},
{
"label": "outer",
"kind": "Keyword",
"detail": "Keyword",
"sortText": "BQ",
"filterText": "outer",
"insertText": "outer ",
"insertTextFormat": "Snippet"
},
{
"label": "join",
"kind": "Keyword",
"detail": "Keyword",
"sortText": "BQ",
"filterText": "join",
"insertText": "join ",
"insertTextFormat": "Snippet"
},
{
"label": "join clause",
"kind": "Snippet",
"detail": "Snippet",
"sortText": "BP",
"filterText": "join",
"insertText": "join ${1:var} ${2:varName} in ${3:expr} on ${4:onExpr} equals ${5:equalsExpr}",
"insertTextFormat": "Snippet"
},
{
"label": "order by",
"kind": "Keyword",
"detail": "Keyword",
"sortText": "BQ",
"filterText": "order by",
"insertText": "order by ",
"insertTextFormat": "Snippet"
},
{
"label": "limit",
"kind": "Keyword",
"detail": "Keyword",
"sortText": "BQ",
"filterText": "limit",
"insertText": "limit ",
"insertTextFormat": "Snippet"
},
{
"label": "do",
"kind": "Snippet",
"detail": "Snippet",
"sortText": "BP",
"filterText": "do",
"insertText": "do {\n\t${1}\n}",
"insertTextFormat": "Snippet"
},
{
"label": "select",
"kind": "Keyword",
"detail": "Keyword",
"sortText": "BQ",
"filterText": "select",
"insertText": "select ",
"insertTextFormat": "Snippet"
},
{
"label": "from",
"kind": "Keyword",
"detail": "Keyword",
"sortText": "BQ",
"filterText": "from",
"insertText": "from ",
"insertTextFormat": "Snippet"
},
{
"label": "group by",
"kind": "Keyword",
"detail": "Keyword",
"sortText": "BQ",
"filterText": "group by",
"insertText": "group by ",
"insertTextFormat": "Snippet"
},
{
"label": "group by clause",
"kind": "Snippet",
"detail": "Snippet",
"sortText": "BP",
"filterText": "group by",
"insertText": "group by ${1:var} ${2:item} = ${3}",
"insertTextFormat": "Snippet"
},
{
"label": "collect",
"kind": "Keyword",
"detail": "Keyword",
"sortText": "BQ",
"filterText": "collect",
"insertText": "collect ",
"insertTextFormat": "Snippet"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
{
"position": {
"line": 5,
"character": 26
},
"source": "query_expression/source/query_expr_ctx_source33.bal",
"description": "",
"items": [
{
"label": "where",
"kind": "Keyword",
"detail": "Keyword",
"sortText": "BQ",
"filterText": "where",
"insertText": "where ",
"insertTextFormat": "Snippet"
},
{
"label": "let",
"kind": "Keyword",
"detail": "Keyword",
"sortText": "BQ",
"filterText": "let",
"insertText": "let",
"insertTextFormat": "Snippet"
},
{
"label": "let clause",
"kind": "Snippet",
"detail": "Snippet",
"sortText": "BP",
"filterText": "let",
"insertText": "let ${1:var} ${2:varName} = ${3}",
"insertTextFormat": "Snippet"
},
{
"label": "outer",
"kind": "Keyword",
"detail": "Keyword",
"sortText": "BQ",
"filterText": "outer",
"insertText": "outer ",
"insertTextFormat": "Snippet"
},
{
"label": "join",
"kind": "Keyword",
"detail": "Keyword",
"sortText": "BQ",
"filterText": "join",
"insertText": "join ",
"insertTextFormat": "Snippet"
},
{
"label": "join clause",
"kind": "Snippet",
"detail": "Snippet",
"sortText": "BP",
"filterText": "join",
"insertText": "join ${1:var} ${2:varName} in ${3:expr} on ${4:onExpr} equals ${5:equalsExpr}",
"insertTextFormat": "Snippet"
},
{
"label": "order by",
"kind": "Keyword",
"detail": "Keyword",
"sortText": "BQ",
"filterText": "order by",
"insertText": "order by ",
"insertTextFormat": "Snippet"
},
{
"label": "limit",
"kind": "Keyword",
"detail": "Keyword",
"sortText": "BQ",
"filterText": "limit",
"insertText": "limit ",
"insertTextFormat": "Snippet"
},
{
"label": "do",
"kind": "Snippet",
"detail": "Snippet",
"sortText": "BP",
"filterText": "do",
"insertText": "do {\n\t${1}\n}",
"insertTextFormat": "Snippet"
},
{
"label": "select",
"kind": "Keyword",
"detail": "Keyword",
"sortText": "BQ",
"filterText": "select",
"insertText": "select ",
"insertTextFormat": "Snippet"
},
{
"label": "from",
"kind": "Keyword",
"detail": "Keyword",
"sortText": "BQ",
"filterText": "from",
"insertText": "from ",
"insertTextFormat": "Snippet"
},
{
"label": "group by",
"kind": "Keyword",
"detail": "Keyword",
"sortText": "BQ",
"filterText": "group by",
"insertText": "group by ",
"insertTextFormat": "Snippet"
},
{
"label": "group by clause",
"kind": "Snippet",
"detail": "Snippet",
"sortText": "BP",
"filterText": "group by",
"insertText": "group by ${1:var} ${2:item} = ${3}",
"insertTextFormat": "Snippet"
},
{
"label": "collect",
"kind": "Keyword",
"detail": "Keyword",
"sortText": "BQ",
"filterText": "collect",
"insertText": "collect ",
"insertTextFormat": "Snippet"
}
]
}
Loading

0 comments on commit b8b78ca

Please sign in to comment.