Skip to content

Add support for fts inside extension #400

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

Draft
wants to merge 2 commits into
base: development
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions images/dark/search-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions images/light/search-icon.svg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 2 icons are very different

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 69 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,18 @@
"SQL++"
],
"configuration": "./language/language-configuration.json"
},

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove extra space in package.json

{
"id":"searchQuery",
"extensions": [
".cbs.json"
],
"aliases": [
"SEARCH"
],
"configuration": "./language/language-configuration.json"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space

}
],
"grammars": [
Expand Down Expand Up @@ -434,6 +446,12 @@
"category": "Couchbase",
"icon": "images/create.svg"
},
{
"command": "vscode-couchbase.openSearchWorkbench",
"title": "New Search Workbench",
"category": "Couchbase",
"icon": "images/create.svg"
},
{
"command": "vscode-couchbase.openQueryWorkbench",
"title": "New Workbench",
Expand Down Expand Up @@ -546,6 +564,14 @@
"title": "Show Output Console",
"category": "Couchbase"
},
{
"command": "vscode-couchbase.runSearch",
"title": "Run Search",
"category": "Couchbase",
"icon": "$(play)",
"tooltip": "Run Search",
"enablement": "vscode-couchbase.runSearchButtonEnabled"
},
{
"command": "vscode-couchbase.runQuery",
"title": "Run Query",
Expand All @@ -569,6 +595,12 @@
"title": "MongoDB Migrate",
"category": "Couchbase"
},
{
"title": "Search Context",
"command": "vscode-couchbase.searchContext",
"category": "Couchbase",
"icon": "$(group-by-ref-type)"
},
{
"command": "vscode-couchbase.tools.dataImport",
"title": "Data Import",
Expand Down Expand Up @@ -695,6 +727,12 @@
"key": "ctrl+shift+e",
"mac": "cmd+shift+e",
"when": "(editorLangId == sqlpp || resourceFilename =~ /.sqlpp$/) && !isKVCluster"
},
{
"command": "vscode-couchbase.runSearch",
"key": "ctrl+shift+e",
"mac": "cmd+shift+e",
"when": "(editorLangId == cbs.json || resourceFilename =~ /.cbs.json$/) && !isKVCluster"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will have to add another condition stating isSearchService. Because by default, search service is not mandatory

}
],
"menus": {
Expand All @@ -705,13 +743,26 @@
"when": "(editorLangId == sqlpp || resourceFilename =~ /.sqlpp$/) && !isKVCluster",
"group": "navigation@1"
},
{
"command": "vscode-couchbase.runSearch",
"category": "Couchbase",
"when": "(editorLangId == cbs.json || resourceFilename =~ /.cbs.json$/) && !isKVCluster",
"group": "navigation@1"
},
{
"title": "Query Context",
"command": "vscode-couchbase.queryContext",
"category": "Couchbase",
"group": "navigation@2",
"when": "(editorLangId == sqlpp || resourceFilename =~ /.sqlpp$/) && !isKVCluster"
},
{
"title": "Search Context",
"command": "vscode-couchbase.searchContext",
"category": "Couchbase",
"group": "navigation@2",
"when": "(editorLangId == cbs.json || resourceFilename =~ /.cbs.json$/) && !isKVCluster"
},
{
"title": "Show Favorite Queries",
"command": "vscode-couchbase.showFavoriteQueries",
Expand Down Expand Up @@ -760,6 +811,11 @@
"command": "vscode-couchbase.runQuery",
"when": "(editorLangId == sqlpp || resourceFilename =~ /.sqlpp$/) && !isKVCluster",
"group": "navigation@1"
},
{
"command": "vscode-couchbase.runSearch",
"when": "(editorLangId == .cbs.json || resourceFilename =~ /.cbs.json$/) && !isKVCluster",
"group": "navigation@1"
}
],
"commandPalette": [
Expand All @@ -779,6 +835,10 @@
"command": "vscode-couchbase.openQueryWorkbench",
"when": "false"
},
{
"command": "vscode-couchbase.openSearchWorkbench",
"when": "false"
},
{
"command": "vscode-couchbase.deleteClusterConnection",
"when": "false"
Expand Down Expand Up @@ -862,6 +922,10 @@
"command": "vscode-couchbase.queryContext",
"when": "false"
},
{
"command": "vscode-couchbase.searchContext",
"when": "false"
},
{
"command": "vscode-couchbase.showFavoriteQueries",
"when": "false"
Expand Down Expand Up @@ -957,6 +1021,11 @@
"when": "view == couchbase && viewItem == active_connection && !isKVCluster",
"group": "workbench@1"
},
{
"command": "vscode-couchbase.openSearchWorkbench",
"when": "view == couchbase && viewItem == searchIndex && !isKVCluster",
"group": "workbench@1"
},
{
"submenu": "vscode-couchbase.toolsMenu",
"when": "view == couchbase && viewItem == active_connection"
Expand Down
5 changes: 5 additions & 0 deletions src/commands/extensionCommands/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,25 @@ export namespace Commands {
export const getBucketMetaData: string = "vscode-couchbase.getBucketInfo";
export const createDocument: string = "vscode-couchbase.createDocument";
export const openDocument: string = "vscode-couchbase.openDocument";
export const openSearchIndex: string = "vscode-couchbase.openSearchIndex";
export const removeDocument: string = "vscode-couchbase.removeDocument";
export const getDocumentMetaData: string = "vscode-couchbase.getDocumentMetaData";
export const searchDocument: string = "vscode-couchbase.searchDocument";
export const openIndexInfo: string = "vscode-couchbase.openIndexInfo";
export const refreshIndexes: string = "vscode-couchbase.refreshIndexes";
export const openQueryNotebook: string = "vscode-couchbase.openQueryNotebook";
export const openQueryWorkbench: string = "vscode-couchbase.openQueryWorkbench";
export const openSearchWorkbench: string = "vscode-couchbase.openSearchWorkbench";
export const getSampleProjects: string = "vscode-couchbase.openSampleProjects";
export const loadMore: string = "vscode-couchbase.loadMore";
export const showOutputConsole: string = "vscode-couchbase.showOutputConsole";
export const runQuery: string = "vscode-couchbase.runQuery";
export const runSearchQuery: string = "vscode-couchbase.runSearch";
export const queryWorkbench: string = "vscode-couchbase.couchbase-query-workbench";
export const searchWorkbench: string = "vscode-couchbase.couchbase-search-workbench";
export const getClusterOverview: string = "vscode-couchbase.getClusterOverview";
export const queryContext: string = "vscode-couchbase.queryContext";
export const searchContext: string = "vscode-couchbase.searchContext";
export const showFavoriteQueries: string = "vscode-couchbase.showFavoriteQueries";
export const markFavoriteQuery: string = "vscode-couchbase.markFavoriteQuery";
export const showNamedParameters: string = "vscode-couchbase.showNamedParameters";
Expand Down
65 changes: 65 additions & 0 deletions src/commands/fts/SearchWorkbench/controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright 2011-2020 Couchbase, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as vscode from 'vscode';
import { MemFS } from '../../../util/fileSystemProvider';
import SearchIndexNode from '../../../model/SearchIndexNode';

class SearchJsonDocumentContentProvider implements vscode.TextDocumentContentProvider {
provideTextDocumentContent(uri: vscode.Uri): string {
return '';
}
}

export default class UntitledSearchJsonDocumentService {
public searchJsonProvider = new SearchJsonDocumentContentProvider();
private untitledCount: number = 1;
private searchJsonScheme: string = '.cbs.json';

public disposable = vscode.workspace.registerTextDocumentContentProvider(this.searchJsonScheme, this.searchJsonProvider);

constructor() {
}



public async openSearchJsonTextDocument(searchIndexNode: SearchIndexNode,memFs: MemFS): Promise<vscode.TextEditor> {
const uri = vscode.Uri.parse(`couchbase:/search-workbench-${searchIndexNode.searchIndexName}-${this.untitledCount}.cbs.json`);
this.untitledCount++;
let documentContent = Buffer.from('');
memFs.writeFile(uri, documentContent, {
create: true,
overwrite: true,
});


const document = await vscode.workspace.openTextDocument(uri);
document.save();
await vscode.window.showTextDocument(document, { preview: false });
return await vscode.window.showTextDocument(document, { preview: false });
}


public showTextDocument(document: vscode.TextDocument, column?: vscode.ViewColumn, preserveFocus?: boolean): Thenable<vscode.TextEditor> {
return vscode.window.showTextDocument(document, column, preserveFocus);
}


public newQuery(searchIndexNode: SearchIndexNode, memFs: MemFS): Promise<vscode.TextEditor> {
return new Promise<vscode.TextEditor>((resolve, reject) => {
this.openSearchJsonTextDocument(searchIndexNode, memFs).then(resolve).catch(reject);
});
}
}
51 changes: 51 additions & 0 deletions src/commands/fts/SearchWorkbench/openSearchIndex.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import * as vscode from "vscode";
import SearchIndexNode from "../../../model/SearchIndexNode";
import { DocumentNotFoundError } from "couchbase/dist/errors";
import { logger } from "../../../logger/logger";
import { MemFS } from "../../../util/fileSystemProvider";
import ClusterConnectionTreeProvider from "../../../tree/ClusterConnectionTreeProvider";
import { getActiveConnection } from "../../../util/connections";
import { CouchbaseRestAPI } from "../../../util/apis/CouchbaseRestAPI";

export const openSearchIndex = async (searchIndexNode: SearchIndexNode, clusterConnectionTreeProvider: ClusterConnectionTreeProvider, uriToCasMap: Map<string, string>, memFs: MemFS) => {
try {
const connection = getActiveConnection();
if (!connection) {
return false;
}
const api = new CouchbaseRestAPI(connection);
const result = await api.fetchSearchIndexDefinition(searchIndexNode.indexName);

if (result?.indexDef instanceof Uint8Array || result?.indexDef instanceof Uint16Array || result?.indexDef instanceof Uint32Array) {
vscode.window.showInformationMessage("Unable to open Index definition: It is not a valid JSON", { modal: true });
return false;
}
const uri = vscode.Uri.parse(
Comment on lines +19 to +23
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this the correct way of confirming it is valid json file?

`couchbase:/${searchIndexNode.bucketName}/${searchIndexNode.scopeName}/Search/${searchIndexNode.indexName}.json`
);
if (result) {
uriToCasMap.set(uri.toString(), result.indexDef.toString());
}
try {
memFs.writeFile(
uri,
Buffer.from(JSON.stringify(result?.indexDef, null, 2)),
{ create: true, overwrite: true }
);
} catch (error) {
vscode.window.showInformationMessage("Unable to open Index definition: It is not a valid JSON ", { modal: true });
return false;
Comment on lines +36 to +37
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Print error message as well, so that detailed debugging is possible here. Use logger.error for that

}
const document = await vscode.workspace.openTextDocument(uri);
await vscode.window.showTextDocument(document, { preview: false });
return true;
} catch (err: any) {
if (err instanceof vscode.FileSystemError && err.name === 'EntryNotFound (FileSystemError)' || err instanceof DocumentNotFoundError) {
clusterConnectionTreeProvider.refresh();
}
logger.error("Failed to open Document");
logger.debug(err);
}


}
Loading