Files
wehub-resource-sync a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:33:42 +08:00

55 lines
1.8 KiB
Go

package lsp
import (
"path/filepath"
"strings"
)
// hasCompileDB reports whether root carries a clangd-usable compilation
// database, or an explicit clangd configuration that means the user
// wired the server up deliberately. Without one, clangd falls back to a
// per-file preamble + AST rebuild on every didOpen — the churn the
// degraded enrichment path exists to avoid.
//
// Probed, in order:
// - <root>/compile_commands.json — the canonical CMake / Bear output
// - <root>/build*/compile_commands.json — out-of-tree build directories
// - <root>/compile_flags.txt — clangd's flat-flags fallback
// - <root>/.clangd — user opted clangd in by hand
//
// This mirrors the indexer's compile-DB probe without importing it: the
// import graph runs indexer→semantic only, so a helper both need must be
// stdlib-only and live on this side of the boundary. No caching — one
// stat set runs per enrichment pass.
func hasCompileDB(root string) bool {
if root == "" {
return false
}
if fileExists(filepath.Join(root, "compile_commands.json")) {
return true
}
if matches, _ := filepath.Glob(filepath.Join(root, "build*", "compile_commands.json")); len(matches) > 0 {
return true
}
if fileExists(filepath.Join(root, "compile_flags.txt")) {
return true
}
if fileExists(filepath.Join(root, ".clangd")) {
return true
}
return false
}
// isCXXHeaderFile reports whether rel names a C / C++ header. A degraded
// (no-compile-database) pass skips headers: opening one directly makes
// clangd treat it as a standalone translation unit and rebuild a full
// fallback AST for a file that, without a database, offers no cross-file
// signal in return.
func isCXXHeaderFile(rel string) bool {
switch strings.ToLower(filepath.Ext(rel)) {
case ".h", ".hh", ".hpp", ".hxx", ".h++":
return true
}
return false
}