Skip to content

Commit

Permalink
Fix issue with comments after end of statement
Browse files Browse the repository at this point in the history
Signed-off-by: Liam Barry Allan <[email protected]>
  • Loading branch information
worksofliam committed Aug 5, 2022
1 parent 54280c8 commit 9d006df
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 17 deletions.
28 changes: 13 additions & 15 deletions src/language/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, ` `);
}

Expand All @@ -214,7 +212,7 @@ module.exports = class Linter {
if (upperLine.startsWith(`//`)) {
currentStatement = ``;
} else if (upperLine.startsWith(`/`)) {
// But not directives!
// But not directives!
continuedStatement = false;
}

Expand Down
33 changes: 31 additions & 2 deletions tests/suite/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 9d006df

Please sign in to comment.