continue icon indicating copy to clipboard operation
continue copied to clipboard

contextItems always empty with custom slash commands

Open frblondin opened this issue 1 year ago • 1 comments

Before submitting your bug report

Relevant environment info

- Continue: 0.9.58
- Version: 1.85.2 (system setup)
- Commit: 8b3775030ed1a69b13e4f4c628c612102e30a681
- Date: 2024-01-18T06:40:10.514Z
- Electron: 25.9.7
- ElectronBuildId: 26354273
- Chromium: 114.0.5735.289
- Node.js: 18.15.0
- V8: 11.4.183.29-electron.0
- OS: Windows_NT x64 10.0.19045

Description

I need to resolve current selected code in a custom slash command. I've reused what is implemented in edit.ts, but surprisingly it doesn't work. I've tried to debug, but I failed at understanding why the gui is only sending the contextItems when /edit used, but not if /mycommand is used.

I'd suggest to provide one more parameter selectedCode, just like you did for context providers. Also, my custom command needs to use edit (it does some prep work and then invokes edit slash command, just like you did for several commands)... but accessing the edit requires a hack (I am providing the config.slashCommands array to my custom slash command in config.ts. Making the config accessible as one more argument in the run method of SlashCommand would be great... so to summarize please add these two arguments: selectedCode and config, please!

To reproduce

Create the following slash command:

export const MyCommand: SlashCommand = {
  name: "mycommand",
  description: "mycommand",
  run: async function* (sdk) {
    let contextItemToEdit = sdk.contextItems.find(
      (item: ContextItemWithId) =>
        item.editing && item.id.providerTitle === "code"
    );
    if (!contextItemToEdit) {
      contextItemToEdit = sdk.contextItems.find(
        (item: ContextItemWithId) => item.id.providerTitle === "code"
      );
    }
    if (!contextItemToEdit) {
      yield "This is always what's happening, unfortunately.";
      return;
    }

Log output

No response

frblondin avatar Feb 09 '24 16:02 frblondin

@frblondin just made the changes here. Will likely not make their way into pre-release until later tomorrow, as I'm hoping to merge together with a larger set of updates

sestinj avatar Feb 19 '24 23:02 sestinj

Thanks @sestinj

frblondin avatar Mar 01 '24 08:03 frblondin