Add lint configuration to enable or disable some feature for syntax check

This commit is contained in:
geequlim
2018-06-29 12:20:09 +08:00
parent 462a7bdbd7
commit 4c0f864cf8
3 changed files with 25 additions and 3 deletions

View File

@@ -1,5 +1,17 @@
# Change Log
### 0.3.7
* Fix error with run godot editor when the editor contains spaces
* Disable semicolons and brackets checks as default can be enabled with project settings
```json
{
"lint": {
"semicolon": true,
"conditionBrackets": true
}
}
```
### 0.3.6
* Fix project configuartion file path

View File

@@ -3,7 +3,7 @@
"displayName": "Godot Tools",
"icon": "icon.png",
"description": "Tools for game development with godot game engine",
"version": "0.3.6",
"version": "0.3.7",
"publisher": "geequlim",
"repository": "https://github.com/GodotExplorer/godot-tools",
"license": "MIT",
@@ -86,6 +86,14 @@
"type": "boolean",
"default": true,
"description": "Turn on/off the syntax checking for GDScript"
},
"GodotTools.lint": {
"type":"object",
"default": {
"semicolon": false,
"conditionBrackets": false
},
"description": "Lint configurations"
}
}
},

View File

@@ -71,6 +71,8 @@ class GDScriptDiagnosticSeverity {
}
private validateExpression(doc : vscode.TextDocument) {
let cfg : any = vscode.workspace.getConfiguration("GodotTools").get("lint");
let diagnostics = [];
let expectEndOfLine = false;
const text = doc.getText();
@@ -88,7 +90,7 @@ class GDScriptDiagnosticSeverity {
line = "\t" + line + "\t";
var range = new vscode.Range(i, curLineStartAt, i, line.length);
if (line.match(/[^#].*?\;/) && !line.match(/[#].*?\;/)) {
if (cfg.semicolon && line.match(/[^#].*?\;/) && !line.match(/[#].*?\;/)) {
const semicolonIndex = line.indexOf(';');
diagnostics.push(new vscode.Diagnostic(new vscode.Range(i, semicolonIndex, i, semicolonIndex + 1), "Statement contains a semicolon.", DiagnosticSeverity.Warning));
}
@@ -121,7 +123,7 @@ class GDScriptDiagnosticSeverity {
if(!(line.match(/".*?for.*?"/) || line.match(/'.*?for.*?'/)))
diagnostics.push(new vscode.Diagnostic(range, "Invalid for expression", DiagnosticSeverity.Error));
}
else if (line.match(/(if|elif|while|match)\s*\(.*\)/))
else if (cfg.conditionBrackets && line.match(/(if|elif|while|match)\s*\(.*\)/))
diagnostics.push(new vscode.Diagnostic(range, "Extra brackets in condition expression.", DiagnosticSeverity.Warning));
const blockIndetCheck = function() {
const err = new vscode.Diagnostic(range, "Expected indented block after expression", DiagnosticSeverity.Error);