Skip to content

In‐Editor Chatting

Silas Marvin edited this page Aug 6, 2024 · 3 revisions

LSP-AI provides powerful in-editor chatting capabilities through code actions, allowing you to interact with AI assistants directly within your code editor. This feature enhances your coding experience by providing instant access to AI-powered help and suggestions.

Quick Start Guide

  1. Configure LSP-AI for in-editor chatting (see Configuration)
  2. Open a file (maybe a Markdown file) in your supported editor
  3. Type a chat trigger (e.g., !C) followed by your question
  4. Activate the code action for chatting (e.g., in Helix, press space + a)
  5. View the AI's response and continue the conversation

Configuration

For detailed information on configuring in-editor chatting, please refer to the Configuration page.

Example Configuration

{
  "chat": [
    {
      "trigger": "!C",
      "action_display_name": "Chat",
      "model": "model1",
      "parameters": {
        "max_context": 4096,
        "max_tokens": 1024,
        "system": "You are a code assistant chatbot. The user will ask you for assistance coding and you will do your best to answer succinctly and accurately"
      }
    },
    {
      "trigger": "!CC",
      "action_display_name": "Chat with context",
      "model": "model1",
      "parameters": {
        "max_context": 4096,
        "max_tokens": 1024,
        "system": "You are a code assistant chatbot. The user will ask you for assistance coding and you will do your best to answer succinctly and accurately given the code context:\n\n{CONTEXT}"
      }
    }
  ]
}

How It Works

The Chat Life Cycle

  1. LSP-AI detects the chat trigger in your file
  2. Your editor requests available code actions
  3. LSP-AI offers the appropriate chat action
  4. You activate the chat action
  5. LSP-AI processes the request and returns the AI's response
  6. The response is inserted into your file

Chat Format

Conversations follow this format:

!C Your question here

<|assistant|>
AI's response here

<|user|>
Your follow-up question here

<|assistant|>
AI's follow-up response here

<|user|>

Best Practices

It is required the LSP-AI is running on the file / buffer to perform the chat action.

You don't have to use Markdown files, but for the Helix editor I have found Markdown is an easy choice for this.

Tip: Create a shortcut to open a dedicated chat file (e.g., lsp-ai-chat.md) for quick access.

Prompting

To chat about your codebase, use the !CC trigger (or your configured equivalent) and ensure you're using a Memory Backend that supports context, such as the VectorStore backend (not the FileStore backend).

For advanced usage and customization of prompts, please read our Prompting page. Note that for chat prompts, we don't recommend using the {CODE} keyword, as it will refer to the chat itself.

Troubleshooting

  • Issue: Chat actions not appearing Solution: Ensure the trigger is present in the file and LSP-AI is properly configured for your file type
  • Issue: Unexpected AI responses Solution: Check your system prompt and consider adjusting it for better results

Editor-Specific Notes

Helix

  • Use space + a to prompt for code actions
  • Create a shortcut (e.g., Ctrl-t) to open your chat file quickly

For more information or if you encounter any issues not covered here, please check our GitHub issues or open a new one.