Skip to content

Commit

Permalink
Merge pull request #143 from halcyon-tech/feature/gotoDefintion_include
Browse files Browse the repository at this point in the history
Go to definition for include and copy directive
  • Loading branch information
worksofliam authored Oct 20, 2022
2 parents e63ac4c + 4732732 commit 9400f9c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 42 deletions.
6 changes: 0 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,6 @@
]
},
"keybindings": [
{
"command": "vscode-rpgle.rpgleOpenInclude",
"key": "shift+f12",
"mac": "shift+f12",
"when": "editorLangId == rpgle"
},
{
"command": "vscode-rpgle.rpgleColumnAssistant",
"key": "shift+f4",
Expand Down
72 changes: 36 additions & 36 deletions src/vscode/LanguageWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,6 @@ module.exports = class LanguageWorker {
this.editTimeout = undefined;

context.subscriptions.push(
vscode.commands.registerCommand(`vscode-rpgle.rpgleOpenInclude`, async () => {
const editor = vscode.window.activeTextEditor;

if (editor) {
const document = editor.document;
const position = editor.selection.active;
if (document.languageId === rpgLanguageid) {
const linePieces = document.lineAt(position.line).text.trim().split(` `);
const copyIndex = linePieces.findIndex(piece => {
if (piece.includes(`*`)) return false; // Comment
const pieceUpper = piece.toUpperCase();
return (pieceUpper.includes(`/COPY`) || pieceUpper.includes(`/INCLUDE`));
});

if (copyIndex >= 0 && linePieces[copyIndex+1]) {
const {uri} = await Parser.getContent(document.uri, linePieces[copyIndex+1]);

if (uri) {
vscode.workspace.openTextDocument(uri).then(doc => {
vscode.window.showTextDocument(doc);
});
}
}
}
}
}),

vscode.commands.registerCommand(`vscode-rpgle.rpgleGetPrototype`, () => {
const editor = vscode.window.activeTextEditor;

Expand Down Expand Up @@ -134,7 +107,6 @@ module.exports = class LanguageWorker {
const range = document.getWordRangeAtPosition(position);
const word = document.getText(range).toUpperCase();

const linePieces = document.lineAt(position.line).text.trim().split(` `);
const procedure = doc.procedures.find(proc => proc.name.toUpperCase() === word);

if (procedure) {
Expand Down Expand Up @@ -202,18 +174,15 @@ module.exports = class LanguageWorker {
)

} else {
const copyIndex = linePieces.findIndex(piece => {
if (piece.includes(`*`)) return false; // Comment
const pieceUpper = piece.toUpperCase();
return (pieceUpper.includes(`/COPY`) || pieceUpper.includes(`/INCLUDE`));
});

const possiblePath = LanguageWorker.getIncludeFromDirective(document.lineAt(position.line).text);

if (copyIndex >= 0 && linePieces[copyIndex+1]) {
const include = await Parser.getContent(document.uri, linePieces[copyIndex+1]);
if (possiblePath) {
const include = await Parser.getContent(document.uri, possiblePath);

return new vscode.Hover(
new vscode.MarkdownString(
(include.path ? `\`${include.path}\`` : linePieces[1]) + `(${include.type}${include.found ? `` : `, not found`})`
(include.path ? `\`${include.path}\`` : possiblePath) + `(${include.type}${include.found ? `` : `, not found`})`
)
)
}
Expand Down Expand Up @@ -448,6 +417,19 @@ module.exports = class LanguageWorker {
}
}
}

const possiblePath = LanguageWorker.getIncludeFromDirective(document.lineAt(line).text);
if (possiblePath) {
const {uri} = await Parser.getContent(document.uri, possiblePath);

if (uri) {
return new vscode.Location(
uri,
new vscode.Range(0, 0, 0, 0)
);
}

}
}}
),

Expand Down Expand Up @@ -810,4 +792,22 @@ module.exports = class LanguageWorker {
return globalDef;
}
}

/**
* Parses a line to get include/copy path
* @param {string} line
* @returns {string|undefined}
*/
static getIncludeFromDirective(line) {
const linePieces = line.trim().split(` `);
const copyIndex = linePieces.findIndex(piece => {
if (piece.includes(`*`)) return false; // Comment
const pieceUpper = piece.toUpperCase();
return (pieceUpper.includes(`/COPY`) || pieceUpper.includes(`/INCLUDE`));
});

if (copyIndex >= 0 && linePieces[copyIndex+1]) {
return linePieces[copyIndex+1];
}
}
}

0 comments on commit 9400f9c

Please sign in to comment.