Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: register/update prompt #680

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

LintaoAmons
Copy link

@LintaoAmons LintaoAmons commented Jan 22, 2025

Description

With this PR, you can use a new method to register a new action or update an existing action
The register call can happen from anywhere and anytime, it doesn't require you restart the neovim to take effect.

try with this snippet, put it anywhere and source it, then you can find the registered action in the action palette

require("codecompanion.config").register_prompt("test register_prompt with references", {
  -- TODO: define a chat name to make it easier when trying to find it with `OpenChat`
  strategy = "chat",
  description = "Add some references",
  opts = {
    index = 11,
    is_default = true,
    is_slash_cmd = false,
    short_name = "ref",
    auto_submit = false,
  },
  -- These will appear at the top of the chat buffer
  references = {
    {
      type = "file",
      path = { -- This can be a string or a table of values
        "lua/codecompanion/health.lua",
        "lua/codecompanion/http.lua",
      },
    },
    {
      type = "file",
      path = "lua/codecompanion/schema.lua",
    },
    {
      type = "symbols",
      path = "lua/codecompanion/strategies/chat/init.lua",
    },
    {
      type = "url", -- This URL will even be cached for you!
      url = "https://raw.githubusercontent.com/olimorris/codecompanion.nvim/refs/heads/main/lua/codecompanion/commands.lua",
    },
  },
  prompts = {
    {
      role = "user",
      content = "I'll think of something clever to put here...",
      opts = {
        contains_code = true,
      },
    },
  },
})

Related Issue(s)

#649

Screenshots

cc

Checklist

  • I've read the CONTRIBUTING guidelines and have adhered to them in this PR
  • I've updated the README
  • I've ran the make docs command

@olimorris
Copy link
Owner

Amazing! Let me know when you're happy for me to review

@LintaoAmons
Copy link
Author

LintaoAmons/bookmarks.nvim#71

Provide the context with the bookmarks in a list with my bookmarks.nvim plugin
cc with bookmarks

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I add this test file to help you review the functions,
if you want to merge it, we can remove it

README.md Show resolved Hide resolved
@LintaoAmons LintaoAmons changed the title WIP: feat: register/update prompt feat: register/update prompt Jan 23, 2025
@LintaoAmons
Copy link
Author

@olimorris Please review~

test.lua Show resolved Hide resolved
@olimorris
Copy link
Owner

Awesome thanks for this. I will test this out today/tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants