-
Notifications
You must be signed in to change notification settings - Fork 4
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
base: development
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -357,6 +357,18 @@ | |
"SQL++" | ||
], | ||
"configuration": "./language/language-configuration.json" | ||
}, | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space |
||
} | ||
], | ||
"grammars": [ | ||
|
@@ -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", | ||
|
@@ -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", | ||
|
@@ -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", | ||
|
@@ -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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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": { | ||
|
@@ -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", | ||
|
@@ -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": [ | ||
|
@@ -779,6 +835,10 @@ | |
"command": "vscode-couchbase.openQueryWorkbench", | ||
"when": "false" | ||
}, | ||
{ | ||
"command": "vscode-couchbase.openSearchWorkbench", | ||
"when": "false" | ||
}, | ||
{ | ||
"command": "vscode-couchbase.deleteClusterConnection", | ||
"when": "false" | ||
|
@@ -862,6 +922,10 @@ | |
"command": "vscode-couchbase.queryContext", | ||
"when": "false" | ||
}, | ||
{ | ||
"command": "vscode-couchbase.searchContext", | ||
"when": "false" | ||
}, | ||
{ | ||
"command": "vscode-couchbase.showFavoriteQueries", | ||
"when": "false" | ||
|
@@ -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" | ||
|
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); | ||
}); | ||
} | ||
} |
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
|
||
|
||
} |
There was a problem hiding this comment.
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