mirror of
https://github.com/MaskRay/ccls.git
synced 2025-03-30 13:32:13 +00:00
Reduce <iostream>; don't include rapidjson in language_server_api.h; add role to lsReferenceContext
This commit is contained in:
parent
d2bc737068
commit
61b5ef4fa0
@ -21,9 +21,6 @@ Range ResolveCXSourceRange(const CXSourceRange& range, CXFile* cx_file) {
|
|||||||
Position((int16_t)end_line - 1, (int16_t)end_column - 1));
|
Position((int16_t)end_line - 1, (int16_t)end_column - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Place this global variable into config
|
|
||||||
extern int g_index_comments;
|
|
||||||
|
|
||||||
ClangType::ClangType() : cx_type() {}
|
ClangType::ClangType() : cx_type() {}
|
||||||
|
|
||||||
ClangType::ClangType(const CXType& other) : cx_type(other) {}
|
ClangType::ClangType(const CXType& other) : cx_type(other) {}
|
||||||
@ -231,8 +228,6 @@ std::string ClangCursor::get_type_description() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
NtString ClangCursor::get_comments() const {
|
NtString ClangCursor::get_comments() const {
|
||||||
if (!g_index_comments)
|
|
||||||
return {};
|
|
||||||
CXSourceRange range = clang_Cursor_getCommentRange(cx_cursor);
|
CXSourceRange range = clang_Cursor_getCommentRange(cx_cursor);
|
||||||
if (clang_Range_isNull(range))
|
if (clang_Range_isNull(range))
|
||||||
return {};
|
return {};
|
||||||
|
@ -6,12 +6,6 @@
|
|||||||
|
|
||||||
#include <loguru.hpp>
|
#include <loguru.hpp>
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
#include <fstream>
|
|
||||||
#include <iostream>
|
|
||||||
#include <mutex>
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
void EmitDiagnostics(std::string path,
|
void EmitDiagnostics(std::string path,
|
||||||
|
@ -577,7 +577,8 @@ void SetVarDetail(IndexVar* var,
|
|||||||
// string. Shorten it to just "lambda".
|
// string. Shorten it to just "lambda".
|
||||||
if (type_name.find("(lambda at") != std::string::npos)
|
if (type_name.find("(lambda at") != std::string::npos)
|
||||||
type_name = "lambda";
|
type_name = "lambda";
|
||||||
def.comments = cursor.get_comments();
|
if (param->config->index.comments)
|
||||||
|
def.comments = cursor.get_comments();
|
||||||
def.storage = GetStorageClass(clang_Cursor_getStorageClass(cursor.cx_cursor));
|
def.storage = GetStorageClass(clang_Cursor_getStorageClass(cursor.cx_cursor));
|
||||||
|
|
||||||
// TODO how to make PrettyPrint'ed variable name qualified?
|
// TODO how to make PrettyPrint'ed variable name qualified?
|
||||||
@ -1258,7 +1259,8 @@ ClangCursor::VisitResult VisitMacroDefinitionAndExpansions(ClangCursor cursor,
|
|||||||
var_def->def.hover =
|
var_def->def.hover =
|
||||||
"#define " + GetDocumentContentInRange(param->tu->cx_tu, cx_extent);
|
"#define " + GetDocumentContentInRange(param->tu->cx_tu, cx_extent);
|
||||||
var_def->def.kind = lsSymbolKind::Macro;
|
var_def->def.kind = lsSymbolKind::Macro;
|
||||||
var_def->def.comments = cursor.get_comments();
|
if (param->config->index.comments)
|
||||||
|
var_def->def.comments = cursor.get_comments();
|
||||||
var_def->def.spell =
|
var_def->def.spell =
|
||||||
SetUse(db, decl_loc_spelling, parent, Role::Definition);
|
SetUse(db, decl_loc_spelling, parent, Role::Definition);
|
||||||
var_def->def.extent = SetUse(
|
var_def->def.extent = SetUse(
|
||||||
@ -1642,7 +1644,8 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
|||||||
|
|
||||||
IndexFuncId func_id = db->ToFuncId(decl_cursor_resolved.cx_cursor);
|
IndexFuncId func_id = db->ToFuncId(decl_cursor_resolved.cx_cursor);
|
||||||
IndexFunc* func = db->Resolve(func_id);
|
IndexFunc* func = db->Resolve(func_id);
|
||||||
func->def.comments = decl_cursor.get_comments();
|
if (param->config->index.comments)
|
||||||
|
func->def.comments = decl_cursor.get_comments();
|
||||||
func->def.kind = GetSymbolKind(decl->entityInfo->kind);
|
func->def.kind = GetSymbolKind(decl->entityInfo->kind);
|
||||||
func->def.storage =
|
func->def.storage =
|
||||||
GetStorageClass(clang_Cursor_getStorageClass(decl->cursor));
|
GetStorageClass(clang_Cursor_getStorageClass(decl->cursor));
|
||||||
@ -1790,7 +1793,8 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
|||||||
SetTypeName(type, decl_cursor, decl->semanticContainer,
|
SetTypeName(type, decl_cursor, decl->semanticContainer,
|
||||||
decl->entityInfo->name, param);
|
decl->entityInfo->name, param);
|
||||||
type->def.kind = GetSymbolKind(decl->entityInfo->kind);
|
type->def.kind = GetSymbolKind(decl->entityInfo->kind);
|
||||||
type->def.comments = decl_cursor.get_comments();
|
if (param->config->index.comments)
|
||||||
|
type->def.comments = decl_cursor.get_comments();
|
||||||
|
|
||||||
// For Typedef/CXXTypeAlias spanning a few lines, display the declaration
|
// For Typedef/CXXTypeAlias spanning a few lines, display the declaration
|
||||||
// line, with spelling name replaced with qualified name.
|
// line, with spelling name replaced with qualified name.
|
||||||
@ -1838,7 +1842,8 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
|||||||
SetTypeName(type, decl_cursor, decl->semanticContainer,
|
SetTypeName(type, decl_cursor, decl->semanticContainer,
|
||||||
decl->entityInfo->name, param);
|
decl->entityInfo->name, param);
|
||||||
type->def.kind = GetSymbolKind(decl->entityInfo->kind);
|
type->def.kind = GetSymbolKind(decl->entityInfo->kind);
|
||||||
type->def.comments = decl_cursor.get_comments();
|
if (param->config->index.comments)
|
||||||
|
type->def.comments = decl_cursor.get_comments();
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if (decl->isDefinition) {
|
if (decl->isDefinition) {
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include <doctest/doctest.h>
|
#include <doctest/doctest.h>
|
||||||
#include <loguru.hpp>
|
#include <loguru.hpp>
|
||||||
|
#include <rapidjson/writer.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -176,6 +177,17 @@ MessageRegistry* MessageRegistry::instance() {
|
|||||||
|
|
||||||
lsBaseOutMessage::~lsBaseOutMessage() = default;
|
lsBaseOutMessage::~lsBaseOutMessage() = default;
|
||||||
|
|
||||||
|
void lsBaseOutMessage::Write(std::ostream& out) {
|
||||||
|
rapidjson::StringBuffer output;
|
||||||
|
rapidjson::Writer<rapidjson::StringBuffer> writer(output);
|
||||||
|
JsonWriter json_writer{&writer};
|
||||||
|
ReflectWriter(json_writer);
|
||||||
|
|
||||||
|
out << "Content-Length: " << output.GetSize() << "\r\n\r\n"
|
||||||
|
<< output.GetString();
|
||||||
|
out.flush();
|
||||||
|
}
|
||||||
|
|
||||||
void lsResponseError::Write(Writer& visitor) {
|
void lsResponseError::Write(Writer& visitor) {
|
||||||
auto& value = *this;
|
auto& value = *this;
|
||||||
int code2 = static_cast<int>(this->code);
|
int code2 = static_cast<int>(this->code);
|
||||||
|
@ -3,17 +3,10 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "ipc.h"
|
#include "ipc.h"
|
||||||
#include "serializer.h"
|
#include "serializer.h"
|
||||||
#include "serializers/json.h"
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
#include <optional.h>
|
#include <iosfwd>
|
||||||
#include <rapidjson/writer.h>
|
|
||||||
#include <variant.h>
|
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <iostream>
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <unordered_set>
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
@ -63,7 +56,10 @@ struct MessageRegistryRegister {
|
|||||||
|
|
||||||
struct lsBaseOutMessage {
|
struct lsBaseOutMessage {
|
||||||
virtual ~lsBaseOutMessage();
|
virtual ~lsBaseOutMessage();
|
||||||
virtual void Write(std::ostream& out) = 0;
|
virtual void ReflectWriter(Writer&) = 0;
|
||||||
|
|
||||||
|
// Send the message to the language client by writing it to stdout.
|
||||||
|
void Write(std::ostream& out);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename TDerived>
|
template <typename TDerived>
|
||||||
@ -71,18 +67,8 @@ struct lsOutMessage : lsBaseOutMessage {
|
|||||||
// All derived types need to reflect on the |jsonrpc| member.
|
// All derived types need to reflect on the |jsonrpc| member.
|
||||||
std::string jsonrpc = "2.0";
|
std::string jsonrpc = "2.0";
|
||||||
|
|
||||||
// Send the message to the language client by writing it to stdout.
|
void ReflectWriter(Writer& writer) override {
|
||||||
void Write(std::ostream& out) override {
|
Reflect(writer, static_cast<TDerived&>(*this));
|
||||||
rapidjson::StringBuffer output;
|
|
||||||
rapidjson::Writer<rapidjson::StringBuffer> writer(output);
|
|
||||||
JsonWriter json_writer(&writer);
|
|
||||||
auto that = static_cast<TDerived*>(this);
|
|
||||||
Reflect(json_writer, *that);
|
|
||||||
|
|
||||||
out << "Content-Length: " << output.GetSize();
|
|
||||||
out << (char)13 << char(10) << char(13) << char(10); // CRLFCRLF
|
|
||||||
out << output.GetString();
|
|
||||||
out.flush();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
#include "queue_manager.h"
|
#include "queue_manager.h"
|
||||||
|
|
||||||
#include <doctest/doctest.h>
|
#include <doctest/doctest.h>
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
// static
|
// static
|
||||||
optional<Matcher> Matcher::Create(const std::string& search) {
|
optional<Matcher> Matcher::Create(const std::string& search) {
|
||||||
|
@ -5,18 +5,17 @@
|
|||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
#include "project.h"
|
#include "project.h"
|
||||||
#include "queue_manager.h"
|
#include "queue_manager.h"
|
||||||
#include "serializer.h"
|
|
||||||
#include "serializers/json.h"
|
#include "serializers/json.h"
|
||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
#include "working_files.h"
|
#include "working_files.h"
|
||||||
|
|
||||||
#include <loguru.hpp>
|
#include <loguru.hpp>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
// TODO Cleanup global variables
|
// TODO Cleanup global variables
|
||||||
extern std::string g_init_options;
|
extern std::string g_init_options;
|
||||||
int g_index_comments;
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
@ -503,7 +502,6 @@ struct InitializeHandler : BaseMessageHandler<Ipc_InitializeRequest> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_index_comments = config->index.comments;
|
|
||||||
if (config->cacheDirectory.empty()) {
|
if (config->cacheDirectory.empty()) {
|
||||||
LOG_S(ERROR) << "cacheDirectory cannot be empty.";
|
LOG_S(ERROR) << "cacheDirectory cannot be empty.";
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -11,6 +11,8 @@ struct Ipc_TextDocumentReferences
|
|||||||
struct lsReferenceContext {
|
struct lsReferenceContext {
|
||||||
// Include the declaration of the current symbol.
|
// Include the declaration of the current symbol.
|
||||||
bool includeDeclaration;
|
bool includeDeclaration;
|
||||||
|
// Include references with these |Role| bits set.
|
||||||
|
Role role = Role::All;
|
||||||
};
|
};
|
||||||
struct Params {
|
struct Params {
|
||||||
lsTextDocumentIdentifier textDocument;
|
lsTextDocumentIdentifier textDocument;
|
||||||
@ -21,7 +23,8 @@ struct Ipc_TextDocumentReferences
|
|||||||
Params params;
|
Params params;
|
||||||
};
|
};
|
||||||
MAKE_REFLECT_STRUCT(Ipc_TextDocumentReferences::lsReferenceContext,
|
MAKE_REFLECT_STRUCT(Ipc_TextDocumentReferences::lsReferenceContext,
|
||||||
includeDeclaration);
|
includeDeclaration,
|
||||||
|
role);
|
||||||
MAKE_REFLECT_STRUCT(Ipc_TextDocumentReferences::Params,
|
MAKE_REFLECT_STRUCT(Ipc_TextDocumentReferences::Params,
|
||||||
textDocument,
|
textDocument,
|
||||||
position,
|
position,
|
||||||
@ -56,9 +59,10 @@ struct TextDocumentReferencesHandler
|
|||||||
// Found symbol. Return references.
|
// Found symbol. Return references.
|
||||||
EachUse(db, sym, request->params.context.includeDeclaration,
|
EachUse(db, sym, request->params.context.includeDeclaration,
|
||||||
[&](Use use) {
|
[&](Use use) {
|
||||||
if (optional<lsLocationEx> ls_loc = GetLsLocationEx(
|
if (use.role & request->params.context.role)
|
||||||
db, working_files, use, config->xref.container))
|
if (optional<lsLocationEx> ls_loc = GetLsLocationEx(
|
||||||
out.result.push_back(*ls_loc);
|
db, working_files, use, config->xref.container))
|
||||||
|
out.result.push_back(*ls_loc);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
#include <doctest/doctest.h>
|
#include <doctest/doctest.h>
|
||||||
#include <loguru.hpp>
|
#include <loguru.hpp>
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -42,7 +42,6 @@
|
|||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -4,13 +4,14 @@
|
|||||||
#include "language.h"
|
#include "language.h"
|
||||||
#include "match.h"
|
#include "match.h"
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
#include "serializer.h"
|
#include "serializers/json.h"
|
||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
#include <clang-c/CXCompilationDatabase.h>
|
#include <clang-c/CXCompilationDatabase.h>
|
||||||
#include <doctest/doctest.h>
|
#include <doctest/doctest.h>
|
||||||
#include <loguru.hpp>
|
#include <loguru.hpp>
|
||||||
|
#include <rapidjson/writer.h>
|
||||||
|
|
||||||
#if defined(__unix__) || defined(__APPLE__)
|
#if defined(__unix__) || defined(__APPLE__)
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
@ -40,6 +40,7 @@ enum class Role : uint16_t {
|
|||||||
Dynamic = 1 << 6,
|
Dynamic = 1 << 6,
|
||||||
Address = 1 << 7,
|
Address = 1 << 7,
|
||||||
Implicit = 1 << 8,
|
Implicit = 1 << 8,
|
||||||
|
All = (1 << 9) - 1,
|
||||||
};
|
};
|
||||||
MAKE_REFLECT_TYPE_PROXY(Role);
|
MAKE_REFLECT_TYPE_PROXY(Role);
|
||||||
MAKE_ENUM_HASHABLE(Role);
|
MAKE_ENUM_HASHABLE(Role);
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
#include <loguru.hpp>
|
#include <loguru.hpp>
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
Timer::Timer() {
|
Timer::Timer() {
|
||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user