Skip to content
This repository has been archived by the owner on Sep 3, 2022. It is now read-only.

Experiment/codelens #2

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"onCommand:watermelon.blame",
"onCommand:watermelon.show",
"onWebviewPanel:watermelon",
"onStartupFinished"
"onStartupFinished",
"onLanguage:javascript"
],
"extensionDependencies": [
"vscode.git"
Expand All @@ -48,6 +49,10 @@
"browser": "./out/extension.js",
"contributes": {
"commands": [
{
"command": "watermelon.addConsoleLog",
"title": "Add Console Log"
},
{
"command": "watermelon.start",
"title": "Get Pull Requests with Watermelon",
Expand Down
37 changes: 37 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,45 @@ export async function activate(context: vscode.ExtensionContext) {
});
}
};
async function addConsoleLog() {
let lineNumStr = await vscode.window.showInputBox({
prompt: "Line Number",
});

let lineNum = lineNumStr ? parseInt(lineNumStr) : 0;
let insertionLocation = new vscode.Range(lineNum - 1, 0, lineNum - 1, 0);
let snippet = new vscode.SnippetString("console.log($1);\n");

vscode.window.activeTextEditor?.insertSnippet(snippet, insertionLocation);
}
class MyCodeLensProvider implements vscode.CodeLensProvider {
async provideCodeLenses(
document: vscode.TextDocument
): Promise<vscode.CodeLens[]> {
let topOfDocument = new vscode.Range(0, 0, 0, 0);

let c: vscode.Command = {
command: "watermelon.addConsoleLog",
title: "Insert console.log",
};

let codeLens = new vscode.CodeLens(topOfDocument, c);

return [codeLens];
}
}
let docSelector = {
language: "javascript",
scheme: "file",
};
let codeLensProviderDisposable = vscode.languages.registerCodeLensProvider(
docSelector,
new MyCodeLensProvider()
);

context.subscriptions.push(codeLensProviderDisposable);
context.subscriptions.push(
vscode.commands.registerCommand("watermelon.addConsoleLog", addConsoleLog),
vscode.commands.registerCommand(
WATERMELON_SHOW_COMMAND,
showCommandHandler
Expand Down