64 lines
2 KiB
JavaScript
64 lines
2 KiB
JavaScript
const vscode = require("vscode");
|
|
const path = require("path");
|
|
|
|
/**
|
|
* @param {vscode.ExtensionContext} context
|
|
*/
|
|
function activate(context) {
|
|
const disposable = vscode.languages.registerHoverProvider("python", {
|
|
/**
|
|
* @param {vscode.TextDocument} document
|
|
* @param {vscode.Position} position
|
|
* @param {vscode.CancellationToken} token
|
|
*/
|
|
async provideHover(document, position, token) {
|
|
const { activeSignature, signatures } =
|
|
await vscode.commands.executeCommand(
|
|
"vscode.executeSignatureHelpProvider",
|
|
document.uri,
|
|
position
|
|
);
|
|
const { label, parameters, activeParameter } =
|
|
signatures[activeSignature];
|
|
const type_name = label
|
|
.substring(...parameters[activeParameter].label)
|
|
.split(":")
|
|
.at(-1)
|
|
.trim();
|
|
const type_list = type_name.split("|").map((x) => x.trim());
|
|
if (!type_list.includes("Res")) return;
|
|
const code_line = document.lineAt(position).text;
|
|
const res_range = document.getWordRangeAtPosition(position, /".*?"/);
|
|
// let start, end;
|
|
// for (start = position.character; start >= 0; --start)
|
|
// if (code_line.charAt(start) == '"') break;
|
|
// for (end = position.character; end < code_line.length; ++end)
|
|
// if (code_line.charAt(end) == '"') break;
|
|
// let res = code_line.substring(start + 1, end);
|
|
// console.log(document.getWordRangeAtPosition(position, /".*?"/));
|
|
let res = code_line.substring(
|
|
res_range.start.character + 1,
|
|
res_range.end.character - 1
|
|
);
|
|
console.log(res);
|
|
if (!res.endsWith(".jpg")) res += ".png";
|
|
const img_path = path.join(
|
|
vscode.workspace.workspaceFolders[0].uri.path,
|
|
"mower",
|
|
"resources",
|
|
res
|
|
);
|
|
const md = new vscode.MarkdownString(``);
|
|
return new vscode.Hover(md);
|
|
},
|
|
});
|
|
|
|
context.subscriptions.push(disposable);
|
|
}
|
|
|
|
function deactivate() {}
|
|
|
|
module.exports = {
|
|
activate,
|
|
deactivate,
|
|
};
|