improved variable parsing

improved unused variable checking fix #10
This commit is contained in:
geequlim
2017-03-13 09:48:29 +08:00
parent 77dcdf5a5b
commit 236adcab1c
2 changed files with 3 additions and 3 deletions

View File

@@ -60,9 +60,9 @@ class GDScriptDiagnosticSeverity {
const text = doc.getText();
const check = (name:string, range: vscode.Range) => {
var matchs = text.match(new RegExp(`[^\w]\\s*${name}[^\w]\\s*`, 'g'));
var matchs = text.match(new RegExp(`[^\\w]\\s*${name}[^\\w]\\s*`, 'g'));
let count = matchs?matchs.length:0;
var incomment = text.match(new RegExp(`#.*?[^\w]*${name}[^\w]`, 'g'));
var incomment = text.match(new RegExp(`#.*?[^\\w]*${name}[^\\w]`, 'g'));
count -= incomment?incomment.length:0;
if(count <= 1)
diagnostics.push(new vscode.Diagnostic(range, `${name} is never used.`, DiagnosticSeverity.Warning));

View File

@@ -138,7 +138,7 @@ class GDScriptSymbolParser {
}
let varreg = /var\s+([_A-Za-z]+[_A-Za-z0-9]*)\s*/;
let varreg2 = "var\\s+$X$\\s*";
let varreg2 = "var\\s+$X$([^\\w]|$)";
let vargroup = 1;
if(ignoreIndentedVars) {
varreg = /^((export.*?var)|var)\s+([_A-Za-z]+[_A-Za-z0-9]*)\s?/;