Skip to content

Commit

Permalink
Rendering New Notebooks Panel using VS Code Task Provider (#1784)
Browse files Browse the repository at this point in the history
* Refactor New Runme Notebooks Panel to use Runme Tasks

* Optimize tree view rendering and improve child item handling

- Introduced caching for notebooks and their cells to optimize tree view rendering.
- Added a parent property to RunmeFile to properly associate child items with their parent notebooks.
- Updated getChildren method to use cached data and return child items based on their parent.
- Removed unnecessary sauceCount logic, simplifying the tree re-rendering workaround.
- Added logic to store and preserve the collapsibleState when including named or unnamed cells

* Adds Open and Run view actions

* If no named cell was found this is fatal so continue

* Add button at notebook level

---------

Co-authored-by: Sebastian Tiedtke <sebastiantiedtke@gmail.com>
  • Loading branch information
pastuxso and sourishkrout authored Nov 26, 2024
1 parent a3a820f commit ce5c5af
Show file tree
Hide file tree
Showing 6 changed files with 244 additions and 193 deletions.
32 changes: 32 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,21 @@
"title": "Open Cloud Panel",
"category": "Runme",
"description": "Open Cloud Panel"
},
{
"command": "runme.openNotebook",
"title": "Open",
"icon": "$(preferences-open-settings)"
},
{
"command": "runme.runSelectedCell",
"title": "Run",
"icon": "$(play)"
},
{
"command": "runme.openSelectedCell",
"title": "Open",
"icon": "$(preferences-open-settings)"
}
],
"menus": {
Expand Down Expand Up @@ -617,6 +632,23 @@
"group": "navigation",
"when": "notebookType == runme && notebookMode != sessionOutputs && notebookCellType == 'code'"
}
],
"view/item/context": [
{
"command": "runme.openNotebook",
"when": "view == runme.launcher && viewItem == markdownNotebook",
"group": "inline"
},
{
"command": "runme.runSelectedCell",
"when": "view == runme.launcher && viewItem == markdownCell",
"group": "inline"
},
{
"command": "runme.openSelectedCell",
"when": "view == runme.launcher && viewItem == markdownCell",
"group": "inline"
}
]
},
"languages": [
Expand Down
36 changes: 27 additions & 9 deletions src/extension/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,33 @@ export class RunmeExtension {
let treeViewer: RunmeTreeProvider

if (kernel.isFeatureOn(FeatureName.NewTreeProvider)) {
await commands.executeCommand('setContext', 'runme.launcher.isExpanded', true)
await commands.executeCommand('setContext', 'runme.launcher.includeUnnamed', true)
treeViewer = new RunmeLauncherProviderBeta(
kernel,
server,
serializer,
getDefaultWorkspace(),
runner,
)
await commands.executeCommand('setContext', 'runme.launcher.isExpanded', false)
await commands.executeCommand('setContext', 'runme.launcher.includeUnnamed', false)
treeViewer = new RunmeLauncherProviderBeta(kernel, serializer)

if (treeViewer.openNotebook) {
context.subscriptions.push(
RunmeExtension.registerCommand(
'runme.openNotebook',
treeViewer.openNotebook.bind(treeViewer),
),
)
}

if (treeViewer.runCell) {
context.subscriptions.push(
RunmeExtension.registerCommand(
'runme.runSelectedCell',
treeViewer.runCell.bind(treeViewer),
),
)
}
if (treeViewer.openCell) {
RunmeExtension.registerCommand(
'runme.openSelectedCell',
treeViewer.openCell.bind(treeViewer),
)
}
} else {
treeViewer = new RunmeLauncherProvider(getDefaultWorkspace())
}
Expand Down
14 changes: 7 additions & 7 deletions src/extension/provider/codelens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,15 @@ export class RunmeCodeLensProvider implements CodeLensProvider, Disposable {
break
}

const task = await RunmeTaskProvider.newRunmeTask(
document.uri.fsPath,
getAnnotations(cell.metadata).name,
const task = await RunmeTaskProvider.newRunmeTask({
filePath: document.uri.fsPath,
command: getAnnotations(cell.metadata).name,
notebook,
cell,
{},
this.runner!,
this.kernel?.getRunnerEnvironment(),
)
options: {},
runner: this.runner!,
runnerEnv: this.kernel?.getRunnerEnvironment(),
})

await tasks.executeTask(task)
}
Expand Down
13 changes: 13 additions & 0 deletions src/extension/provider/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ interface IRunmeFileProps {
description?: string
iconPath?: string | Uri | { light: string | Uri; dark: string | Uri } | ThemeIcon
resourceUri?: Uri
cellIndex?: number
parent?: string
documentPath?: string
}

interface TreeFile {
Expand All @@ -43,6 +46,10 @@ let i = 0
export const GLOB_PATTERN = '**/*.{md,mdr,mdx}'

export class RunmeFile extends TreeItem {
public readonly cellIndex: number | undefined
public readonly parent?: string
public readonly documentPath?: string

constructor(
public label: string,
options: IRunmeFileProps,
Expand All @@ -54,6 +61,9 @@ export class RunmeFile extends TreeItem {
this.contextValue = options.contextValue
this.description = options.description
this.resourceUri = options.resourceUri
this.cellIndex = options.cellIndex
this.parent = options.parent
this.documentPath = options.documentPath

if (options.iconPath) {
this.iconPath = options.iconPath
Expand All @@ -75,6 +85,9 @@ export interface RunmeTreeProvider extends TreeDataProvider<RunmeFile>, Disposab
collapseAll(): Promise<void>
expandAll(): Promise<void>
openFile(options: OpenFileOptions): Promise<void>
openNotebook?(runmeFile: RunmeFile): Promise<void>
openCell?(runmeFile: RunmeFile): Promise<void>
runCell?(runmeFile: RunmeFile): Promise<void>
}

export class RunmeLauncherProvider implements RunmeTreeProvider {
Expand Down
Loading

0 comments on commit ce5c5af

Please sign in to comment.