Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
dimacodota committed Nov 29, 2023
1 parent 82f9fa3 commit fc79ee4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
import {
CodeLens,
CodeLensProvider,
commands,
DocumentSymbol,
Location,
SymbolInformation,
SymbolKind,
TextDocument,
} from "vscode";
import { CodeLens, CodeLensProvider, Location, TextDocument } from "vscode";
import { fireEvent } from "../../../binary/requests/requests";
import { getFuctionsSymbols } from "../getFuctionsSymbols";

const CODE_LENS_ACTIONS = [
["test", "generate-test-for-code"],
["fix", "fix-code"],
["explain", "explain-code"],
];

const VALID_SYMBOLS = [SymbolKind.Function, SymbolKind.Method];

const MAX_LINES = 2500;

export default class ChatCodeLensProvider implements CodeLensProvider {
Expand All @@ -28,31 +18,18 @@ export default class ChatCodeLensProvider implements CodeLensProvider {
if (document.lineCount > MAX_LINES) {
return [];
}
const documnetSymbols = await commands.executeCommand<
(SymbolInformation & DocumentSymbol)[]
>("vscode.executeDocumentSymbolProvider", document.uri);

const documnetSymbols = await getFuctionsSymbols(document);

if (!documnetSymbols?.length) {
return [];
}

const lenses: CodeLens[] = [];

documnetSymbols
?.filter((fn) => VALID_SYMBOLS.includes(fn.kind))
.forEach(({ location }) =>
lenses.push(...toIntentLens(location), toAskLens(location))
);

documnetSymbols
?.filter((symbol) => symbol.kind === SymbolKind.Class)
.forEach((classSymbol) => {
classSymbol.children
.filter((child) => VALID_SYMBOLS.includes(child.kind))
.forEach((method) => {
const { location } = (method as unknown) as SymbolInformation;
lenses.push(...toIntentLens(location), toAskLens(location));
});
});
documnetSymbols.forEach(({ location }) => {
lenses.push(...toIntentLens(location), toAskLens(location));
});

void fireEvent({
name: "chat-lens-label-rendered",
Expand Down
14 changes: 10 additions & 4 deletions src/tabnineChatWidget/extensionCommands/slashCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,29 @@ export type SlashCommand = {
};
export const SLASH_COMANDS: SlashCommand[] = [
{
label: "explain",
label: "$(feedback) explain",
intent: "/explain-code",
description: "Explain the selected code",
},
{
label: "test",
label: "$(beaker) test",
intent: "/generate-test-for-code",
description: "Write tests for the selected code",
},
{
label: "document",
label: "$(checklist) document",
intent: "/document-code",
description: "Add documentation for the selected code",
},
{
label: "fix",
label: "$(symbol-property) fix",
intent: "/fix-code",
description: "Find errors in the selected code and fix them",
},
{
label: "$(search) workspace",
intent: "/workspace",
description:
"Ask a question related to any code within your current workspace",
},
];
2 changes: 1 addition & 1 deletion src/tabnineChatWidget/tabnineChatWidgetWebview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,6 @@ function registerWebview(context: ExtensionContext, serverUrl?: string): void {
})
);
context.subscriptions.push(registerChatCommnmads(chatProvider));
registerChatActionProvider(context, chatProvider);
registerChatActionProvider(context);
registerChatCodeLens(context, chatProvider);
}

0 comments on commit fc79ee4

Please sign in to comment.