Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection Session Files #188

Merged
merged 11 commits into from May 18, 2019

fsprovider: Session files working. Missing docs

  • Loading branch information...
mtxr committed May 16, 2019
commit f5a670a29810850735e9e297ebd12d1fd68b05b4
@@ -18,7 +18,6 @@ import DependencyManagerPlugin from '@sqltools/plugins/dependency-manager/extens
import HistoryManagerPlugin from '@sqltools/plugins/history-manager/extension';
import BookmarksManagerPlugin from '@sqltools/plugins/bookmarks-manager/extension';
import FormatterPlugin from '@sqltools/plugins/formatter/extension';
import CodeLensPlugin from '@sqltools/plugins/codelens/extension';

export class SQLToolsExtension implements SQLTools.ExtensionInterface {
private telemetry: Telemetry;
@@ -254,14 +253,14 @@ export class SQLToolsExtension implements SQLTools.ExtensionInterface {
let instance: SQLToolsExtension;
export function activate(context: ExtensionContext) {
if (instance) return;
instance = new SQLToolsExtension(context)
instance = new SQLToolsExtension(context);
instance
.registerPlugin(FormatterPlugin)
.registerPlugin(AutoRestartPlugin)
.registerPlugin(new ConnectionManagerPlugin)
.registerPlugin(new ConnectionManagerPlugin(instance))
.registerPlugin(new DependencyManagerPlugin)
.registerPlugin(new HistoryManagerPlugin)
.registerPlugin(new BookmarksManagerPlugin)
.registerPlugin(new CodeLensPlugin);
.registerPlugin(new BookmarksManagerPlugin);

return instance.activate();
}
@@ -117,12 +117,12 @@
}
},
{
"title": "Create from selection",
"title": "Create From Selection",
"command": "SQLTools.bookmarkSelection",
"category": "SQLTools Bookmarks"
},
{
"title": "Delete all",
"title": "Delete All",
"command": "SQLTools.clearBookmarks",
"category": "SQLTools Bookmarks"
},
@@ -147,47 +147,47 @@
"category": "SQLTools History"
},
{
"title": "Edit from history",
"title": "Edit From History",
"command": "SQLTools.editHistory",
"category": "SQLTools History"
},
{
"title": "Describe table",
"title": "Describe Table",
"command": "SQLTools.describeTable",
"category": "SQLTools Connection"
},
{
"title": "Format SQL (for any doc)",
"title": "Format Sql (For Any Document)",
"command": "SQLTools.formatSql",
"category": "SQLTools"
},
{
"title": "Run selected query",
"title": "Run Selected Query",
"command": "SQLTools.executeQuery",
"category": "SQLTools Connection"
},
{
"title": "Run this file",
"title": "Run This File",
"command": "SQLTools.executeQueryFromFile",
"category": "SQLTools Connection"
},
{
"title": "Run query",
"title": "Run Query",
"command": "SQLTools.executeFromInput",
"category": "SQLTools Connection"
},
{
"title": "Show output channel (Logs)",
"title": "Show Output Channel (Logs)",
"command": "SQLTools.showOutputChannel",
"category": "SQLTools Management"
},
{
"title": "Focus on connection explorer",
"title": "Focus On Connection Explorer",
"command": "SQLTools.focusOnExplorer",
"category": "SQLTools Management"
},
{
"title": "Show table records",
"title": "Show Table Records",
"command": "SQLTools.showRecords",
"category": "SQLTools Connection",
"icon": {
@@ -196,12 +196,12 @@
}
},
{
"title": "About SQLTools",
"title": "About",
"command": "SQLTools.aboutVersion",
"category": "SQLTools Management"
},
{
"title": "Add new connection",
"title": "Add New Connection",
"command": "SQLTools.openAddConnectionScreen",
"category": "SQLTools Management",
"icon": {
@@ -210,17 +210,17 @@
}
},
{
"title": "Edit connection",
"title": "Edit Connection",
"command": "SQLTools.openEditConnectionScreen",
"category": "SQLTools Management"
},
{
"title": "Delete connection",
"title": "Delete Connection",
"command": "SQLTools.deleteConnection",
"category": "SQLTools Management"
},
{
"title": "Add name to cursor",
"title": "Add Name To Cursor",
"command": "SQLTools.insertText",
"category": "SQLTools Sidebar"
},
@@ -243,7 +243,7 @@
}
},
{
"title": "New SQL File",
"title": "New Sql File",
"command": "SQLTools.newSqlFile",
"category": "SQLTools",
"icon": {
@@ -252,13 +252,23 @@
}
},
{
"title": "Save results",
"title": "Save Results",
"command": "SQLTools.saveResults",
"category": "SQLTools Results",
"icon": {
"light": "icons/save-light.svg",
"dark": "icons/save-dark.svg"
}
},
{
"title": "SQLTools: Attach Connection To This File",
"command": "SQLTools.attachFileToConnection",
"category": "SQLTools Internal"
},
{
"title": "SQLTools: Detach Connection From File",
"command": "SQLTools.detachConnectionFromFile",
"category": "SQLTools Internal"
}
],
"keybindings": [
@@ -719,6 +729,14 @@
"command": "SQLTools.generateInsertQuery",
"when": "false"
},
{
"command": "SQLTools.attachFileToConnection",
"when": "false"
},
{
"command": "SQLTools.detachConnectionFromFile",
"when": "false"
},
{
"command": "SQLTools.saveResults",
"when": "sqltools.Results.active"
@@ -861,6 +879,18 @@
"group": "navigation",
"when": "sqltools.Results.active"
}
],
"editor/context": [
{
"command": "SQLTools.attachFileToConnection",
"group": "sqltools@0",
"when": "!sqltools.file.connectionAttached && editorLangId == sql"
},
{
"command": "SQLTools.detachConnectionFromFile",
"group": "sqltools@0",
"when": "sqltools.file.connectionAttached && editorLangId == sql"
}
]
}
},
@@ -7,13 +7,14 @@ import * as Utils from '@sqltools/core/utils';
export default class CodeLensPlugin implements SQLTools.ExtensionPlugin {
private codelensDisposable: Disposable;
private registeredLanguages: string[] = [];
private provider: SQLToolsCodeLensProvider;
async dispose() {
if (!this.codelensDisposable) return;
await this.codelensDisposable.dispose();
this.codelensDisposable = null;
}

async createCodelens() {
async createCodelens(context: SQLTools.ExtensionInterface['context']) {
const oldLang = this.registeredLanguages.sort(Utils.sortText);
const newLang = ConfigManager.codelensLanguages.sort(Utils.sortText);
const shouldRegister = newLang.length > 0 && (oldLang.join() !== newLang.join());
@@ -23,18 +24,23 @@ export default class CodeLensPlugin implements SQLTools.ExtensionPlugin {
if(this.registeredLanguages) {
await this.dispose();
}
this.provider = new SQLToolsCodeLensProvider(context);
this.codelensDisposable = languages.registerCodeLensProvider(
ConfigManager.codelensLanguages.map(language => ({ language })),
new SQLToolsCodeLensProvider(),
this.provider,
);
this.registeredLanguages = ConfigManager.codelensLanguages;
}

register(extension: SQLTools.ExtensionInterface) {
extension.context.subscriptions.push(this);
this.createCodelens();
this.createCodelens(extension.context);
ConfigManager.addOnUpdateHook(() => {
this.createCodelens();
this.createCodelens(extension.context);
});
}

reset() {
return this.provider.reset();
}
}
@@ -1,13 +1,34 @@
import { CodeLensProvider, TextDocument, CodeLens, Range, Command } from 'vscode';
import { CodeLensProvider, TextDocument, CodeLens, Range, Command, Event, EventEmitter } from 'vscode';
import * as Constants from '@sqltools/core/constants';
import Selector from '@sqltools/core/utils/vscode/selector';
import { getNameFromId } from '@sqltools/core/utils';
import SQLTools from '@sqltools/core/plugin-api';

export default class SQLToolsCodeLensProvider implements CodeLensProvider {
private _onDidChangeCodeLenses = new EventEmitter<void>();
get onDidChangeCodeLenses(): Event<void> {
return this._onDidChangeCodeLenses.event;
}

reset() {
this._onDidChangeCodeLenses.fire();
}
async provideCodeLenses(document: TextDocument): Promise<CodeLens[]> {
const lines: string[] = document.getText().split(Constants.LineSplitterRegex);
const requestRanges: [number, number][] = Selector.getQueryRanges(lines);
const defaultConn = (document.getText(new Range(0, 0, 1, 0)).match(/@conn\s*(.+)$/) || [])[1];
const lenses: CodeLens[] = [];
const attachedId = this.context.workspaceState.get('attachedFilesMap', {})[document.uri.toString()];
if (attachedId) {
// attached to a connection
const connName = getNameFromId(attachedId);
const runCmd: Command = {
arguments: [document.uri],
title: `Detach file from ${connName.trim()}`,
command: `${Constants.EXT_NAME}.detachConnectionFromFile`,
};
lenses.push(new CodeLens(new Range(0, 0, 0, 0), runCmd))
}
requestRanges.forEach(([blockStart, blockEnd]) => {
const range = new Range(blockStart, 0, blockEnd, 0);
const queries = document.getText(range);
@@ -29,4 +50,8 @@ export default class SQLToolsCodeLensProvider implements CodeLensProvider {

return lenses;
}

constructor(private context: SQLTools.ExtensionInterface['context']) {
context.subscriptions.push(this._onDidChangeCodeLenses);
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.