2017-12-05 07:57:41 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-03-31 05:05:21 +00:00
|
|
|
#include "lru_cache.h"
|
2018-02-24 00:12:39 +00:00
|
|
|
#include "lsp.h"
|
2018-03-31 05:05:21 +00:00
|
|
|
#include "match.h"
|
2018-03-22 05:01:21 +00:00
|
|
|
#include "method.h"
|
2017-12-05 07:57:41 +00:00
|
|
|
#include "query.h"
|
2017-12-29 16:29:47 +00:00
|
|
|
|
2018-03-31 03:16:33 +00:00
|
|
|
#include <optional>
|
2017-12-29 16:29:47 +00:00
|
|
|
#include <memory>
|
2018-03-31 05:05:21 +00:00
|
|
|
#include <unordered_map>
|
2017-12-29 16:29:47 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
struct ClangCompleteManager;
|
|
|
|
struct CodeCompleteCache;
|
|
|
|
struct Config;
|
2018-03-06 01:18:33 +00:00
|
|
|
class DiagnosticsEngine;
|
2017-12-29 16:29:47 +00:00
|
|
|
struct FileConsumerSharedState;
|
|
|
|
struct ImportManager;
|
|
|
|
struct ImportPipelineStatus;
|
|
|
|
struct IncludeComplete;
|
|
|
|
struct MultiQueueWaiter;
|
2018-01-06 21:40:33 +00:00
|
|
|
struct Project;
|
2017-12-29 16:29:47 +00:00
|
|
|
struct QueryDatabase;
|
|
|
|
struct TimestampManager;
|
|
|
|
struct WorkingFile;
|
|
|
|
struct WorkingFiles;
|
2017-12-05 07:57:41 +00:00
|
|
|
|
2018-03-31 05:05:21 +00:00
|
|
|
// Caches symbols for a single file for semantic highlighting to provide
|
|
|
|
// relatively stable ids. Only supports xxx files at a time.
|
|
|
|
struct SemanticHighlightSymbolCache {
|
|
|
|
struct Entry {
|
|
|
|
SemanticHighlightSymbolCache* all_caches_ = nullptr;
|
|
|
|
|
|
|
|
// The path this cache belongs to.
|
|
|
|
std::string path;
|
|
|
|
// Detailed symbol name to stable id.
|
|
|
|
using TNameToId = std::unordered_map<std::string, int>;
|
|
|
|
TNameToId detailed_type_name_to_stable_id;
|
|
|
|
TNameToId detailed_func_name_to_stable_id;
|
|
|
|
TNameToId detailed_var_name_to_stable_id;
|
|
|
|
|
|
|
|
Entry(SemanticHighlightSymbolCache* all_caches, const std::string& path);
|
|
|
|
|
|
|
|
std::optional<int> TryGetStableId(SymbolKind kind,
|
|
|
|
const std::string& detailed_name);
|
|
|
|
int GetStableId(SymbolKind kind, const std::string& detailed_name);
|
|
|
|
|
|
|
|
TNameToId* GetMapForSymbol_(SymbolKind kind);
|
|
|
|
};
|
|
|
|
|
|
|
|
constexpr static int kCacheSize = 10;
|
|
|
|
LruCache<std::string, Entry> cache_;
|
|
|
|
uint32_t next_stable_id_ = 0;
|
|
|
|
std::unique_ptr<GroupMatch> match_;
|
|
|
|
|
|
|
|
SemanticHighlightSymbolCache();
|
|
|
|
void Init(Config*);
|
|
|
|
std::shared_ptr<Entry> GetCacheForFile(const std::string& path);
|
|
|
|
};
|
|
|
|
|
2018-03-31 03:16:33 +00:00
|
|
|
struct Out_CclsPublishSemanticHighlighting
|
|
|
|
: public lsOutMessage<Out_CclsPublishSemanticHighlighting> {
|
2018-01-28 20:34:31 +00:00
|
|
|
struct Symbol {
|
|
|
|
int stableId = 0;
|
2018-03-07 08:29:53 +00:00
|
|
|
lsSymbolKind parentKind;
|
2018-02-18 19:29:38 +00:00
|
|
|
lsSymbolKind kind;
|
2018-01-28 20:34:31 +00:00
|
|
|
StorageClass storage;
|
|
|
|
std::vector<lsRange> ranges;
|
|
|
|
};
|
|
|
|
struct Params {
|
|
|
|
lsDocumentUri uri;
|
|
|
|
std::vector<Symbol> symbols;
|
|
|
|
};
|
2018-03-31 03:16:33 +00:00
|
|
|
std::string method = "$ccls/publishSemanticHighlighting";
|
2018-01-28 20:34:31 +00:00
|
|
|
Params params;
|
|
|
|
};
|
2018-03-31 03:16:33 +00:00
|
|
|
MAKE_REFLECT_STRUCT(Out_CclsPublishSemanticHighlighting::Symbol,
|
2018-01-28 20:34:31 +00:00
|
|
|
stableId,
|
|
|
|
parentKind,
|
|
|
|
kind,
|
|
|
|
storage,
|
|
|
|
ranges);
|
2018-03-31 03:16:33 +00:00
|
|
|
MAKE_REFLECT_STRUCT(Out_CclsPublishSemanticHighlighting::Params,
|
2018-01-28 20:34:31 +00:00
|
|
|
uri,
|
|
|
|
symbols);
|
2018-03-31 03:16:33 +00:00
|
|
|
MAKE_REFLECT_STRUCT(Out_CclsPublishSemanticHighlighting,
|
2018-01-28 20:34:31 +00:00
|
|
|
jsonrpc,
|
|
|
|
method,
|
|
|
|
params);
|
|
|
|
|
2017-12-05 07:57:41 +00:00
|
|
|
// Usage:
|
|
|
|
//
|
|
|
|
// struct FooHandler : MessageHandler {
|
|
|
|
// // ...
|
|
|
|
// };
|
|
|
|
// REGISTER_MESSAGE_HANDLER(FooHandler);
|
|
|
|
//
|
|
|
|
// Then there will be a global FooHandler instance in
|
|
|
|
// |MessageHandler::message_handlers|.
|
|
|
|
|
|
|
|
#define REGISTER_MESSAGE_HANDLER(type) \
|
|
|
|
static type type##message_handler_instance_;
|
|
|
|
|
|
|
|
struct MessageHandler {
|
|
|
|
Config* config = nullptr;
|
|
|
|
QueryDatabase* db = nullptr;
|
|
|
|
MultiQueueWaiter* waiter = nullptr;
|
|
|
|
Project* project = nullptr;
|
2018-03-06 01:18:33 +00:00
|
|
|
DiagnosticsEngine* diag_engine = nullptr;
|
2017-12-29 16:29:47 +00:00
|
|
|
FileConsumerSharedState* file_consumer_shared = nullptr;
|
2017-12-05 07:57:41 +00:00
|
|
|
ImportManager* import_manager = nullptr;
|
2017-12-28 16:55:46 +00:00
|
|
|
ImportPipelineStatus* import_pipeline_status = nullptr;
|
2017-12-05 07:57:41 +00:00
|
|
|
TimestampManager* timestamp_manager = nullptr;
|
2017-12-06 03:32:33 +00:00
|
|
|
SemanticHighlightSymbolCache* semantic_cache = nullptr;
|
2017-12-05 07:57:41 +00:00
|
|
|
WorkingFiles* working_files = nullptr;
|
|
|
|
ClangCompleteManager* clang_complete = nullptr;
|
|
|
|
IncludeComplete* include_complete = nullptr;
|
|
|
|
CodeCompleteCache* global_code_complete_cache = nullptr;
|
|
|
|
CodeCompleteCache* non_global_code_complete_cache = nullptr;
|
|
|
|
CodeCompleteCache* signature_cache = nullptr;
|
|
|
|
|
2018-03-22 04:05:25 +00:00
|
|
|
virtual MethodType GetMethodType() const = 0;
|
2018-03-22 05:01:21 +00:00
|
|
|
virtual void Run(std::unique_ptr<InMessage> message) = 0;
|
2017-12-05 07:57:41 +00:00
|
|
|
|
|
|
|
static std::vector<MessageHandler*>* message_handlers;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
MessageHandler();
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename TMessage>
|
|
|
|
struct BaseMessageHandler : MessageHandler {
|
|
|
|
virtual void Run(TMessage* message) = 0;
|
|
|
|
|
|
|
|
// MessageHandler:
|
2018-03-22 05:01:21 +00:00
|
|
|
void Run(std::unique_ptr<InMessage> message) override {
|
2018-03-22 04:05:25 +00:00
|
|
|
Run(static_cast<TMessage*>(message.get()));
|
2017-12-05 07:57:41 +00:00
|
|
|
}
|
|
|
|
};
|
2017-12-06 03:32:33 +00:00
|
|
|
|
|
|
|
bool FindFileOrFail(QueryDatabase* db,
|
2018-01-06 21:40:33 +00:00
|
|
|
const Project* project,
|
2018-03-31 03:16:33 +00:00
|
|
|
std::optional<lsRequestId> id,
|
2017-12-06 03:32:33 +00:00
|
|
|
const std::string& absolute_path,
|
|
|
|
QueryFile** out_query_file,
|
|
|
|
QueryFileId* out_file_id = nullptr);
|
|
|
|
|
|
|
|
void EmitInactiveLines(WorkingFile* working_file,
|
|
|
|
const std::vector<Range>& inactive_regions);
|
|
|
|
|
|
|
|
void EmitSemanticHighlighting(QueryDatabase* db,
|
|
|
|
SemanticHighlightSymbolCache* semantic_cache,
|
|
|
|
WorkingFile* working_file,
|
2017-12-07 01:00:19 +00:00
|
|
|
QueryFile* file);
|