mirror of
				https://github.com/MaskRay/ccls.git
				synced 2025-11-04 06:15:20 +00:00 
			
		
		
		
	Misc
This commit is contained in:
		
							parent
							
								
									c202dd3775
								
							
						
					
					
						commit
						a7c1633b51
					
				@ -1261,7 +1261,7 @@ Index(CompletionManager *completion, WorkingFiles *wfiles, VFS *vfs,
 | 
			
		||||
  }
 | 
			
		||||
  std::string buf = wfiles->GetContent(file);
 | 
			
		||||
  std::vector<std::unique_ptr<llvm::MemoryBuffer>> Bufs;
 | 
			
		||||
  if (buf.size()) {
 | 
			
		||||
  if (g_config->index.onChange && buf.size()) {
 | 
			
		||||
    // If there is a completion session, reuse its preamble if exists.
 | 
			
		||||
    bool done_remap = false;
 | 
			
		||||
    std::shared_ptr<CompletionSession> session =
 | 
			
		||||
 | 
			
		||||
@ -160,8 +160,8 @@ bool FindFileOrFail(DB *db, Project *project, std::optional<lsRequestId> id,
 | 
			
		||||
  bool indexing;
 | 
			
		||||
  {
 | 
			
		||||
    std::lock_guard<std::mutex> lock(project->mutex_);
 | 
			
		||||
    indexing = project->absolute_path_to_entry_index_.find(absolute_path) !=
 | 
			
		||||
               project->absolute_path_to_entry_index_.end();
 | 
			
		||||
    indexing = project->path_to_entry_index.find(absolute_path) !=
 | 
			
		||||
               project->path_to_entry_index.end();
 | 
			
		||||
  }
 | 
			
		||||
  if (indexing)
 | 
			
		||||
    LOG_S(INFO) << "\"" << absolute_path << "\" is being indexed.";
 | 
			
		||||
 | 
			
		||||
@ -57,8 +57,8 @@ struct Handler_WorkspaceDidChangeWatchedFiles
 | 
			
		||||
      Project::Entry entry;
 | 
			
		||||
      {
 | 
			
		||||
        std::lock_guard<std::mutex> lock(project->mutex_);
 | 
			
		||||
        auto it = project->absolute_path_to_entry_index_.find(path);
 | 
			
		||||
        if (it == project->absolute_path_to_entry_index_.end())
 | 
			
		||||
        auto it = project->path_to_entry_index.find(path);
 | 
			
		||||
        if (it == project->path_to_entry_index.end())
 | 
			
		||||
          continue;
 | 
			
		||||
        entry = project->entries[it->second];
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
@ -32,6 +32,8 @@ limitations under the License.
 | 
			
		||||
using namespace llvm;
 | 
			
		||||
 | 
			
		||||
#include <chrono>
 | 
			
		||||
#include <mutex>
 | 
			
		||||
#include <shared_mutex>
 | 
			
		||||
#include <thread>
 | 
			
		||||
#ifndef _WIN32
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
@ -99,6 +101,7 @@ struct InMemoryIndexFile {
 | 
			
		||||
  std::string content;
 | 
			
		||||
  IndexFile index;
 | 
			
		||||
};
 | 
			
		||||
std::shared_mutex g_index_mutex;
 | 
			
		||||
std::unordered_map<std::string, InMemoryIndexFile> g_index;
 | 
			
		||||
 | 
			
		||||
bool CacheInvalid(VFS *vfs, IndexFile *prev, const std::string &path,
 | 
			
		||||
@ -147,6 +150,7 @@ std::string GetCachePath(const std::string &source_file) {
 | 
			
		||||
 | 
			
		||||
std::unique_ptr<IndexFile> RawCacheLoad(const std::string &path) {
 | 
			
		||||
  if (g_config->cacheDirectory.empty()) {
 | 
			
		||||
    std::shared_lock lock(g_index_mutex);
 | 
			
		||||
    auto it = g_index.find(path);
 | 
			
		||||
    if (it == g_index.end())
 | 
			
		||||
      return nullptr;
 | 
			
		||||
@ -189,8 +193,8 @@ bool Indexer_Parse(CompletionManager *completion, WorkingFiles *wfiles,
 | 
			
		||||
  Project::Entry entry;
 | 
			
		||||
  {
 | 
			
		||||
    std::lock_guard<std::mutex> lock(project->mutex_);
 | 
			
		||||
    auto it = project->absolute_path_to_entry_index_.find(request.path);
 | 
			
		||||
    if (it != project->absolute_path_to_entry_index_.end())
 | 
			
		||||
    auto it = project->path_to_entry_index.find(request.path);
 | 
			
		||||
    if (it != project->path_to_entry_index.end())
 | 
			
		||||
      entry = project->entries[it->second];
 | 
			
		||||
    else {
 | 
			
		||||
      entry.filename = request.path;
 | 
			
		||||
@ -307,6 +311,7 @@ bool Indexer_Parse(CompletionManager *completion, WorkingFiles *wfiles,
 | 
			
		||||
    LOG_IF_S(INFO, loud) << "store index for " << path << " (delta: " << !!prev
 | 
			
		||||
                         << ")";
 | 
			
		||||
    if (g_config->cacheDirectory.empty()) {
 | 
			
		||||
      std::lock_guard lock(g_index_mutex);
 | 
			
		||||
      auto it = g_index.insert_or_assign(
 | 
			
		||||
        path, InMemoryIndexFile{curr->file_contents, *curr});
 | 
			
		||||
      std::string().swap(it.first->second.index.file_contents);
 | 
			
		||||
@ -321,7 +326,7 @@ bool Indexer_Parse(CompletionManager *completion, WorkingFiles *wfiles,
 | 
			
		||||
    if (entry.id >= 0) {
 | 
			
		||||
      std::lock_guard<std::mutex> lock(project->mutex_);
 | 
			
		||||
      for (auto &dep : curr->dependencies)
 | 
			
		||||
        project->absolute_path_to_entry_index_[dep.first()] = entry.id;
 | 
			
		||||
        project->path_to_entry_index[dep.first()] = entry.id;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Build delta update.
 | 
			
		||||
@ -548,6 +553,7 @@ std::optional<int64_t> LastWriteTime(const std::string &path) {
 | 
			
		||||
 | 
			
		||||
std::optional<std::string> LoadIndexedContent(const std::string &path) {
 | 
			
		||||
  if (g_config->cacheDirectory.empty()) {
 | 
			
		||||
    std::shared_lock lock(g_index_mutex);
 | 
			
		||||
    auto it = g_index.find(path);
 | 
			
		||||
    if (it == g_index.end())
 | 
			
		||||
      return {};
 | 
			
		||||
 | 
			
		||||
@ -377,13 +377,21 @@ void Project::Load(const std::string &root_directory) {
 | 
			
		||||
    EnsureEndsInSlash(path);
 | 
			
		||||
    LOG_S(INFO) << "angle_include_dir: " << path;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Setup project entries.
 | 
			
		||||
  std::lock_guard lock(mutex_);
 | 
			
		||||
  path_to_entry_index.reserve(entries.size());
 | 
			
		||||
  for (size_t i = 0; i < entries.size(); ++i) {
 | 
			
		||||
    entries[i].id = i;
 | 
			
		||||
    path_to_entry_index[entries[i].filename] = i;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Project::SetFlagsForFile(const std::vector<std::string> &flags,
 | 
			
		||||
                              const std::string &path) {
 | 
			
		||||
  std::lock_guard<std::mutex> lock(mutex_);
 | 
			
		||||
  auto it = absolute_path_to_entry_index_.find(path);
 | 
			
		||||
  if (it != absolute_path_to_entry_index_.end()) {
 | 
			
		||||
  auto it = path_to_entry_index.find(path);
 | 
			
		||||
  if (it != path_to_entry_index.end()) {
 | 
			
		||||
    // The entry already exists in the project, just set the flags.
 | 
			
		||||
    this->entries[it->second].args = flags;
 | 
			
		||||
  } else {
 | 
			
		||||
@ -400,8 +408,8 @@ Project::Entry
 | 
			
		||||
Project::FindCompilationEntryForFile(const std::string &filename) {
 | 
			
		||||
  {
 | 
			
		||||
    std::lock_guard<std::mutex> lock(mutex_);
 | 
			
		||||
    auto it = absolute_path_to_entry_index_.find(filename);
 | 
			
		||||
    if (it != absolute_path_to_entry_index_.end())
 | 
			
		||||
    auto it = path_to_entry_index.find(filename);
 | 
			
		||||
    if (it != path_to_entry_index.end())
 | 
			
		||||
      return entries[it->second];
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -43,7 +43,7 @@ struct Project {
 | 
			
		||||
 | 
			
		||||
  std::vector<Entry> entries;
 | 
			
		||||
  std::mutex mutex_;
 | 
			
		||||
  std::unordered_map<std::string, int> absolute_path_to_entry_index_;
 | 
			
		||||
  std::unordered_map<std::string, int> path_to_entry_index;
 | 
			
		||||
 | 
			
		||||
  // Loads a project for the given |directory|.
 | 
			
		||||
  //
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										17
									
								
								src/query.cc
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								src/query.cc
									
									
									
									
									
								
							@ -227,16 +227,21 @@ void DB::ApplyIndexUpdate(IndexUpdate *u) {
 | 
			
		||||
                 SymbolKind kind, Use &use, int delta, int k = 1) {
 | 
			
		||||
    use.file_id =
 | 
			
		||||
        use.file_id == -1 ? u->file_id : lid2fid.find(use.file_id)->second;
 | 
			
		||||
    SymbolRef sym{{use.range, usr, kind, use.role}};
 | 
			
		||||
    if (k & 1) {
 | 
			
		||||
      int &v =
 | 
			
		||||
        files[use.file_id]
 | 
			
		||||
        .symbol2refcnt[SymbolRef{{use.range, usr, kind, use.role}}];
 | 
			
		||||
      int &v = files[use.file_id].symbol2refcnt[sym];
 | 
			
		||||
      v += delta;
 | 
			
		||||
      assert(v >= 0);
 | 
			
		||||
      if (!v)
 | 
			
		||||
        files[use.file_id].symbol2refcnt.erase(sym);
 | 
			
		||||
    }
 | 
			
		||||
    if (k & 2) {
 | 
			
		||||
      int &v = files[use.file_id].outline2refcnt[sym];
 | 
			
		||||
      v += delta;
 | 
			
		||||
      assert(v >= 0);
 | 
			
		||||
      if (!v)
 | 
			
		||||
        files[use.file_id].outline2refcnt.erase(sym);
 | 
			
		||||
    }
 | 
			
		||||
    if (k & 2)
 | 
			
		||||
      files[use.file_id]
 | 
			
		||||
          .outline2refcnt[SymbolRef{{use.range, usr, kind, use.role}}] += delta;
 | 
			
		||||
  };
 | 
			
		||||
  auto RefDecl = [&](std::unordered_map<int, int> &lid2fid, Usr usr,
 | 
			
		||||
                     SymbolKind kind, DeclRef &dr, int delta) {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user