Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
yonip23 committed Jul 30, 2023
1 parent 2b44a9f commit 2e47bba
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
16 changes: 9 additions & 7 deletions src/tabnineChatWidget/handlers/context/diagnosticsContext.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import vscode from "vscode";
import { DiagnosticsContext } from "./enrichingContextTypes";
import { ContextTypeData, DiagnosticsContext } from "./enrichingContextTypes";

export default async function getDiagnosticsContext(
editor: vscode.TextEditor
): Promise<DiagnosticsContext | undefined> {
const diagnosticsText = getDiagnosticsText(editor);
if (!diagnosticsText) return undefined;
): Promise<ContextTypeData | undefined> {
const diagnosticsContext = buildDiagnosticsContext(editor);
if (!diagnosticsContext) return undefined;

return Promise.resolve({ diagnosticsText });
return Promise.resolve({ type: "Diagnostics", ...diagnosticsContext });
}

function getDiagnosticsText(editor: vscode.TextEditor): string | undefined {
function buildDiagnosticsContext(
editor: vscode.TextEditor
): DiagnosticsContext | undefined {
const visibleDiagnostics = vscode.languages
.getDiagnostics(editor.document.uri)
.filter(
Expand All @@ -19,7 +21,7 @@ function getDiagnosticsText(editor: vscode.TextEditor): string | undefined {
editor.visibleRanges.some((r) => r.contains(e.range))
);
if (!visibleDiagnostics.length) return undefined;
return formatDiagnostics(visibleDiagnostics);
return { diagnosticsText: formatDiagnostics(visibleDiagnostics) };
}

function formatDiagnostics(diagnostics: vscode.Diagnostic[]): string {
Expand Down
11 changes: 8 additions & 3 deletions src/tabnineChatWidget/handlers/context/editorContext.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import vscode from "vscode";
import { EditorContext } from "./enrichingContextTypes";
import { ContextTypeData, EditorContext } from "./enrichingContextTypes";

export default async function getEditorContext(
editor: vscode.TextEditor
): Promise<EditorContext | undefined> {
): Promise<ContextTypeData | undefined> {
const fileCode = editor.document.getText();
const selectedCode = editor.document.getText(editor.selection);
const currentLine = editor.document.lineAt(editor.selection.active);

return Promise.resolve({
const editorContext: EditorContext = {
fileCode,
selectedCode,
selectedCodeUsages: [],
lineTextAtCursor: currentLine.text,
currentLineIndex: currentLine.lineNumber,
};

return Promise.resolve({
type: "Editor",
...editorContext,
});
}
6 changes: 3 additions & 3 deletions src/tabnineChatWidget/handlers/context/workspaceContext.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import executeWorkspaceCommand, {
WorkspaceCommandInstruction,
} from "../../workspaceCommands";
import { WorkspaceContext } from "./enrichingContextTypes";
import { ContextTypeData, WorkspaceContext } from "./enrichingContextTypes";

export default async function getWorkspaceContext(
workspaceCommands?: WorkspaceCommandInstruction[]
): Promise<WorkspaceContext | undefined> {
): Promise<ContextTypeData | undefined> {
if (!workspaceCommands || !workspaceCommands.length) return undefined;

const workspaceData: WorkspaceContext = {
Expand All @@ -24,5 +24,5 @@ export default async function getWorkspaceContext(
}
});

return workspaceData;
return { type: "Workspace", ...workspaceData };
}

0 comments on commit 2e47bba

Please sign in to comment.