mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-22 07:35:08 +00:00
Simplify lsp.h and fix qual_name_offset when SetVarDetail is called on an existing variable
This commit is contained in:
parent
cdc7544471
commit
9ed024f5cc
@ -632,6 +632,7 @@ void SetVarDetail(IndexVar* var,
|
||||
else
|
||||
hover += std::to_string(clang_getEnumConstantDeclValue(cursor.cx_cursor));
|
||||
def.detailed_name = std::move(qualified_name);
|
||||
def.qual_name_offset = 0;
|
||||
def.hover = hover;
|
||||
} else {
|
||||
#if 0 && CINDEX_HAVE_PRETTY
|
||||
@ -639,9 +640,9 @@ void SetVarDetail(IndexVar* var,
|
||||
#else
|
||||
int offset = type_name.size();
|
||||
offset += ConcatTypeAndName(type_name, qualified_name);
|
||||
def.detailed_name = type_name;
|
||||
def.qual_name_offset = offset;
|
||||
def.short_name_offset += offset;
|
||||
def.detailed_name = type_name;
|
||||
// Append the textual initializer, bit field, constructor to |hover|.
|
||||
// Omit |hover| for these types:
|
||||
// int (*a)(); int (&a)(); int (&&a)(); int a[1]; auto x = ...
|
||||
@ -664,12 +665,6 @@ void SetVarDetail(IndexVar* var,
|
||||
}
|
||||
#endif
|
||||
}
|
||||
// FIXME QualifiedName should return index
|
||||
auto idx = def.detailed_name.rfind(short_name.begin(), std::string::npos,
|
||||
short_name.size());
|
||||
assert(idx != std::string::npos);
|
||||
def.short_name_offset = idx;
|
||||
def.short_name_size = short_name.size();
|
||||
|
||||
if (is_first_seen) {
|
||||
std::optional<IndexTypeId> var_type =
|
||||
@ -1711,9 +1706,6 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
||||
// indexing the definition, then there will not be any (ie) outline
|
||||
// information.
|
||||
if (!is_template_specialization) {
|
||||
// Build detailed name. The type desc looks like void (void *). We
|
||||
// insert the qualified name before the first '('.
|
||||
// FIXME GetFunctionSignature should set index
|
||||
#if CINDEX_HAVE_PRETTY
|
||||
std::tie(func->def.detailed_name, func->def.qual_name_offset,
|
||||
func->def.short_name_offset, func->def.short_name_size) =
|
||||
@ -2384,7 +2376,7 @@ void Reflect(Writer& visitor, Reference& value) {
|
||||
char buf[99];
|
||||
snprintf(buf, sizeof buf, "%s|%" PRId32 "|%d|%d",
|
||||
value.range.ToString().c_str(),
|
||||
static_cast<std::make_signed<RawId>::type>(value.id.id),
|
||||
static_cast<std::make_signed_t<RawId>>(value.id.id),
|
||||
int(value.kind), int(value.role));
|
||||
std::string s(buf);
|
||||
Reflect(visitor, s);
|
||||
|
@ -15,7 +15,6 @@
|
||||
#include "utils.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <stdint.h>
|
||||
#include <algorithm>
|
||||
#include <unordered_map>
|
||||
@ -40,14 +39,13 @@ struct Id {
|
||||
explicit Id(RawId id) : id(id) {}
|
||||
// Id<T> -> Id<void> or Id<T> -> Id<T> is allowed implicitly.
|
||||
template <typename U,
|
||||
typename std::enable_if<std::is_void<T>::value ||
|
||||
std::is_same<T, U>::value,
|
||||
bool>::type = false>
|
||||
typename std::enable_if_t<std::is_void_v<T> || std::is_same_v<T, U>,
|
||||
bool> = false>
|
||||
Id(Id<U> o) : id(o.id) {}
|
||||
template <typename U,
|
||||
typename std::enable_if<!(std::is_void<T>::value ||
|
||||
std::is_same<T, U>::value),
|
||||
bool>::type = false>
|
||||
template <
|
||||
typename U,
|
||||
typename std::enable_if_t<!(std::is_void_v<T> || std::is_same_v<T, U>),
|
||||
bool> = false>
|
||||
explicit Id(Id<U> o) : id(o.id) {}
|
||||
|
||||
// Needed for google::dense_hash_map.
|
||||
@ -84,15 +82,11 @@ struct SymbolIdx {
|
||||
bool operator==(const SymbolIdx& o) const {
|
||||
return id == o.id && kind == o.kind;
|
||||
}
|
||||
bool operator!=(const SymbolIdx& o) const { return !(*this == o); }
|
||||
bool operator<(const SymbolIdx& o) const {
|
||||
if (id != o.id)
|
||||
return id < o.id;
|
||||
return kind < o.kind;
|
||||
return !(id == o.id) ? id < o.id : kind < o.kind;
|
||||
}
|
||||
};
|
||||
MAKE_REFLECT_STRUCT(SymbolIdx, kind, id);
|
||||
MAKE_HASHABLE(SymbolIdx, t.kind, t.id);
|
||||
|
||||
struct Reference {
|
||||
Range range;
|
||||
@ -240,7 +234,6 @@ struct IndexType {
|
||||
|
||||
bool operator<(const IndexType& other) const { return id < other.id; }
|
||||
};
|
||||
MAKE_HASHABLE(IndexType, t.id);
|
||||
|
||||
template <typename F>
|
||||
struct FuncDef : NameMixin<FuncDef<F>> {
|
||||
@ -332,7 +325,6 @@ struct IndexFunc : NameMixin<IndexFunc> {
|
||||
|
||||
bool operator<(const IndexFunc& other) const { return id < other.id; }
|
||||
};
|
||||
MAKE_HASHABLE(IndexFunc, t.id);
|
||||
MAKE_REFLECT_STRUCT(IndexFunc::Declaration, spell, param_spellings);
|
||||
|
||||
template <typename F>
|
||||
@ -401,7 +393,6 @@ struct IndexVar {
|
||||
|
||||
bool operator<(const IndexVar& other) const { return id < other.id; }
|
||||
};
|
||||
MAKE_HASHABLE(IndexVar, t.id);
|
||||
|
||||
struct IdCache {
|
||||
std::string primary_file;
|
||||
|
@ -200,8 +200,6 @@ lsDocumentUri lsDocumentUri::FromPath(const std::string& path) {
|
||||
return result;
|
||||
}
|
||||
|
||||
lsDocumentUri::lsDocumentUri() {}
|
||||
|
||||
bool lsDocumentUri::operator==(const lsDocumentUri& other) const {
|
||||
return raw_uri == other.raw_uri;
|
||||
}
|
||||
|
@ -89,7 +89,6 @@ struct lsResponseError {
|
||||
struct lsDocumentUri {
|
||||
static lsDocumentUri FromPath(const std::string& path);
|
||||
|
||||
lsDocumentUri();
|
||||
bool operator==(const lsDocumentUri& other) const;
|
||||
|
||||
void SetPath(const std::string& path);
|
||||
@ -97,7 +96,6 @@ struct lsDocumentUri {
|
||||
|
||||
std::string raw_uri;
|
||||
};
|
||||
MAKE_HASHABLE(lsDocumentUri, t.raw_uri);
|
||||
|
||||
template <typename TVisitor>
|
||||
void Reflect(TVisitor& visitor, lsDocumentUri& value) {
|
||||
@ -115,7 +113,6 @@ struct lsPosition {
|
||||
}
|
||||
std::string ToString() const;
|
||||
};
|
||||
MAKE_HASHABLE(lsPosition, t.line, t.character);
|
||||
MAKE_REFLECT_STRUCT(lsPosition, line, character);
|
||||
|
||||
struct lsRange {
|
||||
@ -128,7 +125,6 @@ struct lsRange {
|
||||
return !(start == o.start) ? start < o.start : end < o.end;
|
||||
}
|
||||
};
|
||||
MAKE_HASHABLE(lsRange, t.start, t.end);
|
||||
MAKE_REFLECT_STRUCT(lsRange, start, end);
|
||||
|
||||
struct lsLocation {
|
||||
@ -142,7 +138,6 @@ struct lsLocation {
|
||||
: range < o.range;
|
||||
}
|
||||
};
|
||||
MAKE_HASHABLE(lsLocation, t.uri, t.range);
|
||||
MAKE_REFLECT_STRUCT(lsLocation, uri, range);
|
||||
|
||||
enum class lsSymbolKind : uint8_t {
|
||||
@ -358,11 +353,13 @@ MAKE_REFLECT_STRUCT(lsTextDocumentDidChangeParams,
|
||||
// Show a message to the user.
|
||||
enum class lsMessageType : int { Error = 1, Warning = 2, Info = 3, Log = 4 };
|
||||
MAKE_REFLECT_TYPE_PROXY(lsMessageType)
|
||||
|
||||
struct Out_ShowLogMessageParams {
|
||||
lsMessageType type = lsMessageType::Error;
|
||||
std::string message;
|
||||
};
|
||||
MAKE_REFLECT_STRUCT(Out_ShowLogMessageParams, type, message);
|
||||
|
||||
struct Out_ShowLogMessage : public lsOutMessage<Out_ShowLogMessage> {
|
||||
enum class DisplayType { Show, Log };
|
||||
DisplayType display_type = DisplayType::Show;
|
||||
@ -370,6 +367,7 @@ struct Out_ShowLogMessage : public lsOutMessage<Out_ShowLogMessage> {
|
||||
std::string method();
|
||||
Out_ShowLogMessageParams params;
|
||||
};
|
||||
|
||||
template <typename TVisitor>
|
||||
void Reflect(TVisitor& visitor, Out_ShowLogMessage& value) {
|
||||
REFLECT_MEMBER_START();
|
||||
|
@ -9,6 +9,8 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
MAKE_HASHABLE(SymbolIdx, t.kind, t.id);
|
||||
|
||||
namespace {
|
||||
|
||||
struct Out_CclsSetInactiveRegion
|
||||
|
@ -6,6 +6,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <numeric>
|
||||
|
||||
MAKE_HASHABLE(SymbolIdx, t.kind, t.id);
|
||||
|
||||
namespace {
|
||||
MethodType kMethodType = "$ccls/random";
|
||||
|
||||
|
@ -59,13 +59,10 @@ void AddCodeLens(const char* singular,
|
||||
code_lens.command->arguments.position = code_lens.range.start;
|
||||
|
||||
// Add unique uses.
|
||||
std::unordered_set<lsLocation> unique_uses;
|
||||
std::vector<lsLocation> unique_uses;
|
||||
for (Use use1 : uses) {
|
||||
std::optional<lsLocation> location =
|
||||
GetLsLocation(common->db, common->working_files, use1);
|
||||
if (!location)
|
||||
continue;
|
||||
unique_uses.insert(*location);
|
||||
if (auto ls_loc = GetLsLocation(common->db, common->working_files, use1))
|
||||
unique_uses.push_back(*ls_loc);
|
||||
}
|
||||
code_lens.command->arguments.locations.assign(unique_uses.begin(),
|
||||
unique_uses.end());
|
||||
|
@ -41,7 +41,7 @@ struct Handler_TextDocumentDocumentSymbol
|
||||
|
||||
for (SymbolRef sym : file->def->outline) {
|
||||
std::optional<lsSymbolInformation> info =
|
||||
GetSymbolInfo(db, working_files, sym, true /*use_short_name*/);
|
||||
GetSymbolInfo(db, working_files, sym, false);
|
||||
if (!info)
|
||||
continue;
|
||||
if (sym.kind == SymbolKind::Var) {
|
||||
|
@ -20,13 +20,12 @@ bool InsertSymbolIntoResult(QueryDatabase* db,
|
||||
SymbolIdx symbol,
|
||||
std::vector<lsSymbolInformation>* result) {
|
||||
std::optional<lsSymbolInformation> info =
|
||||
GetSymbolInfo(db, working_files, symbol, false /*use_short_name*/);
|
||||
GetSymbolInfo(db, working_files, symbol, true);
|
||||
if (!info)
|
||||
return false;
|
||||
|
||||
Maybe<Use> location = GetDefinitionExtent(db, symbol);
|
||||
Use loc;
|
||||
if (location)
|
||||
if (Maybe<Use> location = GetDefinitionExtent(db, symbol))
|
||||
loc = *location;
|
||||
else {
|
||||
auto decls = GetNonDefDeclarations(db, symbol);
|
||||
|
@ -284,7 +284,7 @@ lsSymbolKind GetSymbolKind(QueryDatabase* db, SymbolIdx sym) {
|
||||
std::optional<lsSymbolInformation> GetSymbolInfo(QueryDatabase* db,
|
||||
WorkingFiles* working_files,
|
||||
SymbolIdx sym,
|
||||
bool use_short_name) {
|
||||
bool detailed_name) {
|
||||
switch (sym.kind) {
|
||||
case SymbolKind::Invalid:
|
||||
break;
|
||||
@ -301,10 +301,10 @@ std::optional<lsSymbolInformation> GetSymbolInfo(QueryDatabase* db,
|
||||
default: {
|
||||
lsSymbolInformation info;
|
||||
EachEntityDef(db, sym, [&](const auto& def) {
|
||||
if (use_short_name)
|
||||
info.name = def.Name(true);
|
||||
else
|
||||
if (detailed_name)
|
||||
info.name = def.detailed_name;
|
||||
else
|
||||
info.name = def.Name(true);
|
||||
info.kind = def.kind;
|
||||
info.containerName = def.detailed_name;
|
||||
return false;
|
||||
|
@ -46,7 +46,7 @@ std::vector<lsLocationEx> GetLsLocationExs(QueryDatabase* db,
|
||||
std::optional<lsSymbolInformation> GetSymbolInfo(QueryDatabase* db,
|
||||
WorkingFiles* working_files,
|
||||
SymbolIdx sym,
|
||||
bool use_short_name);
|
||||
bool detailed_name);
|
||||
|
||||
std::vector<SymbolRef> FindSymbolsAtLocation(WorkingFile* working_file,
|
||||
QueryFile* file,
|
||||
|
@ -76,7 +76,7 @@ struct IndexFile;
|
||||
#define REFLECT_MEMBER2(name, value) ReflectMember(visitor, name, value)
|
||||
|
||||
#define MAKE_REFLECT_TYPE_PROXY(type_name) \
|
||||
MAKE_REFLECT_TYPE_PROXY2(type_name, std::underlying_type<type_name>::type)
|
||||
MAKE_REFLECT_TYPE_PROXY2(type_name, std::underlying_type_t<type_name>)
|
||||
#define MAKE_REFLECT_TYPE_PROXY2(type, as_type) \
|
||||
ATTRIBUTE_UNUSED inline void Reflect(Reader& visitor, type& value) { \
|
||||
as_type value0; \
|
||||
@ -243,19 +243,13 @@ struct ReflectVariant {
|
||||
// If T appears in Ts..., we should set the value of std::variant<Ts...> to
|
||||
// what we get from Reader.
|
||||
template <typename T>
|
||||
typename std::enable_if<std::disjunction<std::is_same<T, Ts>...>::value,
|
||||
void>::type
|
||||
ReflectTag(Reader& visitor, std::variant<Ts...>& value) {
|
||||
T a;
|
||||
Reflect(visitor, a);
|
||||
value = std::move(a);
|
||||
void ReflectTag(Reader& visitor, std::variant<Ts...>& value) {
|
||||
if constexpr (std::disjunction_v<std::is_same<T, Ts>...>) {
|
||||
T a;
|
||||
Reflect(visitor, a);
|
||||
value = std::move(a);
|
||||
}
|
||||
}
|
||||
// This SFINAE overload is used to prevent compile error. value = a; is not
|
||||
// allowed if T does not appear in Ts...
|
||||
template <typename T>
|
||||
typename std::enable_if<!std::disjunction<std::is_same<T, Ts>...>::value,
|
||||
void>::type
|
||||
ReflectTag(Reader&, std::variant<Ts...>&) {}
|
||||
|
||||
void operator()(Reader& visitor, std::variant<Ts...>& value) {
|
||||
// Based on tag dispatch, call different ReflectTag helper.
|
||||
@ -263,7 +257,7 @@ struct ReflectVariant {
|
||||
ReflectTag<std::monostate>(visitor, value);
|
||||
// It is possible that IsInt64() && IsInt(). We don't call ReflectTag<int>
|
||||
// if int is not in Ts...
|
||||
else if (std::disjunction<std::is_same<int, Ts>...>::value && visitor.IsInt())
|
||||
else if (std::disjunction_v<std::is_same<int, Ts>...> && visitor.IsInt())
|
||||
ReflectTag<int>(visitor, value);
|
||||
else if (visitor.IsInt64())
|
||||
ReflectTag<int64_t>(visitor, value);
|
||||
|
@ -256,8 +256,7 @@ void WorkingFile::ComputeLineMapping() {
|
||||
// For index line i, set index_to_buffer[i] to -1 if line i is duplicated.
|
||||
int i = 0;
|
||||
for (auto& line : index_lines) {
|
||||
std::string trimmed = Trim(line);
|
||||
uint64_t h = HashUsr(trimmed);
|
||||
uint64_t h = HashUsr(line);
|
||||
auto it = hash_to_unique.find(h);
|
||||
if (it == hash_to_unique.end()) {
|
||||
hash_to_unique[h] = i;
|
||||
@ -274,8 +273,7 @@ void WorkingFile::ComputeLineMapping() {
|
||||
i = 0;
|
||||
hash_to_unique.clear();
|
||||
for (auto& line : buffer_lines) {
|
||||
std::string trimmed = Trim(line);
|
||||
uint64_t h = HashUsr(trimmed);
|
||||
uint64_t h = HashUsr(line);
|
||||
auto it = hash_to_unique.find(h);
|
||||
if (it == hash_to_unique.end()) {
|
||||
hash_to_unique[h] = i;
|
||||
|
Loading…
Reference in New Issue
Block a user