Skip to content

Commit e48f179

Browse files
authored
Merge notebook and text observable document interfaces (#544)
1 parent 87365ac commit e48f179

File tree

2 files changed

+5
-59
lines changed

2 files changed

+5
-59
lines changed

src/extension/inlineEdits/vscode-node/parts/vscodeWorkspace.ts

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { DocumentId } from '../../../../platform/inlineEdits/common/dataTypes/do
1212
import { LanguageId } from '../../../../platform/inlineEdits/common/dataTypes/languageId';
1313
import { EditReason } from '../../../../platform/inlineEdits/common/editReason';
1414
import { IObservableDocument, ObservableWorkspace, StringEditWithReason } from '../../../../platform/inlineEdits/common/observableWorkspace';
15-
import { createAlternativeNotebookDocument, IAlternativeNotebookDocument, toAltDiagnostics, toAltNotebookCellChangeEdit, toAltNotebookChangeEdit } from '../../../../platform/notebook/common/alternativeNotebookTextDocument';
15+
import { createAlternativeNotebookDocument, IAlternativeNotebookDocument, toAltNotebookCellChangeEdit, toAltNotebookChangeEdit } from '../../../../platform/notebook/common/alternativeNotebookTextDocument';
1616
import { getDefaultLanguage } from '../../../../platform/notebook/common/helpers';
1717
import { IExperimentationService } from '../../../../platform/telemetry/common/nullExperimentationService';
1818
import { ITelemetryService } from '../../../../platform/telemetry/common/telemetry';
@@ -366,7 +366,7 @@ export class VSCodeWorkspace extends ObservableWorkspace implements IDisposable
366366
}
367367

368368

369-
export interface IBaseVSCodeObservableDocument extends IObservableDocument {
369+
export interface IVSCodeObservableDocument extends IObservableDocument {
370370
/**
371371
* Converts the OffsetRange of the Observable document to a range within the provided Text document.
372372
* If this is a Text Document, performs a simple OffsetRange to Range translation.
@@ -410,7 +410,7 @@ export interface IBaseVSCodeObservableDocument extends IObservableDocument {
410410
getCodeActions(range: OffsetRange, itemResolveCount: number, token: CancellationToken): Promise<CodeActionData[] | undefined>;
411411
}
412412

413-
export interface IVSCodeObservableTextDocument extends IObservableDocument, IBaseVSCodeObservableDocument {
413+
export interface IVSCodeObservableTextDocument extends IObservableDocument, IVSCodeObservableDocument {
414414
kind: 'textDocument';
415415
readonly textDocument: TextDocument;
416416
}
@@ -518,14 +518,7 @@ class VSCodeObservableTextDocument extends AbstractVSCodeObservableDocument impl
518518
}
519519
}
520520

521-
export interface IVSCodeObservableNotebookDocument extends IObservableDocument, IBaseVSCodeObservableDocument {
522-
kind: 'notebookDocument';
523-
readonly notebook: NotebookDocument;
524-
/** @deprecated Do not use this. Use diagnostics property instead. */
525-
projectDiagnostics(cell: TextDocument, diagnostics: readonly Diagnostic[]): Diagnostic[];
526-
}
527-
528-
class VSCodeObservableNotebookDocument extends AbstractVSCodeObservableDocument implements IVSCodeObservableNotebookDocument {
521+
class VSCodeObservableNotebookDocument extends AbstractVSCodeObservableDocument implements IVSCodeObservableDocument {
529522
/** @deprecated Do not use this */
530523
public kind: 'notebookDocument' = 'notebookDocument';
531524

@@ -582,13 +575,6 @@ class VSCodeObservableNotebookDocument extends AbstractVSCodeObservableDocument
582575
const offsetRanges = this.altNotebook.toAltOffsetRange(cell, [range]);
583576
return offsetRanges.length ? offsetRanges[0] : undefined;
584577
}
585-
projectDiagnostics(textDocument: TextDocument, diagnostics: readonly Diagnostic[]): Diagnostic[] {
586-
const cell = this.altNotebook.getCell(textDocument);
587-
if (!cell) {
588-
return [];
589-
}
590-
return toAltDiagnostics(this.altNotebook, cell, diagnostics);
591-
}
592578
toRange(textDocument: TextDocument, range: Range): Range | undefined {
593579
const cell = this.altNotebook.getCell(textDocument);
594580
if (!cell) {
@@ -623,8 +609,6 @@ class VSCodeObservableNotebookDocument extends AbstractVSCodeObservableDocument
623609
}
624610
}
625611

626-
export type IVSCodeObservableDocument = IVSCodeObservableTextDocument | IVSCodeObservableNotebookDocument;
627-
628612
function getTextDocuments(excludeNotebookCells: boolean): IObservable<readonly TextDocument[]> {
629613
return observableFromEvent(undefined, e => {
630614
const d1 = workspace.onDidOpenTextDocument(e);

src/platform/notebook/common/alternativeNotebookTextDocument.ts

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import type { Diagnostic, DiagnosticRelatedInformation, NotebookCell, NotebookDocument, NotebookDocumentContentChange, TextDocument, TextDocumentContentChangeEvent } from 'vscode';
6+
import type { NotebookCell, NotebookDocument, NotebookDocumentContentChange, TextDocument, TextDocumentContentChangeEvent } from 'vscode';
77
import { coalesce } from '../../../util/vs/base/common/arrays';
88
import { findLastIdxMonotonous } from '../../../util/vs/base/common/arraysFind';
99
import { StringEdit } from '../../../util/vs/editor/common/core/edits/stringEdit';
@@ -14,8 +14,6 @@ import { PositionOffsetTransformer } from '../../editing/common/positionOffsetTr
1414
import { generateCellTextMarker, getBlockComment, getLineCommentStart } from './alternativeContentProvider.text';
1515
import { EOL, summarize } from './helpers';
1616
import { CrLfOffsetTranslator } from './offsetTranslator';
17-
import { ResourceMap } from '../../../util/vs/base/common/map';
18-
import { isEqual } from '../../../util/vs/base/common/resources';
1917

2018

2119
class AlternativeNotebookCellSnapshot {
@@ -452,39 +450,3 @@ function toAltCellTextDocumentContentChangeEvents(notebook: AbstractAlternativeN
452450
} as typeof e;
453451
}));
454452
}
455-
456-
export function toAltDiagnostics(notebook: AbstractAlternativeNotebookDocument, cell: NotebookCell, diagnostics: readonly Diagnostic[]): Diagnostic[] {
457-
const cellUris = new ResourceMap(notebook.cells.map(cell => [cell.altCell.cell.document.uri, cell.altCell.cell] as const));
458-
if (!cellUris.get(cell.document.uri)) {
459-
return [];
460-
}
461-
return coalesce(diagnostics.map(diagnostic => toAltDiagnostic(notebook, cell, diagnostic)));
462-
}
463-
464-
function toAltDiagnostic(notebook: AbstractAlternativeNotebookDocument, cell: NotebookCell, diagnostic: Diagnostic): Diagnostic | undefined {
465-
const altDiagnostic = { ...diagnostic };
466-
const altRanges = notebook.toAltRange(cell, [diagnostic.range]);
467-
if (!altRanges.length) {
468-
return;
469-
}
470-
altDiagnostic.range = altRanges[0];
471-
if (altDiagnostic.relatedInformation) {
472-
altDiagnostic.relatedInformation = coalesce(altDiagnostic.relatedInformation.map(info => {
473-
if (!isEqual(info.location.uri, cell.document.uri)) {
474-
return info;
475-
}
476-
const altRange = notebook.toAltRange(cell, [info.location.range]);
477-
if (!altRange.length) {
478-
return;
479-
}
480-
return {
481-
...info,
482-
location: {
483-
uri: notebook.notebook.uri,
484-
range: altRange[0],
485-
},
486-
} satisfies DiagnosticRelatedInformation;
487-
}));
488-
}
489-
return altDiagnostic;
490-
}

0 commit comments

Comments
 (0)