跳转至

clangd(cix-compiler)

当前项目的 .vscode/settings.json

JSON
{
  // --- clangd (recommended) ---
  // 使用稳定的 clangd 15(与项目构建用的 clang++ 15 一致)。
  // 系统默认 PATH 中存在一个损坏的 clangd 21(target triple 为空),会导致
  // 所有文件报 "unknown target triple 'unknown'" 而 AST 构建失败,跳转失效。
  // "clangd.path": "${workspaceFolder}/build/bin/clangd",
  "clangd.path": "/home/ken/workspace/llvm15/build/bin/clangd",

  // clangd 自动接管 IntelliSense;显式禁用 cpptools 的 IntelliSense 以避免冲突。
  "clangd.arguments": [
    "--compile-commands-dir=build",
    "--background-index",
    "--clang-tidy",
    "--header-insertion=never",
    "--completion-style=detailed",
    "--pch-storage=memory"
  ],
  "clangd.onConfigChanged": "restart",
  "clangd.checkUpdates": false,

  // --- Disable cpptools IntelliSense to prevent conflicts ---
  "C_Cpp.intelliSenseEngine": "disabled",
  "C_Cpp.autocomplete": "disabled",
  "C_Cpp.errorSquiggles": "disabled",
  "C_Cpp.formatting": "disabled",

  // Keep cpptools compile commands path as a fallback reference (not used when
  // IntelliSense engine is disabled, but documents the build db location).
  "C_Cpp.default.compileCommands": "${workspaceFolder}/build/compile_commands.json",

  // --- File associations for this MLIR/LLVM project ---
  "files.associations": {
    "*.td": "tablegen",
    "*.mlir": "mlir",
    "*.ll": "llvm",
    "*.tpp": "cpp"
  },

  // Exclude large third-party dirs from clangd indexing to speed things up.
  "files.exclude": {
    "**/.git": true,
    "**/.svn": true,
    "**/.hg": true,
    "**/CVS": true,
    "**/.DS_Store": true
  },
  "search.exclude": {
    "**/build": true,
    "**/third_party/llvm-project": true,
    "**/third_party/iree": true,
    "**/third_party/torch-mlir": true
  }
}

项目根目录下还要有.clangd

YAML
---
# clangd configuration for cix-compiler project
# See: https://clangd.llvm.org/config

CompileFlags:
  # Path to the directory containing compile_commands.json (generated by CMake)
  CompilationDatabase: /home/ken/workspace/cix-compiler/build

  # Remove flags that cause issues with clangd
  Remove:
    - -Werror=date-time
    - -Werror=unguarded-availability-new
    - -Werror=global-constructors

Index:
  # Enable background indexing for better cross-file navigation
  Background: Build
  StandardLibrary: true

InlayHints:
  Enabled: Yes
  ParameterNames: Yes
  DeducedTypes: Yes

# Tidy checks tuned for this codebase
Diagnostics:
  ClangTidy:
    Add: [modernize-*, bugprone-*, performance-*]
    Remove: [modernize-use-trailing-return-type]
  Suppress: [unused_includes]