• ↑↓ pour naviguer
  • pour ouvrir
  • pour sélectionner
  • ⌘ ⌥ ↵ pour ouvrir dans un panneau
  • ←→ pour naviguer
  • esc pour rejeter
⌘ '
raccourcis clavier

The Problem

LSP servers need to know the project root to provide accurate analysis—finding dependencies, resolving imports, understanding project structure. Without knowing the root, the server might behave incorrectly or provide incomplete results.

Core Idea

Root Markers are files or directories (like .git, package.json, pyproject.toml) that Neovim uses to identify the project workspace root. When a buffer matches a config’s filetypes, Neovim searches upward for root markers to determine where the LSP server operates.

How It Works

  1. Config specifies root_markers: {'.git', 'package.json', 'pyproject.toml'}
  2. When enabling LSP for a buffer, Neovim searches upward from the buffer’s directory
  3. First marker found determines the root; search stops at that directory
  4. Multiple markers in nested array have equal priority: {{'a', 'b'}, 'c'} means find either a or b first, else c
  5. If root_dir is explicitly defined, root_markers are ignored

Key Properties

  • Marker can be a file or directory name
  • Order in the array determines search priority
  • Nested arrays indicate equal-priority markers
  • Can be overridden by explicit root_dir function
  • Used by vim.lsp.enable() for auto-activation decisions

Connections

  • Built from: LSP Configuration — part of config
  • Builds into: LSP Client — root_dir becomes client property
  • Related: vim.lsp — used by enable() for workspace detection

Edge Cases & Gotchas

  • Without matching root markers, LSP won’t auto-activate
  • Search traverses upward until root filesystem or found
  • Polyglot projects may need careful marker ordering
  • Some languages have specific markers (e.g., .clangd for clangd)