Browse Source

Extract LintFile config and add AGENTS guide

Leon Versteeg 3 months ago
parent
commit
4ef315acc4
5 changed files with 131 additions and 3 deletions
  1. 53 0
      AGENTS.md
  2. 17 2
      coc-settings.json
  3. 1 0
      init.vim
  4. 2 1
      nvim-config/leader.vim
  5. 58 0
      nvim-config/lint.vim

+ 53 - 0
AGENTS.md

@@ -0,0 +1,53 @@
+# AGENTS.md
+
+## Purpose
+This file gives future coding agents a fast, reliable workflow for this Neovim repo.
+
+## Repo Layout
+- `init.vim`: minimal entrypoint, only plugin bootstrap + `source` statements + tiny misc settings.
+- `nvim-config/*.vim`: Vimscript modules by concern (leader maps, coc, lint, theme, etc.).
+- `nvim-config/*.lua`: Lua plugin configs and modern Neovim setup.
+- `coc-settings.json`: CoC language server and extension behavior.
+- `KEYMAPS.md`: user-facing shortcut overview. Keep in sync with mappings.
+
+## Editing Rules
+- Keep `init.vim` small. New logic belongs in a focused file under `nvim-config/`.
+- Prefer one concern per file (example: lint logic in `nvim-config/lint.vim`).
+- Avoid breaking existing `<leader>` mappings unless explicitly requested.
+- Do not silently remove language support; replace with an equivalent path first.
+- Preserve user customizations and avoid wide refactors unless needed for a concrete fix.
+
+## Validation Checklist (run after changes)
+- Config load:
+  - `/usr/local/bin/nvim --headless "+qa"`
+- Command existence:
+  - `/usr/local/bin/nvim --headless "+verbose command LintFile" "+qa"`
+- Mapping existence:
+  - `rg --line-number "<leader>lf|<leader>a|CocAction|LintFile" /Users/leon/.config/nvim/nvim-config`
+- Health checks when touching plugins/LSP:
+  - Open Neovim and run `:checkhealth`
+  - Run `:messages` after startup and after `:CocRestart`
+
+## Known Environment Notes
+- In non-interactive shells `nvim` may be missing from `PATH`; use `/usr/local/bin/nvim`.
+- A recurring message may appear: `Failed to find executable tmux`. Treat separately from lint/LSP issues.
+- CoC is used for LSP/code actions. Formatting is handled by `conform.nvim` (not `coc-prettier`).
+
+## Linting/Formatting Behavior
+- `:LintFile` lives in `nvim-config/lint.vim`.
+- JS/TS/Vue/Svelte/Astro:
+  - First try CoC ESLint autofix command.
+  - Fallback to local `node_modules/.bin/eslint --fix`.
+- Terraform/HCL: use `tflint` if installed.
+- Java diagnostics: via `coc-java` (JDTLS).
+- Formatting on save should remain with `conform.nvim` unless user asks otherwise.
+
+## Git Workflow
+- Make small, reviewable commits with clear messages.
+- Do not use destructive git commands (`reset --hard`, forced checkout) unless explicitly asked.
+- Never revert unrelated user changes.
+
+## When Unsure
+- Prefer adding a small module file over expanding `init.vim`.
+- Prefer explicit diagnostics (`echom`, `:messages`, `:checkhealth`) over guessing.
+- If behavior changes for a key mapping, update `KEYMAPS.md` in the same change.

+ 17 - 2
coc-settings.json

@@ -1,3 +1,18 @@
 {
-  "snippets.ultisnips.pythonPrompt": false
-}
+  "snippets.ultisnips.pythonPrompt": false,
+  "eslint.enable": true,
+  "eslint.workingDirectories": [
+    {
+      "mode": "auto"
+    }
+  ],
+  "eslint.validate": [
+    "javascript",
+    "javascriptreact",
+    "typescript",
+    "typescriptreact",
+    "vue",
+    "svelte",
+    "astro"
+  ]
+}

+ 1 - 0
init.vim

@@ -19,6 +19,7 @@ source $HOME/.config/nvim/nvim-config/goyo.vim
 source $HOME/.config/nvim/nvim-config/start-screen.vim
 source $HOME/.config/nvim/nvim-config/vim-test.vim
 source $HOME/.config/nvim/nvim-config/vimspector.vim
+source $HOME/.config/nvim/nvim-config/lint.vim
 
 source $HOME/.config/nvim/nvim-config/leader.vim
 

+ 2 - 1
nvim-config/leader.vim

@@ -62,7 +62,8 @@ nnoremap <silent> <leader>r <Cmd>Rg<CR>
 
 " Diagnostics and code actions
 nnoremap <silent> <leader>/ <Cmd>noh<CR>
-nnoremap <silent> <leader>a <Cmd>CocAction<CR>
+nmap <silent> <leader>a <Plug>(coc-codeaction-cursor)
+nnoremap <silent> <leader>lf <Cmd>LintFile<CR>
 nnoremap <silent> <leader>F <Cmd>Format<CR>
 nmap <silent> <leader>cl <Plug>(coc-codelens-action)
 nmap <silent> <leader>en <Plug>(coc-diagnostic-next)

+ 58 - 0
nvim-config/lint.vim

@@ -0,0 +1,58 @@
+" Per-file lint entrypoint used by <leader>lf / :LintFile
+function! s:lint_file() abort
+  let l:ft = &filetype
+  let l:filepath = expand('%:p')
+
+  if empty(l:filepath)
+    echohl WarningMsg
+    echom 'LintFile: no file to lint'
+    echohl None
+    return
+  endif
+
+  if index(['javascript', 'javascriptreact', 'typescript', 'typescriptreact', 'vue', 'svelte', 'astro'], l:ft) >= 0
+    if exists('*CocAction')
+      try
+        call CocAction('runCommand', 'eslint.executeAutofix')
+        echom 'LintFile: eslint autofix via CoC'
+        return
+      catch /.*/
+      endtry
+    endif
+
+    let l:eslint = findfile('node_modules/.bin/eslint', '.;')
+    if !empty(l:eslint)
+      execute 'silent !' . fnameescape(fnamemodify(l:eslint, ':p')) . ' --fix ' . shellescape(l:filepath)
+      checktime
+      edit
+      echom 'LintFile: eslint --fix (local)'
+      return
+    endif
+
+    echohl WarningMsg
+    echom 'LintFile: eslint not found (CoC command failed and no local node_modules/.bin/eslint)'
+    echohl None
+    return
+  endif
+
+  if index(['terraform', 'tf', 'hcl'], l:ft) >= 0
+    if executable('tflint')
+      execute 'silent !tflint --chdir ' . shellescape(expand('%:p:h'))
+      echom 'LintFile: tflint'
+    else
+      echohl WarningMsg
+      echom 'LintFile: tflint not installed'
+      echohl None
+    endif
+    return
+  endif
+
+  if l:ft ==# 'java'
+    echom 'LintFile: Java diagnostics come from coc-java (JDTLS)'
+    return
+  endif
+
+  echom 'LintFile: no linter configured for filetype "' . l:ft . '"'
+endfunction
+
+command! LintFile call <SID>lint_file()