2017-05-16 17:38:59 +08:00
|
|
|
//===--- ClangdUnitStore.cpp - A ClangdUnits container -----------*-C++-*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "ClangdUnitStore.h"
|
|
|
|
#include "llvm/Support/Path.h"
|
|
|
|
|
|
|
|
using namespace clang::clangd;
|
|
|
|
using namespace clang;
|
|
|
|
|
2017-08-01 23:51:38 +08:00
|
|
|
std::shared_ptr<CppFile> CppFileCollection::removeIfPresent(PathRef File) {
|
2017-05-16 17:38:59 +08:00
|
|
|
std::lock_guard<std::mutex> Lock(Mutex);
|
|
|
|
|
|
|
|
auto It = OpenedFiles.find(File);
|
|
|
|
if (It == OpenedFiles.end())
|
2017-08-01 23:51:38 +08:00
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
std::shared_ptr<CppFile> Result = It->second;
|
2017-05-16 17:38:59 +08:00
|
|
|
OpenedFiles.erase(It);
|
2017-08-01 23:51:38 +08:00
|
|
|
return Result;
|
2017-05-16 17:38:59 +08:00
|
|
|
}
|
|
|
|
|
2017-08-01 23:51:38 +08:00
|
|
|
tooling::CompileCommand
|
|
|
|
CppFileCollection::getCompileCommand(GlobalCompilationDatabase &CDB,
|
|
|
|
PathRef File, PathRef ResourceDir) {
|
2017-05-16 17:38:59 +08:00
|
|
|
std::vector<tooling::CompileCommand> Commands = CDB.getCompileCommands(File);
|
2017-07-06 16:44:54 +08:00
|
|
|
if (Commands.empty())
|
2017-05-16 17:38:59 +08:00
|
|
|
// Add a fake command line if we know nothing.
|
2017-07-06 16:44:54 +08:00
|
|
|
Commands.push_back(getDefaultCompileCommand(File));
|
2017-08-01 23:51:38 +08:00
|
|
|
|
|
|
|
// Inject the resource dir.
|
|
|
|
// FIXME: Don't overwrite it if it's already there.
|
|
|
|
Commands.front().CommandLine.push_back("-resource-dir=" +
|
|
|
|
std::string(ResourceDir));
|
|
|
|
return std::move(Commands.front());
|
2017-05-16 17:38:59 +08:00
|
|
|
}
|