diff --git a/src/language/parser.js b/src/language/parser.js index 9cd8f24e..efbefb15 100644 --- a/src/language/parser.js +++ b/src/language/parser.js @@ -121,13 +121,18 @@ module.exports = class Parser { /** * @param {vscode.Uri} workingUri Path being worked with * @param {string} getPath IFS or member path to fetch - * @returns {Promise} + * @returns {Promise<{lines: string[], found: boolean, uri: vscode.Uri, path: string, type: "member"|"streamfile"|"file"}>} + * @deprecated Use `Parser.getContent` instead. */ async getContent(workingUri, getPath) { //const hrstart = process.hrtime(); let content; let lines = undefined; + + let uri; + let found = true; + let attemptedPath; let {type, memberPath, finishedPath} = Generic.getPathInfo(workingUri, getPath); @@ -136,6 +141,7 @@ module.exports = class Parser { let eol; switch (type) { case `member`: + attemptedPath = finishedPath; // We have to be agnostic for the type. First we check if we opened a copybook before. const openDoc = vscode.workspace.textDocuments.find(doc => @@ -149,22 +155,26 @@ module.exports = class Parser { // Otherwise, we go and fetch the correct content doc = await vscode.workspace.openTextDocument(vscode.Uri.from({ scheme: type, - path: finishedPath + `.MBR` + path: finishedPath + `.RPGLE` })); } eol = doc.eol === vscode.EndOfLine.CRLF ? `\r\n` : `\n`; + uri = doc.uri; lines = doc.getText().split(eol); break; case `streamfile`: + attemptedPath = finishedPath; + doc = await vscode.workspace.openTextDocument(vscode.Uri.from({ scheme: type, path: finishedPath })); eol = doc.eol === vscode.EndOfLine.CRLF ? `\r\n` : `\n`; + uri = doc.uri; lines = doc.getText().split(eol); break; @@ -184,6 +194,8 @@ module.exports = class Parser { getPath = memberParts.join(path.sep) + `*` } + attemptedPath = getPath; + /** @type {vscode.Uri} */ let possibleFile; @@ -200,20 +212,29 @@ module.exports = class Parser { if (possibleFile) { content = (await vscode.workspace.fs.readFile(possibleFile)).toString(); + uri = possibleFile; lines = content.replace(new RegExp(`\\\r`, `g`), ``).split(`\n`); } else { lines = []; + found = false; } break; } } catch (e) { lines = []; + found = false; } //const hrend = process.hrtime(hrstart); //console.info(`getContent() took ${hrend[0]}s and ${hrend[1] / 1000000}ms: ${getPath} (${lines.length})`); - return lines; + return { + lines, + path: attemptedPath, + uri, + found, + type + }; } /** @@ -362,9 +383,15 @@ module.exports = class Parser { pieces = line.split(` `).filter(piece => piece !== ``); + this.brokenPaths = []; + if ([`/COPY`, `/INCLUDE`].includes(pieces[0].toUpperCase())) { - files[pieces[1]] = (await this.getContent(workingUri, pieces[1])); + const include = (await this.getContent(workingUri, pieces[1])); + files[pieces[1]] = include.lines; fileList.push(pieces[1]); + + if (include.lines.length === 0) { + } } } } diff --git a/src/vscode/LanguageWorker.js b/src/vscode/LanguageWorker.js index 3294a81c..e6b1988c 100644 --- a/src/vscode/LanguageWorker.js +++ b/src/vscode/LanguageWorker.js @@ -16,7 +16,7 @@ module.exports = class LanguageWorker { */ constructor(context) { context.subscriptions.push( - vscode.commands.registerCommand(`vscode-rpgle.rpgleOpenInclude`, () => { + vscode.commands.registerCommand(`vscode-rpgle.rpgleOpenInclude`, async () => { const editor = vscode.window.activeTextEditor; if (editor) { @@ -25,22 +25,12 @@ module.exports = class LanguageWorker { if (document.languageId === `rpgle`) { const linePieces = document.lineAt(position.line).text.trim().split(` `); if ([`/COPY`, `/INCLUDE`].includes(linePieces[0].toUpperCase())) { - const {finishedPath, type} = Generic.getPathInfo(document.uri, linePieces[1]); + const {uri} = await Parser.getContent(document.uri, linePieces[1]); - switch (type) { - case `member`: - vscode.commands.executeCommand(`code-for-ibmi.openEditable`, `${finishedPath.substring(1)}.rpgle`); - break; - - case `streamfile`: - vscode.commands.executeCommand(`code-for-ibmi.openEditable`, finishedPath); - break; - - case `file`: - vscode.workspace.openTextDocument(vscode.Uri.file(finishedPath)).then(doc => { + if (uri) { + vscode.workspace.openTextDocument(uri).then(doc => { vscode.window.showTextDocument(doc); }); - break; } } } @@ -179,11 +169,11 @@ module.exports = class LanguageWorker { } else { if ([`/COPY`, `/INCLUDE`].includes(linePieces[0].toUpperCase())) { - const {type, memberPath, finishedPath} = Generic.getPathInfo(document.uri, linePieces[1]); + const include = await Parser.getContent(document.uri, linePieces[1]); return new vscode.Hover( new vscode.MarkdownString( - `\`'${finishedPath}'\` (${type})` + `\`'${include.path}'\` (${include.type}${include.found ? `` : `, not found`})` ) ) } @@ -360,22 +350,20 @@ module.exports = class LanguageWorker { } if (def) { - let {finishedPath, type} = Generic.getPathInfo(document.uri, def.position.path); - if (document.uri.path.startsWith(finishedPath)) { + let {path, type, uri} = await Parser.getContent(document.uri, def.position.path); + if (document.uri.path.startsWith(path)) { return new vscode.Location( document.uri, new vscode.Range(def.position.line, 0, def.position.line, 0) ); } else { - if (type === `member`) { - finishedPath = `${finishedPath}.rpgle`; + if (uri) { + return new vscode.Location( + uri, + new vscode.Range(def.position.line, 0, def.position.line, 0) + ); } - - return new vscode.Location( - vscode.Uri.parse(finishedPath).with({scheme: type, path: finishedPath}), - new vscode.Range(def.position.line, 0, def.position.line, 0) - ); } } } diff --git a/src/vscode/LinterWorker.js b/src/vscode/LinterWorker.js index ea6f0cfb..eaeeb2d3 100644 --- a/src/vscode/LinterWorker.js +++ b/src/vscode/LinterWorker.js @@ -392,7 +392,7 @@ module.exports = class LinterWorker { const possibleJson = await this.getLinterFile(workingUri); if (possibleJson) { - const jsonString = possibleJson.join(``).trim(); + const jsonString = possibleJson.lines.join(``).trim(); if (jsonString) { try { options = JSON.parse(jsonString);