Skip to content
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
72 changes: 41 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,12 @@
"main": "./out/extension",
"contributes": {
"views": {
"explorer": [
{
"id": "mysql",
"name": "MySQL"
}
]
"explorer": [{
"id": "mysql",
"name": "MySQL"
}]
},
"commands": [
{
"commands": [{
"command": "mysql.refresh",
"title": "Refresh",
"category": "MySQL"
Expand Down Expand Up @@ -77,32 +74,35 @@
"command": "mysql.selectTop1000",
"title": "Select Top 1000",
"category": "MySQL"
}
],
"keybindings": [
},
{
"command": "mysql.runQuery",
"key": "ctrl+alt+e",
"when": "editorLangId == sql"
"command": "mysql.copyToClipboard",
"title": "Copy To Clipboard",
"category": "MySQL"
},
{
"command": "mysql.pasteToActiveEditor",
"title": "Paste To Active Editor",
"category": "MySQL"
}
],
"keybindings": [{
"command": "mysql.runQuery",
"key": "ctrl+alt+e",
"when": "editorLangId == sql"
}],
"menus": {
"editor/context": [
{
"command": "mysql.runQuery",
"when": "editorLangId == sql",
"group": "navigation"
}
],
"view/title": [
{
"command": "mysql.addConnection",
"when": "view == mysql",
"group": "navigation@1"
}
],
"view/item/context": [
{
"editor/context": [{
"command": "mysql.runQuery",
"when": "editorLangId == sql",
"group": "navigation"
}],
"view/title": [{
"command": "mysql.addConnection",
"when": "view == mysql",
"group": "navigation@1"
}],
"view/item/context": [{
"command": "mysql.newQuery",
"when": "view == mysql && viewItem == connection",
"group": "mysql@1"
Expand Down Expand Up @@ -136,6 +136,16 @@
"command": "mysql.refresh",
"when": "view == mysql && viewItem == table",
"group": "mysql@1"
},
{
"command": "mysql.copyToClipboard",
"when": "view == mysql && viewItem != connection",
"group": "mysql@3"
},
{
"command": "mysql.pasteToActiveEditor",
"when": "view == mysql && viewItem != connection",
"group": "mysql@3"
}
]
},
Expand Down Expand Up @@ -178,4 +188,4 @@
"mysql": "^2.15.0",
"uuid": "^3.1.0"
}
}
}
14 changes: 13 additions & 1 deletion src/common/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class Utility {
if (rows.some(((row) => Array.isArray(row)))) {
rows.forEach((row, index) => {
if (Array.isArray(row)) {
Utility.showQueryResult(row, "Results " + (index + 1));
Utility.showQueryResult(row, "Results " + (index + 1));
} else {
OutputChannel.appendLine(JSON.stringify(row));
}
Expand Down Expand Up @@ -104,6 +104,18 @@ export class Utility {
return mysql.createConnection(newConnectionOptions);
}

public static copyToClipboard(text: string) {
vscode.env.clipboard.writeText(text);
}

public static pasteToActiveEditor(text: string) {
const activeEditor = vscode.window.activeTextEditor;

if (activeEditor) {
activeEditor.insertSnippet(new vscode.SnippetString(text));
}
}

private static getPreviewUri(data) {
const uri = vscode.Uri.parse("sqlresult://mysql/data");

Expand Down
9 changes: 9 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import * as vscode from "vscode";
import { AppInsightsClient } from "./common/appInsightsClient";
import { Utility } from "./common/utility";
import { ColumnNode } from "./model/columnNode";
import { ConnectionNode } from "./model/connectionNode";
import { DatabaseNode } from "./model/databaseNode";
import { INode } from "./model/INode";
Expand Down Expand Up @@ -38,6 +39,14 @@ export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(vscode.commands.registerCommand("mysql.selectTop1000", (tableNode: TableNode) => {
tableNode.selectTop1000();
}));

context.subscriptions.push(vscode.commands.registerCommand("mysql.copyToClipboard", (node: (TableNode | DatabaseNode | ColumnNode)) => {
node.copyToClipboard();
}));

context.subscriptions.push(vscode.commands.registerCommand("mysql.pasteToActiveEditor", (node: (TableNode | DatabaseNode | ColumnNode)) => {
node.pasteToActiveEditor();
}));
}

export function deactivate() {
Expand Down
8 changes: 8 additions & 0 deletions src/model/columnNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,12 @@ export class ColumnNode implements INode {
public async getChildren(): Promise<INode[]> {
return [];
}

public copyToClipboard() {
Utility.copyToClipboard(this.column.COLUMN_NAME);
}

public pasteToActiveEditor() {
Utility.pasteToActiveEditor(this.column.COLUMN_NAME);
}
}
8 changes: 8 additions & 0 deletions src/model/databaseNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,12 @@ export class DatabaseNode implements INode {
certPath: this.certPath,
};
}

public copyToClipboard() {
Utility.copyToClipboard(this.database);
}

public pasteToActiveEditor() {
Utility.pasteToActiveEditor(this.database);
}
}
8 changes: 8 additions & 0 deletions src/model/tableNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,12 @@ export class TableNode implements INode {

Utility.runQuery(sql, connection);
}

public copyToClipboard() {
Utility.copyToClipboard(this.table);
}

public pasteToActiveEditor() {
Utility.pasteToActiveEditor(this.table);
}
}