diff --git a/images/dark/named-parameters.svg b/images/dark/named-parameters.svg new file mode 100644 index 00000000..61a69a8a --- /dev/null +++ b/images/dark/named-parameters.svg @@ -0,0 +1,6 @@ + + + $P + + diff --git a/images/light/named-parameters.svg b/images/light/named-parameters.svg new file mode 100644 index 00000000..7b183198 --- /dev/null +++ b/images/light/named-parameters.svg @@ -0,0 +1,6 @@ + + + $P + + diff --git a/package.json b/package.json index f38a39e7..b149c708 100644 --- a/package.json +++ b/package.json @@ -600,10 +600,16 @@ "command": "vscode-couchbase.showNamedParameters", "category": "Couchbase", "icon": { - "light": "images/light/favorites-list.svg", - "dark": "images/dark/favorites-list.svg" + "light": "images/light/named-parameters.svg", + "dark": "images/dark/named-parameters.svg" } }, + { + "title": "Refresh Named Parameters List", + "command": "vscode-couchbase.refreshNamedParameters", + "category": "Couchbase", + "icon": "$(refresh)" + }, { "title": "Apply Query History", "command": "vscode-couchbase.applyQueryHistory", @@ -675,6 +681,12 @@ "title": "Show iQ settings", "category": "Couchbase", "icon": "$(gear)" + }, + { + "command": "vscode-couchbase.workbench.showSettings", + "title": "Show Workbench settings", + "category": "Couchbase", + "icon": "$(gear)" } ], "keybindings": [ @@ -727,6 +739,20 @@ "category": "Couchbase", "group": "navigation", "when": "activeWebviewPanelId == clusterOverview" + }, + { + "title": "Refresh Named Parameters List", + "command": "vscode-couchbase.refreshNamedParameters", + "category": "Couchbase", + "group": "navigation@2", + "when": "activeWebviewPanelId == showNamedParameters" + }, + { + "title": "Show Named Parameters List", + "command": "vscode-couchbase.workbench.showSettings", + "category": "Couchbase", + "group": "navigation@1", + "when": "activeWebviewPanelId == showNamedParameters" } ], "editor/context": [ @@ -891,6 +917,10 @@ { "command": "vscode-couchbase.iq.showSettings", "when": "false" + }, + { + "command": "vscode-couchbase.workbench.showSettings", + "when": "false" } ], "view/item/context": [ diff --git a/src/commands/extensionCommands/commands.ts b/src/commands/extensionCommands/commands.ts index ff36af39..eb74b5f1 100644 --- a/src/commands/extensionCommands/commands.ts +++ b/src/commands/extensionCommands/commands.ts @@ -46,6 +46,7 @@ export namespace Commands { export const showFavoriteQueries: string = "vscode-couchbase.showFavoriteQueries"; export const markFavoriteQuery: string = "vscode-couchbase.markFavoriteQuery"; export const showNamedParameters: string = "vscode-couchbase.showNamedParameters"; + export const refreshNamedParameters: string = "vscode-couchbase.refreshNamedParameters"; export const applyQueryHistory: string = "vscode-couchbase.applyQueryHistory"; export const deleteQueryHistoryItem: string = "vscode-couchbase.deleteQueryHistoryItem"; export const copyQueryHistoryItem: string = "vscode-couchbase.copyQueryHistoryItem"; @@ -65,5 +66,6 @@ export namespace Commands { export const couchbaseIqViewsCommand: string = "couchbase-iq"; export const logoutIq: string = "vscode-couchbase.iq.logout"; export const showIqSettings: string = "vscode-couchbase.iq.showSettings"; + export const showWorkbenchSettings: string = "vscode-couchbase.workbench.showSettings"; export const newIqChat: string = "vscode-couchbase.iq.newChat"; } diff --git a/src/extension.ts b/src/extension.ts index 2de5ee32..d3ff3f04 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -171,6 +171,14 @@ export function activate(context: vscode.ExtensionContext) { ) ); + subscriptions.push( + vscode.commands.registerCommand( + Commands.showWorkbenchSettings, + () => { + vscode.commands.executeCommand('workbench.action.openSettings', "couchbase.workbench"); + } + ) + ); subscriptions.push( vscode.window.onDidChangeActiveTextEditor(async (editor) => { @@ -601,7 +609,16 @@ export function activate(context: vscode.ExtensionContext) { vscode.commands.registerCommand( Commands.showNamedParameters, () => { - fetchNamedParameters(context); + fetchNamedParameters(); + } + ) + ); + + subscriptions.push( + vscode.commands.registerCommand( + Commands.refreshNamedParameters, + () => { + fetchNamedParameters(true); } ) ); diff --git a/src/pages/namedParameters/namedParameters.ts b/src/pages/namedParameters/namedParameters.ts index f908732d..7e5e8732 100644 --- a/src/pages/namedParameters/namedParameters.ts +++ b/src/pages/namedParameters/namedParameters.ts @@ -1,22 +1,25 @@ import * as vscode from 'vscode'; import { logger } from '../../logger/logger'; import { showNamedParameters } from '../../webViews/namedParameters.webview'; -import { applyQuery } from '../../commands/queryHistory/applyQuery'; -import { Memory, getUUID } from '../../util/util'; -import { IConnection } from '../../types/IConnection'; +import { Memory } from '../../util/util'; import { Constants } from '../../util/constants'; export interface INamedParametersWebviewState { webviewPanel: vscode.WebviewPanel } -export const fetchNamedParameters = (context: vscode.ExtensionContext) => { +export const fetchNamedParameters = (isRefresh:boolean = false) => { const namedParametersWebviewDetails = Memory.state.get(Constants.NAMED_PARAMETERS_WEBVIEW); if (namedParametersWebviewDetails) { + if(isRefresh){ + namedParametersWebviewDetails.webviewPanel.webview.html = showNamedParameters(); + return; + } // Named Parameters Webview already exists, Closing existing and creating new namedParametersWebviewDetails.webviewPanel.dispose(); Memory.state.update(Constants.NAMED_PARAMETERS_WEBVIEW, null); } + const currentPanel = vscode.window.createWebviewPanel( "showNamedParameters", "Named Parameters", @@ -31,8 +34,12 @@ export const fetchNamedParameters = (context: vscode.ExtensionContext) => { try { currentPanel.webview.html = showNamedParameters(); currentPanel.webview.onDidReceiveMessage(async (message) => { - switch (message.command) { + if (message.command === "openSettings") { + vscode.commands.executeCommand('workbench.action.openSettings', "couchbase.workbench"); + } else { + console.debug("Unhandled Message received from named parameters webview", message); } + }); currentPanel.onDidDispose(() => { diff --git a/src/util/constants.ts b/src/util/constants.ts index fdd2b80b..506d353b 100644 --- a/src/util/constants.ts +++ b/src/util/constants.ts @@ -19,7 +19,6 @@ export class Constants { public static connectionKeys = "clusterConnections"; public static QUERY_HISTORY = "cluster.queryHistory"; public static FAVORITE_QUERY = "cluster.favoriteQueries"; - public static NAMED_PARAMETER = "cluster.namedParameters"; public static ACTIVE_CONNECTION = "activeConnection"; public static FAVORITE_QUERIES_WEBVIEW = "favoriteQueriesWebview"; public static NAMED_PARAMETERS_WEBVIEW = "namedParametersWebview"; diff --git a/src/util/namedParameters.ts b/src/util/namedParameters.ts index 66e22b61..f71ff4c1 100644 --- a/src/util/namedParameters.ts +++ b/src/util/namedParameters.ts @@ -1,10 +1,7 @@ -import { fetchNamedParameters } from "../pages/namedParameters/namedParameters"; import { IKeyValuePair } from "../types/IKeyValuePair"; -import { Constants } from "./constants"; -import { Global } from "./util"; import * as vscode from "vscode"; -const fs = require('fs'); -const path = require('path'); +import fs from 'fs'; +import path from 'path'; export function getUsersNamedParameters(): IKeyValuePair[] { try { @@ -45,3 +42,21 @@ export function getProjectsNamedParameters(): IKeyValuePair[] { return []; } } + +export function getAllNamedParameters(): {[key: string]: any} { + const userNamedParameters = getUsersNamedParameters(); + const projectNamedParameters = getProjectsNamedParameters(); + + // if any parameter is repeated, then the user's parameter will be used + let allNamedParameters: {[key: string]: any} = {}; + + for (let parameter of projectNamedParameters) { + allNamedParameters[parameter.key] = parameter.value; + } + + for (let parameter of userNamedParameters) { + allNamedParameters[parameter.key] = parameter.value; + } + + return allNamedParameters; +} \ No newline at end of file diff --git a/src/webViews/favoriteQueries.webiew.ts b/src/webViews/favoriteQueries.webiew.ts index c25a9d49..6e97a20e 100644 --- a/src/webViews/favoriteQueries.webiew.ts +++ b/src/webViews/favoriteQueries.webiew.ts @@ -22,7 +22,7 @@ export const showFavoriteQueries = (): string => { } .favorite-queries-table { - min-height: 150px; + min-height: 200px; display: flex; justify-content: space-between; width: 100%; diff --git a/src/webViews/namedParameters.webview.ts b/src/webViews/namedParameters.webview.ts index 421dd879..893ab690 100644 --- a/src/webViews/namedParameters.webview.ts +++ b/src/webViews/namedParameters.webview.ts @@ -1,36 +1,39 @@ -import { getUsersNamedParameters, getProjectsNamedParameters } from "../util/namedParameters"; +import { + getUsersNamedParameters, + getProjectsNamedParameters, +} from "../util/namedParameters"; export const showNamedParameters = (): string => { let namedParams = getUsersNamedParameters(); let projectNamedParams = getProjectsNamedParameters(); - return /*HTML*/` + return /*HTML*/ ` - Query Context + Named Parameters
-
My Named Parameters
+
User's Named Parameters
Project's Named Parameters
@@ -200,13 +155,21 @@ export const showNamedParameters = (): string => {
Keys
- ${namedParams !== undefined && namedParams.map((kv, index) => { - return (`
${kv.key}
`); - }).join('')} + ${ + namedParams !== undefined && + namedParams + .map((kv, index) => { + return `
${kv.key}
`; + }) + .join("") + }
- + +
+
+ Note: User's parameters are present in VSCode User Settings. You can edit from the settings file.
@@ -217,13 +180,18 @@ export const showNamedParameters = (): string => {
Keys
- ${projectNamedParams !== undefined && projectNamedParams.map((kv, index) => { - return (`
${kv.key}
`); - }).join('')} + ${ + projectNamedParams !== undefined && + projectNamedParams + .map((kv, index) => { + return `
${kv.key}
`; + }) + .join("") + }
- +
Note: Project's parameters are loaded directly from the .cbNamedParams.properties file in the project root directory. You can edit from that file. @@ -285,7 +253,13 @@ export const showNamedParameters = (): string => { evt.currentTarget.className += " active"; } + function openSettings() { + vscode.postMessage({ + command: "openSettings" + }); + } + `; -}; \ No newline at end of file +}; diff --git a/src/workbench/queryWorkbench.ts b/src/workbench/queryWorkbench.ts index a8cdcedc..e11f18a4 100644 --- a/src/workbench/queryWorkbench.ts +++ b/src/workbench/queryWorkbench.ts @@ -24,6 +24,7 @@ import { saveQuery } from '../util/queryHistory'; import { getUUID } from '../util/util'; import { QueryHistoryTreeProvider } from '../tree/QueryHistoryTreeProvider'; import { IQueryContext } from '../types/IQueryContext'; +import { getAllNamedParameters } from '../util/namedParameters'; export class QueryWorkbench { private _untitledSqlppDocumentService: UntitledSqlppDocumentService; @@ -53,10 +54,13 @@ export class QueryWorkbench { const query = activeTextEditor.selection.isEmpty ? activeTextEditor.document.getText() : activeTextEditor.document.getText(activeTextEditor.selection); const queryContext = this.editorToContext.get(activeTextEditor.document.uri.toString()); const queryContextString = queryContext && (`${queryContext?.bucketName}.${queryContext?.scopeName}`); // Query context string is of format bucketName.ScopeName + const queryParameters = getAllNamedParameters(); + const queryOptions: QueryOptions = { profile: QueryProfileMode.Timings, metrics: true, - queryContext: queryContextString + queryContext: queryContextString, + parameters: queryParameters }; try { // Reveal the webview when the extension is activated