Commit 99a83ad4 authored by Pavel Shutsin's avatar Pavel Shutsin 2️⃣
Browse files

feat: Add reset command to GitLab Duo Chat

parent 2212974f
Loading
Loading
Loading
Loading
+16 −2
Original line number Diff line number Diff line
@@ -68,6 +68,11 @@
        "command": "gl.explainSelectedCode",
        "title": "Explain Selected Code",
        "category": "GitLab Duo"
      },
      {
        "command": "gl.newChatConversation",
        "title": "Start new chat conversation",
        "category": "GitLab Duo"
      }
    ],
    "submenus": [
@@ -85,6 +90,10 @@
        {
          "command": "gl.explainSelectedCode",
          "when": "config.gitlab.featureFlags.chat && editorHasSelection && gitlab:validState"
        },
        {
          "command": "gl.newChatConversation",
          "when": "config.gitlab.featureFlags.chat && gitlab:validState"
        }
      ],
      "editor/context": [
@@ -105,12 +114,17 @@
      {
        "command": "gl.openChat",
        "when": "config.gitlab.featureFlags.chat && gitlab:validState",
        "key": "alt+c alt+c"
        "key": "alt+o"
      },
      {
        "command": "gl.explainSelectedCode",
        "when": "config.gitlab.featureFlags.chat && editorHasSelection && gitlab:validState",
        "key": "alt+c alt+e"
        "key": "alt+e"
      },
      {
        "command": "gl.newChatConversation",
        "when": "config.gitlab.featureFlags.chat && gitlab:validState",
        "key": "alt+n"
      }
    ],
    "configuration": {
+23 −0
Original line number Diff line number Diff line
import { GitLabChatController } from '../gitlab_chat_controller';
import { newChatConversation } from './new_chat_conversation';

describe('newChatConversation', () => {
  let controller: GitLabChatController;

  beforeEach(() => {
    controller = {
      processNewUserRecord: jest.fn(),
    } as unknown as Partial<GitLabChatController> as GitLabChatController;
  });

  it('triggers new "/reset" record', async () => {
    await newChatConversation(controller);
    expect(controller.processNewUserRecord).toHaveBeenCalledWith(
      expect.objectContaining({
        content: '/reset',
        role: 'user',
        type: 'newConversation',
      }),
    );
  });
});
+17 −0
Original line number Diff line number Diff line
import { GitLabChatController } from '../gitlab_chat_controller';
import { GitLabChatRecord } from '../gitlab_chat_record';

export const COMMAND_NEW_CHAT_CONVERSATION = 'gl.newChatConversation';

/**
 * Command will start new chat conversation
 */
export const newChatConversation = async (controller: GitLabChatController) => {
  const record = new GitLabChatRecord({
    role: 'user',
    type: 'newConversation',
    content: `/reset`,
  });

  await controller.processNewUserRecord(record);
};
+8 −1
Original line number Diff line number Diff line
@@ -19,7 +19,8 @@ describe('activateChat', () => {
    vscode.commands.registerCommand = jest
      .fn()
      .mockReturnValueOnce('command1')
      .mockReturnValueOnce('command2');
      .mockReturnValueOnce('command2')
      .mockReturnValueOnce('command3');
  });

  it('registers view provider', () => {
@@ -45,8 +46,14 @@ describe('activateChat', () => {
      'gl.explainSelectedCode',
      expect.any(Function),
    );
    expect(vscode.commands.registerCommand).toHaveBeenNthCalledWith(
      3,
      'gl.newChatConversation',
      expect.any(Function),
    );

    expect(context.subscriptions[1]).toEqual('command1');
    expect(context.subscriptions[2]).toEqual('command2');
    expect(context.subscriptions[3]).toEqual('command3');
  });
});
+7 −0
Original line number Diff line number Diff line
@@ -5,6 +5,10 @@ import {
  COMMAND_EXPLAIN_SELECTED_CODE,
  explainSelectedCode,
} from './commands/explain_selected_code';
import {
  COMMAND_NEW_CHAT_CONVERSATION,
  newChatConversation,
} from './commands/new_chat_conversation';
import { GitLabPlatformManager } from '../platform/gitlab_platform';
import { CHAT_SIDEBAR_VIEW_ID } from './gitlab_chat_view';

@@ -24,6 +28,9 @@ export const activateChat = (context: vscode.ExtensionContext, manager: GitLabPl
    vscode.commands.registerCommand(COMMAND_EXPLAIN_SELECTED_CODE, async () => {
      await explainSelectedCode(controller);
    }),
    vscode.commands.registerCommand(COMMAND_NEW_CHAT_CONVERSATION, async () => {
      await newChatConversation(controller);
    }),
  );
};

Loading