Skip to content

Commit f906d2e

Browse files
committed
simplify fix
1 parent e0a50b2 commit f906d2e

File tree

2 files changed

+33
-50
lines changed

2 files changed

+33
-50
lines changed

src/vs/workbench/browser/labels.ts

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -492,40 +492,34 @@ class ResourceLabelWidget extends IconLabel {
492492
if (!options.forceLabel && !isSideBySideEditor && resource?.scheme === Schemas.vscodeNotebookCellOutput) {
493493
const notebookDocument = this.notebookDocumentService.getNotebook(resource);
494494
const outputUriData = extractCellOutputDetails(resource);
495-
496-
let cellIndex: number | undefined;
497-
if (!outputUriData?.notebook) {
498-
return;
499-
}
500-
if (outputUriData.cellHandle) {
501-
// if we have a cell handle, we can use that to get the cell index
495+
if (outputUriData?.cellFragment) {
496+
if (!outputUriData.notebook) {
497+
return;
498+
}
502499
const cellUri = outputUriData.notebook.with({
503500
scheme: Schemas.vscodeNotebookCell,
504501
fragment: outputUriData.cellFragment
505502
});
506-
cellIndex = notebookDocument?.getCellIndex(cellUri);
507-
}
508-
const outputIndex = outputUriData.outputIndex;
509-
510-
if (cellIndex !== undefined && outputIndex !== undefined && typeof label.name === 'string') {
511-
label.name = localize(
512-
'notebookCellOutputLabel',
513-
"{0} • Cell {1} • Output {2}",
514-
label.name,
515-
`${cellIndex + 1}`,
516-
`${outputIndex + 1}`
517-
);
518-
} else if (cellIndex !== undefined && typeof label.name === 'string') {
519-
label.name = localize(
520-
'notebookCellOutputLabelSimple',
521-
"{0} • Cell {1} • Output",
522-
label.name,
523-
`${cellIndex + 1}`
524-
);
525-
} else if (typeof label.name === 'string') {
526-
label.name = localize('notebookCellOutputLabelJustFile', "{0}", label.name);
503+
const cellIndex = notebookDocument?.getCellIndex(cellUri);
504+
const outputIndex = outputUriData.outputIndex;
505+
506+
if (cellIndex !== undefined && outputIndex !== undefined && typeof label.name === 'string') {
507+
label.name = localize(
508+
'notebookCellOutputLabel',
509+
"{0} • Cell {1} • Output {2}",
510+
label.name,
511+
`${cellIndex + 1}`,
512+
`${outputIndex + 1}`
513+
);
514+
} else if (cellIndex !== undefined && typeof label.name === 'string') {
515+
label.name = localize(
516+
'notebookCellOutputLabelSimple',
517+
"{0} • Cell {1} • Output",
518+
label.name,
519+
`${cellIndex + 1}`
520+
);
521+
}
527522
}
528-
529523
}
530524

531525
const hasResourceChanged = this.hasResourceChanged(label);

src/vs/workbench/services/notebook/common/notebookDocumentService.ts

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -78,34 +78,23 @@ export function extractCellOutputDetails(uri: URI): { notebook: URI; openIn: str
7878
}
7979
const outputId = params.get('outputId') ?? undefined;
8080
const notebookScheme = params.get('notebookScheme') ?? undefined;
81-
const outputIndex = params.get('outputIndex') ? parseInt(params.get('outputIndex') || '', 10) : undefined;
82-
83-
if (openIn === 'editor') {
84-
const notebookUri = uri.with({
85-
scheme: notebookScheme || Schemas.file,
86-
fragment: null,
87-
query: null,
88-
});
89-
return {
90-
notebook: notebookUri,
91-
openIn: openIn,
92-
outputId: outputId,
93-
outputIndex: outputIndex,
94-
};
95-
}
96-
// If openIn is not editor, it needs to be opened in the notebook editor
9781
const parsedCell = parse(uri.with({ scheme: Schemas.vscodeNotebookCell, query: null }));
98-
99-
if (parsedCell?.notebook === undefined || parsedCell?.handle === undefined) {
100-
throw new Error('Invalid notebook output cell URI');
82+
const outputIndex = params.get('outputIndex') ? parseInt(params.get('outputIndex') || '', 10) : undefined;
83+
const notebookUri = parsedCell ? parsedCell.notebook : uri.with({
84+
scheme: notebookScheme || Schemas.file,
85+
fragment: null,
86+
query: null,
87+
});
88+
if (notebookUri === undefined) {
89+
throw new Error('Invalid cell URI');
10190
}
10291

10392
return {
104-
notebook: parsedCell.notebook,
93+
notebook: notebookUri,
10594
openIn: openIn,
10695
outputId: outputId,
10796
outputIndex: outputIndex,
108-
cellHandle: parsedCell.handle,
97+
cellHandle: parsedCell?.handle,
10998
cellFragment: uri.fragment,
11099
};
111100
}

0 commit comments

Comments
 (0)