-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.js
More file actions
69 lines (60 loc) · 1.84 KB
/
Copy pathextension.js
File metadata and controls
69 lines (60 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const vscode = require('vscode');
const editor = vscode.window.activeTextEditor;
const assert = require('assert');
const python = require('python-bridge');
// @ts-ignore
const py = python();
/**
* @param {vscode.ExtensionContext} context
*/
function activate(context) {
console.log('Congratulations, your extension "easyimport" is now active!');
// Activation method
let disposable1 = vscode.commands.registerCommand('easyimport.runEasyImport', function () {
vscode.window.showInformationMessage('The extension EasyImport has been activated!');
});
// Main function
let disposable2 = vscode.commands.registerCommand('easyimport.FindPathVersion', function () {
FindPathVersion();
});
context.subscriptions.push(disposable1, disposable2);
}
async function FindPathVersion(){
// Hihglighted text = library name
const lib = editor.document.getText(editor.selection);
// Python Scripts to run
py.ex`import os`;
py.ex`
def find(lib_name):
try:
lib = __import__(lib_name)
except:
return "The library <" + lib_name + "> is not found.", None
path = os.path.dirname(lib.__file__)
try:
version = lib.__version__
except:
return "The library <" + lib_name + "> do not have version variable.", None
return "Path: " + path, "Version: " + version`;
// Returning output and error-handling
try {
py`find(${lib})`.then(output => {
if (output[1] === null) {
vscode.window.showInformationMessage(output[0]);
console.log(output[0].toString());
} else {
console.log(output[0].toString() + "\n" + output[1].toString());
vscode.window.showInformationMessage(output[0]);
vscode.window.showInformationMessage(output[1]);
};
console.log('Extension runs successfully!');
});
} catch(error) {
console.log('Error: '+ error);
};
}
function deactivate() {}
module.exports = {
activate,
deactivate
}