Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Tal Wertheimer <tal@Tals-MacBook-Pro-2.local>
  • Loading branch information
Tal Wertheimer authored and Tal Wertheimer committed Dec 14, 2023
1 parent ed1e8f7 commit 928d9dd
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions src/runCompletion.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { CancellationToken, Position, Range, TextDocument } from "vscode";
import * as vscode from "vscode";
import {
CancellationToken,
Position,
Range,
TextDocument,
window,
Uri,
} from "vscode";
import {
autocomplete,
AutocompleteParams,
Expand All @@ -16,8 +22,8 @@ import languages from "./globals/languages";
import { getSDKPath } from "./languages";

function calculateContextForJupyterNotebook(
notebookEditor: vscode.window.NotebookEditor,
documentUri: vscode.Uri
notebookEditor: window.NotebookEditor,
documentUri: Uri
): { before: string; after: string } {
const cells = notebookEditor.notebook.getCells();

Expand All @@ -33,8 +39,8 @@ function calculateContextForJupyterNotebook(
.map((cell) => cell.document.getText())
.join("\n");
return {
before,
after,
before: before + "\n",

Check failure on line 42 in src/runCompletion.ts

View workflow job for this annotation

GitHub Actions / Build & Lint

Unexpected string concatenation
after: "\n" + after,

Check failure on line 43 in src/runCompletion.ts

View workflow job for this annotation

GitHub Actions / Build & Lint

Unexpected string concatenation
};
}

Expand All @@ -61,12 +67,19 @@ export default async function runCompletion({
const beforeStart = document.positionAt(beforeStartOffset);
const afterEnd = document.positionAt(afterEndOffset);

const notebookEditor = window.activeNotebookEditor;

const { before, after } = notebookEditor
? calculateContextForJupyterNotebook(notebookEditor, document.uri)
: { before: "", after: "" };

const requestData = {
filename: getFileNameWithExtension(document),
before:
before +
document.getText(new Range(beforeStart, position)) +
currentSuggestionText,
after: document.getText(new Range(position, afterEnd)),
after: document.getText(new Range(position, afterEnd)) + after,
region_includes_beginning: beforeStartOffset === 0,
region_includes_end: document.offsetAt(afterEnd) !== afterEndOffset,
max_num_results: getMaxResults(),
Expand All @@ -76,16 +89,6 @@ export default async function runCompletion({
indentation_size: getTabSize(),
sdk_path: getSDKPath(document.languageId),
};
const notebookEditor = vscode.window.activeNotebookEditor;

if (notebookEditor) {
const { before, after } = calculateContextForJupyterNotebook(
notebookEditor,
document.uri
);
requestData.before = [before, requestData.before].join("\n");
requestData.after = [requestData.after, after].join("\n");
}

const isEmptyLine = document.lineAt(position.line).text.trim().length === 0;

Expand Down

0 comments on commit 928d9dd

Please sign in to comment.