Skip to content

Commit

Permalink
fix show view
Browse files Browse the repository at this point in the history
  • Loading branch information
dimacodota committed Dec 11, 2023
1 parent a6a4c62 commit 76a675b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 99 deletions.
75 changes: 11 additions & 64 deletions src/tabnineChatWidget/extensionCommands/ChatActionProvider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable no-param-reassign */
/* eslint-disable max-classes-per-file */
/* eslint-disable class-methods-use-this */
import {
CodeAction,
Expand All @@ -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,
],
}
)
);
}

Expand Down Expand Up @@ -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;
}
}
34 changes: 8 additions & 26 deletions src/tabnineChatWidget/extensionCommands/codeLens/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
});
})
);
}
16 changes: 16 additions & 0 deletions src/tabnineChatWidget/extensionCommands/const.ts
Original file line number Diff line number Diff line change
@@ -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" },
];
Original file line number Diff line number Diff line change
Expand Up @@ -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[]) => {
Expand Down
7 changes: 7 additions & 0 deletions src/tabnineChatWidget/extensionCommands/showInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export function showInput<
T extends QuickPickItem & { multistep: boolean; intent: string }
>(items: T[] = []): Promise<string | undefined> {
return new Promise((resolve) => {
let isAccepted = false;
const view = window.createQuickPick<T>();
view.items = items;
view.title = "Ask Tabnine";
Expand All @@ -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
Expand Down

0 comments on commit 76a675b

Please sign in to comment.