<div dir="ltr">Looks like <a href="http://lab.llvm.org:8011/builders/clang-x64-ninja-win7/">http://lab.llvm.org:8011/builders/clang-x64-ninja-win7/</a> has been red ever since this landed too. Can you take a look or revert if it takes a while to sort out?</div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Feb 16, 2018 at 6:59 PM, Galina Kistanova via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hello Eric,<br><br>It looks like your commit broke tests to one of our builders:<br><a href="http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/15408" target="_blank">http://lab.llvm.org:8011/<wbr>builders/llvm-clang-lld-x86_<wbr>64-scei-ps4-windows10pro-fast/<wbr>builds/15408</a><br><br>. . .<br>Failing Tests (1):<br> Extra Tools Unit Tests :: clangd/./ClangdTests.exe/<wbr>SymbolCollectorTest.IWYUPragma<br><br>Please have a look?<br><br>Thanks<br><br>Galina<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Feb 16, 2018 at 6:15 AM, Eric Liu via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: ioeric<br>
Date: Fri Feb 16 06:15:55 2018<br>
New Revision: 325343<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=325343&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject?rev=325343&view=rev</a><br>
Log:<br>
[clangd] collect symbol #include & insert #include in global code completion.<br>
<br>
Summary:<br>
o Collect suitable #include paths for index symbols. This also does smart mapping<br>
for STL symbols and IWYU pragma (code borrowed from include-fixer).<br>
o For global code completion, add a command for inserting new #include in each code<br>
completion item.<br>
<br>
Reviewers: sammccall<br>
<br>
Reviewed By: sammccall<br>
<br>
Subscribers: klimek, mgorny, ilya-biryukov, jkorous-apple, hintonda, cfe-commits<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D42640" rel="noreferrer" target="_blank">https://reviews.llvm.org/D4264<wbr>0</a><br>
<br>
Added:<br>
clang-tools-extra/trunk/clangd<wbr>/Headers.cpp<br>
clang-tools-extra/trunk/clangd<wbr>/Headers.h<br>
clang-tools-extra/trunk/clangd<wbr>/index/CanonicalIncludes.cpp<br>
clang-tools-extra/trunk/clangd<wbr>/index/CanonicalIncludes.h<br>
clang-tools-extra/trunk/test/c<wbr>langd/insert-include.test<br>
clang-tools-extra/trunk/unitte<wbr>sts/clangd/HeadersTests.cpp<br>
Modified:<br>
clang-tools-extra/trunk/clangd<wbr>/CMakeLists.txt<br>
clang-tools-extra/trunk/clangd<wbr>/ClangdLSPServer.cpp<br>
clang-tools-extra/trunk/clangd<wbr>/ClangdServer.cpp<br>
clang-tools-extra/trunk/clangd<wbr>/ClangdServer.h<br>
clang-tools-extra/trunk/clangd<wbr>/CodeComplete.cpp<br>
clang-tools-extra/trunk/clangd<wbr>/Protocol.cpp<br>
clang-tools-extra/trunk/clangd<wbr>/Protocol.h<br>
clang-tools-extra/trunk/clangd<wbr>/global-symbol-builder/GlobalS<wbr>ymbolBuilderMain.cpp<br>
clang-tools-extra/trunk/clangd<wbr>/index/Index.cpp<br>
clang-tools-extra/trunk/clangd<wbr>/index/Index.h<br>
clang-tools-extra/trunk/clangd<wbr>/index/Merge.cpp<br>
clang-tools-extra/trunk/clangd<wbr>/index/SymbolCollector.cpp<br>
clang-tools-extra/trunk/clangd<wbr>/index/SymbolCollector.h<br>
clang-tools-extra/trunk/clangd<wbr>/index/SymbolYAML.cpp<br>
clang-tools-extra/trunk/clangd<wbr>/tool/ClangdMain.cpp<br>
clang-tools-extra/trunk/test/c<wbr>langd/completion-snippets.test<br>
clang-tools-extra/trunk/test/c<wbr>langd/initialize-params-invali<wbr>d.test<br>
clang-tools-extra/trunk/test/c<wbr>langd/initialize-params.test<br>
clang-tools-extra/trunk/unitte<wbr>sts/clangd/CMakeLists.txt<br>
clang-tools-extra/trunk/unitte<wbr>sts/clangd/ClangdTests.cpp<br>
clang-tools-extra/trunk/unitte<wbr>sts/clangd/SymbolCollectorTest<wbr>s.cpp<br>
<br>
Modified: clang-tools-extra/trunk/clangd<wbr>/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=325343&r1=325342&r2=325343&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/clang-tools-extra/trunk/<wbr>clangd/CMakeLists.txt?rev=<wbr>325343&r1=325342&r2=325343&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/clangd<wbr>/CMakeLists.txt (original)<br>
+++ clang-tools-extra/trunk/clangd<wbr>/CMakeLists.txt Fri Feb 16 06:15:55 2018<br>
@@ -14,6 +14,7 @@ add_clang_library(clangDaemon<br>
DraftStore.cpp<br>
FuzzyMatch.cpp<br>
GlobalCompilationDatabase.cpp<br>
+ Headers.cpp<br>
JSONExpr.cpp<br>
JSONRPCDispatcher.cpp<br>
Logger.cpp<br>
@@ -25,6 +26,7 @@ add_clang_library(clangDaemon<br>
TUScheduler.cpp<br>
URI.cpp<br>
XRefs.cpp<br>
+ index/CanonicalIncludes.cpp<br>
index/FileIndex.cpp<br>
index/Index.cpp<br>
index/MemIndex.cpp<br>
<br>
Modified: clang-tools-extra/trunk/clangd<wbr>/ClangdLSPServer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=325343&r1=325342&r2=325343&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/clang-tools-extra/trunk/<wbr>clangd/ClangdLSPServer.cpp?<wbr>rev=325343&r1=325342&r2=325343<wbr>&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/clangd<wbr>/ClangdLSPServer.cpp (original)<br>
+++ clang-tools-extra/trunk/clangd<wbr>/ClangdLSPServer.cpp Fri Feb 16 06:15:55 2018<br>
@@ -121,7 +121,9 @@ void ClangdLSPServer::onInitialize(<wbr>Initi<br>
{"renameProvider", true},<br>
{"executeCommandProvider",<br>
json::obj{<br>
- {"commands", {ExecuteCommandParams::CLANGD_<wbr>APPLY_FIX_COMMAND}},<br>
+ {"commands",<br>
+ {ExecuteCommandParams::CLANGD_<wbr>APPLY_FIX_COMMAND,<br>
+ ExecuteCommandParams::CLANGD_<wbr>INSERT_HEADER_INCLUDE}},<br>
}},<br>
}}}});<br>
}<br>
@@ -155,6 +157,14 @@ void ClangdLSPServer::onFileEvent(D<wbr>idCha<br>
}<br>
<br>
void ClangdLSPServer::onCommand(Exe<wbr>cuteCommandParams &Params) {<br>
+ auto ApplyEdit = [](WorkspaceEdit WE) {<br>
+ ApplyWorkspaceEditParams Edit;<br>
+ Edit.edit = std::move(WE);<br>
+ // We don't need the response so id == 1 is OK.<br>
+ // Ideally, we would wait for the response and if there is no error, we<br>
+ // would reply success/failure to the original RPC.<br>
+ call("workspace/applyEdit", Edit);<br>
+ };<br>
if (Params.command == ExecuteCommandParams::CLANGD_A<wbr>PPLY_FIX_COMMAND &&<br>
Params.workspaceEdit) {<br>
// The flow for "apply-fix" :<br>
@@ -166,13 +176,35 @@ void ClangdLSPServer::onCommand(Exe<wbr>cuteC<br>
// 6. The editor applies the changes (applyEdit), and sends us a reply (but<br>
// we ignore it)<br>
<br>
- ApplyWorkspaceEditParams ApplyEdit;<br>
- ApplyEdit.edit = *Params.workspaceEdit;<br>
reply("Fix applied.");<br>
- // We don't need the response so id == 1 is OK.<br>
- // Ideally, we would wait for the response and if there is no error, we<br>
- // would reply success/failure to the original RPC.<br>
- call("workspace/applyEdit", ApplyEdit);<br>
+ ApplyEdit(*Params.workspaceEdi<wbr>t);<br>
+ } else if (Params.command ==<br>
+ ExecuteCommandParams::CLANGD_<wbr>INSERT_HEADER_INCLUDE) {<br>
+ auto &FileURI = Params.includeInsertion->textD<wbr>ocument.uri;<br>
+ auto Code = Server.getDocument(FileURI.fil<wbr>e());<br>
+ if (!Code)<br>
+ return replyError(ErrorCode::InvalidP<wbr>arams,<br>
+ ("command " +<br>
+ ExecuteCommandParams::CLANGD_<wbr>INSERT_HEADER_INCLUDE +<br>
+ " called on non-added file " + FileURI.file())<br>
+ .str());<br>
+ auto Replaces = Server.insertInclude(FileURI.f<wbr>ile(), *Code,<br>
+ Params.includeInsertion->head<wbr>er);<br>
+ if (!Replaces) {<br>
+ std::string ErrMsg =<br>
+ ("Failed to generate include insertion edits for adding " +<br>
+ Params.includeInsertion->head<wbr>er + " into " + FileURI.file())<br>
+ .str();<br>
+ log(ErrMsg + ":" + llvm::toString(Replaces.takeEr<wbr>ror()));<br>
+ replyError(ErrorCode::Internal<wbr>Error, ErrMsg);<br>
+ return;<br>
+ }<br>
+ auto Edits = replacementsToEdits(*Code, *Replaces);<br>
+ WorkspaceEdit WE;<br>
+ WE.changes = {{FileURI.uri(), Edits}};<br>
+<br>
+ reply("Inserted header " + Params.includeInsertion->heade<wbr>r);<br>
+ ApplyEdit(std::move(WE));<br>
} else {<br>
// We should not get here because ExecuteCommandParams would not have<br>
// parsed in the first place and this handler should not be called. But if<br>
<br>
Modified: clang-tools-extra/trunk/clangd<wbr>/ClangdServer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=325343&r1=325342&r2=325343&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/clang-tools-extra/trunk/<wbr>clangd/ClangdServer.cpp?rev=<wbr>325343&r1=325342&r2=325343&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/clangd<wbr>/ClangdServer.cpp (original)<br>
+++ clang-tools-extra/trunk/clangd<wbr>/ClangdServer.cpp Fri Feb 16 06:15:55 2018<br>
@@ -9,6 +9,7 @@<br>
<br>
#include "ClangdServer.h"<br>
#include "CodeComplete.h"<br>
+#include "Headers.h"<br>
#include "SourceCode.h"<br>
#include "XRefs.h"<br>
#include "index/Merge.h"<br>
@@ -310,6 +311,47 @@ void ClangdServer::rename(<br>
BindWithForward(Action, File.str(), NewName.str(), std::move(Callback)));<br>
}<br>
<br>
+Expected<tooling::Replacement<wbr>s><br>
+ClangdServer::insertInclude(P<wbr>athRef File, StringRef Code,<br>
+ llvm::StringRef Header) {<br>
+ std::string ToInclude;<br>
+ if (Header.startswith("<") || Header.startswith("\"")) {<br>
+ ToInclude = Header;<br>
+ } else {<br>
+ auto U = URI::parse(Header);<br>
+ if (!U)<br>
+ return U.takeError();<br>
+ auto Resolved = URI::resolve(*U, /*HintPath=*/File);<br>
+ if (!Resolved)<br>
+ return Resolved.takeError();<br>
+<br>
+ auto FS = FSProvider.getTaggedFileSystem<wbr>(File).Value;<br>
+ tooling::CompileCommand CompileCommand =<br>
+ CompileArgs.getCompileCommand(<wbr>File);<br>
+ FS->setCurrentWorkingDirectory<wbr>(CompileCommand.Directory);<br>
+<br>
+ auto Include =<br>
+ shortenIncludePath(File, Code, *Resolved, CompileCommand, FS);<br>
+ if (!Include)<br>
+ return Include.takeError();<br>
+ if (Include->empty())<br>
+ return tooling::Replacements();<br>
+ ToInclude = std::move(*Include);<br>
+ }<br>
+<br>
+ auto Style = format::getStyle("file", File, "llvm");<br>
+ if (!Style) {<br>
+ llvm::consumeError(Style.takeE<wbr>rror());<br>
+ // FIXME(ioeric): needs more consistent style support in clangd server.<br>
+ Style = format::getLLVMStyle();<br>
+ }<br>
+ // Replacement with offset UINT_MAX and length 0 will be treated as include<br>
+ // insertion.<br>
+ tooling::Replacement R(File, /*Offset=*/UINT_MAX, 0, "#include " + ToInclude);<br>
+ return format::cleanupAroundReplaceme<wbr>nts(Code, tooling::Replacements(R),<br>
+ *Style);<br>
+}<br>
+<br>
llvm::Optional<std::string> ClangdServer::getDocument(Path<wbr>Ref File) {<br>
auto Latest = DraftMgr.getDraft(File);<br>
if (!Latest.Draft)<br>
<br>
Modified: clang-tools-extra/trunk/clangd<wbr>/ClangdServer.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.h?rev=325343&r1=325342&r2=325343&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/clang-tools-extra/trunk/<wbr>clangd/ClangdServer.h?rev=<wbr>325343&r1=325342&r2=325343&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/clangd<wbr>/ClangdServer.h (original)<br>
+++ clang-tools-extra/trunk/clangd<wbr>/ClangdServer.h Fri Feb 16 06:15:55 2018<br>
@@ -231,6 +231,13 @@ public:<br>
UniqueFunction<void(Expected<<wbr>std::vector<tooling::Replaceme<wbr>nt>>)><br>
Callback);<br>
<br>
+ /// Inserts a new #include of \p Header into \p File, if it's not present.<br>
+ /// \p Header is either an URI that can be resolved to an #include path that<br>
+ /// is suitable to be inserted or a literal string quoted with <> or "" that<br>
+ /// can be #included directly.<br>
+ Expected<tooling::Replacements<wbr>> insertInclude(PathRef File, StringRef Code,<br>
+ StringRef Header);<br>
+<br>
/// Gets current document contents for \p File. Returns None if \p File is not<br>
/// currently tracked.<br>
/// FIXME(ibiryukov): This function is here to allow offset-to-Position<br>
<br>
Modified: clang-tools-extra/trunk/clangd<wbr>/CodeComplete.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=325343&r1=325342&r2=325343&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/clang-tools-extra/trunk/<wbr>clangd/CodeComplete.cpp?rev=<wbr>325343&r1=325342&r2=325343&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/clangd<wbr>/CodeComplete.cpp (original)<br>
+++ clang-tools-extra/trunk/clangd<wbr>/CodeComplete.cpp Fri Feb 16 06:15:55 2018<br>
@@ -19,13 +19,16 @@<br>
#include "Compiler.h"<br>
#include "FuzzyMatch.h"<br>
#include "Logger.h"<br>
+#include "SourceCode.h"<br>
#include "Trace.h"<br>
#include "index/Index.h"<br>
+#include "clang/Format/Format.h"<br>
#include "clang/Frontend/CompilerInstan<wbr>ce.h"<br>
#include "clang/Frontend/FrontendAction<wbr>s.h"<br>
#include "clang/Index/USRGeneration.h"<br>
#include "clang/Sema/CodeCompleteConsum<wbr>er.h"<br>
#include "clang/Sema/Sema.h"<br>
+#include "clang/Tooling/Core/Replacemen<wbr>t.h"<br>
#include "llvm/Support/Format.h"<br>
#include <queue><br>
<br>
@@ -249,7 +252,8 @@ struct CompletionCandidate {<br>
}<br>
<br>
// Builds an LSP completion item.<br>
- CompletionItem build(const CompletionItemScores &Scores,<br>
+ CompletionItem build(llvm::StringRef FileName,<br>
+ const CompletionItemScores &Scores,<br>
const CodeCompleteOptions &Opts,<br>
CodeCompletionString *SemaCCS) const {<br>
assert(bool(SemaResult) == bool(SemaCCS));<br>
@@ -282,6 +286,28 @@ struct CompletionCandidate {<br>
I.documentation = D->Documentation;<br>
if (I.detail.empty())<br>
I.detail = D->CompletionDetail;<br>
+ // We only insert #include for items with details, since we can't tell<br>
+ // whether the file URI of the canonical declaration would be the<br>
+ // canonical #include without checking IncludeHeader in the detail.<br>
+ // FIXME: delay creating include insertion command to<br>
+ // "completionItem/resolve", when it is supported<br>
+ if (!D->IncludeHeader.empty() ||<br>
+ !IndexResult->CanonicalDeclara<wbr>tion.FileURI.empty()) {<br>
+ // LSP favors additionalTextEdits over command. But we are still using<br>
+ // command here because it would be expensive to calculate #include<br>
+ // insertion edits for all candidates, and the include insertion edit<br>
+ // is unlikely to conflict with the code completion edits.<br>
+ Command Cmd;<br>
+ // Command title is not added since this is not a user-facing command.<br>
+ Cmd.command = ExecuteCommandParams::CLANGD_I<wbr>NSERT_HEADER_INCLUDE;<br>
+ IncludeInsertion Insertion;<br>
+ Insertion.header = D->IncludeHeader.empty()<br>
+ ? IndexResult->CanonicalDeclarat<wbr>ion.FileURI<br>
+ : D->IncludeHeader;<br>
+ Insertion.textDocument.uri = URIForFile(FileName);<br>
+ Cmd.includeInsertion = std::move(Insertion);<br>
+ I.command = std::move(Cmd);<br>
+ }<br>
}<br>
}<br>
I.scoreInfo = Scores;<br>
@@ -806,6 +832,7 @@ clang::CodeCompleteOptions CodeCompleteO<br>
// This score is combined with the result quality score for the final score.<br>
// - TopN determines the results with the best score.<br>
class CodeCompleteFlow {<br>
+ PathRef FileName;<br>
const CodeCompleteOptions &Opts;<br>
// Sema takes ownership of Recorder. Recorder is valid until Sema cleanup.<br>
std::unique_ptr<CompletionRec<wbr>order> RecorderOwner;<br>
@@ -816,9 +843,9 @@ class CodeCompleteFlow {<br>
<br>
public:<br>
// A CodeCompleteFlow object is only useful for calling run() exactly once.<br>
- CodeCompleteFlow(const CodeCompleteOptions &Opts)<br>
- : Opts(Opts), RecorderOwner(new CompletionRecorder(Opts)),<br>
- Recorder(*RecorderOwner) {}<br>
+ CodeCompleteFlow(PathRef FileName, const CodeCompleteOptions &Opts)<br>
+ : FileName(FileName), Opts(Opts),<br>
+ RecorderOwner(new CompletionRecorder(Opts)), Recorder(*RecorderOwner) {}<br>
<br>
CompletionList run(const SemaCompleteInput &SemaCCInput) && {<br>
trace::Span Tracer("CodeCompleteFlow");<br>
@@ -956,7 +983,7 @@ private:<br>
CodeCompletionString *SemaCCS = nullptr;<br>
if (auto *SR = Candidate.SemaResult)<br>
SemaCCS = Recorder.codeCompletionString(<wbr>*SR, Opts.IncludeBriefComments);<br>
- return Candidate.build(Scores, Opts, SemaCCS);<br>
+ return Candidate.build(FileName, Scores, Opts, SemaCCS);<br>
}<br>
};<br>
<br>
@@ -967,8 +994,8 @@ CompletionList codeComplete(PathRef File<br>
IntrusiveRefCntPtr<vfs::FileS<wbr>ystem> VFS,<br>
std::shared_ptr<PCHContainerO<wbr>perations> PCHs,<br>
CodeCompleteOptions Opts) {<br>
- return CodeCompleteFlow(Opts).run(<br>
- {FileName, Command, Preamble, Contents, Pos, VFS, PCHs});<br>
+ return CodeCompleteFlow(FileName, Opts)<br>
+ .run({FileName, Command, Preamble, Contents, Pos, VFS, PCHs});<br>
}<br>
<br>
SignatureHelp signatureHelp(PathRef FileName,<br>
<br>
Added: clang-tools-extra/trunk/clangd<wbr>/Headers.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Headers.cpp?rev=325343&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/clang-tools-extra/trunk/<wbr>clangd/Headers.cpp?rev=325343&<wbr>view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/clangd<wbr>/Headers.cpp (added)<br>
+++ clang-tools-extra/trunk/clangd<wbr>/Headers.cpp Fri Feb 16 06:15:55 2018<br>
@@ -0,0 +1,117 @@<br>
+//===--- Headers.cpp - Include headers ---------------------------*- C++-*-===//<br>
+//<br>
+// The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===------------------------<wbr>------------------------------<wbr>----------------===//<br>
+<br>
+#include "Headers.h"<br>
+#include "Compiler.h"<br>
+#include "Logger.h"<br>
+#include "clang/Frontend/CompilerInstan<wbr>ce.h"<br>
+#include "clang/Frontend/CompilerInvoca<wbr>tion.h"<br>
+#include "clang/Frontend/FrontendAction<wbr>s.h"<br>
+#include "clang/Lex/HeaderSearch.h"<br>
+#include "clang/Lex/PreprocessorOptions<wbr>.h"<br>
+#include "clang/Tooling/CompilationData<wbr>base.h"<br>
+<br>
+namespace clang {<br>
+namespace clangd {<br>
+namespace {<br>
+<br>
+class RecordHeaders : public PPCallbacks {<br>
+public:<br>
+ RecordHeaders(std::set<std::st<wbr>ring> &Headers) : Headers(Headers) {}<br>
+<br>
+ void InclusionDirective(SourceLocat<wbr>ion /*HashLoc*/,<br>
+ const Token & /*IncludeTok*/,<br>
+ llvm::StringRef /*FileName*/, bool /*IsAngled*/,<br>
+ CharSourceRange /*FilenameRange*/,<br>
+ const FileEntry *File, llvm::StringRef /*SearchPath*/,<br>
+ llvm::StringRef /*RelativePath*/,<br>
+ const Module * /*Imported*/) override {<br>
+ if (File != nullptr && !File->tryGetRealPathName().em<wbr>pty())<br>
+ Headers.insert(File->tryGetRea<wbr>lPathName());<br>
+ }<br>
+<br>
+private:<br>
+ std::set<std::string> &Headers;<br>
+};<br>
+<br>
+} // namespace<br>
+<br>
+/// FIXME(ioeric): we might not want to insert an absolute include path if the<br>
+/// path is not shortened.<br>
+llvm::Expected<std::string><br>
+shortenIncludePath(llvm::Stri<wbr>ngRef File, llvm::StringRef Code,<br>
+ llvm::StringRef Header,<br>
+ const tooling::CompileCommand &CompileCommand,<br>
+ IntrusiveRefCntPtr<vfs::FileS<wbr>ystem> FS) {<br>
+ // Set up a CompilerInstance and create a preprocessor to collect existing<br>
+ // #include headers in \p Code. Preprocesor also provides HeaderSearch with<br>
+ // which we can calculate the shortest include path for \p Header.<br>
+ std::vector<const char *> Argv;<br>
+ for (const auto &S : CompileCommand.CommandLine)<br>
+ Argv.push_back(S.c_str());<br>
+ IgnoringDiagConsumer IgnoreDiags;<br>
+ auto CI = clang::createInvocationFromCom<wbr>mandLine(<br>
+ Argv,<br>
+ CompilerInstance::createDiagno<wbr>stics(new DiagnosticOptions(), &IgnoreDiags,<br>
+ false),<br>
+ FS);<br>
+ if (!CI)<br>
+ return llvm::make_error<llvm::StringE<wbr>rror>(<br>
+ "Failed to create a compiler instance for " + File,<br>
+ llvm::inconvertibleErrorCode()<wbr>);<br>
+ CI->getFrontendOpts().DisableF<wbr>ree = false;<br>
+ // Parse the main file to get all existing #includes in the file, and then we<br>
+ // can make sure the same header (even with different include path) is not<br>
+ // added more than once.<br>
+ CI->getPreprocessorOpts().Sing<wbr>leFileParseMode = true;<br>
+<br>
+ auto Clang = prepareCompilerInstance(<br>
+ std::move(CI), /*Preamble=*/nullptr,<br>
+ llvm::MemoryBuffer::getMemBuff<wbr>er(Code, File),<br>
+ std::make_shared<PCHContainerO<wbr>perations>(), FS, IgnoreDiags);<br>
+ auto &DiagOpts = Clang->getDiagnosticOpts();<br>
+ DiagOpts.IgnoreWarnings = true;<br>
+<br>
+ if (Clang->getFrontendOpts().Inpu<wbr>ts.empty())<br>
+ return llvm::make_error<llvm::StringE<wbr>rror>(<br>
+ "Empty frontend action inputs empty for file " + File,<br>
+ llvm::inconvertibleErrorCode()<wbr>);<br>
+ PreprocessOnlyAction Action;<br>
+ if (!Action.BeginSourceFile(*Clan<wbr>g, Clang->getFrontendOpts().Input<wbr>s[0]))<br>
+ return llvm::make_error<llvm::StringE<wbr>rror>(<br>
+ "Failed to begin preprocessor only action for file " + File,<br>
+ llvm::inconvertibleErrorCode()<wbr>);<br>
+ std::set<std::string> ExistingHeaders;<br>
+ Clang->getPreprocessor().addPP<wbr>Callbacks(<br>
+ llvm::make_unique<RecordHeader<wbr>s>(ExistingHeaders));<br>
+ if (!Action.Execute())<br>
+ return llvm::make_error<llvm::StringE<wbr>rror>(<br>
+ "Failed to execute preprocessor only action for file " + File,<br>
+ llvm::inconvertibleErrorCode()<wbr>);<br>
+ if (ExistingHeaders.find(Header) != ExistingHeaders.end()) {<br>
+ return llvm::make_error<llvm::StringE<wbr>rror>(<br>
+ Header + " is already included in " + File,<br>
+ llvm::inconvertibleErrorCode()<wbr>);<br>
+ }<br>
+<br>
+ auto &HeaderSearchInfo = Clang->getPreprocessor().getHe<wbr>aderSearchInfo();<br>
+ bool IsSystem = false;<br>
+ std::string Suggested = HeaderSearchInfo.suggestPathTo<wbr>FileForDiagnostics(<br>
+ Header, CompileCommand.Directory, &IsSystem);<br>
+ if (IsSystem)<br>
+ Suggested = "<" + Suggested + ">";<br>
+ else<br>
+ Suggested = "\"" + Suggested + "\"";<br>
+<br>
+ log("Suggested #include for " + Header + " is: " + Suggested);<br>
+ return Suggested;<br>
+}<br>
+<br>
+} // namespace clangd<br>
+} // namespace clang<br>
<br>
Added: clang-tools-extra/trunk/clangd<wbr>/Headers.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Headers.h?rev=325343&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/clang-tools-extra/trunk/<wbr>clangd/Headers.h?rev=325343&<wbr>view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/clangd<wbr>/Headers.h (added)<br>
+++ clang-tools-extra/trunk/clangd<wbr>/Headers.h Fri Feb 16 06:15:55 2018<br>
@@ -0,0 +1,37 @@<br>
+//===--- Headers.h - Include headers -----------------------------*<wbr>- C++-*-===//<br>
+//<br>
+// The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===------------------------<wbr>------------------------------<wbr>----------------===//<br>
+<br>
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_<wbr>HEADERS_H<br>
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_<wbr>HEADERS_H<br>
+<br>
+#include "Path.h"<br>
+#include "clang/Basic/VirtualFileSystem<wbr>.h"<br>
+#include "clang/Tooling/CompilationData<wbr>base.h"<br>
+#include "llvm/ADT/StringRef.h"<br>
+#include "llvm/Support/Error.h"<br>
+<br>
+namespace clang {<br>
+namespace clangd {<br>
+/// Determines the preferred way to #include a file, taking into account the<br>
+/// search path. Usually this will prefer a shorter representation like<br>
+/// 'Foo/Bar.h' over a longer one like 'Baz/include/Foo/Bar.h'.<br>
+///<br>
+/// \param Header is an absolute file path.<br>
+/// \return A quoted "path" or <path>. If \p Header is already (directly)<br>
+/// included in the file (including those included via different paths), this<br>
+/// returns an empty string.<br>
+llvm::Expected<std::string><br>
+shortenIncludePath(PathRef File, llvm::StringRef Code, llvm::StringRef Header,<br>
+ const tooling::CompileCommand &CompileCommand,<br>
+ IntrusiveRefCntPtr<vfs::FileS<wbr>ystem> FS);<br>
+<br>
+} // namespace clangd<br>
+} // namespace clang<br>
+<br>
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_<wbr>HEADERS_H<br>
<br>
Modified: clang-tools-extra/trunk/clangd<wbr>/Protocol.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.cpp?rev=325343&r1=325342&r2=325343&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/clang-tools-extra/trunk/<wbr>clangd/Protocol.cpp?rev=325343<wbr>&r1=325342&r2=325343&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/clangd<wbr>/Protocol.cpp (original)<br>
+++ clang-tools-extra/trunk/clangd<wbr>/Protocol.cpp Fri Feb 16 06:15:55 2018<br>
@@ -57,6 +57,10 @@ llvm::raw_ostream &operator<<(llvm::raw_<br>
return OS << U.uri();<br>
}<br>
<br>
+json::Expr toJSON(const TextDocumentIdentifier &R) {<br>
+ return json::obj{{"uri", R.uri}};<br>
+}<br>
+<br>
bool fromJSON(const json::Expr &Params, TextDocumentIdentifier &R) {<br>
json::ObjectMapper O(Params);<br>
return O && O.map("uri", R.uri);<br>
@@ -326,6 +330,8 @@ bool fromJSON(const json::Expr &Params,<br>
<br>
const llvm::StringLiteral ExecuteCommandParams::CLANGD_A<wbr>PPLY_FIX_COMMAND =<br>
"clangd.applyFix";<br>
+const llvm::StringLiteral ExecuteCommandParams::CLANGD_I<wbr>NSERT_HEADER_INCLUDE =<br>
+ "clangd.insertInclude";<br>
<br>
bool fromJSON(const json::Expr &Params, ExecuteCommandParams &R) {<br>
json::ObjectMapper O(Params);<br>
@@ -336,10 +342,22 @@ bool fromJSON(const json::Expr &Params,<br>
if (R.command == ExecuteCommandParams::CLANGD_A<wbr>PPLY_FIX_COMMAND) {<br>
return Args && Args->size() == 1 &&<br>
fromJSON(Args->front(), R.workspaceEdit);<br>
+ } else if (R.command == ExecuteCommandParams::CLANGD_I<wbr>NSERT_HEADER_INCLUDE) {<br>
+ return Args && Args->size() == 1 &&<br>
+ fromJSON(Args->front(), R.includeInsertion);<br>
}<br>
return false; // Unrecognized command.<br>
}<br>
<br>
+json::Expr toJSON(const Command &C) {<br>
+ auto Cmd = json::obj{{"title", C.title}, {"command", C.command}};<br>
+ if (C.workspaceEdit)<br>
+ Cmd["arguments"] = {*C.workspaceEdit};<br>
+ else if (C.includeInsertion)<br>
+ Cmd["arguments"] = {*C.includeInsertion};<br>
+ return std::move(Cmd);<br>
+}<br>
+<br>
json::Expr toJSON(const WorkspaceEdit &WE) {<br>
if (!WE.changes)<br>
return json::obj{};<br>
@@ -349,6 +367,15 @@ json::Expr toJSON(const WorkspaceEdit &W<br>
return json::obj{{"changes", std::move(FileChanges)}};<br>
}<br>
<br>
+bool fromJSON(const json::Expr &II, IncludeInsertion &R) {<br>
+ json::ObjectMapper O(II);<br>
+ return O && O.map("textDocument", R.textDocument) &&<br>
+ O.map("header", R.header);<br>
+}<br>
+json::Expr toJSON(const IncludeInsertion &II) {<br>
+ return json::obj{{"textDocument", II.textDocument}, {"header", II.header}};<br>
+}<br>
+<br>
json::Expr toJSON(const ApplyWorkspaceEditParams &Params) {<br>
return json::obj{{"edit", Params.edit}};<br>
}<br>
@@ -380,6 +407,8 @@ json::Expr toJSON(const CompletionItem &<br>
Result["textEdit"] = *CI.textEdit;<br>
if (!CI.additionalTextEdits.empty<wbr>())<br>
Result["additionalTextEdits"] = json::ary(CI.additionalTextEdi<wbr>ts);<br>
+ if (CI.command)<br>
+ Result["command"] = *CI.command;<br>
return std::move(Result);<br>
}<br>
<br>
<br>
Modified: clang-tools-extra/trunk/clangd<wbr>/Protocol.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.h?rev=325343&r1=325342&r2=325343&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/clang-tools-extra/trunk/<wbr>clangd/Protocol.h?rev=325343&<wbr>r1=325342&r2=325343&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/clangd<wbr>/Protocol.h (original)<br>
+++ clang-tools-extra/trunk/clangd<wbr>/Protocol.h Fri Feb 16 06:15:55 2018<br>
@@ -82,6 +82,7 @@ struct TextDocumentIdentifier {<br>
/// The text document's URI.<br>
URIForFile uri;<br>
};<br>
+json::Expr toJSON(const TextDocumentIdentifier &);<br>
bool fromJSON(const json::Expr &, TextDocumentIdentifier &);<br>
<br>
struct Position {<br>
@@ -424,6 +425,17 @@ struct WorkspaceEdit {<br>
bool fromJSON(const json::Expr &, WorkspaceEdit &);<br>
json::Expr toJSON(const WorkspaceEdit &WE);<br>
<br>
+struct IncludeInsertion {<br>
+ /// The document in which the command was invoked.<br>
+ TextDocumentIdentifier textDocument;<br>
+<br>
+ /// The header to be inserted. This could be either a URI ir a literal string<br>
+ /// quoted with <> or "" that can be #included directly.<br>
+ std::string header;<br>
+};<br>
+bool fromJSON(const json::Expr &, IncludeInsertion &);<br>
+json::Expr toJSON(const IncludeInsertion &II);<br>
+<br>
/// Exact commands are not specified in the protocol so we define the<br>
/// ones supported by Clangd here. The protocol specifies the command arguments<br>
/// to be "any[]" but to make this safer and more manageable, each command we<br>
@@ -435,15 +447,25 @@ json::Expr toJSON(const WorkspaceEdit &W<br>
struct ExecuteCommandParams {<br>
// Command to apply fix-its. Uses WorkspaceEdit as argument.<br>
const static llvm::StringLiteral CLANGD_APPLY_FIX_COMMAND;<br>
+ // Command to insert an #include into code.<br>
+ const static llvm::StringLiteral CLANGD_INSERT_HEADER_INCLUDE;<br>
<br>
/// The command identifier, e.g. CLANGD_APPLY_FIX_COMMAND<br>
std::string command;<br>
<br>
// Arguments<br>
llvm::Optional<WorkspaceEdit> workspaceEdit;<br>
+<br>
+ llvm::Optional<IncludeInsertio<wbr>n> includeInsertion;<br>
};<br>
bool fromJSON(const json::Expr &, ExecuteCommandParams &);<br>
<br>
+struct Command : public ExecuteCommandParams {<br>
+ std::string title;<br>
+};<br>
+<br>
+json::Expr toJSON(const Command &C);<br>
+<br>
struct ApplyWorkspaceEditParams {<br>
WorkspaceEdit edit;<br>
};<br>
@@ -560,12 +582,10 @@ struct CompletionItem {<br>
/// themselves.<br>
std::vector<TextEdit> additionalTextEdits;<br>
<br>
+ llvm::Optional<Command> command;<br>
// TODO(krasimir): The following optional fields defined by the language<br>
// server protocol are unsupported:<br>
//<br>
- // command?: Command - An optional command that is executed *after* inserting<br>
- // this completion.<br>
- //<br>
// data?: any - A data entry field that is preserved on a completion item<br>
// between a completion and a completion resolve request.<br>
};<br>
<br>
Modified: clang-tools-extra/trunk/clangd<wbr>/global-symbol-builder/GlobalS<wbr>ymbolBuilderMain.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp?rev=325343&r1=325342&r2=325343&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/clang-tools-extra/trunk/<wbr>clangd/global-symbol-builder/G<wbr>lobalSymbolBuilderMain.cpp?rev<wbr>=325343&r1=325342&r2=325343&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/clangd<wbr>/global-symbol-builder/GlobalS<wbr>ymbolBuilderMain.cpp (original)<br>
+++ clang-tools-extra/trunk/clangd<wbr>/global-symbol-builder/GlobalS<wbr>ymbolBuilderMain.cpp Fri Feb 16 06:15:55 2018<br>
@@ -13,10 +13,12 @@<br>
//<br>
//===------------------------<wbr>------------------------------<wbr>---------------===//<br>
<br>
+#include "index/CanonicalIncludes.h"<br>
#include "index/Index.h"<br>
#include "index/Merge.h"<br>
#include "index/SymbolCollector.h"<br>
#include "index/SymbolYAML.h"<br>
+#include "clang/Frontend/CompilerInstan<wbr>ce.h"<br>
#include "clang/Frontend/FrontendAction<wbr>s.h"<br>
#include "clang/Frontend/CompilerInstan<wbr>ce.h"<br>
#include "clang/Index/IndexDataConsumer<wbr>.h"<br>
@@ -57,11 +59,19 @@ public:<br>
class WrappedIndexAction : public WrapperFrontendAction {<br>
public:<br>
WrappedIndexAction(std::share<wbr>d_ptr<SymbolCollector> C,<br>
+ std::unique_ptr<CanonicalIncl<wbr>udes> Includes,<br>
const index::IndexingOptions &Opts,<br>
tooling::ExecutionContext *Ctx)<br>
: WrapperFrontendAction(<br>
index::createIndexingAction(<wbr>C, Opts, nullptr)),<br>
- Ctx(Ctx), Collector(C) {}<br>
+ Ctx(Ctx), Collector(C), Includes(std::move(Includes)),<br>
+ PragmaHandler(collectIWYUHeade<wbr>rMaps(this->Includes.get())) {}<br>
+<br>
+ std::unique_ptr<ASTConsumer><br>
+ CreateASTConsumer(CompilerInst<wbr>ance &CI, StringRef InFile) override {<br>
+ CI.getPreprocessor().addCommen<wbr>tHandler(PragmaHandler.get());<br>
+ return WrapperFrontendAction::CreateA<wbr>STConsumer(CI, InFile);<br>
+ }<br>
<br>
void EndSourceFileAction() override {<br>
WrapperFrontendAction::EndSou<wbr>rceFileAction();<br>
@@ -78,6 +88,8 @@ public:<br>
private:<br>
tooling::ExecutionContext *Ctx;<br>
std::shared_ptr<SymbolCollect<wbr>or> Collector;<br>
+ std::unique_ptr<CanonicalInclu<wbr>des> Includes;<br>
+ std::unique_ptr<CommentHandler<wbr>> PragmaHandler;<br>
};<br>
<br>
index::IndexingOptions IndexOpts;<br>
@@ -86,9 +98,13 @@ public:<br>
IndexOpts.IndexFunctionLocals = false;<br>
auto CollectorOpts = SymbolCollector::Options();<br>
CollectorOpts.FallbackDir = AssumedHeaderDir;<br>
+ CollectorOpts.CollectIncludePa<wbr>th = true;<br>
+ auto Includes = llvm::make_unique<CanonicalInc<wbr>ludes>();<br>
+ addSystemHeadersMapping(Includ<wbr>es.get());<br>
+ CollectorOpts.Includes = Includes.get();<br>
return new WrappedIndexAction(<br>
- std::make_shared<SymbolCollect<wbr>or>(std::move(CollectorOpts)), IndexOpts,<br>
- Ctx);<br>
+ std::make_shared<SymbolCollect<wbr>or>(std::move(CollectorOpts)),<br>
+ std::move(Includes), IndexOpts, Ctx);<br>
}<br>
<br>
tooling::ExecutionContext *Ctx;<br>
<br>
Added: clang-tools-extra/trunk/clangd<wbr>/index/CanonicalIncludes.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp?rev=325343&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/clang-tools-extra/trunk/<wbr>clangd/index/CanonicalIncludes<wbr>.cpp?rev=325343&view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/clangd<wbr>/index/CanonicalIncludes.cpp (added)<br>
+++ clang-tools-extra/trunk/clangd<wbr>/index/CanonicalIncludes.cpp Fri Feb 16 06:15:55 2018<br>
@@ -0,0 +1,704 @@<br>
+//===-- CanonicalIncludes.h - remap #inclue headers--------------*- C++ -*-===//<br>
+//<br>
+// The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===------------------------<wbr>------------------------------<wbr>----------------===//<br>
+<br>
+#include "CanonicalIncludes.h"<br>
+#include "llvm/Support/Regex.h"<br>
+<br>
+namespace clang {<br>
+namespace clangd {<br>
+namespace {<br>
+const char IWYUPragma[] = "// IWYU pragma: private, include ";<br>
+} // namespace<br>
+<br>
+void CanonicalIncludes::addMapping(<wbr>llvm::StringRef Path,<br>
+ llvm::StringRef CanonicalPath) {<br>
+ addRegexMapping((llvm::Twine("<wbr>^") + Path + "$").str(), CanonicalPath);<br>
+};<br>
+<br>
+void CanonicalIncludes::addRegexMap<wbr>ping(llvm::StringRef RE,<br>
+ llvm::StringRef CanonicalPath) {<br>
+ this->RegexHeaderMappingTable.<wbr>emplace_back(llvm::Regex(RE), CanonicalPath);<br>
+}<br>
+<br>
+llvm::StringRef CanonicalIncludes::mapHeader(l<wbr>lvm::StringRef Header) const {<br>
+ for (auto &Entry : RegexHeaderMappingTable) {<br>
+#ifndef NDEBUG<br>
+ std::string Dummy;<br>
+ assert(Entry.first.isValid(Dum<wbr>my) && "Regex should never be invalid!");<br>
+#endif<br>
+ if (Entry.first.match(Header))<br>
+ return Entry.second;<br>
+ }<br>
+ return Header;<br>
+}<br>
+<br>
+std::unique_ptr<CommentHandle<wbr>r><br>
+collectIWYUHeaderMaps(Canonic<wbr>alIncludes *Includes) {<br>
+ class PragmaCommentHandler : public clang::CommentHandler {<br>
+ public:<br>
+ PragmaCommentHandler(Canonical<wbr>Includes *Includes) : Includes(Includes) {}<br>
+<br>
+ bool HandleComment(Preprocessor &PP, SourceRange Range) override {<br>
+ StringRef Text =<br>
+ Lexer::getSourceText(CharSourc<wbr>eRange::getCharRange(Range),<br>
+ PP.getSourceManager(), PP.getLangOpts());<br>
+ if (!Text.consume_front(IWYUPragm<wbr>a))<br>
+ return false;<br>
+ // FIXME(ioeric): resolve the header and store actual file path. For now,<br>
+ // we simply assume the written header is suitable to be #included.<br>
+ Includes->addMapping(PP.getSou<wbr>rceManager().getFilename(<wbr>Range.getBegin()),<br>
+ Text.startswith("<") ? Text.str()<br>
+ : ("\"" + Text + "\"").str());<br>
+ return false;<br>
+ }<br>
+<br>
+ private:<br>
+ CanonicalIncludes *const Includes;<br>
+ };<br>
+ return llvm::make_unique<PragmaCommen<wbr>tHandler>(Includes);<br>
+}<br>
+<br>
+void addSystemHeadersMapping(Canoni<wbr>calIncludes *Includes) {<br>
+ static const std::vector<std::pair<const char *, const char *>><br>
+ SystemHeaderMap = {<br>
+ {"include/__stddef_max_align_t<wbr>.h$", "<cstddef>"},<br>
+ {"include/__wmmintrin_aes.h$", "<wmmintrin.h>"},<br>
+ {"include/__wmmintrin_pclmul.h<wbr>$", "<wmmintrin.h>"},<br>
+ {"include/adxintrin.h$", "<immintrin.h>"},<br>
+ {"include/ammintrin.h$", "<ammintrin.h>"},<br>
+ {"include/avx2intrin.h$", "<immintrin.h>"},<br>
+ {"include/avx512bwintrin.h$", "<immintrin.h>"},<br>
+ {"include/avx512cdintrin.h$", "<immintrin.h>"},<br>
+ {"include/avx512dqintrin.h$", "<immintrin.h>"},<br>
+ {"include/avx512erintrin.h$", "<immintrin.h>"},<br>
+ {"include/avx512fintrin.h$", "<immintrin.h>"},<br>
+ {"include/avx512ifmaintrin.h$"<wbr>, "<immintrin.h>"},<br>
+ {"include/avx512ifmavlintrin.h<wbr>$", "<immintrin.h>"},<br>
+ {"include/avx512pfintrin.h$", "<immintrin.h>"},<br>
+ {"include/avx512vbmiintrin.h$"<wbr>, "<immintrin.h>"},<br>
+ {"include/avx512vbmivlintrin.h<wbr>$", "<immintrin.h>"},<br>
+ {"include/avx512vlbwintrin.h$"<wbr>, "<immintrin.h>"},<br>
+ {"include/avx512vlcdintrin.h$"<wbr>, "<immintrin.h>"},<br>
+ {"include/avx512vldqintrin.h$"<wbr>, "<immintrin.h>"},<br>
+ {"include/avx512vlintrin.h$", "<immintrin.h>"},<br>
+ {"include/avxintrin.h$", "<immintrin.h>"},<br>
+ {"include/bmi2intrin.h$", "<x86intrin.h>"},<br>
+ {"include/bmiintrin.h$", "<x86intrin.h>"},<br>
+ {"include/emmintrin.h$", "<emmintrin.h>"},<br>
+ {"include/f16cintrin.h$", "<emmintrin.h>"},<br>
+ {"include/float.h$", "<cfloat>"},<br>
+ {"include/fma4intrin.h$", "<x86intrin.h>"},<br>
+ {"include/fmaintrin.h$", "<immintrin.h>"},<br>
+ {"include/fxsrintrin.h$", "<immintrin.h>"},<br>
+ {"include/ia32intrin.h$", "<x86intrin.h>"},<br>
+ {"include/immintrin.h$", "<immintrin.h>"},<br>
+ {"include/inttypes.h$", "<cinttypes>"},<br>
+ {"include/limits.h$", "<climits>"},<br>
+ {"include/lzcntintrin.h$", "<x86intrin.h>"},<br>
+ {"include/mm3dnow.h$", "<mm3dnow.h>"},<br>
+ {"include/mm_malloc.h$", "<mm_malloc.h>"},<br>
+ {"include/mmintrin.h$", "<mmintrin>"},<br>
+ {"include/mwaitxintrin.h$", "<x86intrin.h>"},<br>
+ {"include/pkuintrin.h$", "<immintrin.h>"},<br>
+ {"include/pmmintrin.h$", "<pmmintrin.h>"},<br>
+ {"include/popcntintrin.h$", "<popcntintrin.h>"},<br>
+ {"include/prfchwintrin.h$", "<x86intrin.h>"},<br>
+ {"include/rdseedintrin.h$", "<x86intrin.h>"},<br>
+ {"include/rtmintrin.h$", "<immintrin.h>"},<br>
+ {"include/shaintrin.h$", "<immintrin.h>"},<br>
+ {"include/smmintrin.h$", "<smmintrin.h>"},<br>
+ {"include/stdalign.h$", "<cstdalign>"},<br>
+ {"include/stdarg.h$", "<cstdarg>"},<br>
+ {"include/stdbool.h$", "<cstdbool>"},<br>
+ {"include/stddef.h$", "<cstddef>"},<br>
+ {"include/stdint.h$", "<cstdint>"},<br>
+ {"include/tbmintrin.h$", "<x86intrin.h>"},<br>
+ {"include/tmmintrin.h$", "<tmmintrin.h>"},<br>
+ {"include/wmmintrin.h$", "<wmmintrin.h>"},<br>
+ {"include/x86intrin.h$", "<x86intrin.h>"},<br>
+ {"include/xmmintrin.h$", "<xmmintrin.h>"},<br>
+ {"include/xopintrin.h$", "<x86intrin.h>"},<br>
+ {"include/xsavecintrin.h$", "<immintrin.h>"},<br>
+ {"include/xsaveintrin.h$", "<immintrin.h>"},<br>
+ {"include/xsaveoptintrin.h$", "<immintrin.h>"},<br>
+ {"include/xsavesintrin.h$", "<immintrin.h>"},<br>
+ {"include/xtestintrin.h$", "<immintrin.h>"},<br>
+ {"include/_G_config.h$", "<cstdio>"},<br>
+ {"include/assert.h$", "<cassert>"},<br>
+ {"algorithm$", "<algorithm>"},<br>
+ {"array$", "<array>"},<br>
+ {"atomic$", "<atomic>"},<br>
+ {"backward/auto_ptr.h$", "<memory>"},<br>
+ {"backward/binders.h$", "<string>"},<br>
+ {"bits/algorithmfwd.h$", "<algorithm>"},<br>
+ {"bits/alloc_traits.h$", "<unordered_set>"},<br>
+ {"bits/allocator.h$", "<string>"},<br>
+ {"bits/atomic_base.h$", "<atomic>"},<br>
+ {"bits/atomic_lockfree_defines<wbr>.h$", "<exception>"},<br>
+ {"bits/basic_ios.h$", "<ios>"},<br>
+ {"bits/basic_ios.tcc$", "<ios>"},<br>
+ {"bits/basic_string.h$", "<string>"},<br>
+ {"bits/basic_string.tcc$", "<string>"},<br>
+ {"bits/char_traits.h$", "<string>"},<br>
+ {"bits/codecvt.h$", "<locale>"},<br>
+ {"bits/concept_check.h$", "<numeric>"},<br>
+ {"bits/cpp_type_traits.h$", "<cmath>"},<br>
+ {"bits/cxxabi_forced.h$", "<cxxabi.h>"},<br>
+ {"bits/deque.tcc$", "<deque>"},<br>
+ {"bits/exception_defines.h$", "<exception>"},<br>
+ {"bits/exception_ptr.h$", "<exception>"},<br>
+ {"bits/forward_list.h$", "<forward_list>"},<br>
+ {"bits/forward_list.tcc$", "<forward_list>"},<br>
+ {"bits/fstream.tcc$", "<fstream>"},<br>
+ {"bits/functexcept.h$", "<list>"},<br>
+ {"bits/functional_hash.h$", "<string>"},<br>
+ {"bits/gslice.h$", "<valarray>"},<br>
+ {"bits/gslice_array.h$", "<valarray>"},<br>
+ {"bits/hash_bytes.h$", "<typeinfo>"},<br>
+ {"bits/hashtable.h$", "<unordered_set>"},<br>
+ {"bits/hashtable_policy.h$", "<unordered_set>"},<br>
+ {"bits/indirect_array.h$", "<valarray>"},<br>
+ {"bits/ios_base.h$", "<ios>"},<br>
+ {"bits/istream.tcc$", "<istream>"},<br>
+ {"bits/list.tcc$", "<list>"},<br>
+ {"bits/locale_classes.h$", "<locale>"},<br>
+ {"bits/locale_classes.tcc$", "<locale>"},<br>
+ {"bits/locale_facets.h$", "<locale>"},<br>
+ {"bits/locale_facets.tcc$", "<locale>"},<br>
+ {"bits/locale_facets_nonio.h$"<wbr>, "<locale>"},<br>
+ {"bits/locale_facets_nonio.tcc<wbr>$", "<locale>"},<br>
+ {"bits/localefwd.h$", "<locale>"},<br>
+ {"bits/mask_array.h$", "<valarray>"},<br>
+ {"bits/memoryfwd.h$", "<memory>"},<br>
+ {"bits/move.h$", "<utility>"},<br>
+ {"bits/nested_exception.h$", "<exception>"},<br>
+ {"bits/ostream.tcc$", "<ostream>"},<br>
+ {"bits/ostream_insert.h$", "<ostream>"},<br>
+ {"bits/postypes.h$", "<iosfwd>"},<br>
+ {"bits/ptr_traits.h$", "<memory>"},<br>
+ {"bits/random.h$", "<random>"},<br>
+ {"bits/random.tcc$", "<random>"},<br>
+ {"bits/range_access.h$", "<iterator>"},<br>
+ {"bits/regex.h$", "<regex>"},<br>
+ {"bits/regex_compiler.h$", "<regex>"},<br>
+ {"bits/regex_constants.h$", "<regex>"},<br>
+ {"bits/regex_cursor.h$", "<regex>"},<br>
+ {"bits/regex_error.h$", "<regex>"},<br>
+ {"bits/regex_grep_matcher.h$", "<regex>"},<br>
+ {"bits/regex_grep_matcher.tcc$<wbr>", "<regex>"},<br>
+ {"bits/regex_nfa.h$", "<regex>"},<br>
+ {"bits/shared_ptr.h$", "<memory>"},<br>
+ {"bits/shared_ptr_base.h$", "<memory>"},<br>
+ {"bits/slice_array.h$", "<valarray>"},<br>
+ {"bits/sstream.tcc$", "<sstream>"},<br>
+ {"bits/stl_algo.h$", "<algorithm>"},<br>
+ {"bits/stl_algobase.h$", "<list>"},<br>
+ {"bits/stl_bvector.h$", "<vector>"},<br>
+ {"bits/stl_construct.h$", "<deque>"},<br>
+ {"bits/stl_deque.h$", "<deque>"},<br>
+ {"bits/stl_function.h$", "<string>"},<br>
+ {"bits/stl_heap.h$", "<queue>"},<br>
+ {"bits/stl_iterator.h$", "<iterator>"},<br>
+ {"bits/stl_iterator_base_funcs<wbr>.h$", "<iterator>"},<br>
+ {"bits/stl_iterator_base_types<wbr>.h$", "<numeric>"},<br>
+ {"bits/stl_list.h$", "<list>"},<br>
+ {"bits/stl_map.h$", "<map>"},<br>
+ {"bits/stl_multimap.h$", "<map>"},<br>
+ {"bits/stl_multiset.h$", "<set>"},<br>
+ {"bits/stl_numeric.h$", "<numeric>"},<br>
+ {"bits/stl_pair.h$", "<utility>"},<br>
+ {"bits/stl_queue.h$", "<queue>"},<br>
+ {"bits/stl_raw_storage_iter.h$<wbr>", "<memory>"},<br>
+ {"bits/stl_relops.h$", "<utility>"},<br>
+ {"bits/stl_set.h$", "<set>"},<br>
+ {"bits/stl_stack.h$", "<stack>"},<br>
+ {"bits/stl_tempbuf.h$", "<memory>"},<br>
+ {"bits/stl_tree.h$", "<map>"},<br>
+ {"bits/stl_uninitialized.h$", "<deque>"},<br>
+ {"bits/stl_vector.h$", "<vector>"},<br>
+ {"bits/stream_iterator.h$", "<iterator>"},<br>
+ {"bits/streambuf.tcc$", "<streambuf>"},<br>
+ {"bits/streambuf_iterator.h$", "<iterator>"},<br>
+ {"bits/stringfwd.h$", "<string>"},<br>
+ {"bits/unique_ptr.h$", "<memory>"},<br>
+ {"bits/unordered_map.h$", "<unordered_map>"},<br>
+ {"bits/unordered_set.h$", "<unordered_set>"},<br>
+ {"bits/uses_allocator.h$", "<tuple>"},<br>
+ {"bits/valarray_after.h$", "<valarray>"},<br>
+ {"bits/valarray_array.h$", "<valarray>"},<br>
+ {"bits/valarray_array.tcc$", "<valarray>"},<br>
+ {"bits/valarray_before.h$", "<valarray>"},<br>
+ {"bits/vector.tcc$", "<vector>"},<br>
+ {"bitset$", "<bitset>"},<br>
+ {"ccomplex$", "<ccomplex>"},<br>
+ {"cctype$", "<cctype>"},<br>
+ {"cerrno$", "<cerrno>"},<br>
+ {"cfenv$", "<cfenv>"},<br>
+ {"cfloat$", "<cfloat>"},<br>
+ {"chrono$", "<chrono>"},<br>
+ {"cinttypes$", "<cinttypes>"},<br>
+ {"climits$", "<climits>"},<br>
+ {"clocale$", "<clocale>"},<br>
+ {"cmath$", "<cmath>"},<br>
+ {"complex$", "<complex>"},<br>
+ {"complex.h$", "<complex.h>"},<br>
+ {"condition_variable$", "<condition_variable>"},<br>
+ {"csetjmp$", "<csetjmp>"},<br>
+ {"csignal$", "<csignal>"},<br>
+ {"cstdalign$", "<cstdalign>"},<br>
+ {"cstdarg$", "<cstdarg>"},<br>
+ {"cstdbool$", "<cstdbool>"},<br>
+ {"cstdint$", "<cstdint>"},<br>
+ {"cstdio$", "<cstdio>"},<br>
+ {"cstdlib$", "<cstdlib>"},<br>
+ {"cstring$", "<cstring>"},<br>
+ {"ctgmath$", "<ctgmath>"},<br>
+ {"ctime$", "<ctime>"},<br>
+ {"cwchar$", "<cwchar>"},<br>
+ {"cwctype$", "<cwctype>"},<br>
+ {"cxxabi.h$", "<cxxabi.h>"},<br>
+ {"debug/debug.h$", "<numeric>"},<br>
+ {"deque$", "<deque>"},<br>
+ {"exception$", "<exception>"},<br>
+ {"ext/alloc_traits.h$", "<deque>"},<br>
+ {"ext/atomicity.h$", "<memory>"},<br>
+ {"ext/concurrence.h$", "<memory>"},<br>
+ {"ext/new_allocator.h$", "<string>"},<br>
+ {"ext/numeric_traits.h$", "<list>"},<br>
+ {"ext/string_conversions.h$", "<string>"},<br>
+ {"ext/type_traits.h$", "<cmath>"},<br>
+ {"fenv.h$", "<fenv.h>"},<br>
+ {"forward_list$", "<forward_list>"},<br>
+ {"fstream$", "<fstream>"},<br>
+ {"functional$", "<functional>"},<br>
+ {"future$", "<future>"},<br>
+ {"initializer_list$", "<initializer_list>"},<br>
+ {"iomanip$", "<iomanip>"},<br>
+ {"ios$", "<ios>"},<br>
+ {"iosfwd$", "<iosfwd>"},<br>
+ {"iostream$", "<iostream>"},<br>
+ {"istream$", "<istream>"},<br>
+ {"iterator$", "<iterator>"},<br>
+ {"limits$", "<limits>"},<br>
+ {"list$", "<list>"},<br>
+ {"locale$", "<locale>"},<br>
+ {"map$", "<map>"},<br>
+ {"memory$", "<memory>"},<br>
+ {"mutex$", "<mutex>"},<br>
+ {"new$", "<new>"},<br>
+ {"numeric$", "<numeric>"},<br>
+ {"ostream$", "<ostream>"},<br>
+ {"queue$", "<queue>"},<br>
+ {"random$", "<random>"},<br>
+ {"ratio$", "<ratio>"},<br>
+ {"regex$", "<regex>"},<br>
+ {"scoped_allocator$", "<scoped_allocator>"},<br>
+ {"set$", "<set>"},<br>
+ {"sstream$", "<sstream>"},<br>
+ {"stack$", "<stack>"},<br>
+ {"stdexcept$", "<stdexcept>"},<br>
+ {"streambuf$", "<streambuf>"},<br>
+ {"string$", "<string>"},<br>
+ {"system_error$", "<system_error>"},<br>
+ {"tgmath.h$", "<tgmath.h>"},<br>
+ {"thread$", "<thread>"},<br>
+ {"tuple$", "<tuple>"},<br>
+ {"type_traits$", "<type_traits>"},<br>
+ {"typeindex$", "<typeindex>"},<br>
+ {"typeinfo$", "<typeinfo>"},<br>
+ {"unordered_map$", "<unordered_map>"},<br>
+ {"unordered_set$", "<unordered_set>"},<br>
+ {"utility$", "<utility>"},<br>
+ {"valarray$", "<valarray>"},<br>
+ {"vector$", "<vector>"},<br>
+ {"include/complex.h$", "<complex.h>"},<br>
+ {"include/ctype.h$", "<cctype>"},<br>
+ {"include/errno.h$", "<cerrno>"},<br>
+ {"include/fenv.h$", "<fenv.h>"},<br>
+ {"include/inttypes.h$", "<cinttypes>"},<br>
+ {"include/libio.h$", "<cstdio>"},<br>
+ {"include/limits.h$", "<climits>"},<br>
+ {"include/locale.h$", "<clocale>"},<br>
+ {"include/math.h$", "<cmath>"},<br>
+ {"include/setjmp.h$", "<csetjmp>"},<br>
+ {"include/signal.h$", "<csignal>"},<br>
+ {"include/stdint.h$", "<cstdint>"},<br>
+ {"include/stdio.h$", "<cstdio>"},<br>
+ {"include/stdlib.h$", "<cstdlib>"},<br>
+ {"include/string.h$", "<cstring>"},<br>
+ {"include/time.h$", "<ctime>"},<br>
+ {"include/wchar.h$", "<cwchar>"},<br>
+ {"include/wctype.h$", "<cwctype>"},<br>
+ {"bits/cmathcalls.h$", "<complex.h>"},<br>
+ {"bits/errno.h$", "<cerrno>"},<br>
+ {"bits/fenv.h$", "<fenv.h>"},<br>
+ {"bits/huge_val.h$", "<cmath>"},<br>
+ {"bits/huge_valf.h$", "<cmath>"},<br>
+ {"bits/huge_vall.h$", "<cmath>"},<br>
+ {"bits/inf.h$", "<cmath>"},<br>
+ {"bits/local_lim.h$", "<climits>"},<br>
+ {"bits/locale.h$", "<clocale>"},<br>
+ {"bits/mathcalls.h$", "<math.h>"},<br>
+ {"bits/mathdef.h$", "<cmath>"},<br>
+ {"bits/nan.h$", "<cmath>"},<br>
+ {"bits/posix1_lim.h$", "<climits>"},<br>
+ {"bits/posix2_lim.h$", "<climits>"},<br>
+ {"bits/setjmp.h$", "<csetjmp>"},<br>
+ {"bits/sigaction.h$", "<csignal>"},<br>
+ {"bits/sigcontext.h$", "<csignal>"},<br>
+ {"bits/siginfo.h$", "<csignal>"},<br>
+ {"bits/signum.h$", "<csignal>"},<br>
+ {"bits/sigset.h$", "<csignal>"},<br>
+ {"bits/sigstack.h$", "<csignal>"},<br>
+ {"bits/stdio_lim.h$", "<cstdio>"},<br>
+ {"bits/sys_errlist.h$", "<cstdio>"},<br>
+ {"bits/time.h$", "<ctime>"},<br>
+ {"bits/timex.h$", "<ctime>"},<br>
+ {"bits/typesizes.h$", "<cstdio>"},<br>
+ {"bits/wchar.h$", "<cwchar>"},<br>
+ {"bits/wordsize.h$", "<csetjmp>"},<br>
+ {"bits/xopen_lim.h$", "<climits>"},<br>
+ {"include/xlocale.h$", "<cstring>"},<br>
+ {"bits/atomic_word.h$", "<memory>"},<br>
+ {"bits/basic_file.h$", "<fstream>"},<br>
+ {"bits/c\\+\\+allocator.h$", "<string>"},<br>
+ {"bits/c\\+\\+config.h$", "<iosfwd>"},<br>
+ {"bits/c\\+\\+io.h$", "<ios>"},<br>
+ {"bits/c\\+\\+locale.h$", "<locale>"},<br>
+ {"bits/cpu_defines.h$", "<iosfwd>"},<br>
+ {"bits/ctype_base.h$", "<locale>"},<br>
+ {"bits/cxxabi_tweaks.h$", "<cxxabi.h>"},<br>
+ {"bits/error_constants.h$", "<system_error>"},<br>
+ {"bits/gthr-default.h$", "<memory>"},<br>
+ {"bits/gthr.h$", "<memory>"},<br>
+ {"bits/opt_random.h$", "<random>"},<br>
+ {"bits/os_defines.h$", "<iosfwd>"},<br>
+ // GNU C headers<br>
+ {"include/aio.h$", "<aio.h>"},<br>
+ {"include/aliases.h$", "<aliases.h>"},<br>
+ {"include/alloca.h$", "<alloca.h>"},<br>
+ {"include/ar.h$", "<ar.h>"},<br>
+ {"include/argp.h$", "<argp.h>"},<br>
+ {"include/argz.h$", "<argz.h>"},<br>
+ {"include/arpa/nameser.h$", "<resolv.h>"},<br>
+ {"include/arpa/nameser_compat.<wbr>h$", "<resolv.h>"},<br>
+ {"include/byteswap.h$", "<byteswap.h>"},<br>
+ {"include/cpio.h$", "<cpio.h>"},<br>
+ {"include/crypt.h$", "<crypt.h>"},<br>
+ {"include/dirent.h$", "<dirent.h>"},<br>
+ {"include/dlfcn.h$", "<dlfcn.h>"},<br>
+ {"include/elf.h$", "<elf.h>"},<br>
+ {"include/endian.h$", "<endian.h>"},<br>
+ {"include/envz.h$", "<envz.h>"},<br>
+ {"include/err.h$", "<err.h>"},<br>
+ {"include/error.h$", "<error.h>"},<br>
+ {"include/execinfo.h$", "<execinfo.h>"},<br>
+ {"include/fcntl.h$", "<fcntl.h>"},<br>
+ {"include/features.h$", "<features.h>"},<br>
+ {"include/fenv.h$", "<fenv.h>"},<br>
+ {"include/fmtmsg.h$", "<fmtmsg.h>"},<br>
+ {"include/fnmatch.h$", "<fnmatch.h>"},<br>
+ {"include/fstab.h$", "<fstab.h>"},<br>
+ {"include/fts.h$", "<fts.h>"},<br>
+ {"include/ftw.h$", "<ftw.h>"},<br>
+ {"include/gconv.h$", "<gconv.h>"},<br>
+ {"include/getopt.h$", "<getopt.h>"},<br>
+ {"include/glob.h$", "<glob.h>"},<br>
+ {"include/grp.h$", "<grp.h>"},<br>
+ {"include/gshadow.h$", "<gshadow.h>"},<br>
+ {"include/iconv.h$", "<iconv.h>"},<br>
+ {"include/ifaddrs.h$", "<ifaddrs.h>"},<br>
+ {"include/kdb.h$", "<kdb.h>"},<br>
+ {"include/langinfo.h$", "<langinfo.h>"},<br>
+ {"include/libgen.h$", "<libgen.h>"},<br>
+ {"include/libintl.h$", "<libintl.h>"},<br>
+ {"include/link.h$", "<link.h>"},<br>
+ {"include/malloc.h$", "<malloc.h>"},<br>
+ {"include/mcheck.h$", "<mcheck.h>"},<br>
+ {"include/memory.h$", "<memory.h>"},<br>
+ {"include/mntent.h$", "<mntent.h>"},<br>
+ {"include/monetary.h$", "<monetary.h>"},<br>
+ {"include/mqueue.h$", "<mqueue.h>"},<br>
+ {"include/netdb.h$", "<netdb.h>"},<br>
+ {"include/netinet/in.h$", "<netinet/in.h>"},<br>
+ {"include/nl_types.h$", "<nl_types.h>"},<br>
+ {"include/nss.h$", "<nss.h>"},<br>
+ {"include/obstack.h$", "<obstack.h>"},<br>
+ {"include/panel.h$", "<panel.h>"},<br>
+ {"include/paths.h$", "<paths.h>"},<br>
+ {"include/printf.h$", "<printf.h>"},<br>
+ {"include/profile.h$", "<profile.h>"},<br>
+ {"include/pthread.h$", "<pthread.h>"},<br>
+ {"include/pty.h$", "<pty.h>"},<br>
+ {"include/pwd.h$", "<pwd.h>"},<br>
+ {"include/re_comp.h$", "<re_comp.h>"},<br>
+ {"include/regex.h$", "<regex.h>"},<br>
+ {"include/regexp.h$", "<regexp.h>"},<br>
+ {"include/resolv.h$", "<resolv.h>"},<br>
+ {"include/rpc/netdb.h$", "<netdb.h>"},<br>
+ {"include/sched.h$", "<sched.h>"},<br>
+ {"include/search.h$", "<search.h>"},<br>
+ {"include/semaphore.h$", "<semaphore.h>"},<br>
+ {"include/sgtty.h$", "<sgtty.h>"},<br>
+ {"include/shadow.h$", "<shadow.h>"},<br>
+ {"include/spawn.h$", "<spawn.h>"},<br>
+ {"include/stab.h$", "<stab.h>"},<br>
+ {"include/stdc-predef.h$", "<stdc-predef.h>"},<br>
+ {"include/stdio_ext.h$", "<stdio_ext.h>"},<br>
+ {"include/strings.h$", "<strings.h>"},<br>
+ {"include/stropts.h$", "<stropts.h>"},<br>
+ {"include/sudo_plugin.h$", "<sudo_plugin.h>"},<br>
+ {"include/sysexits.h$", "<sysexits.h>"},<br>
+ {"include/tar.h$", "<tar.h>"},<br>
+ {"include/tcpd.h$", "<tcpd.h>"},<br>
+ {"include/term.h$", "<term.h>"},<br>
+ {"include/term_entry.h$", "<term_entry.h>"},<br>
+ {"include/termcap.h$", "<termcap.h>"},<br>
+ {"include/termios.h$", "<termios.h>"},<br>
+ {"include/thread_db.h$", "<thread_db.h>"},<br>
+ {"include/tic.h$", "<tic.h>"},<br>
+ {"include/ttyent.h$", "<ttyent.h>"},<br>
+ {"include/uchar.h$", "<uchar.h>"},<br>
+ {"include/ucontext.h$", "<ucontext.h>"},<br>
+ {"include/ulimit.h$", "<ulimit.h>"},<br>
+ {"include/unctrl.h$", "<unctrl.h>"},<br>
+ {"include/unistd.h$", "<unistd.h>"},<br>
+ {"include/utime.h$", "<utime.h>"},<br>
+ {"include/utmp.h$", "<utmp.h>"},<br>
+ {"include/utmpx.h$", "<utmpx.h>"},<br>
+ {"include/values.h$", "<values.h>"},<br>
+ {"include/wordexp.h$", "<wordexp.h>"},<br>
+ {"fpu_control.h$", "<fpu_control.h>"},<br>
+ {"ieee754.h$", "<ieee754.h>"},<br>
+ {"include/xlocale.h$", "<xlocale.h>"},<br>
+ {"gnu/lib-names.h$", "<gnu/lib-names.h>"},<br>
+ {"gnu/libc-version.h$", "<gnu/libc-version.h>"},<br>
+ {"gnu/option-groups.h$", "<gnu/option-groups.h>"},<br>
+ {"gnu/stubs-32.h$", "<gnu/stubs-32.h>"},<br>
+ {"gnu/stubs-64.h$", "<gnu/stubs-64.h>"},<br>
+ {"gnu/stubs-x32.h$", "<gnu/stubs-x32.h>"},<br>
+ {"include/rpc/auth_des.h$", "<rpc/auth_des.h>"},<br>
+ {"include/rpc/rpc_msg.h$", "<rpc/rpc_msg.h>"},<br>
+ {"include/rpc/pmap_clnt.h$", "<rpc/pmap_clnt.h>"},<br>
+ {"include/rpc/rpc.h$", "<rpc/rpc.h>"},<br>
+ {"include/rpc/types.h$", "<rpc/types.h>"},<br>
+ {"include/rpc/auth_unix.h$", "<rpc/auth_unix.h>"},<br>
+ {"include/rpc/key_prot.h$", "<rpc/key_prot.h>"},<br>
+ {"include/rpc/pmap_prot.h$", "<rpc/pmap_prot.h>"},<br>
+ {"include/rpc/auth.h$", "<rpc/auth.h>"},<br>
+ {"include/rpc/svc_auth.h$", "<rpc/svc_auth.h>"},<br>
+ {"include/rpc/xdr.h$", "<rpc/xdr.h>"},<br>
+ {"include/rpc/pmap_rmt.h$", "<rpc/pmap_rmt.h>"},<br>
+ {"include/rpc/des_crypt.h$", "<rpc/des_crypt.h>"},<br>
+ {"include/rpc/svc.h$", "<rpc/svc.h>"},<br>
+ {"include/rpc/rpc_des.h$", "<rpc/rpc_des.h>"},<br>
+ {"include/rpc/clnt.h$", "<rpc/clnt.h>"},<br>
+ {"include/scsi/scsi.h$", "<scsi/scsi.h>"},<br>
+ {"include/scsi/sg.h$", "<scsi/sg.h>"},<br>
+ {"include/scsi/scsi_ioctl.h$", "<scsi/scsi_ioctl>"},<br>
+ {"include/netrose/rose.h$", "<netrose/rose.h>"},<br>
+ {"include/nfs/nfs.h$", "<nfs/nfs.h>"},<br>
+ {"include/netatalk/at.h$", "<netatalk/at.h>"},<br>
+ {"include/netinet/ether.h$", "<netinet/ether.h>"},<br>
+ {"include/netinet/icmp6.h$", "<netinet/icmp6.h>"},<br>
+ {"include/netinet/if_ether.h$"<wbr>, "<netinet/if_ether.h>"},<br>
+ {"include/netinet/if_fddi.h$", "<netinet/if_fddi.h>"},<br>
+ {"include/netinet/if_tr.h$", "<netinet/if_tr.h>"},<br>
+ {"include/netinet/igmp.h$", "<netinet/igmp.h>"},<br>
+ {"include/netinet/in.h$", "<netinet/in.h>"},<br>
+ {"include/netinet/in_systm.h$"<wbr>, "<netinet/in_systm.h>"},<br>
+ {"include/netinet/ip.h$", "<netinet/ip.h>"},<br>
+ {"include/netinet/ip6.h$", "<netinet/ip6.h>"},<br>
+ {"include/netinet/ip_icmp.h$", "<netinet/ip_icmp.h>"},<br>
+ {"include/netinet/tcp.h$", "<netinet/tcp.h>"},<br>
+ {"include/netinet/udp.h$", "<netinet/udp.h>"},<br>
+ {"include/netrom/netrom.h$", "<netrom/netrom.h>"},<br>
+ {"include/protocols/routed.h$"<wbr>, "<protocols/routed.h>"},<br>
+ {"include/protocols/rwhod.h$", "<protocols/rwhod.h>"},<br>
+ {"include/protocols/talkd.h$", "<protocols/talkd.h>"},<br>
+ {"include/protocols/timed.h$", "<protocols/timed.h>"},<br>
+ {"include/rpcsvc/klm_prot.x$", "<rpcsvc/klm_prot.x>"},<br>
+ {"include/rpcsvc/rstat.h$", "<rpcsvc/rstat.h>"},<br>
+ {"include/rpcsvc/spray.x$", "<rpcsvc/spray.x>"},<br>
+ {"include/rpcsvc/nlm_prot.x$", "<rpcsvc/nlm_prot.x>"},<br>
+ {"include/rpcsvc/nis_callback.<wbr>x$", "<rpcsvc/nis_callback.x>"},<br>
+ {"include/rpcsvc/yp.h$", "<rpcsvc/yp.h>"},<br>
+ {"include/rpcsvc/yp.x$", "<rpcsvc/yp.x>"},<br>
+ {"include/rpcsvc/nfs_prot.h$", "<rpcsvc/nfs_prot.h>"},<br>
+ {"include/rpcsvc/rex.h$", "<rpcsvc/rex.h>"},<br>
+ {"include/rpcsvc/yppasswd.h$", "<rpcsvc/yppasswd.h>"},<br>
+ {"include/rpcsvc/rex.x$", "<rpcsvc/rex.x>"},<br>
+ {"include/rpcsvc/nis_tags.h$", "<rpcsvc/nis_tags.h>"},<br>
+ {"include/rpcsvc/nis_callback.<wbr>h$", "<rpcsvc/nis_callback.h>"},<br>
+ {"include/rpcsvc/nfs_prot.x$", "<rpcsvc/nfs_prot.x>"},<br>
+ {"include/rpcsvc/bootparam_pro<wbr>t.x$", "<rpcsvc/bootparam_prot.x>"},<br>
+ {"include/rpcsvc/rusers.x$", "<rpcsvc/rusers.x>"},<br>
+ {"include/rpcsvc/rquota.x$", "<rpcsvc/rquota.x>"},<br>
+ {"include/rpcsvc/nis.h$", "<rpcsvc/nis.h>"},<br>
+ {"include/rpcsvc/nislib.h$", "<rpcsvc/nislib.h>"},<br>
+ {"include/rpcsvc/ypupd.h$", "<rpcsvc/ypupd.h>"},<br>
+ {"include/rpcsvc/bootparam.h$"<wbr>, "<rpcsvc/bootparam.h>"},<br>
+ {"include/rpcsvc/spray.h$", "<rpcsvc/spray.h>"},<br>
+ {"include/rpcsvc/key_prot.h$", "<rpcsvc/key_prot.h>"},<br>
+ {"include/rpcsvc/klm_prot.h$", "<rpcsvc/klm_prot.h>"},<br>
+ {"include/rpcsvc/sm_inter.h$", "<rpcsvc/sm_inter.h>"},<br>
+ {"include/rpcsvc/nlm_prot.h$", "<rpcsvc/nlm_prot.h>"},<br>
+ {"include/rpcsvc/yp_prot.h$", "<rpcsvc/yp_prot.h>"},<br>
+ {"include/rpcsvc/ypclnt.h$", "<rpcsvc/ypclnt.h>"},<br>
+ {"include/rpcsvc/rstat.x$", "<rpcsvc/rstat.x>"},<br>
+ {"include/rpcsvc/rusers.h$", "<rpcsvc/rusers.h>"},<br>
+ {"include/rpcsvc/key_prot.x$", "<rpcsvc/key_prot.x>"},<br>
+ {"include/rpcsvc/sm_inter.x$", "<rpcsvc/sm_inter.x>"},<br>
+ {"include/rpcsvc/rquota.h$", "<rpcsvc/rquota.h>"},<br>
+ {"include/rpcsvc/nis.x$", "<rpcsvc/nis.x>"},<br>
+ {"include/rpcsvc/bootparam_pro<wbr>t.h$", "<rpcsvc/bootparam_prot.h>"},<br>
+ {"include/rpcsvc/mount.h$", "<rpcsvc/mount.h>"},<br>
+ {"include/rpcsvc/mount.x$", "<rpcsvc/mount.x>"},<br>
+ {"include/rpcsvc/nis_object.x$<wbr>", "<rpcsvc/nis_object.x>"},<br>
+ {"include/rpcsvc/yppasswd.x$", "<rpcsvc/yppasswd.x>"},<br>
+ {"sys/acct.h$", "<sys/acct.h>"},<br>
+ {"sys/auxv.h$", "<sys/auxv.h>"},<br>
+ {"sys/cdefs.h$", "<sys/cdefs.h>"},<br>
+ {"sys/debugreg.h$", "<sys/debugreg.h>"},<br>
+ {"sys/dir.h$", "<sys/dir.h>"},<br>
+ {"sys/elf.h$", "<sys/elf.h>"},<br>
+ {"sys/epoll.h$", "<sys/epoll.h>"},<br>
+ {"sys/eventfd.h$", "<sys/eventfd.h>"},<br>
+ {"sys/fanotify.h$", "<sys/fanotify.h>"},<br>
+ {"sys/file.h$", "<sys/file.h>"},<br>
+ {"sys/fsuid.h$", "<sys/fsuid.h>"},<br>
+ {"sys/gmon.h$", "<sys/gmon.h>"},<br>
+ {"sys/gmon_out.h$", "<sys/gmon_out.h>"},<br>
+ {"sys/inotify.h$", "<sys/inotify.h>"},<br>
+ {"sys/io.h$", "<sys/io.h>"},<br>
+ {"sys/ioctl.h$", "<sys/ioctl.h>"},<br>
+ {"sys/ipc.h$", "<sys/ipc.h>"},<br>
+ {"sys/kd.h$", "<sys/kd.h>"},<br>
+ {"sys/kdaemon.h$", "<sys/kdaemon.h>"},<br>
+ {"sys/klog.h$", "<sys/klog.h>"},<br>
+ {"sys/mman.h$", "<sys/mman.h>"},<br>
+ {"sys/mount.h$", "<sys/mount.h>"},<br>
+ {"sys/msg.h$", "<sys/msg.h>"},<br>
+ {"sys/mtio.h$", "<sys/mtio.h>"},<br>
+ {"sys/param.h$", "<sys/param.h>"},<br>
+ {"sys/pci.h$", "<sys/pci.h>"},<br>
+ {"sys/perm.h$", "<sys/perm.h>"},<br>
+ {"sys/personality.h$", "<sys/personality.h>"},<br>
+ {"sys/poll.h$", "<sys/poll.h>"},<br>
+ {"sys/prctl.h$", "<sys/prctl.h>"},<br>
+ {"sys/procfs.h$", "<sys/procfs.h>"},<br>
+ {"sys/profil.h$", "<sys/profil.h>"},<br>
+ {"sys/ptrace.h$", "<sys/ptrace.h>"},<br>
+ {"sys/queue.h$", "<sys/queue.h>"},<br>
+ {"sys/quota.h$", "<sys/quota.h>"},<br>
+ {"sys/raw.h$", "<sys/raw.h>"},<br>
+ {"sys/reboot.h$", "<sys/reboot.h>"},<br>
+ {"sys/reg.h$", "<sys/reg.h>"},<br>
+ {"sys/resource.h$", "<sys/resource.h>"},<br>
+ {"sys/select.h$", "<sys/select.h>"},<br>
+ {"sys/sem.h$", "<sys/sem.h>"},<br>
+ {"sys/sendfile.h$", "<sys/sendfile.h>"},<br>
+ {"sys/shm.h$", "<sys/shm.h>"},<br>
+ {"sys/signalfd.h$", "<sys/signalfd.h>"},<br>
+ {"sys/socket.h$", "<sys/socket.h>"},<br>
+ {"sys/stat.h$", "<sys/stat.h>"},<br>
+ {"sys/statfs.h$", "<sys/statfs.h>"},<br>
+ {"sys/statvfs.h$", "<sys/statvfs.h>"},<br>
+ {"sys/swap.h$", "<sys/swap.h>"},<br>
+ {"sys/syscall.h$", "<sys/syscall.h>"},<br>
+ {"sys/sysctl.h$", "<sys/sysctl.h>"},<br>
+ {"sys/sysinfo.h$", "<sys/sysinfo.h>"},<br>
+ {"sys/syslog.h$", "<sys/syslog.h>"},<br>
+ {"sys/sysmacros.h$", "<sys/sysmacros.h>"},<br>
+ {"sys/termios.h$", "<sys/termios.h>"},<br>
+ {"sys/time.h$", "<sys/select.h>"},<br>
+ {"sys/timeb.h$", "<sys/timeb.h>"},<br>
+ {"sys/timerfd.h$", "<sys/timerfd.h>"},<br>
+ {"sys/times.h$", "<sys/times.h>"},<br>
+ {"sys/timex.h$", "<sys/timex.h>"},<br>
+ {"sys/ttychars.h$", "<sys/ttychars.h>"},<br>
+ {"sys/ttydefaults.h$", "<sys/ttydefaults.h>"},<br>
+ {"sys/types.h$", "<sys/types.h>"},<br>
+ {"sys/ucontext.h$", "<sys/ucontext.h>"},<br>
+ {"sys/uio.h$", "<sys/uio.h>"},<br>
+ {"sys/un.h$", "<sys/un.h>"},<br>
+ {"sys/user.h$", "<sys/user.h>"},<br>
+ {"sys/ustat.h$", "<sys/ustat.h>"},<br>
+ {"sys/utsname.h$", "<sys/utsname.h>"},<br>
+ {"sys/vlimit.h$", "<sys/vlimit.h>"},<br>
+ {"sys/vm86.h$", "<sys/vm86.h>"},<br>
+ {"sys/vtimes.h$", "<sys/vtimes.h>"},<br>
+ {"sys/wait.h$", "<sys/wait.h>"},<br>
+ {"sys/xattr.h$", "<sys/xattr.h>"},<br>
+ {"bits/epoll.h$", "<sys/epoll.h>"},<br>
+ {"bits/eventfd.h$", "<sys/eventfd.h>"},<br>
+ {"bits/inotify.h$", "<sys/inotify.h>"},<br>
+ {"bits/ipc.h$", "<sys/ipc.h>"},<br>
+ {"bits/ipctypes.h$", "<sys/ipc.h>"},<br>
+ {"bits/mman-linux.h$", "<sys/mman.h>"},<br>
+ {"bits/mman.h$", "<sys/mman.h>"},<br>
+ {"bits/msq.h$", "<sys/msg.h>"},<br>
+ {"bits/resource.h$", "<sys/resource.h>"},<br>
+ {"bits/sem.h$", "<sys/sem.h>"},<br>
+ {"bits/shm.h$", "<sys/shm.h>"},<br>
+ {"bits/signalfd.h$", "<sys/signalfd.h>"},<br>
+ {"bits/statfs.h$", "<sys/statfs.h>"},<br>
+ {"bits/statvfs.h$", "<sys/statvfs.h>"},<br>
+ {"bits/timerfd.h$", "<sys/timerfd.h>"},<br>
+ {"bits/utsname.h$", "<sys/utsname.h>"},<br>
+ {"bits/auxv.h$", "<sys/auxv.h>"},<br>
+ {"bits/byteswap-16.h$", "<byteswap.h>"},<br>
+ {"bits/byteswap.h$", "<byteswap.h>"},<br>
+ {"bits/confname.h$", "<unistd.h>"},<br>
+ {"bits/dirent.h$", "<dirent.h>"},<br>
+ {"bits/dlfcn.h$", "<dlfcn.h>"},<br>
+ {"bits/elfclass.h$", "<link.h>"},<br>
+ {"bits/endian.h$", "<endian.h>"},<br>
+ {"bits/environments.h$", "<unistd.h>"},<br>
+ {"bits/fcntl-linux.h$", "<fcntl.h>"},<br>
+ {"bits/fcntl.h$", "<fcntl.h>"},<br>
+ {"bits/in.h$", "<netinet/in.h>"},<br>
+ {"bits/ioctl-types.h$", "<sys/ioctl.h>"},<br>
+ {"bits/ioctls.h$", "<sys/ioctl.h>"},<br>
+ {"bits/link.h$", "<link.h>"},<br>
+ {"bits/mqueue.h$", "<mqueue.h>"},<br>
+ {"bits/netdb.h$", "<netdb.h>"},<br>
+ {"bits/param.h$", "<sys/param.h>"},<br>
+ {"bits/poll.h$", "<sys/poll.h>"},<br>
+ {"bits/posix_opt.h$", "<bits/posix_opt.h>"},<br>
+ {"bits/pthreadtypes.h$", "<pthread.h>"},<br>
+ {"bits/sched.h$", "<sched.h>"},<br>
+ {"bits/select.h$", "<sys/select.h>"},<br>
+ {"bits/semaphore.h$", "<semaphore.h>"},<br>
+ {"bits/sigthread.h$", "<pthread.h>"},<br>
+ {"bits/sockaddr.h$", "<sys/socket.h>"},<br>
+ {"bits/socket.h$", "<sys/socket.h>"},<br>
+ {"bits/socket_type.h$", "<sys/socket.h>"},<br>
+ {"bits/stab.def$", "<stab.h>"},<br>
+ {"bits/stat.h$", "<sys/stat.h>"},<br>
+ {"bits/stropts.h$", "<stropts.h>"},<br>
+ {"bits/syscall.h$", "<sys/syscall.h>"},<br>
+ {"bits/syslog-path.h$", "<sys/syslog.h>"},<br>
+ {"bits/termios.h$", "<termios.h>"},<br>
+ {"bits/types.h$", "<sys/types.h>"},<br>
+ {"bits/typesizes.h$", "<sys/types.h>"},<br>
+ {"bits/uio.h$", "<sys/uio.h>"},<br>
+ {"bits/ustat.h$", "<sys/ustat.h>"},<br>
+ {"bits/utmp.h$", "<utmp.h>"},<br>
+ {"bits/utmpx.h$", "<utmpx.h>"},<br>
+ {"bits/waitflags.h$", "<sys/wait.h>"},<br>
+ {"bits/waitstatus.h$", "<sys/wait.h>"},<br>
+ {"bits/xtitypes.h$", "<stropts.h>"},<br>
+ };<br>
+ for (const auto &Pair : SystemHeaderMap)<br>
+ Includes->addRegexMapping(Pair<wbr>.first, Pair.second);<br>
+}<br>
+<br>
+} // namespace clangd<br>
+} // namespace clang<br>
<br>
Added: clang-tools-extra/trunk/clangd<wbr>/index/CanonicalIncludes.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/CanonicalIncludes.h?rev=325343&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/clang-tools-extra/trunk/<wbr>clangd/index/CanonicalIncludes<wbr>.h?rev=325343&view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/clangd<wbr>/index/CanonicalIncludes.h (added)<br>
+++ clang-tools-extra/trunk/clangd<wbr>/index/CanonicalIncludes.h Fri Feb 16 06:15:55 2018<br>
@@ -0,0 +1,79 @@<br>
+//===-- CanonicalIncludes.h - remap #include header -------------*- C++ -*-===//<br>
+//<br>
+// The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===------------------------<wbr>------------------------------<wbr>----------------===//<br>
+//<br>
+// At indexing time, we decide which file to #included for a symbol.<br>
+// Usually this is the file with the canonical decl, but there are exceptions:<br>
+// - private headers may have pragmas pointing to the matching public header.<br>
+// (These are "IWYU" pragmas, named after the include-what-you-use tool).<br>
+// - the standard library is implemented in many files, without any pragmas.<br>
+// We have a lookup table for common standard library implementations.<br>
+// libstdc++ puts char_traits in bits/char_traits.h, but we #include <string>.<br>
+//<br>
+//===------------------------<wbr>------------------------------<wbr>---------------===//<br>
+<br>
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_<wbr>INDEX_CANONICALINCLUDES_H<br>
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_<wbr>INDEX_CANONICALINCLUDES_H<br>
+<br>
+#include "clang/Lex/Preprocessor.h"<br>
+#include "llvm/ADT/StringMap.h"<br>
+#include "llvm/Support/Regex.h"<br>
+#include <string><br>
+#include <vector><br>
+<br>
+namespace clang {<br>
+namespace clangd {<br>
+<br>
+/// Maps a definition location onto an #include file, based on a set of filename<br>
+/// rules.<br>
+class CanonicalIncludes {<br>
+public:<br>
+ CanonicalIncludes() = default;<br>
+<br>
+ /// Adds a string-to-string mapping from \p Path to \p CanonicalPath.<br>
+ void addMapping(llvm::StringRef Path, llvm::StringRef CanonicalPath);<br>
+<br>
+ /// Maps all files matching \p RE to \p CanonicalPath<br>
+ void addRegexMapping(llvm::StringRe<wbr>f RE, llvm::StringRef CanonicalPath);<br>
+<br>
+ /// \return \p Header itself if there is no mapping for it; otherwise, return<br>
+ /// a canonical header name.<br>
+ llvm::StringRef mapHeader(llvm::StringRef Header) const;<br>
+<br>
+private:<br>
+ // A map from header patterns to header names. This needs to be mutable so<br>
+ // that we can match again a Regex in a const function member.<br>
+ // FIXME(ioeric): All the regexes we have so far are suffix matches. The<br>
+ // performance could be improved by allowing only suffix matches instead of<br>
+ // arbitrary regexes.<br>
+ mutable std::vector<std::pair<llvm::Re<wbr>gex, std::string>><br>
+ RegexHeaderMappingTable;<br>
+};<br>
+<br>
+/// Returns a CommentHandler that parses pragma comment on include files to<br>
+/// determine when we should include a different header from the header that<br>
+/// directly defines a symbol. Mappinps are registered with \p Includes.<br>
+///<br>
+/// Currently it only supports IWYU private pragma:<br>
+/// <a href="https://github.com/include-what-you-use/include-what-you-use/blob/master/docs/IWYUPragmas.md#iwyu-pragma-private" rel="noreferrer" target="_blank">https://github.com/include-wha<wbr>t-you-use/include-what-you-use<wbr>/blob/master/docs/IWYUPragmas.<wbr>md#iwyu-pragma-private</a><br>
+std::unique_ptr<CommentHandle<wbr>r><br>
+collectIWYUHeaderMaps(Canonic<wbr>alIncludes *Includes);<br>
+<br>
+/// Adds mapping for system headers. Approximately, the following system headers<br>
+/// are handled:<br>
+/// - C++ standard library e.g. bits/basic_string.h$ -> <string><br>
+/// - Posix library e.g. bits/pthreadtypes.h$ -> <pthread.h><br>
+/// - Compiler extensions, e.g. include/avx512bwintrin.h$ -> <immintrin.h><br>
+/// The mapping is hardcoded and hand-maintained, so it might not cover all<br>
+/// headers.<br>
+void addSystemHeadersMapping(Canoni<wbr>calIncludes *Includes);<br>
+<br>
+} // namespace clangd<br>
+} // namespace clang<br>
+<br>
+#endif //LLVM_CLANG_TOOLS_EXTRA_CLANG<wbr>D_INDEX_HEADERMAPCOLLECTOR_H<br>
<br>
Modified: clang-tools-extra/trunk/clangd<wbr>/index/Index.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.cpp?rev=325343&r1=325342&r2=325343&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/clang-tools-extra/trunk/<wbr>clangd/index/Index.cpp?rev=<wbr>325343&r1=325342&r2=325343&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/clangd<wbr>/index/Index.cpp (original)<br>
+++ clang-tools-extra/trunk/clangd<wbr>/index/Index.cpp Fri Feb 16 06:15:55 2018<br>
@@ -80,6 +80,7 @@ static void own(Symbol &S, DenseSet<Stri<br>
// Intern the actual strings.<br>
Intern(Detail->Documentation)<wbr>;<br>
Intern(Detail->CompletionDeta<wbr>il);<br>
+ Intern(Detail->IncludeHeader);<br>
// Replace the detail pointer with our copy.<br>
S.Detail = Detail;<br>
}<br>
<br>
Modified: clang-tools-extra/trunk/clangd<wbr>/index/Index.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.h?rev=325343&r1=325342&r2=325343&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/clang-tools-extra/trunk/<wbr>clangd/index/Index.h?rev=<wbr>325343&r1=325342&r2=325343&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/clangd<wbr>/index/Index.h (original)<br>
+++ clang-tools-extra/trunk/clangd<wbr>/index/Index.h Fri Feb 16 06:15:55 2018<br>
@@ -152,11 +152,19 @@ struct Symbol {<br>
/// and have clients resolve full symbol information for a specific candidate<br>
/// if needed.<br>
struct Details {<br>
- // Documentation including comment for the symbol declaration.<br>
+ /// Documentation including comment for the symbol declaration.<br>
llvm::StringRef Documentation;<br>
- // This is what goes into the LSP detail field in a completion item. For<br>
- // example, the result type of a function.<br>
+ /// This is what goes into the LSP detail field in a completion item. For<br>
+ /// example, the result type of a function.<br>
llvm::StringRef CompletionDetail;<br>
+ /// This can be either a URI of the header to be #include'd for this symbol,<br>
+ /// or a literal header quoted with <> or "" that is suitable to be included<br>
+ /// directly. When this is a URI, the exact #include path needs to be<br>
+ /// calculated according to the URI scheme.<br>
+ ///<br>
+ /// If empty, FileURI in CanonicalDeclaration should be used to calculate<br>
+ /// the #include path.<br>
+ llvm::StringRef IncludeHeader;<br>
};<br>
<br>
// Optional details of the symbol.<br>
<br>
Modified: clang-tools-extra/trunk/clangd<wbr>/index/Merge.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Merge.cpp?rev=325343&r1=325342&r2=325343&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/clang-tools-extra/trunk/<wbr>clangd/index/Merge.cpp?rev=<wbr>325343&r1=325342&r2=325343&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/clangd<wbr>/index/Merge.cpp (original)<br>
+++ clang-tools-extra/trunk/clangd<wbr>/index/Merge.cpp Fri Feb 16 06:15:55 2018<br>
@@ -90,6 +90,8 @@ mergeSymbol(const Symbol &L, const Symbo<br>
Scratch->Documentation = O.Detail->Documentation;<br>
if (Scratch->CompletionDetail == "")<br>
Scratch->CompletionDetail = O.Detail->CompletionDetail;<br>
+ if (Scratch->IncludeHeader == "")<br>
+ Scratch->IncludeHeader = O.Detail->IncludeHeader;<br>
S.Detail = Scratch;<br>
} else<br>
S.Detail = O.Detail;<br>
<br>
Modified: clang-tools-extra/trunk/clangd<wbr>/index/SymbolCollector.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp?rev=325343&r1=325342&r2=325343&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/clang-tools-extra/trunk/<wbr>clangd/index/SymbolCollector.<wbr>cpp?rev=325343&r1=325342&r2=<wbr>325343&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/clangd<wbr>/index/SymbolCollector.cpp (original)<br>
+++ clang-tools-extra/trunk/clangd<wbr>/index/SymbolCollector.cpp Fri Feb 16 06:15:55 2018<br>
@@ -11,6 +11,7 @@<br>
#include "../CodeCompletionStrings.h"<br>
#include "../Logger.h"<br>
#include "../URI.h"<br>
+#include "CanonicalIncludes.h"<br>
#include "clang/AST/DeclCXX.h"<br>
#include "clang/ASTMatchers/ASTMatchFin<wbr>der.h"<br>
#include "clang/Basic/SourceManager.h"<br>
@@ -127,6 +128,51 @@ bool shouldFilterDecl(const NamedDecl *N<br>
return false;<br>
}<br>
<br>
+// We only collect #include paths for symbols that are suitable for global code<br>
+// completion, except for namespaces since #include path for a namespace is hard<br>
+// to define.<br>
+bool shouldCollectIncludePath(index<wbr>::SymbolKind Kind) {<br>
+ using SK = index::SymbolKind;<br>
+ switch (Kind) {<br>
+ case SK::Macro:<br>
+ case SK::Enum:<br>
+ case SK::Struct:<br>
+ case SK::Class:<br>
+ case SK::Union:<br>
+ case SK::TypeAlias:<br>
+ case SK::Using:<br>
+ case SK::Function:<br>
+ case SK::Variable:<br>
+ case SK::EnumConstant:<br>
+ return true;<br>
+ default:<br>
+ return false;<br>
+ }<br>
+}<br>
+<br>
+/// Gets a canonical include (<header> or "header") for header of \p Loc.<br>
+/// Returns None if the header has no canonical include.<br>
+/// FIXME: we should handle .inc files whose symbols are expected be exported by<br>
+/// their containing headers.<br>
+llvm::Optional<std::string><br>
+getIncludeHeader(const SourceManager &SM, SourceLocation Loc,<br>
+ const SymbolCollector::Options &Opts) {<br>
+ llvm::StringRef FilePath = SM.getFilename(Loc);<br>
+ if (FilePath.empty())<br>
+ return llvm::None;<br>
+ if (Opts.Includes) {<br>
+ llvm::StringRef Mapped = Opts.Includes->mapHeader(FileP<wbr>ath);<br>
+ if (Mapped != FilePath)<br>
+ return (Mapped.startswith("<") || Mapped.startswith("\""))<br>
+ ? Mapped.str()<br>
+ : ("\"" + Mapped + "\"").str();<br>
+ }<br>
+ // If the header path is the same as the file path of the declaration, we skip<br>
+ // storing the #include path; users can use the URI in declaration location to<br>
+ // calculate the #include path.<br>
+ return llvm::None;<br>
+}<br>
+<br>
// Return the symbol location of the given declaration `D`.<br>
//<br>
// For symbols defined inside macros:<br>
@@ -252,6 +298,14 @@ const Symbol *SymbolCollector::addDeclar<br>
std::string Documentation = getDocumentation(*CCS);<br>
std::string CompletionDetail = getDetail(*CCS);<br>
<br>
+ std::string Include;<br>
+ if (Opts.CollectIncludePath && shouldCollectIncludePath(S.Sym<wbr>Info.Kind)) {<br>
+ // Use the expansion location to get the #include header since this is<br>
+ // where the symbol is exposed.<br>
+ if (auto Header =<br>
+ getIncludeHeader(SM, SM.getExpansionLoc(ND.getLocat<wbr>ion()), Opts))<br>
+ Include = std::move(*Header);<br>
+ }<br>
S.CompletionFilterText = FilterText;<br>
S.CompletionLabel = Label;<br>
S.CompletionPlainInsertText = PlainInsertText;<br>
@@ -259,6 +313,7 @@ const Symbol *SymbolCollector::addDeclar<br>
Symbol::Details Detail;<br>
Detail.Documentation = Documentation;<br>
Detail.CompletionDetail = CompletionDetail;<br>
+ Detail.IncludeHeader = Include;<br>
S.Detail = &Detail;<br>
<br>
Symbols.insert(S);<br>
<br>
Modified: clang-tools-extra/trunk/clangd<wbr>/index/SymbolCollector.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolCollector.h?rev=325343&r1=325342&r2=325343&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/clang-tools-extra/trunk/<wbr>clangd/index/SymbolCollector.<wbr>h?rev=325343&r1=325342&r2=<wbr>325343&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/clangd<wbr>/index/SymbolCollector.h (original)<br>
+++ clang-tools-extra/trunk/clangd<wbr>/index/SymbolCollector.h Fri Feb 16 06:15:55 2018<br>
@@ -7,6 +7,7 @@<br>
//<br>
//===------------------------<wbr>------------------------------<wbr>----------------===//<br>
<br>
+#include "CanonicalIncludes.h"<br>
#include "Index.h"<br>
#include "clang/AST/ASTContext.h"<br>
#include "clang/AST/Decl.h"<br>
@@ -39,6 +40,10 @@ public:<br>
/// in symbols. The list of schemes will be tried in order until a working<br>
/// scheme is found. If no scheme works, symbol location will be dropped.<br>
std::vector<std::string> URISchemes = {"file"};<br>
+ bool CollectIncludePath = false;<br>
+ /// If set, this is used to map symbol #include path to a potentially<br>
+ /// different #include path.<br>
+ const CanonicalIncludes *Includes = nullptr;<br>
};<br>
<br>
SymbolCollector(Options Opts);<br>
<br>
Modified: clang-tools-extra/trunk/clangd<wbr>/index/SymbolYAML.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp?rev=325343&r1=325342&r2=325343&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/clang-tools-extra/trunk/<wbr>clangd/index/SymbolYAML.cpp?<wbr>rev=325343&r1=325342&r2=325343<wbr>&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/clangd<wbr>/index/SymbolYAML.cpp (original)<br>
+++ clang-tools-extra/trunk/clangd<wbr>/index/SymbolYAML.cpp Fri Feb 16 06:15:55 2018<br>
@@ -64,6 +64,7 @@ template <> struct MappingTraits<Symbol:<br>
static void mapping(IO &io, Symbol::Details &Detail) {<br>
io.mapOptional("<wbr>Documentation", Detail.Documentation);<br>
io.mapOptional("CompletionDet<wbr>ail", Detail.CompletionDetail);<br>
+ io.mapOptional("IncludeHeader"<wbr>, Detail.IncludeHeader);<br>
}<br>
};<br>
<br>
<br>
Modified: clang-tools-extra/trunk/clangd<wbr>/tool/ClangdMain.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp?rev=325343&r1=325342&r2=325343&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/clang-tools-extra/trunk/<wbr>clangd/tool/ClangdMain.cpp?<wbr>rev=325343&r1=325342&r2=325343<wbr>&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/clangd<wbr>/tool/ClangdMain.cpp (original)<br>
+++ clang-tools-extra/trunk/clangd<wbr>/tool/ClangdMain.cpp Fri Feb 16 06:15:55 2018<br>
@@ -16,6 +16,7 @@<br>
#include "llvm/Support/FileSystem.h"<br>
#include "llvm/Support/Path.h"<br>
#include "llvm/Support/Program.h"<br>
+#include "llvm/Support/Signals.h"<br>
#include "llvm/Support/raw_ostream.h"<br>
#include <cstdlib><br>
#include <iostream><br>
<br>
Modified: clang-tools-extra/trunk/test/c<wbr>langd/completion-snippets.test<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/completion-snippets.test?rev=325343&r1=325342&r2=325343&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/clang-tools-extra/trunk/<wbr>test/clangd/completion-snippet<wbr>s.test?rev=325343&r1=325342&<wbr>r2=325343&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/test/c<wbr>langd/completion-snippets.test (original)<br>
+++ clang-tools-extra/trunk/test/c<wbr>langd/completion-snippets.test Fri Feb 16 06:15:55 2018<br>
@@ -28,9 +28,7 @@<br>
# CHECK-NEXT: "result": {<br>
# CHECK-NEXT: "isIncomplete": {{.*}}<br>
# CHECK-NEXT: "items": [<br>
-# CHECK-NEXT: {<br>
-# CHECK-NEXT: "detail": "int",<br>
-# CHECK-NEXT: "filterText": "func_with_args",<br>
+# CHECK: "filterText": "func_with_args",<br>
# CHECK-NEXT: "insertText": "func_with_args(${1:int a}, ${2:int b})",<br>
# CHECK-NEXT: "insertTextFormat": 2,<br>
# CHECK-NEXT: "kind": 3,<br>
<br>
Modified: clang-tools-extra/trunk/test/c<wbr>langd/initialize-params-invali<wbr>d.test<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/initialize-params-invalid.test?rev=325343&r1=325342&r2=325343&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/clang-tools-extra/trunk/<wbr>test/clangd/initialize-params-<wbr>invalid.test?rev=325343&r1=<wbr>325342&r2=325343&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/test/c<wbr>langd/initialize-params-invali<wbr>d.test (original)<br>
+++ clang-tools-extra/trunk/test/c<wbr>langd/initialize-params-invali<wbr>d.test Fri Feb 16 06:15:55 2018<br>
@@ -24,7 +24,8 @@<br>
# CHECK-NEXT: "documentRangeFormattingProvid<wbr>er": true,<br>
# CHECK-NEXT: "executeCommandProvider": {<br>
# CHECK-NEXT: "commands": [<br>
-# CHECK-NEXT: "clangd.applyFix"<br>
+# CHECK-NEXT: "clangd.applyFix",<br>
+# CHECK-NEXT: "clangd.insertInclude"<br>
# CHECK-NEXT: ]<br>
# CHECK-NEXT: },<br>
# CHECK-NEXT: "renameProvider": true,<br>
<br>
Modified: clang-tools-extra/trunk/test/c<wbr>langd/initialize-params.test<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/initialize-params.test?rev=325343&r1=325342&r2=325343&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/clang-tools-extra/trunk/<wbr>test/clangd/initialize-params.<wbr>test?rev=325343&r1=325342&r2=<wbr>325343&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/test/c<wbr>langd/initialize-params.test (original)<br>
+++ clang-tools-extra/trunk/test/c<wbr>langd/initialize-params.test Fri Feb 16 06:15:55 2018<br>
@@ -24,7 +24,8 @@<br>
# CHECK-NEXT: "documentRangeFormattingProvid<wbr>er": true,<br>
# CHECK-NEXT: "executeCommandProvider": {<br>
# CHECK-NEXT: "commands": [<br>
-# CHECK-NEXT: "clangd.applyFix"<br>
+# CHECK-NEXT: "clangd.applyFix",<br>
+# CHECK-NEXT: "clangd.insertInclude"<br>
# CHECK-NEXT: ]<br>
# CHECK-NEXT: },<br>
# CHECK-NEXT: "renameProvider": true,<br>
<br>
Added: clang-tools-extra/trunk/test/c<wbr>langd/insert-include.test<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/insert-include.test?rev=325343&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/clang-tools-extra/trunk/<wbr>test/clangd/insert-include.<wbr>test?rev=325343&view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/test/c<wbr>langd/insert-include.test (added)<br>
+++ clang-tools-extra/trunk/test/c<wbr>langd/insert-include.test Fri Feb 16 06:15:55 2018<br>
@@ -0,0 +1,36 @@<br>
+# RUN: clangd -lit-test < %s | FileCheck -strict-whitespace %s<br>
+# RUN: clangd -lit-test -pch-storage=memory < %s | FileCheck -strict-whitespace %s<br>
+{"jsonrpc":"2.0","id":0,"meth<wbr>od":"initialize","params":{"<wbr>processId":123,"rootPath":"cla<wbr>ngd","capabilities":{},"trace"<wbr>:"off"}}<br>
+---<br>
+{"jsonrpc":"2.0","method":"te<wbr>xtDocument/didOpen","params":{<wbr>"textDocument":{"uri":"test://<wbr>/main.cpp","languageId":"cpp",<wbr>"version":1,"text":"void f() {}"}}}<br>
+---<br>
+{"jsonrpc":"2.0","id":3,"meth<wbr>od":"workspace/executeCommand"<wbr>,"params":{"arguments":[{"<wbr>header":"<vector>","<wbr>textDocument":{"uri":"test:///<wbr>main.cpp"}}],"command":"<wbr>clangd.insertInclude"}}<br>
+# CHECK: "id": 3,<br>
+# CHECK-NEXT: "jsonrpc": "2.0",<br>
+# CHECK-NEXT: "result": "Inserted header <vector>"<br>
+# CHECK-NEXT: }<br>
+# CHECK: "method": "workspace/applyEdit",<br>
+# CHECK-NEXT: "params": {<br>
+# CHECK-NEXT: "edit": {<br>
+# CHECK-NEXT: "changes": {<br>
+# CHECK-NEXT: "file:///clangd-test/main.cpp"<wbr>: [<br>
+# CHECK-NEXT: {<br>
+# CHECK-NEXT: "newText": "#include <vector>\n",<br>
+# CHECK-NEXT: "range": {<br>
+# CHECK-NEXT: "end": {<br>
+# CHECK-NEXT: "character": 0,<br>
+# CHECK-NEXT: "line": 0<br>
+# CHECK-NEXT: },<br>
+# CHECK-NEXT: "start": {<br>
+# CHECK-NEXT: "character": 0,<br>
+# CHECK-NEXT: "line": 0<br>
+# CHECK-NEXT: }<br>
+# CHECK-NEXT: }<br>
+# CHECK-NEXT: }<br>
+# CHECK-NEXT: ]<br>
+# CHECK-NEXT: }<br>
+# CHECK-NEXT: }<br>
+# CHECK-NEXT: }<br>
+# CHECK-NEXT: }<br>
+---<br>
+{"jsonrpc":"2.0","id":4,"meth<wbr>od":"shutdown"}<br>
<br>
Modified: clang-tools-extra/trunk/unitte<wbr>sts/clangd/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt?rev=325343&r1=325342&r2=325343&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/clang-tools-extra/trunk/<wbr>unittests/clangd/CMakeLists.<wbr>txt?rev=325343&r1=325342&r2=<wbr>325343&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/unitte<wbr>sts/clangd/CMakeLists.txt (original)<br>
+++ clang-tools-extra/trunk/unitte<wbr>sts/clangd/CMakeLists.txt Fri Feb 16 06:15:55 2018<br>
@@ -17,6 +17,7 @@ add_extra_unittest(ClangdTests<br>
ContextTests.cpp<br>
FileIndexTests.cpp<br>
FuzzyMatchTests.cpp<br>
+ HeadersTests.cpp<br>
IndexTests.cpp<br>
JSONExprTests.cpp<br>
SourceCodeTests.cpp<br>
<br>
Modified: clang-tools-extra/trunk/unitte<wbr>sts/clangd/ClangdTests.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp?rev=325343&r1=325342&r2=325343&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/clang-tools-extra/trunk/<wbr>unittests/clangd/ClangdTests.<wbr>cpp?rev=325343&r1=325342&r2=<wbr>325343&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/unitte<wbr>sts/clangd/ClangdTests.cpp (original)<br>
+++ clang-tools-extra/trunk/unitte<wbr>sts/clangd/ClangdTests.cpp Fri Feb 16 06:15:55 2018<br>
@@ -12,6 +12,7 @@<br>
#include "Matchers.h"<br>
#include "SyncAPI.h"<br>
#include "TestFS.h"<br>
+#include "URI.h"<br>
#include "clang/Config/config.h"<br>
#include "llvm/ADT/SmallVector.h"<br>
#include "llvm/ADT/StringMap.h"<br>
@@ -100,8 +101,6 @@ std::string dumpASTWithoutMemoryLocs(Cla<br>
return replacePtrsInDump(DumpWithMemL<wbr>ocs);<br>
}<br>
<br>
-} // namespace<br>
-<br>
class ClangdVFSTest : public ::testing::Test {<br>
protected:<br>
std::string parseSourceAndDumpAST(<br>
@@ -819,5 +818,38 @@ int d;<br>
ASSERT_EQ(DiagConsumer.Count, 2); // Sanity check - we actually ran both?<br>
}<br>
<br>
+TEST_F(ClangdVFSTest, InsertIncludes) {<br>
+ MockFSProvider FS;<br>
+ ErrorCheckingDiagConsumer DiagConsumer;<br>
+ MockCompilationDatabase CDB;<br>
+ ClangdServer Server(CDB, DiagConsumer, FS,<br>
+ /*AsyncThreadsCount=*/0,<br>
+ /*StorePreamblesInMemory=*/tru<wbr>e);<br>
+<br>
+ // No need to sync reparses, because reparses are performed on the calling<br>
+ // thread.<br>
+ auto FooCpp = testPath("foo.cpp");<br>
+ const auto Code = R"cpp(<br>
+#include "x.h"<br>
+<br>
+void f() {}<br>
+)cpp";<br>
+ FS.Files[FooCpp] = Code;<br>
+ Server.addDocument(FooCpp, Code);<br>
+<br>
+ auto Inserted = [&](llvm::StringRef Header, llvm::StringRef Expected) {<br>
+ auto Replaces = Server.insertInclude(FooCpp, Code, Header);<br>
+ EXPECT_TRUE(static_cast<bool>(<wbr>Replaces));<br>
+ auto Changed = tooling::applyAllReplacements(<wbr>Code, *Replaces);<br>
+ EXPECT_TRUE(static_cast<bool>(<wbr>Changed));<br>
+ return llvm::StringRef(*Changed).cont<wbr>ains(<br>
+ (llvm::Twine("#include ") + Expected + "").str());<br>
+ };<br>
+<br>
+ EXPECT_TRUE(Inserted("\"y.h\""<wbr>, "\"y.h\""));<br>
+ EXPECT_TRUE(Inserted("<string><wbr>", "<string>"));<br>
+}<br>
+<br>
+} // namespace<br>
} // namespace clangd<br>
} // namespace clang<br>
<br>
Added: clang-tools-extra/trunk/unitte<wbr>sts/clangd/HeadersTests.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/HeadersTests.cpp?rev=325343&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/clang-tools-extra/trunk/<wbr>unittests/clangd/HeadersTests.<wbr>cpp?rev=325343&view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/unitte<wbr>sts/clangd/HeadersTests.cpp (added)<br>
+++ clang-tools-extra/trunk/unitte<wbr>sts/clangd/HeadersTests.cpp Fri Feb 16 06:15:55 2018<br>
@@ -0,0 +1,98 @@<br>
+//===-- HeadersTests.cpp - Include headers unit tests -----------*- C++ -*-===//<br>
+//<br>
+// The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===------------------------<wbr>------------------------------<wbr>----------------===//<br>
+<br>
+#include "Headers.h"<br>
+#include "TestFS.h"<br>
+#include "gmock/gmock.h"<br>
+#include "gtest/gtest.h"<br>
+<br>
+namespace clang {<br>
+namespace clangd {<br>
+namespace {<br>
+<br>
+class HeadersTest : public ::testing::Test {<br>
+public:<br>
+ HeadersTest() {<br>
+ CDB.ExtraClangFlags = {SearchDirArg.c_str()};<br>
+ FS.Files[MainFile] = "";<br>
+ }<br>
+<br>
+protected:<br>
+ // Adds \p File with content \p Code to the sub directory and returns the<br>
+ // absolute path.<br>
+// std::string addToSubdir(PathRef File, llvm::StringRef Code = "") {<br>
+// assert(llvm::sys::path::is_rel<wbr>ative(File) && "FileName should be relative");<br>
+// llvm::SmallString<32> Path;<br>
+// llvm::sys::path::append(Path, Subdir, File);<br>
+// FS.Files[Path] = Code;<br>
+// return Path.str();<br>
+// };<br>
+<br>
+ // Shortens the header and returns "" on error.<br>
+ std::string shorten(PathRef Header) {<br>
+ auto VFS = FS.getTaggedFileSystem(MainFil<wbr>e).Value;<br>
+ auto Cmd = CDB.getCompileCommand(MainFile<wbr>);<br>
+ assert(static_cast<bool>(Cmd))<wbr>;<br>
+ VFS->setCurrentWorkingDirector<wbr>y(Cmd->Directory);<br>
+ auto Path =<br>
+ shortenIncludePath(MainFile, FS.Files[MainFile], Header, *Cmd, VFS);<br>
+ if (!Path) {<br>
+ llvm::consumeError(Path.takeEr<wbr>ror());<br>
+ return std::string();<br>
+ }<br>
+ return std::move(*Path);<br>
+ }<br>
+ MockFSProvider FS;<br>
+ MockCompilationDatabase CDB;<br>
+ std::string MainFile = testPath("main.cpp");<br>
+ std::string Subdir = testPath("sub");<br>
+ std::string SearchDirArg = (llvm::Twine("-I") + Subdir).str();<br>
+};<br>
+<br>
+TEST_F(HeadersTest, InsertInclude) {<br>
+ std::string Path = testPath("sub/bar.h");<br>
+ FS.Files[Path] = "";<br>
+ EXPECT_EQ(shorten(Path), "\"bar.h\"");<br>
+}<br>
+<br>
+TEST_F(HeadersTest, DontInsertDuplicateSameName) {<br>
+ FS.Files[MainFile] = R"cpp(<br>
+#include "bar.h"<br>
+)cpp";<br>
+ std::string BarHeader = testPath("sub/bar.h");<br>
+ FS.Files[BarHeader] = "";<br>
+ EXPECT_EQ(shorten(BarHeader), "");<br>
+}<br>
+<br>
+TEST_F(HeadersTest, DontInsertDuplicateDifferentNa<wbr>me) {<br>
+ std::string BarHeader = testPath("sub/bar.h");<br>
+ FS.Files[BarHeader] = "";<br>
+ FS.Files[MainFile] = R"cpp(<br>
+#include "sub/bar.h" // not shortest<br>
+)cpp";<br>
+ EXPECT_EQ(shorten(BarHeader), "");<br>
+}<br>
+<br>
+TEST_F(HeadersTest, StillInsertIfTrasitivelyInclud<wbr>ed) {<br>
+ std::string BazHeader = testPath("sub/baz.h");<br>
+ FS.Files[BazHeader] = "";<br>
+ std::string BarHeader = testPath("sub/bar.h");<br>
+ FS.Files[BarHeader] = R"cpp(<br>
+#include "baz.h"<br>
+)cpp";<br>
+ FS.Files[MainFile] = R"cpp(<br>
+#include "bar.h"<br>
+)cpp";<br>
+ EXPECT_EQ(shorten(BazHeader), "\"baz.h\"");<br>
+}<br>
+<br>
+} // namespace<br>
+} // namespace clangd<br>
+} // namespace clang<br>
+<br>
<br>
Modified: clang-tools-extra/trunk/unitte<wbr>sts/clangd/SymbolCollectorTest<wbr>s.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp?rev=325343&r1=325342&r2=325343&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/clang-tools-extra/trunk/<wbr>unittests/clangd/SymbolCollect<wbr>orTests.cpp?rev=325343&r1=<wbr>325342&r2=325343&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/unitte<wbr>sts/clangd/SymbolCollectorTest<wbr>s.cpp (original)<br>
+++ clang-tools-extra/trunk/unitte<wbr>sts/clangd/SymbolCollectorTest<wbr>s.cpp Fri Feb 16 06:15:55 2018<br>
@@ -47,6 +47,9 @@ MATCHER_P(Snippet, S, "") {<br>
}<br>
MATCHER_P(QName, Name, "") { return (arg.Scope + arg.Name).str() == Name; }<br>
MATCHER_P(DeclURI, P, "") { return arg.CanonicalDeclaration.FileU<wbr>RI == P; }<br>
+MATCHER_P(IncludeHeader, P, "") {<br>
+ return arg.Detail && arg.Detail->IncludeHeader == P;<br>
+}<br>
MATCHER_P(DeclRange, Offsets, "") {<br>
return arg.CanonicalDeclaration.Start<wbr>Offset == Offsets.first &&<br>
arg.CanonicalDeclaration.EndO<wbr>ffset == Offsets.second;<br>
@@ -62,28 +65,50 @@ namespace clangd {<br>
namespace {<br>
class SymbolIndexActionFactory : public tooling::FrontendActionFactory {<br>
public:<br>
- SymbolIndexActionFactory(Symbo<wbr>lCollector::Options COpts)<br>
- : COpts(std::move(COpts)) {}<br>
+ SymbolIndexActionFactory(Symbo<wbr>lCollector::Options COpts,<br>
+ CommentHandler *PragmaHandler)<br>
+ : COpts(std::move(COpts)), PragmaHandler(PragmaHandler) {}<br>
<br>
clang::FrontendAction *create() override {<br>
+ class WrappedIndexAction : public WrapperFrontendAction {<br>
+ public:<br>
+ WrappedIndexAction(std::shared<wbr>_ptr<SymbolCollector> C,<br>
+ const index::IndexingOptions &Opts,<br>
+ CommentHandler *PragmaHandler)<br>
+ : WrapperFrontendAction(<br>
+ index::createIndexingAction(C, Opts, nullptr)),<br>
+ PragmaHandler(PragmaHandler) {}<br>
+<br>
+ std::unique_ptr<ASTConsumer><br>
+ CreateASTConsumer(CompilerInst<wbr>ance &CI, StringRef InFile) override {<br>
+ if (PragmaHandler)<br>
+ CI.getPreprocessor().addCommen<wbr>tHandler(PragmaHandler);<br>
+ return WrapperFrontendAction::CreateA<wbr>STConsumer(CI, InFile);<br>
+ }<br>
+<br>
+ private:<br>
+ index::IndexingOptions IndexOpts;<br>
+ CommentHandler *PragmaHandler;<br>
+ };<br>
index::IndexingOptions IndexOpts;<br>
IndexOpts.SystemSymbolFilter =<br>
index::IndexingOptions::Syste<wbr>mSymbolFilterKind::All;<br>
IndexOpts.IndexFunctionLocals = false;<br>
Collector = std::make_shared<SymbolCollect<wbr>or>(COpts);<br>
- FrontendAction *Action =<br>
- index::createIndexingAction(Co<wbr>llector, IndexOpts, nullptr).release();<br>
- return Action;<br>
+ return new WrappedIndexAction(Collector, std::move(IndexOpts),<br>
+ PragmaHandler);<br>
}<br>
<br>
std::shared_ptr<SymbolCollect<wbr>or> Collector;<br>
SymbolCollector::Options COpts;<br>
+ CommentHandler *PragmaHandler;<br>
};<br>
<br>
class SymbolCollectorTest : public ::testing::Test {<br>
public:<br>
SymbolCollectorTest()<br>
- : TestHeaderName(testPath("symbo<wbr>l.h")),<br>
+ : InMemoryFileSystem(new vfs::InMemoryFileSystem),<br>
+ TestHeaderName(testPath("symbo<wbr>l.h")),<br>
TestFileName(testPath("<wbr>symbol.cc")) {<br>
TestHeaderURI = URI::createFile(TestHeaderName<wbr>).toString();<br>
TestFileURI = URI::createFile(TestFileName).<wbr>toString();<br>
@@ -91,12 +116,11 @@ public:<br>
<br>
bool runSymbolCollector(StringRef HeaderCode, StringRef MainCode,<br>
const std::vector<std::string> &ExtraArgs = {}) {<br>
- llvm::IntrusiveRefCntPtr<vfs::<wbr>InMemoryFileSystem> InMemoryFileSystem(<br>
- new vfs::InMemoryFileSystem);<br>
llvm::IntrusiveRefCntPtr<File<wbr>Manager> Files(<br>
new FileManager(FileSystemOptions(<wbr>), InMemoryFileSystem));<br>
<br>
- auto Factory = llvm::make_unique<SymbolIndexA<wbr>ctionFactory>(CollectorOpts);<br>
+ auto Factory = llvm::make_unique<SymbolIndexA<wbr>ctionFactory>(<br>
+ CollectorOpts, PragmaHandler.get());<br>
<br>
std::vector<std::string> Args = {"symbol_collector", "-fsyntax-only",<br>
"-std=c++11", "-include",<br>
@@ -117,12 +141,14 @@ public:<br>
}<br>
<br>
protected:<br>
+ llvm::IntrusiveRefCntPtr<vfs::<wbr>InMemoryFileSystem> InMemoryFileSystem;<br>
std::string TestHeaderName;<br>
std::string TestHeaderURI;<br>
std::string TestFileName;<br>
std::string TestFileURI;<br>
SymbolSlab Symbols;<br>
SymbolCollector::Options CollectorOpts;<br>
+ std::unique_ptr<CommentHandler<wbr>> PragmaHandler;<br>
};<br>
<br>
TEST_F(SymbolCollectorTest, CollectSymbols) {<br>
@@ -554,6 +580,46 @@ CompletionSnippetInsertText: 'snippet<br>
QName("clang::Foo2")));<br>
}<br>
<br>
+TEST_F(SymbolCollectorTest, IncludeHeaderSameAsFileURI) {<br>
+ CollectorOpts.CollectIncludePa<wbr>th = true;<br>
+ runSymbolCollector("class Foo {};", /*Main=*/"");<br>
+ EXPECT_THAT(Symbols,<br>
+ UnorderedElementsAre(AllOf(QNa<wbr>me("Foo"), DeclURI(TestHeaderURI),<br>
+ IncludeHeader(""))));<br>
+}<br>
+<br>
+#ifndef LLVM_ON_WIN32<br>
+TEST_F(SymbolCollectorTest, CanonicalSTLHeader) {<br>
+ CollectorOpts.CollectIncludePa<wbr>th = true;<br>
+ CanonicalIncludes Includes;<br>
+ addSystemHeadersMapping(&Inclu<wbr>des);<br>
+ CollectorOpts.Includes = &Includes;<br>
+ // bits/basic_string.h$ should be mapped to <string><br>
+ TestHeaderName = "/nasty/bits/basic_string.h";<br>
+ TestFileName = "/nasty/bits/basic_string.cpp"<wbr>;<br>
+ TestHeaderURI = URI::createFile(TestHeaderName<wbr>).toString();<br>
+ runSymbolCollector("class string {};", /*Main=*/"");<br>
+ EXPECT_THAT(Symbols, UnorderedElementsAre(AllOf(QNa<wbr>me("string"),<br>
+ DeclURI(TestHeaderURI),<br>
+ IncludeHeader("<string>"))));<br>
+}<br>
+#endif<br>
+<br>
+TEST_F(SymbolCollectorTest, IWYUPragma) {<br>
+ CollectorOpts.CollectIncludePa<wbr>th = true;<br>
+ CanonicalIncludes Includes;<br>
+ PragmaHandler = collectIWYUHeaderMaps(&Include<wbr>s);<br>
+ CollectorOpts.Includes = &Includes;<br>
+ const std::string Header = R"(<br>
+ // IWYU pragma: private, include the/good/header.h<br>
+ class Foo {};<br>
+ )";<br>
+ runSymbolCollector(Header, /*Main=*/"");<br>
+ EXPECT_THAT(Symbols, UnorderedElementsAre(<br>
+ AllOf(QName("Foo"), DeclURI(TestHeaderURI),<br>
+ IncludeHeader("\"the/good/hea<wbr>der.h\""))));<br>
+}<br>
+<br>
} // namespace<br>
} // namespace clangd<br>
} // namespace clang<br>
<br>
<br>
______________________________<wbr>_________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>
<br>______________________________<wbr>_________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br>
<br></blockquote></div><br></div>