Skip to content

Customization

Lavin Raj Mohan edited this page May 12, 2025 · 3 revisions

Mappings

Mappings can be customized by mappings key in the plugin options

  {
    mappings = {
      dialog = { ... },
      panel = { ... },
      patcher = { ... },
      picker = { ... },
      previewer = { ... },
    }
  }

Default mappings

local default_mappings = {
  picker = {
    n = {
      ['?'] = actions.which_key,
      ['q'] = actions.close_current,
      ['<ESC>'] = actions.close_current,
      ['<C-c>'] = actions.close_current,
    },
  },
  panel = {
    n = {
      ['?'] = actions.which_key,
      ['q'] = actions.close_current,
      ['<ESC>'] = actions.close_current,
      ['<C-c>'] = actions.close_current,
      ['i'] = actions.run_interactive,
      ['r'] = actions.run_testcases,
      ['s'] = actions.toggle_cur_selection,
      ['a'] = actions.toggle_all_selection,
      ['c'] = actions.create_new_testcase,
      ['d'] = actions.remove_testcases,
      ['e'] = actions.patch_testcase,
      ['<C-l>'] = actions.focus_previewer,
    },
  },
  previewer = {
    n = {
      ['?'] = actions.which_key,
      ['q'] = actions.close_current,
      ['<ESC>'] = actions.close_current,
      ['<C-c>'] = actions.close_current,
      ['<C-h>'] = actions.focus_panel,
    },
  },
  dialog = {
    n = {
      ['?'] = actions.which_key,
      ['q'] = actions.close_current,
      ['<ESC>'] = actions.close_current,
      ['<C-c>'] = actions.close_current,
    },
  },
  patcher = {
    n = {
      ['?'] = actions.which_key,
      ['q'] = actions.close_current,
      ['<ESC>'] = actions.close_current,
      ['<C-c>'] = actions.close_current,
    },
  },
}

every UI component can have mappings for normal, insert and visual mode, Below is an example of setting up new mapping in normal mode for picker component

  {
    mappings = {
      picker = {
        n = {
          ["<C-y>"] = require("assistant.actions").close_current
        }
      },
    }
  }

For left hand side of the mapping you can either pass an action or a function which will get invoke on key press. You can also explore builtin actions here

Commands

By default assistant comes with general commands for cpp and python files. Below are the snippets for cpp and python command:

-- interpreted languages do not compile
-- shell command to run python code: python3 code.py

  {
    python = {
        extension = 'py',
        template = nil,
        compile = nil,
        execute = {
            main = 'python3',
            args = { '$FILENAME_WITH_EXTENSION' },
        },
    },

-- shell command to compile c++ code: g++ code.cpp -o code
-- shell command to execute c++ code: ./code

    cpp = {
        extension = 'cpp',
        template = nil,
        compile = {
            main = 'g++',
            args = { '$FILENAME_WITH_EXTENSION', '-o', '$FILENAME_WITHOUT_EXTENSION' },
        },
        execute = {
            main = './$FILENAME_WITHOUT_EXTENSION',
            args = nil,
        },
    },
  }

If we compare the shell commands written in comments and lua snippet, we can easily write another command for rust files as follows:

-- shell command to compile rust code: rustc code.rs
-- shell command to execute rust code: ./code

  {
    rust = {
        extension = 'rs',
        template = nil,
        compile = {
            main = 'rustc',
            args = { '$FILENAME_WITH_EXTENSION' },
        },
        execute = {
            main = './$FILENAME_WITHOUT_EXTENSION',
            args = nil,
        },
    },
  }
Clone this wiki locally