Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
dimacodota committed Dec 14, 2023
1 parent cff1aaf commit 4361407
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 40 deletions.
32 changes: 14 additions & 18 deletions src/tabnineChatWidget/extensionCommands/ChatCodeLensProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from "vscode";
import { fireEvent } from "../../binary/requests/requests";
import { getFuctionsSymbols } from "./getFuctionsSymbols";
import { Action, COMANDS } from "./commands";
import { Action, CODE_LENS_COMMANDS } from "./commands";
import tabnineExtensionProperties from "../../globals/tabnineExtensionProperties";
import { languagesFilter } from "./const";

Expand Down Expand Up @@ -108,23 +108,19 @@ function toIntentLens(
location: Location,
diagnostics: Diagnostic[]
): CodeLens[] {
return (
COMANDS.filter(
({ text, lensOrder }) =>
lensOrder && filterRelevantActions(text, location, diagnostics)
)
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
.sort((a, b) => a.lensOrder! - b.lensOrder!)
.map(
({ text, intent }, index) =>
new CodeLens(location.range, {
title: `${index === 0 ? "tabnine: " : ""}${text}`,
tooltip: `tabnine ${text}`,
command: "tabnine.chat.commands.any",
arguments: [location.range, intent],
})
)
);
return CODE_LENS_COMMANDS.filter(({ text }) =>
filterRelevantActions(text, location, diagnostics)
)
.sort((a, b) => a.lensOrder - b.lensOrder)
.map(
({ text, intent }, index) =>
new CodeLens(location.range, {
title: `${index === 0 ? "tabnine: " : ""}${text}`,
tooltip: `tabnine ${text}`,
command: "tabnine.chat.commands.any",
arguments: [location.range, intent],
})
);
}
function filterRelevantActions(
text: Action,
Expand Down
12 changes: 8 additions & 4 deletions src/tabnineChatWidget/extensionCommands/commands.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type SCOPE = "block" | "selection" | "none";
export type Scope = "block" | "selection" | "none";
export type Action = "test" | "fix" | "explain" | "document" | "workspace";
export type Intent =
| "/generate-test-for-code"
Expand All @@ -19,12 +19,12 @@ export type Command = {
text: Action;
intent: Intent;
description: string;
scope: SCOPE[];
scope: Scope[];
multistep: boolean;
lensOrder?: LensOrder | undefined;
};
export type LensCommand = Command & { lensOrder: number };

export const COMANDS: Command[] = [
export const CODE_LENS_COMMANDS: LensCommand[] = [
{
label: "$(feedback) explain",
text: "explain",
Expand Down Expand Up @@ -61,6 +61,10 @@ export const COMANDS: Command[] = [
multistep: false,
lensOrder: LensOrder.fix,
},
];

export const COMANDS: Command[] = [
...CODE_LENS_COMMANDS,
{
label: "$(search) workspace",
text: "workspace",
Expand Down
20 changes: 11 additions & 9 deletions src/tabnineChatWidget/extensionCommands/registerChatCommnmads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ export function registerChatCommnmads(
commands.registerTextEditorCommand(
"tabnine.chat.commands.inline.action",
(textEditor: TextEditor) => {
void showInput(COMANDS).then((result) => {
if (textEditor.selection.isEmpty) {
void showInput(COMANDS).then(([result, command]) => {
if (
textEditor.selection.isEmpty &&
!command?.scope.includes("none")
) {
void getFuctionsSymbols(textEditor.document).then(
(relevantSymbols: SymbolInformation[]) => {
const symbolInRange = relevantSymbols?.find((s) =>
Expand Down Expand Up @@ -97,13 +100,12 @@ export function registerChatCommnmads(
intent: "ask-question",
language: window.activeTextEditor?.document.languageId,
});

const editor = window.activeTextEditor;
if (editor) {
const newSelection = new Selection(range.start, range.end);
editor.selection = newSelection;
}
void showInput(COMANDS).then((question) => {
void showInput(COMANDS).then(([question, command]) => {
const editor = window.activeTextEditor;
if (question && editor && !command?.scope.includes("none")) {
const newSelection = new Selection(range.start, range.end);
editor.selection = newSelection;
}
if (question) {
void chatProvider.handleMessageSubmitted(question);
}
Expand Down
19 changes: 10 additions & 9 deletions src/tabnineChatWidget/extensionCommands/showInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import { QuickPickItem, window } from "vscode";

export function showInput<
T extends QuickPickItem & { multistep: boolean; intent: string }
>(items: T[] = []): Promise<string | undefined> {
>(items: T[] = []): Promise<[string?, T?]> {
return new Promise((resolve) => {
let isAccepted = false;
const view = window.createQuickPick<T>();
view.items = items;
view.title = "Ask Tabnine";
view.canSelectMany = false;
view.ignoreFocusOut = true;
view.placeholder = `Type your question${
items.length ? " or select from the list" : ""
}`;
Expand All @@ -20,7 +19,7 @@ export function showInput<

view.onDidHide(() => {
if (!isAccepted) {
resolve(undefined);
resolve([]);
view.dispose();
return;
}
Expand All @@ -29,28 +28,30 @@ export function showInput<
void window
.showInputBox({
placeHolder: view.selectedItems[0].description,
ignoreFocusOut: true,
})
.then(
(value) => {
if (value) {
resolve(`${view.selectedItems[0].intent} ${value}`);
resolve([
`${view.selectedItems[0].intent} ${value}`,
view.selectedItems[0],
]);
} else {
resolve(undefined);
resolve([]);
}
view.dispose();
},
() => {
resolve(undefined);
resolve([]);
view.dispose();
}
);
} else {
resolve(view.selectedItems[0].intent);
resolve([view.selectedItems[0].intent, view.selectedItems[0]]);
view.dispose();
}
} else {
resolve(view.value);
resolve([view.value]);
view.dispose();
}
});
Expand Down

0 comments on commit 4361407

Please sign in to comment.