Skip to content

Commit 71ebcd0

Browse files
authored
Merge branch 'main' into addFolderSharing
2 parents 14c02a7 + 41c41c6 commit 71ebcd0

2 files changed

Lines changed: 200 additions & 137 deletions

File tree

src/index.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,13 +365,30 @@ const CREATE_PLUGIN_ARGS_SCHEMA = {
365365
type: 'object',
366366
additionalProperties: false,
367367
properties: {
368+
cwd: {
369+
type: 'string',
370+
description:
371+
'Optional current working directory. Used as the default parent directory when `path` is not provided and as the base for relative `path` values.'
372+
},
368373
path: {
369374
type: 'string',
370375
description:
371376
'Optional file path. Relative paths are resolved from the current working directory; paths starting with "/" are resolved from the workspace root. If no extension is provided, ".ts" is appended.'
372377
}
373378
}
374379
};
380+
381+
const CREATE_PLUGIN_FROM_NOTEBOOK_TREE_ARGS_SCHEMA = {
382+
type: 'object',
383+
additionalProperties: false,
384+
properties: {
385+
cwd: {
386+
type: 'string',
387+
description:
388+
'Optional current working directory used as the default parent directory for the new file.'
389+
}
390+
}
391+
};
375392
const LOAD_ON_SAVE_TOGGLE_TOOLBAR_ITEM = 'plugin-playground-load-on-save';
376393
const SHARE_LINK_TOOLBAR_ITEM = 'share-extension-link';
377394
const LOAD_ON_SAVE_CHECKBOX_LABEL = 'Auto Load on Save';
@@ -702,8 +719,13 @@ class PluginPlayground {
702719
const rawPathArg =
703720
typeof args.path === 'string' ? args.path.trim() : '';
704721
const isRootRelativePath = rawPathArg.startsWith('/');
722+
const rawCwdArg = typeof args.cwd === 'string' ? args.cwd.trim() : '';
723+
const normalizedCwdArg = ContentUtils.normalizeContentsPath(rawCwdArg);
724+
const createInPath =
725+
!isRootRelativePath && normalizedCwdArg ? normalizedCwdArg : '';
705726

706727
const model = await app.serviceManager.contents.newUntitled({
728+
...(createInPath ? { path: createInPath } : {}),
707729
type: 'file',
708730
ext: 'ts'
709731
});
@@ -3535,10 +3557,14 @@ const notebookTreePlugin: JupyterFrontEndPlugin<void> = {
35353557
label: 'Plugin (Playground)',
35363558
caption:
35373559
'Create a new TypeScript plugin file and open the playground sidebar',
3538-
describedBy: { args: null },
3560+
describedBy: { args: CREATE_PLUGIN_FROM_NOTEBOOK_TREE_ARGS_SCHEMA },
35393561
icon: extensionIcon,
3540-
execute: async () => {
3562+
execute: async args => {
3563+
const rawCwdArg = typeof args.cwd === 'string' ? args.cwd.trim() : '';
3564+
const normalizedCwdArg =
3565+
ContentUtils.normalizeContentsPath(rawCwdArg);
35413566
const model = await app.serviceManager.contents.newUntitled({
3567+
...(normalizedCwdArg ? { path: normalizedCwdArg } : {}),
35423568
type: 'file',
35433569
ext: 'ts'
35443570
});

0 commit comments

Comments
 (0)