Skip to content

Commit 1b175c1

Browse files
authored
Ensure Notebook completion is translated (#388)
1 parent c6137bf commit 1b175c1

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/extension/inlineEdits/vscode-node/inlineCompletionProvider.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,9 @@ export class InlineCompletionProviderImpl implements InlineCompletionItemProvide
233233
: undefined
234234
);
235235

236-
const displayLocation: InlineCompletionDisplayLocation | undefined = result.displayLocation ? {
237-
range: toExternalRange(result.displayLocation.range),
236+
const displayRange = result.displayLocation ? doc.fromRange(document, toExternalRange(result.displayLocation.range)) : undefined;
237+
const displayLocation: InlineCompletionDisplayLocation | undefined = result.displayLocation && displayRange ? {
238+
range: displayRange,
238239
label: result.displayLocation.label
239240
} : undefined;
240241

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ export interface IVSCodeObservableTextDocument extends IObservableDocument {
385385
kind: 'textDocument';
386386
readonly textDocument: TextDocument;
387387
fromOffsetRange(textDocument: TextDocument, range: OffsetRange): Range | undefined;
388+
fromRange(textDocument: TextDocument, range: Range): Range | undefined;
388389
toOffsetRange(textDocument: TextDocument, range: Range): OffsetRange | undefined;
389390
}
390391

@@ -443,6 +444,10 @@ class VSCodeObservableTextDocument extends AbstractVSCodeObservableDocument impl
443444
toOffsetRange(textDocument: TextDocument, range: Range): OffsetRange | undefined {
444445
return new OffsetRange(textDocument.offsetAt(range.start), textDocument.offsetAt(range.end));
445446
}
447+
448+
fromRange(_textDocument: TextDocument, range: Range): Range | undefined {
449+
return range;
450+
}
446451
}
447452

448453
export interface IVSCodeObservableNotebookDocument extends IObservableDocument {
@@ -458,6 +463,7 @@ export interface IVSCodeObservableNotebookDocument extends IObservableDocument {
458463
* The range provided could span multiple cells, so it returns an array of tuples containing the cell document and the range within that cell.
459464
*/
460465
fromOffsetRange(range: OffsetRange): [TextDocument, Range][];
466+
fromRange(textDocument: TextDocument, range: Range): Range | undefined;
461467
fromRange(range: Range): [TextDocument, Range][];
462468
projectDiagnostics(cell: TextDocument, diagnostics: readonly Diagnostic[]): Diagnostic[];
463469
}
@@ -495,8 +501,20 @@ class VSCodeObservableNotebookDocument extends AbstractVSCodeObservableDocument
495501
}
496502
return undefined;
497503
}
498-
fromRange(range: Range): [TextDocument, Range][] {
499-
return this.altNotebook.fromAltRange(range).map(r => [r[0].document, r[1]]);
504+
fromRange(textDocument: TextDocument, range: Range): Range | undefined;
505+
fromRange(range: Range): [TextDocument, Range][];
506+
fromRange(arg1: TextDocument | Range, range?: Range): Range | undefined | [TextDocument, Range][] {
507+
if (arg1 instanceof Range) {
508+
return this.altNotebook.fromAltRange(arg1).map(r => [r[0].document, r[1]]);
509+
} else if (range !== undefined) {
510+
const cell = this.altNotebook.getCell(arg1);
511+
if (!cell) {
512+
return undefined;
513+
}
514+
const results = this.altNotebook.fromAltRange(range);
515+
const found = results.find(r => r[0].document === arg1);
516+
return found ? found[1] : undefined;
517+
}
500518
}
501519
projectDiagnostics(textDocument: TextDocument, diagnostics: readonly Diagnostic[]): Diagnostic[] {
502520
const cell = this.altNotebook.getCell(textDocument);

0 commit comments

Comments
 (0)