[clangd] Suggest adding missing includes for incomplete type diagnostics.
Summary:
This enables clangd to intercept compiler diagnostics and attach fixes (e.g. by
querying index). This patch adds missing includes for incomplete types e.g.
member access into class with only forward declaration. This would allow adding
missing includes for user-typed symbol names that are missing declarations
(e.g. typos) in the future.
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: mgorny, ilya-biryukov, javed.absar, MaskRay, jkorous, mgrang, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D56903
llvm-svn: 352361
diff --git a/clang-tools-extra/clangd/SourceCode.cpp b/clang-tools-extra/clangd/SourceCode.cpp
index ede6435..1d8ceb2 100644
--- a/clang-tools-extra/clangd/SourceCode.cpp
+++ b/clang-tools-extra/clangd/SourceCode.cpp
@@ -248,5 +248,18 @@
return digest(Content);
}
+format::FormatStyle getFormatStyleForFile(llvm::StringRef File,
+ llvm::StringRef Content,
+ llvm::vfs::FileSystem *FS) {
+ auto Style = format::getStyle(format::DefaultFormatStyle, File,
+ format::DefaultFallbackStyle, Content, FS);
+ if (!Style) {
+ log("getStyle() failed for file {0}: {1}. Fallback is LLVM style.", File,
+ Style.takeError());
+ Style = format::getLLVMStyle();
+ }
+ return *Style;
+}
+
} // namespace clangd
} // namespace clang