[clang] [clang-tools-extra] [CodeCompletion] Consider header files without extension, if... (PR #166447)

Björn Schäpers via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 24 13:15:43 PST 2025


https://github.com/HazardyKnusperkeks updated https://github.com/llvm/llvm-project/pull/166447

>From f779bc650104e79e911630d67e963b72db08d7a9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Sch=C3=A4pers?= <bjoern at hazardy.de>
Date: Tue, 4 Nov 2025 22:25:53 +0100
Subject: [PATCH] [CodeCompletion] Consider header files without extension,
 if...

... the path passed to -I ends with /include.

I've brought it up, when the special handling for Qt was added
(https://reviews.llvm.org/D112996#3349609) but got no feedback.
---
 clang-tools-extra/docs/ReleaseNotes.rst      | 2 ++
 clang/lib/Sema/SemaCodeComplete.cpp          | 3 ++-
 clang/test/CodeCompletion/included-files.cpp | 9 +++++++--
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 924b2c03cfd18..c373f3f5c178b 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -111,6 +111,8 @@ Code completion
   allow fuzzy-matching with the ``FuzzyMatch`` option when suggesting 
   macros. ``ExactPrefix`` is the default, which retains previous 
   behavior of suggesting macros which match the prefix exactly.  
+- Now also provides include files without extension, if they are in a directory
+  only called ``include``.
 
 Code actions
 ^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp
index aa93507ab5c30..5739ee7699802 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -10366,7 +10366,8 @@ void SemaCodeCompletion::CodeCompleteIncludedFile(llvm::StringRef Dir,
     const StringRef &Dirname = llvm::sys::path::filename(Dir);
     const bool isQt = Dirname.starts_with("Qt") || Dirname == "ActiveQt";
     const bool ExtensionlessHeaders =
-        IsSystem || isQt || Dir.ends_with(".framework/Headers");
+        IsSystem || isQt || Dir.ends_with(".framework/Headers") ||
+        IncludeDir.ends_with("/include") || IncludeDir.ends_with("\\include");
     std::error_code EC;
     unsigned Count = 0;
     for (auto It = FS.dir_begin(Dir, EC);
diff --git a/clang/test/CodeCompletion/included-files.cpp b/clang/test/CodeCompletion/included-files.cpp
index 9ad3e28b21231..1ab8e5ee2ac21 100644
--- a/clang/test/CodeCompletion/included-files.cpp
+++ b/clang/test/CodeCompletion/included-files.cpp
@@ -1,6 +1,6 @@
-// RUN: rm -rf %t && mkdir %t && cp %s %t/main.cc && mkdir %t/a && mkdir %t/QtCore && mkdir %t/Headers %t/Some.framework %t/Some.framework/Headers
+// RUN: rm -rf %t && mkdir %t && cp %s %t/main.cc && mkdir %t/a && mkdir %t/QtCore && mkdir %t/Headers %t/Some.framework %t/Some.framework/Headers %t/include %t/include/Headers
 // RUN: touch %t/foo.h %t/foo.hxx %t/foo.cc %t/a/foosys %t/a/foosys.h %t/QtCore/foosys %t/QtCore/foo.h
-// RUN: touch %t/Headers/foosys %t/Headers/foo.h %t/Some.framework/Headers/foosys %t/Some.framework/Headers/foo.h
+// RUN: touch %t/Headers/foosys %t/Headers/foo.h %t/Some.framework/Headers/foosys %t/Some.framework/Headers/foo.h %t/include/Headers/foosys
 
 // Quoted string shows header-ish files from CWD, and all from system.
 #include "foo.h"
@@ -56,3 +56,8 @@
 // CHECK-8-NOT: foo.cc>
 // CHECK-8: foo.h>
 // CHECK-8-NOT: foosys>
+
+// But simply naming a directory "include" is enough to allow extension-less headers.
+#include <Headers/foosys>
+// RUN: %clang -fsyntax-only -isystem %t/a -I %t/include -Xclang -code-completion-at=%t/main.cc:61:21 %t/main.cc -fms-compatibility | FileCheck -check-prefix=CHECK-9 %s
+// CHECK-9: foosys>



More information about the cfe-commits mailing list