mirror of
https://github.com/MaskRay/ccls.git
synced 2025-01-31 09:50:26 +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));
|
||||
}
|
||||
|
||||
// TODO Place this global variable into config
|
||||
extern int g_index_comments;
|
||||
|
||||
ClangType::ClangType() : cx_type() {}
|
||||
|
||||
ClangType::ClangType(const CXType& other) : cx_type(other) {}
|
||||
@ -231,8 +228,6 @@ std::string ClangCursor::get_type_description() const {
|
||||
}
|
||||
|
||||
NtString ClangCursor::get_comments() const {
|
||||
if (!g_index_comments)
|
||||
return {};
|
||||
CXSourceRange range = clang_Cursor_getCommentRange(cx_cursor);
|
||||
if (clang_Range_isNull(range))
|
||||
return {};
|
||||
|
@ -6,12 +6,6 @@
|
||||
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cassert>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <mutex>
|
||||
#include <sstream>
|
||||
|
||||
namespace {
|
||||
|
||||
void EmitDiagnostics(std::string path,
|
||||
|
@ -577,7 +577,8 @@ void SetVarDetail(IndexVar* var,
|
||||
// string. Shorten it to just "lambda".
|
||||
if (type_name.find("(lambda at") != std::string::npos)
|
||||
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));
|
||||
|
||||
// TODO how to make PrettyPrint'ed variable name qualified?
|
||||
@ -1258,7 +1259,8 @@ ClangCursor::VisitResult VisitMacroDefinitionAndExpansions(ClangCursor cursor,
|
||||
var_def->def.hover =
|
||||
"#define " + GetDocumentContentInRange(param->tu->cx_tu, cx_extent);
|
||||
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 =
|
||||
SetUse(db, decl_loc_spelling, parent, Role::Definition);
|
||||
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);
|
||||
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.storage =
|
||||
GetStorageClass(clang_Cursor_getStorageClass(decl->cursor));
|
||||
@ -1790,7 +1793,8 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
||||
SetTypeName(type, decl_cursor, decl->semanticContainer,
|
||||
decl->entityInfo->name, param);
|
||||
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
|
||||
// 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,
|
||||
decl->entityInfo->name, param);
|
||||
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) {
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <loguru.hpp>
|
||||
#include <rapidjson/writer.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
@ -176,6 +177,17 @@ MessageRegistry* MessageRegistry::instance() {
|
||||
|
||||
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) {
|
||||
auto& value = *this;
|
||||
int code2 = static_cast<int>(this->code);
|
||||
|
@ -3,17 +3,10 @@
|
||||
#include "config.h"
|
||||
#include "ipc.h"
|
||||
#include "serializer.h"
|
||||
#include "serializers/json.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include <optional.h>
|
||||
#include <rapidjson/writer.h>
|
||||
#include <variant.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <iosfwd>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
@ -63,7 +56,10 @@ struct MessageRegistryRegister {
|
||||
|
||||
struct 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>
|
||||
@ -71,18 +67,8 @@ struct lsOutMessage : lsBaseOutMessage {
|
||||
// All derived types need to reflect on the |jsonrpc| member.
|
||||
std::string jsonrpc = "2.0";
|
||||
|
||||
// Send the message to the language client by writing it to stdout.
|
||||
void Write(std::ostream& out) override {
|
||||
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();
|
||||
void ReflectWriter(Writer& writer) override {
|
||||
Reflect(writer, static_cast<TDerived&>(*this));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include "queue_manager.h"
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <iostream>
|
||||
|
||||
// static
|
||||
optional<Matcher> Matcher::Create(const std::string& search) {
|
||||
|
@ -5,18 +5,17 @@
|
||||
#include "platform.h"
|
||||
#include "project.h"
|
||||
#include "queue_manager.h"
|
||||
#include "serializer.h"
|
||||
#include "serializers/json.h"
|
||||
#include "timer.h"
|
||||
#include "working_files.h"
|
||||
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
// TODO Cleanup global variables
|
||||
extern std::string g_init_options;
|
||||
int g_index_comments;
|
||||
|
||||
namespace {
|
||||
|
||||
@ -503,7 +502,6 @@ struct InitializeHandler : BaseMessageHandler<Ipc_InitializeRequest> {
|
||||
}
|
||||
}
|
||||
|
||||
g_index_comments = config->index.comments;
|
||||
if (config->cacheDirectory.empty()) {
|
||||
LOG_S(ERROR) << "cacheDirectory cannot be empty.";
|
||||
exit(1);
|
||||
|
@ -11,6 +11,8 @@ struct Ipc_TextDocumentReferences
|
||||
struct lsReferenceContext {
|
||||
// Include the declaration of the current symbol.
|
||||
bool includeDeclaration;
|
||||
// Include references with these |Role| bits set.
|
||||
Role role = Role::All;
|
||||
};
|
||||
struct Params {
|
||||
lsTextDocumentIdentifier textDocument;
|
||||
@ -21,7 +23,8 @@ struct Ipc_TextDocumentReferences
|
||||
Params params;
|
||||
};
|
||||
MAKE_REFLECT_STRUCT(Ipc_TextDocumentReferences::lsReferenceContext,
|
||||
includeDeclaration);
|
||||
includeDeclaration,
|
||||
role);
|
||||
MAKE_REFLECT_STRUCT(Ipc_TextDocumentReferences::Params,
|
||||
textDocument,
|
||||
position,
|
||||
@ -56,9 +59,10 @@ struct TextDocumentReferencesHandler
|
||||
// Found symbol. Return references.
|
||||
EachUse(db, sym, request->params.context.includeDeclaration,
|
||||
[&](Use use) {
|
||||
if (optional<lsLocationEx> ls_loc = GetLsLocationEx(
|
||||
db, working_files, use, config->xref.container))
|
||||
out.result.push_back(*ls_loc);
|
||||
if (use.role & request->params.context.role)
|
||||
if (optional<lsLocationEx> ls_loc = GetLsLocationEx(
|
||||
db, working_files, use, config->xref.container))
|
||||
out.result.push_back(*ls_loc);
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
@ -3,7 +3,6 @@
|
||||
#include <doctest/doctest.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
@ -42,7 +42,6 @@
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
namespace {
|
||||
|
@ -4,13 +4,14 @@
|
||||
#include "language.h"
|
||||
#include "match.h"
|
||||
#include "platform.h"
|
||||
#include "serializer.h"
|
||||
#include "serializers/json.h"
|
||||
#include "timer.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include <clang-c/CXCompilationDatabase.h>
|
||||
#include <doctest/doctest.h>
|
||||
#include <loguru.hpp>
|
||||
#include <rapidjson/writer.h>
|
||||
|
||||
#if defined(__unix__) || defined(__APPLE__)
|
||||
#include <unistd.h>
|
||||
|
@ -11,7 +11,6 @@
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
@ -40,6 +40,7 @@ enum class Role : uint16_t {
|
||||
Dynamic = 1 << 6,
|
||||
Address = 1 << 7,
|
||||
Implicit = 1 << 8,
|
||||
All = (1 << 9) - 1,
|
||||
};
|
||||
MAKE_REFLECT_TYPE_PROXY(Role);
|
||||
MAKE_ENUM_HASHABLE(Role);
|
||||
|
@ -2,8 +2,6 @@
|
||||
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
Timer::Timer() {
|
||||
Reset();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user