Skip to content

Commit 0caa6ef

Browse files
committed
update usage docs regarding contexts
1 parent eb177de commit 0caa6ef

File tree

1 file changed

+132
-22
lines changed

1 file changed

+132
-22
lines changed

docs/usage.md

Lines changed: 132 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,22 @@ Everything you need to get productive with ECA inside Neovim.
1717

1818
| Command | Description | Example |
1919
|--------|-------------|---------|
20-
| `:EcaChat` | Opens ECA chat | `:EcaChat` |
21-
| `:EcaToggle` | Toggles sidebar visibility | `:EcaToggle` |
22-
| `:EcaFocus` | Focus on ECA sidebar | `:EcaFocus` |
23-
| `:EcaClose` | Closes ECA sidebar | `:EcaClose` |
24-
| `:EcaAddFile [file]` | Adds file as context | `:EcaAddFile src/main.lua` |
25-
| `:EcaAddSelection` | Adds current selection as context | `:EcaAddSelection` |
26-
| `:EcaServerStart` | Starts ECA server manually | `:EcaServerStart` |
27-
| `:EcaServerStop` | Stops ECA server | `:EcaServerStop` |
28-
| `:EcaServerRestart` | Restarts ECA server | `:EcaServerRestart` |
29-
| `:EcaSend <message>` | Sends message directly | `:EcaSend Explain this function` |
20+
| `:EcaChat` | Open ECA chat sidebar | `:EcaChat` |
21+
| `:EcaToggle` | Toggle sidebar visibility | `:EcaToggle` |
22+
| `:EcaFocus` | Focus ECA sidebar | `:EcaFocus` |
23+
| `:EcaClose` | Close ECA sidebar | `:EcaClose` |
24+
| `:EcaChatAddFile [file]` | Add a file as context for the current chat | `:EcaChatAddFile lua/eca/sidebar.lua` |
25+
| `:EcaChatRemoveFile [file]` | Remove a file context from the current chat | `:EcaChatRemoveFile lua/eca/sidebar.lua` |
26+
| `:EcaChatAddSelection` | Add current visual selection as a file-range context | `:EcaChatAddSelection` |
27+
| `:EcaChatAddUrl` | Add a URL as "web" context | `:EcaChatAddUrl` |
28+
| `:EcaChatListContexts` | List active contexts for the current chat | `:EcaChatListContexts` |
29+
| `:EcaChatClearContexts` | Clear all contexts for the current chat | `:EcaChatClearContexts` |
30+
| `:EcaServerStart` | Start ECA server manually | `:EcaServerStart` |
31+
| `:EcaServerStop` | Stop ECA server | `:EcaServerStop` |
32+
| `:EcaServerRestart` | Restart ECA server | `:EcaServerRestart` |
33+
| `:EcaSend <message>` | Send message directly (without opening chat) | `:EcaSend Explain this function` |
34+
35+
Deprecated aliases (still available but log a warning): `:EcaAddFile`, `:EcaAddSelection`, `:EcaRemoveContext`, `:EcaListContexts`, `:EcaClearContexts`. Prefer the `:EcaChat*` variants above.
3036

3137
---
3238

@@ -81,30 +87,134 @@ Consider readability and maintainability.
8187
### Current file
8288

8389
```vim
84-
:EcaAddFile
90+
:EcaChatAddFile
8591
```
8692

93+
Adds the current buffer as a file context for the active chat.
94+
8795
### Specific file
8896

8997
```vim
90-
:EcaAddFile src/main.lua
91-
:EcaAddFile /full/path/to/file.js
98+
:EcaChatAddFile src/main.lua
99+
:EcaChatAddFile /full/path/to/file.js
92100
```
93101

102+
Pass a path to add that file as context. Relative paths are resolved to absolute paths.
103+
94104
### Code selection
95105

96106
1. Select code in visual mode (`v`, `V`, or `Ctrl+v`)
97-
2. Run `:EcaAddSelection`
98-
3. Selected code will be added as context
107+
2. Run `:EcaChatAddSelection`
108+
3. The selected lines will be added as a file-range context (file + line range)
109+
110+
### Web URLs
111+
112+
```vim
113+
:EcaChatAddUrl
114+
```
115+
116+
Prompts for a URL and adds it as a `web` context. The URL label in the input is truncated for display, but the full URL is sent to the server.
117+
118+
### Listing and clearing contexts
119+
120+
```vim
121+
:EcaChatListContexts " show all active contexts
122+
:EcaChatClearContexts " remove all contexts from the current chat
123+
:EcaChatRemoveFile " remove the current file from contexts
124+
```
99125

100126
### Multiple files
101127

102128
```vim
103-
:EcaAddFile src/utils.lua
104-
:EcaAddFile src/config.lua
105-
:EcaAddFile tests/test_utils.lua
129+
:EcaChatAddFile
130+
:EcaChatAddFile src/utils.lua
131+
:EcaChatAddFile src/config.lua
132+
:EcaChatAddFile tests/test_utils.lua
133+
```
134+
135+
### Context area in the input
136+
137+
When the sidebar is open, the chat input buffer has **two parts**:
138+
139+
1. **First line – context area**: shows one label per active context (e.g. `sidebar.lua `, `sidebar.lua:25-50 ` or a truncated URL).
140+
2. **Below that – message input**: your prompt, prefixed by `> ` (configurable via `windows.input.prefix`).
141+
142+
You normally do not need to edit the first line manually, but you can:
143+
144+
- **Remove a single context**: move the cursor to the corresponding label on the first line and delete it; the context is removed from the current chat while your message text is preserved.
145+
- **Clear all contexts**: delete the whole first line; ECA restores an empty context line and clears all contexts.
146+
147+
#### Examples
148+
149+
**No contexts yet**
150+
151+
```text
152+
@
153+
> Explain this code
154+
```
155+
156+
**Single file context**
157+
158+
```text
159+
@sidebar.lua @
160+
> Explain this code
106161
```
107162

163+
**Two contexts (file + line range)**
164+
165+
```text
166+
@sidebar.lua @sidebar.lua:25-50 @
167+
> Explain this selection
168+
```
169+
170+
If you now delete just the `sidebar.lua:25-50 ` label on the first line, only that context is removed:
171+
172+
```text
173+
@sidebar.lua @
174+
> Explain this selection
175+
```
176+
177+
If instead you delete the **entire first line**, all contexts are cleared. ECA recreates an empty context line internally and keeps your input text:
178+
179+
```text
180+
@
181+
> Explain this selection
182+
```
183+
184+
When typing paths directly with `@` to trigger completion, the input might briefly look like:
185+
186+
```text
187+
@lua/eca/sidebar.lua
188+
> Input text
189+
```
190+
191+
After confirming a completion item, that `@...` reference is turned into a context entry and shown as a short label (for example `sidebar.lua `) in the context area.
192+
193+
### Context completion and `@` / `#` path shortcuts
194+
195+
Inside the input (filetype `eca-input`):
196+
197+
- Typing `@` or `#` followed by part of a path triggers context completion (via the provided `cmp`/`blink` sources).
198+
- Selecting a completion item in the **context area line** automatically adds that item as a context for the current chat and shows it as a label on the first line.
199+
200+
Semantics of the two prefixes:
201+
202+
- **`@` prefix***inline content*:
203+
- `@path/to/file.lua` means: "resolve this to the file contents and send those contents to the model".
204+
- The server expands the `@` reference to the actual file content before forming the prompt.
205+
- **`#` prefix***path reference*:
206+
- `#path/to/file.lua` means: "send the full absolute path; the model will fetch and read the file itself".
207+
- The server keeps it as a path reference in the prompt so the model can look up the file by path.
208+
209+
In both cases, when you send a message any occurrences like:
210+
211+
```text
212+
@relative/path/to/file.lua
213+
#another/path
214+
```
215+
216+
are first expanded to absolute paths on the Neovim side (including `~` expansion). The difference is how the server then interprets `@` (inline file contents) versus `#` (path-only reference that the model resolves).
217+
108218
---
109219

110220
## Common Use Cases
@@ -145,7 +255,7 @@ Consider readability and maintainability.
145255
## Recommended Workflow
146256

147257
1. Open the file you want to analyze
148-
2. Add as context: `:EcaAddFile`
258+
2. Add as context: `:EcaChatAddFile`
149259
3. Open chat: `<leader>ec`
150260
4. Ask your question:
151261
```markdown
@@ -190,7 +300,7 @@ Consider readability and maintainability.
190300
## Tips and Tricks
191301

192302
### Productivity
193-
1. Use `:EcaAddFile` before asking about specific code
303+
1. Use `:EcaChatAddFile` before asking about specific code
194304
2. Combine contexts: add multiple related files
195305
3. Be specific: detailed questions generate better responses
196306
4. Use Markdown: ECA understands Markdown formatting
@@ -230,10 +340,10 @@ Consider readability and maintainability.
230340
-- More convenient shortcuts
231341
vim.keymap.set("n", "<F12>", ":EcaChat<CR>")
232342
vim.keymap.set("n", "<F11>", ":EcaToggle<CR>")
233-
vim.keymap.set("v", "<leader>ea", ":EcaAddSelection<CR>")
343+
vim.keymap.set("v", "<leader>ea", ":EcaChatAddSelection<CR>")
234344

235345
-- Shortcut to add current file
236346
vim.keymap.set("n", "<leader>ef", function()
237-
vim.cmd("EcaAddFile " .. vim.fn.expand("%"))
347+
vim.cmd("EcaChatAddFile " .. vim.fn.expand("%"))
238348
end)
239349
```

0 commit comments

Comments
 (0)