Skip to content
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

Use workspace folders as cwd for remote notebooks #1931

Merged
merged 2 commits into from
Jan 28, 2025
Merged
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
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,10 @@
{
"view": "runme.launcher",
"contents": "Open a workspace/folder to display Runme files here"
},
{
"view": "runme.remoteNotebooks",
"contents": "Explore Cloud Notebooks"
}
],
"keybindings": [
Expand Down
16 changes: 15 additions & 1 deletion src/extension/executors/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from 'node:path'
import fs from 'node:fs/promises'
import os from 'node:os'

import {
NotebookCellOutput,
Expand All @@ -10,13 +11,16 @@ import {
NotebookCellData,
Uri,
NotebookDocument,
workspace,
WorkspaceFolder,
} from 'vscode'

import { DEFAULT_PROMPT_ENV, OutputType, RUNME_FRONTMATTER_PARSED } from '../../constants'
import type { CellOutputPayload, Serializer, ShellType } from '../../types'
import { NotebookCellOutputManager } from '../cell'
import { getAnnotations, getWorkspaceFolder } from '../utils'
import { CommandMode, CommandModeEnum } from '../grpc/runner/types'
import { RunmeFsScheme } from '../provider/runmeFs'

const HASH_PREFIX_REGEXP = /^\s*\#\s*/g
const ENV_VAR_REGEXP = /(\$\w+)/g
Expand Down Expand Up @@ -240,7 +244,17 @@ export async function getCellCwd(
// TODO: support windows here
(notebook?.metadata as Serializer.Metadata | undefined)?.[RUNME_FRONTMATTER_PARSED]?.cwd,
getAnnotations(cell.metadata as Serializer.Metadata | undefined).cwd,
]
].filter(Boolean)

if (notebook && 'uri' in notebook && notebook.uri.scheme === RunmeFsScheme) {
const folders: readonly WorkspaceFolder[] = workspace.workspaceFolders || []
if (folders.length > 0) {
candidates.push(...folders.map((f) => f.uri.fsPath))
} else {
const fallbackCwd = await fs.mkdtemp(path.join(os.tmpdir(), 'runme-fallback-cwd-'))
candidates.push(fallbackCwd)
}
}

for (let candidate of candidates) {
if (!candidate) {
Expand Down
4 changes: 2 additions & 2 deletions src/extension/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ import { RunmeIdentity } from './grpc/parser/tcp/types'
import * as features from './features'
import AuthSessionChangeHandler from './authSessionChangeHandler'
import { CloudNotebooks } from './provider/cloudNotebooks'
import RunmeFS from './provider/runmeFs'
import RunmeFS, { RunmeFsScheme } from './provider/runmeFs'

export class RunmeExtension {
protected serializer?: ISerializer
Expand All @@ -107,7 +107,7 @@ export class RunmeExtension {
await ContextState.addKey(FeatureName.RemoteNotebooks, true)
const runmeFs = new RunmeFS()
context.subscriptions.push(
workspace.registerFileSystemProvider('runmefs', runmeFs, {
workspace.registerFileSystemProvider(RunmeFsScheme, runmeFs, {
isReadonly: false,
}),
commands.registerCommand('runme.addRemoteNotebooks', (_) => {
Expand Down
6 changes: 4 additions & 2 deletions src/extension/provider/runmeFs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const excludedPaths = [
'.runme_bootstrap_demo',
]

export const RunmeFsScheme = 'runmefs'

export function mergeUriPaths(uri: Uri, newPath: string): Uri {
const isAbsolutePath = newPath.startsWith('/')

Expand All @@ -54,11 +56,11 @@ export default class RunmeFS implements FileSystemProvider {
#pathTree: PathTree = {}

get root() {
return Uri.parse('runmefs:///')
return Uri.parse(`${RunmeFsScheme}:///`)
}

static resolveUri(path: string) {
return Uri.parse(`runmefs:///${path}`)
return Uri.parse(`${RunmeFsScheme}:///${path}`)
}

async readFile(uri: Uri): Promise<Uint8Array> {
Expand Down