Search sections in Jupyter Viewlet (#9346)

This commit is contained in:
Chris LaFreniere
2020-02-26 13:59:38 -08:00
committed by GitHub
parent 924815353d
commit 29cf1f898e
4 changed files with 16 additions and 15 deletions

View File

@@ -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"
]
},

View File

@@ -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();
}

View File

@@ -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<BookTreeItem> {
private _onDidChangeTreeData: vscode.EventEmitter<BookTreeItem | undefined> = new vscode.EventEmitter<BookTreeItem | undefined>();
@@ -94,9 +96,9 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
const bookRoot = this.currentBook.bookItems[0];
const sectionToOpen = bookRoot.findChildSection(urlToOpen);
const urlPath = sectionToOpen ? sectionToOpen.url : bookRoot.tableOfContents.sections[0].url;
const sectionToOpenMarkdown: string = path.join(this.currentBook.bookPath, 'content', urlPath.concat('.md'));
const sectionToOpenMarkdown: string = path.join(this.currentBook.bookPath, Content, urlPath.concat('.md'));
// The Notebook editor expects a posix path for the resource (it will still resolve to the correct fsPath based on OS)
const sectionToOpenNotebook: string = path.posix.join(this.currentBook.bookPath, 'content', urlPath.concat('.ipynb'));
const sectionToOpenNotebook: string = path.posix.join(this.currentBook.bookPath, Content, urlPath.concat('.ipynb'));
if (await fs.pathExists(sectionToOpenMarkdown)) {
this.openMarkdown(sectionToOpenMarkdown);
}
@@ -189,9 +191,13 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
}
}
public async searchJupyterBooks(): Promise<void> {
public async searchJupyterBooks(treeItem?: BookTreeItem): Promise<void> {
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<BookTreeIte
if (element) {
let parentPath;
if (element.root.endsWith('.md')) {
parentPath = path.join(this.currentBook.bookPath, 'content', 'readme.md');
parentPath = path.join(this.currentBook.bookPath, Content, 'readme.md');
if (parentPath === element.root) {
return undefined;
}

View File

@@ -34,7 +34,7 @@ export async function activate(extensionContext: vscode.ExtensionContext): Promi
extensionContext.subscriptions.push(vscode.commands.registerCommand('bookTreeView.openMarkdown', (resource) => 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()));