Skip to content

Commit

Permalink
activate extension only for selected languages
Browse files Browse the repository at this point in the history
  • Loading branch information
tintinweb committed Jul 13, 2020
1 parent aeaed70 commit 813b652
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 41 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Change Log

## 0.0.3
- only activate for: typescript, markdown, javascript, solidity

## 0.0.1
- Initial release
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ Hover over an ethereum address and:
* Show reconstructed contract source from [evm.js](https://www.npmjs.com/package/evm)
* run [vscode-decompiler](https://marketplace.visualstudio.com/items?itemName=tintinweb.vscode-decompiler) to decompile it manually using panoramix (eveem.org) locally

### Currently enabled for the following filetypes

* TypeScript
* JavaScript
* Markdown
* Solidity

Let me know if you want to enable this extension for more filetypes.

## Credits

Expand Down
19 changes: 16 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-ethover",
"displayName": "ETHover",
"description": "Ethereum Account Address Hover Info and Actions",
"version": "0.0.2",
"version": "0.0.3",
"keywords": [
"solidity",
"ethereum",
Expand All @@ -27,8 +27,21 @@
},
"main": "./src/extension.js",
"activationEvents": [
"*",
"onCommand:etherscanio.getSource"
"onLanguage:solidity",
"onLanguage:typescript",
"onLanguage:javascript",
"onLanguage:solidity",
"onLanguage:evmtrace",
"onLanguage:evmbytecode",
"onCommand:vscode-ethover.account.getCode",
"onCommand:vscode-ethover.ui.getByteCode",
"onCommand:vscode-ethover.ui.getVerifiedSource",
"onCommand:vscode-ethover.ui.getDecompiledSourceCode",
"onCommand:vscode-ethover.ui.eveem.getDecompiledSourceCode",
"onCommand:vscode-ethover.ui.evmjs.getDecompiledSourceCode",
"onCommand:vscode-ethover.ui.getDisassembledByteCode",
"onCommand:vscode-ethover.activeFile.getDisassembledByteCode",
"onCommand:vscode-ethover.activeFile.evmjs.getDecompiledByteCode"
],
"contributes": {
"languages": [
Expand Down
77 changes: 39 additions & 38 deletions src/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ const evmTrace = require('./features/evm');


const DOC_SELECTOR = [
{ language: "markdown" },
{ language: "solidity" },
{ language: "javascript" },
{ language: "typescript" }
{ language: "typescript" },
];

function openEvmTrace(uri){
function openEvmTrace(uri) {
let fileUri = vscode.Uri.file(uri.concat('.evmtrace'));
let evmTraceUri = fileUri.with({ scheme: 'evmtrace' });

Expand Down Expand Up @@ -52,23 +53,23 @@ function onActivate(context) {
);

context.subscriptions.push(
vscode.languages.registerHoverProvider({language: 'evmtrace'}, {
vscode.languages.registerHoverProvider({ language: 'evmtrace' }, {
provideHover(document, position, token) {
return hover.provideGenericEvmTraceAsmHover(document, position, token);
}
})
);

/* doc content provider */
context.subscriptions.push(vscode.workspace.registerTextDocumentContentProvider('evmtrace', new evmTrace.EvmTraceContentProvider()));
context.subscriptions.push(vscode.workspace.registerTextDocumentContentProvider('evmtrace', new evmTrace.EvmTraceContentProvider()));

/* commands */

context.subscriptions.push(
vscode.commands.registerCommand("vscode-ethover.ui.getByteCode", async () => {
vscode.window.showInputBox({
prompt:"Ethereum Account Address",
placeHolder:"0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae"
prompt: "Ethereum Account Address",
placeHolder: "0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae"
}).then(address => {
etherscan.api.proxy.eth_getCode(address, 'latest').then(resp => {
vscode.workspace.openTextDocument({ content: resp.result, language: "evmbytecode" })
Expand All @@ -82,7 +83,7 @@ function onActivate(context) {

context.subscriptions.push(
vscode.commands.registerCommand("vscode-ethover.ui.getDisassembledByteCode", async (address) => {
if(address){
if (address) {
etherscan.api.proxy.eth_getCode(address, 'latest').then(resp => {
vscode.workspace.openTextDocument({ content: evmTrace.getPrintEvmDisassemblyView(resp.result), language: "evmtrace" })
.then(doc => vscode.window.showTextDocument(doc, vscode.ViewColumn.Beside)).then(editor => evmTrace.decorateEvmTrace(editor));
Expand All @@ -91,8 +92,8 @@ function onActivate(context) {
});
} else {
vscode.window.showInputBox({
prompt:"Ethereum Account Address",
placeHolder:"0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae"
prompt: "Ethereum Account Address",
placeHolder: "0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae"
}).then(address => {
etherscan.api.proxy.eth_getCode(address, 'latest').then(resp => {
vscode.workspace.openTextDocument({ content: evmTrace.getPrintEvmDisassemblyView(resp.result), language: "evmtrace" })
Expand All @@ -108,7 +109,7 @@ function onActivate(context) {
context.subscriptions.push(
vscode.commands.registerCommand("vscode-ethover.activeFile.getDisassembledByteCode", async () => {
let activeEditor = vscode.window.activeTextEditor;
if(!activeEditor ||!activeEditor.document) return;
if (!activeEditor || !activeEditor.document) return;

vscode.workspace.openTextDocument({ content: evmTrace.getPrintEvmDisassemblyView(activeEditor.document.getText()), language: "evmtrace" })
.then(doc => vscode.window.showTextDocument(doc, vscode.ViewColumn.Beside)).then(editor => evmTrace.decorateEvmTrace(editor));
Expand All @@ -117,7 +118,7 @@ function onActivate(context) {

context.subscriptions.push(
vscode.commands.registerCommand("vscode-ethover.ui.evmjs.getDecompiledSourceCode", async (address) => {
if(address){
if (address) {
etherscan.api.proxy.eth_getCode(address, 'latest').then(resp => {
vscode.workspace.openTextDocument({ content: evmTrace.getDecompiledByteCode(resp.result), language: "solidity" })
.then(doc => vscode.window.showTextDocument(doc, vscode.ViewColumn.Beside));
Expand All @@ -126,8 +127,8 @@ function onActivate(context) {
});
} else {
vscode.window.showInputBox({
prompt:"Ethereum Account Address",
placeHolder:"0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae"
prompt: "Ethereum Account Address",
placeHolder: "0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae"
}).then(address => {
etherscan.api.proxy.eth_getCode(address, 'latest').then(resp => {
vscode.workspace.openTextDocument({ content: evmTrace.getDecompiledByteCode(resp.result), language: "solidity" })
Expand All @@ -144,7 +145,7 @@ function onActivate(context) {
context.subscriptions.push(
vscode.commands.registerCommand("vscode-ethover.activeFile.evmjs.getDecompiledByteCode", async () => {
let activeEditor = vscode.window.activeTextEditor;
if(!activeEditor ||!activeEditor.document) return;
if (!activeEditor || !activeEditor.document) return;

vscode.workspace.openTextDocument({ content: evmTrace.getDecompiledByteCode(activeEditor.document.getText()), language: "solidity" })
.then(doc => vscode.window.showTextDocument(doc, vscode.ViewColumn.Beside));
Expand All @@ -154,8 +155,8 @@ function onActivate(context) {
context.subscriptions.push(
vscode.commands.registerCommand("vscode-ethover.ui.getVerifiedSource", async () => {
vscode.window.showInputBox({
prompt:"Ethereum Account Address",
placeHolder:"0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae"
prompt: "Ethereum Account Address",
placeHolder: "0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae"
}).then(address => {
etherscan.getVerifiedSource(address)
.then(content => {
Expand All @@ -172,8 +173,8 @@ function onActivate(context) {
context.subscriptions.push(
vscode.commands.registerCommand("vscode-ethover.ui.getDecompiledSourceCode", async () => {
vscode.window.showInputBox({
prompt:"Ethereum Account Address",
placeHolder:"0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae"
prompt: "Ethereum Account Address",
placeHolder: "0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae"
}).then(address => {
etherscan.api.proxy.eth_getCode(address, 'latest').then(resp => {
vscode.commands.executeCommand("vscode-decompiler.decompileShowContent", `${address}.evm`, resp.result)
Expand All @@ -189,32 +190,32 @@ function onActivate(context) {

context.subscriptions.push(
vscode.commands.registerCommand("vscode-ethover.ui.eveem.getDecompiledSourceCode", async (address) => {
if(address){
if (address) {
eveem.eveemGetDecompiledSource(address).then(resp => {
vscode.workspace.openTextDocument({ content: resp, language: "python" })
.then(doc => vscode.window.showTextDocument(doc, vscode.ViewColumn.Beside));
})
.catch(err => {
vscode.window.showWarningMessage(err.message);
});
.catch(err => {
vscode.window.showWarningMessage(err.message);
});
} else {
vscode.window.showInputBox({
prompt:"Ethereum Account Address",
placeHolder:"0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae"
prompt: "Ethereum Account Address",
placeHolder: "0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae"
}).then(address => {
eveem.eveemGetDecompiledSource(address).then(resp => {
vscode.workspace.openTextDocument({ content: resp, language: "python" })
.then(doc => vscode.window.showTextDocument(doc, vscode.ViewColumn.Beside));
})
.catch(err => {
vscode.window.showWarningMessage(err.message);
});
.catch(err => {
vscode.window.showWarningMessage(err.message);
});
});
}
})
);



context.subscriptions.push(
vscode.commands.registerCommand("vscode-ethover.account.getCode", async (args) => {
Expand Down Expand Up @@ -260,35 +261,35 @@ function onActivate(context) {

vscode.workspace.onDidChangeTextDocument(e => {
if (e && e.document) {
if(e.document.uri.scheme === 'evmtrace' || e.document.languageId=='evmtrace'){
if (e.document.uri.scheme === 'evmtrace' || e.document.languageId == 'evmtrace') {
evmTrace.decorateEvmTrace(activeEditor);
} else if (e.document.uri.scheme === 'evmbytecode' || e.document.languageId=='evmbytecode'){
} else if (e.document.uri.scheme === 'evmbytecode' || e.document.languageId == 'evmbytecode') {
evmTrace.decorateEvmByteCode(activeEditor);
}
}
}
}, null, context.subscriptions);
}, null, context.subscriptions);

vscode.window.onDidChangeActiveTextEditor(e => {
if (e && e.document) {
if(e.document.uri.scheme === 'evmtrace' || e.document.languageId=='evmtrace'){
if (e.document.uri.scheme === 'evmtrace' || e.document.languageId == 'evmtrace') {
activeEditor = e;
evmTrace.decorateEvmTrace(e);
} else if (e.document.uri.scheme === 'evmbytecode' || e.document.languageId=='evmbytecode'){
} else if (e.document.uri.scheme === 'evmbytecode' || e.document.languageId == 'evmbytecode') {
activeEditor = e;
evmTrace.decorateEvmByteCode(e);
}
}
}
}, null, context.subscriptions);

vscode.window.onDidChangeTextEditorSelection(e => {
if (!e || !e.textEditor || !e.selections) {
return;
}
if (e.textEditor.document.uri.scheme === 'evmbytecode' || e.textEditor.document.languageId=='evmbytecode'){
if (e.textEditor.document.uri.scheme === 'evmbytecode' || e.textEditor.document.languageId == 'evmbytecode') {
activeEditor = e.textEditor;
evmTrace.decorateEvmByteCodeSelection(e.textEditor, e.selections[0].anchor);
}
}

}, null, context.subscriptions);
}

Expand Down

0 comments on commit 813b652

Please sign in to comment.