remove cursor and annoying light bulb

This commit is contained in:
Raoul Branten 2025-12-23 14:54:16 +01:00
parent c6146055fb
commit bb0a48dafb
7 changed files with 11 additions and 284 deletions

View File

@ -1,103 +0,0 @@
# Cursor Autocompletion for Neovim
This setup integrates Cursor's AI-powered autocompletion into Neovim using `cursor-agent` CLI and `nvim-cmp`.
## Features
- **AI-powered completions**: Get intelligent code completions powered by Cursor's AI
- **Context-aware**: Uses surrounding code context (last 30 lines) for better suggestions
- **Integrated with nvim-cmp**: Works seamlessly with other completion sources (LSP, snippets, buffer, etc.)
- **Prioritized suggestions**: Cursor completions appear at the top of the completion menu
## Setup
The integration is already configured! Just make sure:
1. **cursor-agent CLI is installed and authenticated**:
```bash
cursor-agent status
```
If not authenticated, run:
```bash
cursor-agent login
```
2. **Restart Neovim** to load the new configuration
3. **Install plugins** (if using lazy.nvim, they'll auto-install):
```vim
:Lazy sync
```
## Usage
1. **Start typing** in any file
2. **Press `<C-Space>`** to trigger completion manually, or wait for automatic triggers
3. **Look for `[Cursor]`** in the completion menu to see AI suggestions
4. **Navigate** with `<Tab>`/`<S-Tab>` and **accept** with `<Enter>`
## Configuration
### Keybindings
Default keybindings (can be customized in `lua/config/plugin/cmp.lua`):
- `<C-Space>` - Trigger completion
- `<Tab>` - Next completion item / Expand snippet
- `<S-Tab>` - Previous completion item / Jump snippet backward
- `<Enter>` - Confirm completion
- `<C-e>` - Close completion menu
### Adjusting Completion Behavior
Edit `lua/plugins/cmp-cursor.lua` to customize:
- **Context window**: Change `line_num - 30` to adjust how many lines of context are sent
- **Minimum trigger length**: Change `#before_cursor:gsub('%s+', '') < 3` to require more/less context
- **Timeout**: Change `8000` (8 seconds) to adjust how long to wait for completions
### Disabling Cursor Completions
To temporarily disable Cursor completions, comment out the cursor source in `lua/config/plugin/cmp.lua`:
```lua
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
-- { name = 'cursor', source = cursor_completion_source }, -- Disabled
{ name = 'luasnip' },
}, {
```
## How It Works
1. When you trigger completion, the plugin captures:
- Current line up to cursor position
- Last 30 lines of context
- File content
2. It sends a prompt to `cursor-agent --print` asking for completion suggestions
3. The AI response is parsed and formatted as completion items
4. These appear in the nvim-cmp completion menu with `[Cursor]` label
## Troubleshooting
**No Cursor completions appearing:**
- Check `cursor-agent status` to ensure you're authenticated
- Verify `cursor-agent` is in your PATH: `which cursor-agent`
- Check Neovim messages: `:messages` for any errors
**Completions are slow:**
- This is expected - AI completions take 2-8 seconds
- Consider increasing the minimum trigger length to reduce API calls
- The timeout is set to 8 seconds
**Completions don't make sense:**
- The AI uses context from your file - ensure you have meaningful code before the cursor
- Try typing more context before triggering completion
## Notes
- Cursor completions use API credits from your Cursor account
- Completions are generated on-demand, not cached
- The integration works best with code files (not plain text)
- For best results, ensure your code is syntactically correct before requesting completions

View File

@ -16,10 +16,9 @@
- **Mason + Mason-LSPConfig**: LSP server management
- **nvim-lspconfig**: LSP client configuration
- **Lspsaga**: Enhanced LSP UI (code actions, definitions, diagnostics, outline)
- **nvim-cmp**: Completion engine with:
- Buffer, path, LSP, cmdline sources
- LuaSnip snippets
- Custom Cursor AI completion source (`cursor-agent` integration)
- **nvim-cmp**: Completion engine with:
- Buffer, path, LSP, cmdline sources
- LuaSnip snippets
### Syntax & Highlighting
- **nvim-treesitter**: Syntax highlighting via language parsers
@ -130,8 +129,7 @@
- Shell commands run interactively (`-ic` flag)
## Special Features
1. **Cursor AI Integration**: Custom completion source using `cursor-agent` for AI-powered completions
2. **PHP Helper**: Custom function for inserting debug backtraces
1. **PHP Helper**: Custom function for inserting debug backtraces
3. **Custom Aliases**: `Bufdel` command for buffer management
4. **Quick Directory Navigation**: Shortcuts to LMS project directories (`<leader>c`)

View File

@ -5,5 +5,4 @@ require("config.lazy")
require("config.keymaps")
require("config.options")
require("config.aliases")
require("config.cmp-cursor")
require("config.plugin")

View File

@ -1,161 +0,0 @@
-- Custom nvim-cmp source for Cursor Agent autocompletion
local cmp = require('cmp')
local source = {}
source.new = function()
return setmetatable({}, { __index = source })
end
source.is_available = function()
-- Check if cursor-agent is available
return vim.fn.executable('cursor-agent') == 1
end
source.get_trigger_characters = function()
return {}
end
source.complete = function(self, request, callback)
-- Only trigger if there's meaningful context (at least 3 characters typed)
local bufnr = request.context.bufnr
local cursor = vim.api.nvim_win_get_cursor(0)
local line_num = cursor[1]
local col_num = cursor[2] + 1 -- Convert to 1-indexed
-- Get current line and context
local current_line = vim.api.nvim_buf_get_lines(bufnr, line_num - 1, line_num, false)[1] or ''
local before_cursor = current_line:sub(1, col_num - 1)
-- Skip if too little context (less than 3 characters before cursor)
if #before_cursor:gsub('%s+', '') < 3 then
callback({ items = {} })
return
end
-- Get surrounding context (last 30 lines for better context)
local start_line = math.max(0, line_num - 30)
local context_lines = vim.api.nvim_buf_get_lines(bufnr, start_line, line_num, false)
local context = table.concat(context_lines, '\n')
-- Build prompt for cursor-agent - optimized for completion
local prompt = string.format(
"Complete the code after the cursor. Return ONLY the text that should appear after the cursor position, nothing else. Do not include any explanation or the existing code.\n\nContext:\n%s\n\nComplete after cursor (|): %s|",
context,
before_cursor
)
-- Call cursor-agent with --print flag
local cmd = {
'cursor-agent',
'--print',
'--output-format', 'text',
prompt
}
local completed = false
local job_id = vim.fn.jobstart(cmd, {
stdout_buffered = true,
stderr_buffered = true,
on_stdout = function(_, data, _)
if completed then return end
completed = true
if not data or #data == 0 then
callback({ items = {} })
return
end
-- Parse completion suggestions
local items = {}
local full_text = table.concat(data, '\n'):gsub('%s+', ' '):gsub('^%s+', ''):gsub('%s+$', '')
if full_text and full_text ~= '' then
-- Try to extract just the completion part
-- Remove any text that matches the before_cursor context
local completion = full_text
-- Clean up common prefixes that might be repeated
if before_cursor ~= '' then
local escaped_prefix = vim.pesc(before_cursor:match('[%w_]+$') or '')
if escaped_prefix ~= '' then
completion = completion:gsub('^' .. escaped_prefix, '')
end
end
-- Split into potential multiple completions (by lines or common patterns)
if completion:find('\n') then
-- Multiple lines - create separate items
for line in completion:gmatch('[^\n]+') do
line = line:gsub('^%s+', ''):gsub('%s+$', '')
if line ~= '' and #line > 0 then
table.insert(items, {
label = line,
kind = cmp.lsp.CompletionItemKind.Text,
documentation = {
kind = 'markdown',
value = '**Cursor AI Completion**\n\n' .. line
},
sortText = '0' .. line, -- Prioritize Cursor completions
})
end
end
else
-- Single line completion
completion = completion:gsub('^%s+', ''):gsub('%s+$', '')
if completion ~= '' and #completion > 0 then
-- Create multiple suggestions: full completion, first word, etc.
table.insert(items, {
label = completion,
kind = cmp.lsp.CompletionItemKind.Text,
documentation = {
kind = 'markdown',
value = '**Cursor AI Completion**\n\n' .. completion
},
sortText = '0' .. completion,
})
-- Also add first word/phrase as a shorter option
local first_part = completion:match('^([%w_]+)') or completion:match('^([^%s]+)')
if first_part and first_part ~= completion and #first_part > 2 then
table.insert(items, {
label = first_part,
kind = cmp.lsp.CompletionItemKind.Text,
documentation = {
kind = 'markdown',
value = '**Cursor AI Completion** (partial)\n\n' .. first_part
},
sortText = '1' .. first_part,
})
end
end
end
end
callback({ items = items })
end,
on_stderr = function(_, data, _)
if completed then return end
completed = true
-- On error, return empty completions
callback({ items = {} })
end,
on_exit = function(_, code, _)
if completed then return end
completed = true
if code ~= 0 then
callback({ items = {} })
end
end
})
-- Set timeout (8 seconds for AI completion)
vim.defer_fn(function()
if not completed and vim.fn.jobwait({ job_id }, 0)[1] == -1 then
vim.fn.jobstop(job_id)
completed = true
callback({ items = {} })
end
end, 8000)
end
return source

View File

@ -1,11 +1,7 @@
-- nvim-cmp configuration with Cursor Agent completion source
-- nvim-cmp configuration
local cmp = require('cmp')
local luasnip = require('luasnip')
-- Register custom Cursor completion source
local cursor_source = require('config.cmp-cursor')
cmp.register_source('cursor', cursor_source.new())
cmp.setup({
snippet = {
expand = function(args)
@ -42,7 +38,6 @@ cmp.setup({
sources = cmp.config.sources({
sources = cmp.config.sources({
{ name = 'nvim_lsp', priority = 1000 },
{ name = 'cursor', priority = 900 }, -- Lower priority than LSP
{ name = 'luasnip', priority = 750 },
}, {
{ name = 'buffer', priority = 500 },
@ -67,7 +62,6 @@ cmp.setup({
format = function(entry, vim_item)
vim_item.menu = ({
nvim_lsp = '[LSP]',
cursor = '[Cursor]',
luasnip = '[Snippet]',
buffer = '[Buffer]',
path = '[Path]',

View File

@ -1,5 +1 @@
require('lspsaga').setup({
lightbulb = {
enable = false,
},
})
require('lspsaga').config.lightbulb.enabled = false

View File

@ -190,7 +190,11 @@ return {
{
'nvimdev/lspsaga.nvim',
config = function()
require('lspsaga').setup({})
require('lspsaga').setup({
lightbulb = {
enable = false,
},
})
end,
dependencies = {
'nvim-treesitter/nvim-treesitter', -- optional