diff --git a/src/tabnineChatWidget/extensionCommands/ChatActionProvider.ts b/src/tabnineChatWidget/extensionCommands/ChatActionProvider.ts index 1e27bae3f0..2cdbc51eff 100644 --- a/src/tabnineChatWidget/extensionCommands/ChatActionProvider.ts +++ b/src/tabnineChatWidget/extensionCommands/ChatActionProvider.ts @@ -1,5 +1,3 @@ -/* eslint-disable no-param-reassign */ -/* eslint-disable max-classes-per-file */ /* eslint-disable class-methods-use-this */ import { CodeAction, @@ -11,15 +9,20 @@ import { languages, CodeActionProvider, } from "vscode"; +import { languagesFilter } from "./const"; export function registerChatActionProvider(context: ExtensionContext) { context.subscriptions.push( - languages.registerCodeActionsProvider("*", new ChatActionProvider(), { - providedCodeActionKinds: [ - CodeActionKind.RefactorRewrite, - CodeActionKind.QuickFix, - ], - }) + languages.registerCodeActionsProvider( + languagesFilter, + new ChatActionProvider(), + { + providedCodeActionKinds: [ + CodeActionKind.RefactorRewrite, + CodeActionKind.QuickFix, + ], + } + ) ); } @@ -59,61 +62,5 @@ class ChatActionProvider implements CodeActionProvider { }; resultActions.push(refactor); return resultActions; - - // if (!window.activeTextEditor?.selection.isEmpty) { - // const refactor = new CodeAction( - // "Ask Tabnine", - // CodeActionKind.RefactorRewrite - // ); - - // refactor.command = { - // title: refactor.title, - // command: "tabnine.chat.commands.refactor-inline", - // arguments: [range], - // }; - - // resultActions.push(refactor); - // return resultActions; - // } - // if (!document.lineAt(range.start.line).text.trim()) { - // const refactor = new CodeAction( - // "Ask Tabnine", - // CodeActionKind.RefactorRewrite - // ); - - // refactor.command = { - // title: refactor.title, - // command: "tabnine.chat.commands.refactor-inline", - // arguments: [range], - // }; - - // resultActions.push(refactor); - // return resultActions; - // } - - // const relevantSymbols: SymbolInformation[] = await getFuctionsSymbols( - // document - // ); - - // const symbolInRange = relevantSymbols?.find((s) => - // s.location.range.contains(range) - // ); - // if (symbolInRange) { - // const refactor = new CodeAction( - // "Ask Tabnine", - // CodeActionKind.RefactorRewrite - // ); - - // refactor.command = { - // title: refactor.title, - // command: "tabnine.chat.commands.refactor-inline", - // arguments: [symbolInRange.location.range], - // }; - - // resultActions.push(refactor); - // return resultActions; - // } - - return resultActions; } } diff --git a/src/tabnineChatWidget/extensionCommands/codeLens/index.ts b/src/tabnineChatWidget/extensionCommands/codeLens/index.ts index c0d8d3f109..0aa2e00d7f 100644 --- a/src/tabnineChatWidget/extensionCommands/codeLens/index.ts +++ b/src/tabnineChatWidget/extensionCommands/codeLens/index.ts @@ -11,23 +11,10 @@ import ChatCodeLensProvider from "./ChatCodeLensProvider"; import ChatViewProvider from "../../ChatViewProvider"; import tabnineExtensionProperties from "../../../globals/tabnineExtensionProperties"; import { fireEvent } from "../../../binary/requests/requests"; +import { showInput } from "../showInput"; +import { SLASH_COMANDS } from "../slashCommands"; +import { languagesFilter } from "../const"; -const languagesFilter = [ - { language: "javascript" }, - { pattern: "**/*[!d].ts", scheme: "file" }, - { language: "javascriptreact" }, - { language: "typescriptreact" }, - { language: "python" }, - { language: "ruby" }, - { language: "go" }, - { language: "rust" }, - { language: "swift" }, - { language: "java" }, - { language: "c" }, - { language: "cpp" }, - { language: "csharp" }, - { language: "php" }, -]; export default function registerChatCodeLens( context: ExtensionContext, chatProvider: ChatViewProvider @@ -69,16 +56,11 @@ export default function registerChatCodeLens( const newSelection = new Selection(range.start, range.end); editor.selection = newSelection; } - void window - .showInputBox({ - prompt: "ask tabnine", - ignoreFocusOut: true, - }) - .then((question) => { - if (question) { - void chatProvider.handleMessageSubmitted(question); - } - }); + void showInput(SLASH_COMANDS).then((question) => { + if (question) { + void chatProvider.handleMessageSubmitted(question); + } + }); }) ); } diff --git a/src/tabnineChatWidget/extensionCommands/const.ts b/src/tabnineChatWidget/extensionCommands/const.ts new file mode 100644 index 0000000000..63ef83cc19 --- /dev/null +++ b/src/tabnineChatWidget/extensionCommands/const.ts @@ -0,0 +1,16 @@ +export const languagesFilter = [ + { language: "javascript" }, + { pattern: "**/*[!d].ts", scheme: "file" }, + { language: "javascriptreact" }, + { language: "typescriptreact" }, + { language: "python" }, + { language: "ruby" }, + { language: "go" }, + { language: "rust" }, + { language: "swift" }, + { language: "java" }, + { language: "c" }, + { language: "cpp" }, + { language: "csharp" }, + { language: "php" }, +]; diff --git a/src/tabnineChatWidget/extensionCommands/registerChatCommnmads.ts b/src/tabnineChatWidget/extensionCommands/registerChatCommnmads.ts index 0b57d6ec81..10abffa976 100644 --- a/src/tabnineChatWidget/extensionCommands/registerChatCommnmads.ts +++ b/src/tabnineChatWidget/extensionCommands/registerChatCommnmads.ts @@ -42,15 +42,7 @@ export function registerChatCommnmads( commands.registerTextEditorCommand( "tabnine.chat.commands.inline.action", (textEditor: TextEditor) => { - const items = SLASH_COMANDS.map( - ({ label, description, multistep, intent }) => ({ - label, - description, - multistep, - intent, - }) - ); - void showInput(items).then((result) => { + void showInput(SLASH_COMANDS).then((result) => { if (textEditor.selection.isEmpty) { void getFuctionsSymbols(textEditor.document).then( (relevantSymbols: SymbolInformation[]) => { diff --git a/src/tabnineChatWidget/extensionCommands/showInput.ts b/src/tabnineChatWidget/extensionCommands/showInput.ts index 08e44c9d46..6030323b3c 100644 --- a/src/tabnineChatWidget/extensionCommands/showInput.ts +++ b/src/tabnineChatWidget/extensionCommands/showInput.ts @@ -4,6 +4,7 @@ export function showInput< T extends QuickPickItem & { multistep: boolean; intent: string } >(items: T[] = []): Promise { return new Promise((resolve) => { + let isAccepted = false; const view = window.createQuickPick(); view.items = items; view.title = "Ask Tabnine"; @@ -14,9 +15,15 @@ export function showInput< }`; view.onDidAccept(() => { view.hide(); + isAccepted = true; }); view.onDidHide(() => { + if (!isAccepted) { + resolve(undefined); + view.dispose(); + return; + } if (view.selectedItems.length) { if (view.selectedItems[0].multistep) { void window