diff --git a/src/language/linter.js b/src/language/linter.js index 71654977..d3e4793c 100644 --- a/src/language/linter.js +++ b/src/language/linter.js @@ -186,24 +186,22 @@ module.exports = class Linter { } if (!isLineComment) { - if (line.endsWith(`;`)) { - statementEnd = new vscode.Position(lineNumber, line.length - 1); - line = line.substr(0, line.length-1); + const semiIndex = line.lastIndexOf(`;`); + const commentIndex = line.lastIndexOf(`//`); + + if (commentIndex > semiIndex && semiIndex >= 0) { + // Replace comments after the semicolon... + line = line.substring(0, semiIndex+1) + ``.padEnd(line.length - semiIndex - 1); + } + + if (line.trimEnd().endsWith(`;`)) { + statementEnd = new vscode.Position(lineNumber, semiIndex); + line = line.substring(0, semiIndex); currentStatement += line; continuedStatement = false; } else { - - const semiIndex = line.lastIndexOf(`;`); - const commentIndex = line.lastIndexOf(`//`); - - if (commentIndex > semiIndex && semiIndex >= 0) { - statementEnd = new vscode.Position(lineNumber, line.lastIndexOf(`;`)); - line = line.substr(0, semiIndex); - continuedStatement = false; - } else { - continuedStatement = true; - } + continuedStatement = true; currentStatement += currentLine + ``.padEnd(newLineLength, ` `); } @@ -214,7 +212,7 @@ module.exports = class Linter { if (upperLine.startsWith(`//`)) { currentStatement = ``; } else if (upperLine.startsWith(`/`)) { - // But not directives! + // But not directives! continuedStatement = false; } diff --git a/tests/suite/linter.js b/tests/suite/linter.js index 4ec087ef..94bcb8c2 100644 --- a/tests/suite/linter.js +++ b/tests/suite/linter.js @@ -2229,9 +2229,38 @@ exports.linter35 = async () => { const parser = new Parser(); const cache = await parser.getDocs(uri, lines); - const { indentErrors } = Linter.getErrors({uri, content: lines}, { + const { errors } = Linter.getErrors({uri, content: lines}, { + ForceOptionalParens: true + }, cache); + + assert.strictEqual(errors.length, 0); +} + +exports.linter36 = async () => { + const lines = [ + `**FREE`, + ``, + `Ctl-Opt DFTACTGRP(*No);`, + ``, + `// My variable`, + `Dcl-s MyVariable2 Char(20);`, + `Dcl-s abcd ind;`, + ``, + `myVariable2 = *blank; // Why comment here`, + ``, + `// a comment // Why comment here`, + `if (abcd = *off); // Why comment here`, + ` // Inside if`, + ` MyVariable2 = 'Hello world'; // Why comment here`, + `Endif; // Why comment here`, + `Return;` + ].join(`\n`); + + const parser = new Parser(); + const cache = await parser.getDocs(uri, lines); + const { errors } = Linter.getErrors({uri, content: lines}, { ForceOptionalParens: true }, cache); - assert.strictEqual(indentErrors.length, 0); + assert.strictEqual(errors.length, 0); } \ No newline at end of file