diff --git a/language/parser.ts b/language/parser.ts index 4217702a..664c426a 100644 --- a/language/parser.ts +++ b/language/parser.ts @@ -557,17 +557,21 @@ export default class Parser { if (includePath) { const include = await this.includeFileFetch(workingUri, includePath); - if (include.found) { - scopes[0].includes.push({ - toPath: include.uri, - line: lineNumber - }); - - try { - await parseContent(include.uri, include.content); - } catch (e) { - console.log(`Error parsing include: ${include.uri}`); - console.log(e); + if (include.found && include.uri) { + if (!scopes[0].includes.some(inc => inc.toPath === include.uri)) { + scopes[0].includes.push({ + toPath: include.uri, + line: lineNumber + }); + + try { + await parseContent(include.uri, include.content); + } catch (e) { + console.log(`Error parsing include: ${include.uri}`); + console.log(e); + } + } else { + console.log(`Circular include detected: ${includePath}`); } } } diff --git a/tests/parserSetup.ts b/tests/parserSetup.ts index f5c5dd88..55d13c4a 100644 --- a/tests/parserSetup.ts +++ b/tests/parserSetup.ts @@ -24,14 +24,14 @@ export default function setupParser(projectRoot = TEST_INCLUDE_DIR): Parser { } const globPath = path.join(`**`, includeFile); - const files = glob.sync(globPath, { + const files: string[] = glob.sync(globPath, { cwd: projectRoot, absolute: true, nocase: true, }); if (files.length >= 1) { - const file = files[0]; + const file = files.find(f => f.toLowerCase().endsWith(`rpgleinc`)) || files[0]; const content = await readFile(file, { encoding: `utf-8` }); diff --git a/tests/sources/rpgle-repl b/tests/sources/rpgle-repl new file mode 160000 index 00000000..b4240b03 --- /dev/null +++ b/tests/sources/rpgle-repl @@ -0,0 +1 @@ +Subproject commit b4240b0314ce9d90dc59c48858e3809ba0924815