Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class LvExpressionDiagnosticRequest extends DiagnosticsRequest {
private static final DiagnosticErrorCode INVALID_EXPRESSION_CODE = DiagnosticErrorCode.INVALID_EXPR_STATEMENT;
private static final DiagnosticErrorCode UNDERSCORE_NOT_ALLOWED_CODE =
DiagnosticErrorCode.UNDERSCORE_NOT_ALLOWED_AS_IDENTIFIER;
private static final DiagnosticErrorCode VARIABLE_NOT_INITIALIZED_CODE =
DiagnosticErrorCode.USAGE_OF_UNINITIALIZED_VARIABLE;

public LvExpressionDiagnosticRequest(ExpressionEditorContext context) {
super(context);
Expand Down Expand Up @@ -109,8 +111,14 @@ protected Set<Diagnostic> getSemanticDiagnostics(ExpressionEditorContext context
context.workspaceManager().semanticModel(context.filePath());
return semanticModel.map(model -> model.diagnostics(lineRange).stream()
.filter(diagnostic -> diagnostic.diagnosticInfo().severity() == DiagnosticSeverity.ERROR
&& !UNDERSCORE_NOT_ALLOWED_CODE.diagnosticId().equals(diagnostic.diagnosticInfo().code()))
&& isRelevantDiagnostic(diagnostic))
.map(CommonUtils::transformBallerinaDiagnostic)
.collect(Collectors.toSet())).orElseGet(Set::of);
}

private boolean isRelevantDiagnostic(io.ballerina.tools.diagnostics.Diagnostic diagnostic) {
String code = diagnostic.diagnosticInfo().code();
return !UNDERSCORE_NOT_ALLOWED_CODE.diagnosticId().equals(code)
&& !VARIABLE_NOT_INITIALIZED_CODE.diagnosticId().equals(code);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"description": "Uninitialized variable",
"filePath": "empty.bal",
"context": {
"expression": "var1",
"startLine": {
"line": 4,
"offset": 22
},
"offset": 0,
"lineOffset": 0,
"codedata": {
"node": "ASSIGN",
"isNew": true
},
"property": {
"metadata": {
"label": "Variable",
"description": "Name of the variable/field"
},
"optional": false,
"editable": true,
"advanced": false,
"types": [
{
"fieldType": "LV_EXPRESSION",
"selected": false
}
],
"diagnostics": {
"hasDiagnostics": false,
"diagnostics": []
}
}
},
"diagnostics": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import ballerina/log;

public function main() returns error? {
do {
string[] var1;
} on fail error e {
log:printError("Error occurred", 'error = e);
return e;
}
}
Loading