2018-08-21 05:27:52 +00:00
|
|
|
// Copyright 2017-2018 ccls Authors
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2017-05-21 19:51:15 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-10-28 17:49:31 +00:00
|
|
|
#include "message_handler.hh"
|
2017-05-21 19:51:15 +00:00
|
|
|
|
|
|
|
#include <atomic>
|
|
|
|
#include <mutex>
|
|
|
|
|
2018-10-28 17:49:31 +00:00
|
|
|
namespace ccls {
|
2017-05-21 19:51:15 +00:00
|
|
|
struct GroupMatch;
|
|
|
|
struct Project;
|
|
|
|
|
2017-05-27 04:21:00 +00:00
|
|
|
struct IncludeComplete {
|
2018-08-09 17:08:14 +00:00
|
|
|
IncludeComplete(Project *project);
|
2017-05-21 19:51:15 +00:00
|
|
|
|
|
|
|
// Starts scanning directories. Clears existing cache.
|
|
|
|
void Rescan();
|
|
|
|
|
|
|
|
// Ensures the one-off file is inside |completion_items|.
|
2018-08-09 17:08:14 +00:00
|
|
|
void AddFile(const std::string &absolute_path);
|
2017-05-21 19:51:15 +00:00
|
|
|
|
2017-09-22 01:14:57 +00:00
|
|
|
// Scans the given directory and inserts all includes from this. This is a
|
2017-05-21 19:51:15 +00:00
|
|
|
// blocking function and should be run off the querydb thread.
|
2017-09-22 01:14:57 +00:00
|
|
|
void InsertIncludesFromDirectory(std::string directory,
|
|
|
|
bool use_angle_brackets);
|
2017-05-21 19:51:15 +00:00
|
|
|
|
2018-11-03 20:52:43 +00:00
|
|
|
std::optional<ccls::CompletionItem>
|
2018-08-09 17:08:14 +00:00
|
|
|
FindCompletionItemForAbsolutePath(const std::string &absolute_path);
|
2017-05-29 23:57:19 +00:00
|
|
|
|
2018-02-09 08:55:53 +00:00
|
|
|
// Insert item to |completion_items|.
|
|
|
|
// Update |absolute_path_to_completion_item| and |inserted_paths|.
|
2018-08-09 17:08:14 +00:00
|
|
|
void InsertCompletionItem(const std::string &absolute_path,
|
2018-11-03 20:52:43 +00:00
|
|
|
ccls::CompletionItem &&item);
|
2018-02-09 08:55:53 +00:00
|
|
|
|
2017-05-21 19:51:15 +00:00
|
|
|
// Guards |completion_items| when |is_scanning| is true.
|
|
|
|
std::mutex completion_items_mutex;
|
|
|
|
std::atomic<bool> is_scanning;
|
2018-11-03 20:52:43 +00:00
|
|
|
std::vector<ccls::CompletionItem> completion_items;
|
2017-09-22 01:14:57 +00:00
|
|
|
|
2018-02-09 08:55:53 +00:00
|
|
|
// Absolute file path to the completion item in |completion_items|.
|
|
|
|
// Keep the one with shortest include path.
|
2017-05-29 23:57:19 +00:00
|
|
|
std::unordered_map<std::string, int> absolute_path_to_completion_item;
|
2017-05-21 19:51:15 +00:00
|
|
|
|
2018-02-09 08:55:53 +00:00
|
|
|
// Only one completion item per include path.
|
|
|
|
std::unordered_map<std::string, int> inserted_paths;
|
|
|
|
|
2017-05-21 19:51:15 +00:00
|
|
|
// Cached references
|
2018-08-09 17:08:14 +00:00
|
|
|
Project *project_;
|
2017-05-21 19:51:15 +00:00
|
|
|
std::unique_ptr<GroupMatch> match_;
|
|
|
|
};
|
2018-10-28 17:49:31 +00:00
|
|
|
} // namespace ccls
|