From 29cf1f898e2c5190650883d15fc04f124111213f Mon Sep 17 00:00:00 2001 From: Chris LaFreniere <40371649+chlafreniere@users.noreply.github.com> Date: Wed, 26 Feb 2020 13:59:38 -0800 Subject: [PATCH] Search sections in Jupyter Viewlet (#9346) --- extensions/notebook/package.json | 10 +--------- extensions/notebook/src/book/bookTreeItem.ts | 3 +++ extensions/notebook/src/book/bookTreeView.ts | 16 +++++++++++----- extensions/notebook/src/extension.ts | 2 +- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/extensions/notebook/package.json b/extensions/notebook/package.json index 6f691c7eed..bb4d96c279 100644 --- a/extensions/notebook/package.json +++ b/extensions/notebook/package.json @@ -293,11 +293,6 @@ "when": "nodeType=~/^mssqlCluster/ && nodeLabel=~/[^\\s]+(\\.(csv|tsv|txt))$/ && nodeType == mssqlCluster:file", "group": "1notebook@1" }, - { - "command": "jupyter.cmd.newNotebook", - "when": "connectionProvider == HADOOP_KNOX && nodeType && nodeType == Server", - "group": "1root@1" - }, { "command": "jupyter.cmd.analyzeNotebook", "when": "nodeType=~/^hdfs/ && nodeLabel=~/[^\\s]+(\\.(csv|tsv|txt))$/ && nodeType == hdfs:file", @@ -307,7 +302,7 @@ "view/item/context": [ { "command": "notebook.command.searchBook", - "when": "view == bookTreeView && viewItem == savedBook", + "when": "view == bookTreeView && viewItem == savedBook || viewItem == section", "group": "inline" }, { @@ -398,7 +393,6 @@ "name": "pysparkkernel", "displayName": "PySpark", "connectionProviderIds": [ - "HADOOP_KNOX", "MSSQL" ] }, @@ -406,7 +400,6 @@ "name": "sparkkernel", "displayName": "Spark | Scala", "connectionProviderIds": [ - "HADOOP_KNOX", "MSSQL" ] }, @@ -414,7 +407,6 @@ "name": "sparkrkernel", "displayName": "Spark | R", "connectionProviderIds": [ - "HADOOP_KNOX", "MSSQL" ] }, diff --git a/extensions/notebook/src/book/bookTreeItem.ts b/extensions/notebook/src/book/bookTreeItem.ts index a2c8f0bcaa..d24809619a 100644 --- a/extensions/notebook/src/book/bookTreeItem.ts +++ b/extensions/notebook/src/book/bookTreeItem.ts @@ -45,6 +45,9 @@ export class BookTreeItem extends vscode.TreeItem { this.contextValue = 'savedBook'; } } else { + if (book.type === BookTreeItemType.Markdown && book.page.expand_sections) { + this.contextValue = 'section'; + } this.setPageVariables(); this.setCommand(); } diff --git a/extensions/notebook/src/book/bookTreeView.ts b/extensions/notebook/src/book/bookTreeView.ts index ae6e972914..0923330c83 100644 --- a/extensions/notebook/src/book/bookTreeView.ts +++ b/extensions/notebook/src/book/bookTreeView.ts @@ -14,6 +14,8 @@ import { BookModel } from './bookModel'; import { Deferred } from '../common/promise'; import * as loc from '../common/localizedConstants'; +const Content = 'content'; + export class BookTreeViewProvider implements vscode.TreeDataProvider { private _onDidChangeTreeData: vscode.EventEmitter = new vscode.EventEmitter(); @@ -94,9 +96,9 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider { + public async searchJupyterBooks(treeItem?: BookTreeItem): Promise { if (this.currentBook && this.currentBook.bookPath) { - let filesToIncludeFiltered = path.join(this.currentBook.bookPath, '**', '*.md') + ',' + path.join(this.currentBook.bookPath, '**', '*.ipynb'); + let folderToSearch = this.currentBook.bookPath; + if (treeItem && treeItem.uri) { + folderToSearch = path.join(folderToSearch, Content, path.dirname(treeItem.uri)); + } + let filesToIncludeFiltered = path.join(folderToSearch, '**', '*.md') + ',' + path.join(folderToSearch, '**', '*.ipynb'); vscode.commands.executeCommand('workbench.action.findInFiles', { filesToInclude: filesToIncludeFiltered, query: '' }); } } @@ -272,7 +278,7 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider bookTreeViewProvider.openMarkdown(resource))); extensionContext.subscriptions.push(vscode.commands.registerCommand('bookTreeView.openExternalLink', (resource) => bookTreeViewProvider.openExternalLink(resource))); extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.saveBook', () => untitledBookTreeViewProvider.saveJupyterBooks())); - extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.searchBook', () => bookTreeViewProvider.searchJupyterBooks())); + extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.searchBook', (item) => bookTreeViewProvider.searchJupyterBooks(item))); extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.searchUntitledBook', () => untitledBookTreeViewProvider.searchJupyterBooks())); extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.openBook', () => bookTreeViewProvider.openNewBook()));