From 2e47bbaedc0498bcd529fdb99e8720f38cfef8f5 Mon Sep 17 00:00:00 2001 From: yonip23 Date: Sun, 30 Jul 2023 22:10:59 +0300 Subject: [PATCH] fix lint --- .../handlers/context/diagnosticsContext.ts | 16 +++++++++------- .../handlers/context/editorContext.ts | 11 ++++++++--- .../handlers/context/workspaceContext.ts | 6 +++--- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/tabnineChatWidget/handlers/context/diagnosticsContext.ts b/src/tabnineChatWidget/handlers/context/diagnosticsContext.ts index 8d026d27d1..ee5469c501 100644 --- a/src/tabnineChatWidget/handlers/context/diagnosticsContext.ts +++ b/src/tabnineChatWidget/handlers/context/diagnosticsContext.ts @@ -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 { - const diagnosticsText = getDiagnosticsText(editor); - if (!diagnosticsText) return undefined; +): Promise { + 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( @@ -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 { diff --git a/src/tabnineChatWidget/handlers/context/editorContext.ts b/src/tabnineChatWidget/handlers/context/editorContext.ts index 9da566dca8..b0eceeb137 100644 --- a/src/tabnineChatWidget/handlers/context/editorContext.ts +++ b/src/tabnineChatWidget/handlers/context/editorContext.ts @@ -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 { +): Promise { 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, }); } diff --git a/src/tabnineChatWidget/handlers/context/workspaceContext.ts b/src/tabnineChatWidget/handlers/context/workspaceContext.ts index 076f6e19da..68252963e3 100644 --- a/src/tabnineChatWidget/handlers/context/workspaceContext.ts +++ b/src/tabnineChatWidget/handlers/context/workspaceContext.ts @@ -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 { +): Promise { if (!workspaceCommands || !workspaceCommands.length) return undefined; const workspaceData: WorkspaceContext = { @@ -24,5 +24,5 @@ export default async function getWorkspaceContext( } }); - return workspaceData; + return { type: "Workspace", ...workspaceData }; }