Skip to content

Commit c47c53f

Browse files
authored
Merge pull request #335 from sebCIL/Fix/copy_include_error
Fix(getIncludeFromDirective): ignore the comment line
2 parents 5b1a6bd + 2c34494 commit c47c53f

File tree

2 files changed

+82
-22
lines changed

2 files changed

+82
-22
lines changed

language/parser.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export default class Parser {
126126
*/
127127
static getIncludeFromDirective(line) {
128128
if (line.includes(`*`)) return; // Likely comment
129-
if (line.includes(`//`)) return; // Likely comment
129+
if (line.trim().startsWith(`//`)) return; // Likely comment
130130

131131
const upperLine = line.toUpperCase();
132132
let comment = -1;
@@ -441,23 +441,23 @@ export default class Parser {
441441
// End of parsing for this file
442442
break;
443443
} else
444-
if (parts[0] === `/IF`) {
444+
if (parts[0] === `/IF`) {
445445
// Directive IF
446-
directIfScope += 1;
447-
continue;
448-
} else
449-
if (parts[0] === `/ENDIF`) {
450-
// Directive ENDIF
451-
directIfScope -= 1;
452-
continue;
453-
} else
454-
if (directIfScope > 0) {
455-
// Ignore lines inside the IF scope.
456-
continue;
457-
} else
458-
if (line.startsWith(`/`)) {
459-
continue;
460-
}
446+
directIfScope += 1;
447+
continue;
448+
} else
449+
if (parts[0] === `/ENDIF`) {
450+
// Directive ENDIF
451+
directIfScope -= 1;
452+
continue;
453+
} else
454+
if (directIfScope > 0) {
455+
// Ignore lines inside the IF scope.
456+
continue;
457+
} else
458+
if (line.startsWith(`/`)) {
459+
continue;
460+
}
461461
}
462462

463463
if (pieces.length > 1 && pieces[1].includes(`//`)) line = pieces[0] + `;`;
@@ -671,9 +671,9 @@ export default class Parser {
671671
if (dsScopes.length === 1) {
672672
scope.structs.push(dsScopes.pop());
673673
} else
674-
if (dsScopes.length > 1) {
675-
dsScopes[dsScopes.length - 2].subItems.push(dsScopes.pop());
676-
}
674+
if (dsScopes.length > 1) {
675+
dsScopes[dsScopes.length - 2].subItems.push(dsScopes.pop());
676+
}
677677
break;
678678

679679
case `DCL-PR`:
@@ -914,8 +914,8 @@ export default class Parser {
914914
currentSqlItem.name = qualifiedObjectPath.name;
915915

916916
if (currentSqlItem.name)
917-
918-
currentSqlItem.keywords = [];
917+
currentSqlItem.keywords = [];
918+
919919
currentSqlItem.description = qualifiedObjectPath.schema || ``;
920920

921921
currentSqlItem.position = {

tests/suite/basics.test.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,66 @@ test('test12', async () => {
398398
expect(theLocalProc.scope.variables.length).toBe(1);
399399
});
400400

401+
test('test13', async () => {
402+
const lines = [
403+
`**FREE`,
404+
``,
405+
`Ctl-Opt DftActGrp(*No);`,
406+
``,
407+
`/copy './tests/rpgle/copy1.rpgle' // Test copy`,
408+
``,
409+
`Dcl-S globalVar Char(20);`,
410+
``,
411+
`Dcl-C theConstant 'Hello world';`,
412+
``,
413+
`globalVar = theConstant;`,
414+
``,
415+
`theLocalProc(globalVar);`,
416+
``,
417+
`Return;`,
418+
``,
419+
`Dcl-Proc theLocalProc;`,
420+
` Dcl-Pi *N;`,
421+
` newValue Char(20);`,
422+
` End-Pi;`,
423+
` Dcl-S localVar Char(20);`,
424+
` localVar = %trimr(newValue) + '!';`,
425+
` globalVar = localVar;`,
426+
`End-Proc;`,
427+
``
428+
].join(`\n`);
429+
430+
const cache = await parser.getDocs(uri, lines, {withIncludes: true, ignoreCache: true});
431+
432+
expect(cache.includes.length).toBe(1);
433+
434+
expect(cache.variables.length).toBe(1);
435+
expect(cache.constants.length).toBe(1);
436+
437+
// One prototype and one declared
438+
expect(cache.procedures.length).toBe(2);
439+
440+
// Valid names
441+
expect(cache.procedures[0].name).toBe(`theExtProcedure`);
442+
expect(cache.procedures[1].name).toBe(`theLocalProc`);
443+
444+
const theLocalProc = cache.find(`theLocalProc`);
445+
446+
expect(theLocalProc.range).toEqual({
447+
start: 16,
448+
end: 23
449+
});
450+
451+
// Has a parameter
452+
expect(theLocalProc.subItems.length).toBe(1);
453+
454+
// Has a local scope
455+
expect(theLocalProc.scope !== undefined).toBe(true);
456+
457+
// Should have a local variable
458+
expect(theLocalProc.scope.variables.length).toBe(1);
459+
});
460+
401461
test('indicators1', async () => {
402462
const lines = [
403463
`**FREE`,

0 commit comments

Comments
 (0)