Skip to content

Commit

Permalink
Use workspace folders as cwd for remote notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
pastuxso committed Jan 27, 2025
1 parent d89a8b2 commit 3cdd877
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
10 changes: 9 additions & 1 deletion src/extension/executors/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,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 +243,12 @@ 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 || []
candidates.push(...folders.map((f) => f.uri.fsPath))
}

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

0 comments on commit 3cdd877

Please sign in to comment.