2017-06-15 05:32:23 +00:00
|
|
|
#include "query_utils.h"
|
|
|
|
|
2017-12-24 01:30:52 +00:00
|
|
|
#include "queue_manager.h"
|
|
|
|
|
2018-02-10 00:42:33 +00:00
|
|
|
#include <loguru.hpp>
|
|
|
|
|
2017-06-16 17:14:09 +00:00
|
|
|
#include <climits>
|
2018-02-07 05:26:38 +00:00
|
|
|
#include <queue>
|
2018-02-21 04:26:17 +00:00
|
|
|
#include <stack>
|
2018-02-21 01:50:48 +00:00
|
|
|
#include <unordered_set>
|
2017-06-16 17:14:09 +00:00
|
|
|
|
2017-06-16 06:43:02 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Computes roughly how long |range| is.
|
|
|
|
int ComputeRangeSize(const Range& range) {
|
|
|
|
if (range.start.line != range.end.line)
|
|
|
|
return INT_MAX;
|
|
|
|
return range.end.column - range.start.column;
|
|
|
|
}
|
|
|
|
|
2018-02-20 21:56:56 +00:00
|
|
|
template <typename Q>
|
|
|
|
std::vector<Use> ToUsesHelper(std::vector<Q>& entities,
|
|
|
|
const std::vector<Id<Q>>& ids) {
|
|
|
|
std::vector<Use> ret;
|
|
|
|
ret.reserve(ids.size());
|
|
|
|
for (auto id : ids) {
|
|
|
|
Q& entity = entities[id.id];
|
|
|
|
bool has_def = false;
|
|
|
|
for (auto& def : entity.def)
|
|
|
|
if (def.spell) {
|
|
|
|
ret.push_back(*def.spell);
|
|
|
|
has_def = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!has_def && entity.declarations.size())
|
|
|
|
ret.push_back(entity.declarations[0]);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-02-09 05:11:35 +00:00
|
|
|
} // namespace
|
|
|
|
|
2018-02-11 04:30:27 +00:00
|
|
|
Maybe<Use> GetDefinitionSpellingOfSymbol(QueryDatabase* db,
|
2018-02-11 18:25:37 +00:00
|
|
|
SymbolIdx sym) {
|
2018-02-21 01:50:48 +00:00
|
|
|
Maybe<Use> ret;
|
|
|
|
EachEntityDef(db, sym, [&](const auto& def) { return !(ret = def.spell); });
|
|
|
|
return ret;
|
2017-06-15 05:32:23 +00:00
|
|
|
}
|
|
|
|
|
2018-02-11 18:25:37 +00:00
|
|
|
Maybe<Use> GetDefinitionExtentOfSymbol(QueryDatabase* db, SymbolIdx sym) {
|
2018-02-21 01:50:48 +00:00
|
|
|
// Used to jump to file.
|
|
|
|
if (sym.kind == SymbolKind::File)
|
|
|
|
return Use(Range(Position(0, 0), Position(0, 0)), sym.id, sym.kind,
|
|
|
|
Role::None, QueryFileId(sym.id));
|
|
|
|
Maybe<Use> ret;
|
|
|
|
EachEntityDef(db, sym, [&](const auto& def) { return !(ret = def.extent); });
|
|
|
|
return ret;
|
2017-06-15 05:32:23 +00:00
|
|
|
}
|
|
|
|
|
2018-02-10 08:19:17 +00:00
|
|
|
Maybe<QueryFileId> GetDeclarationFileForSymbol(QueryDatabase* db,
|
2018-02-11 18:25:37 +00:00
|
|
|
SymbolIdx sym) {
|
2018-02-09 17:42:10 +00:00
|
|
|
switch (sym.kind) {
|
2018-02-18 07:09:05 +00:00
|
|
|
case SymbolKind::File:
|
|
|
|
return QueryFileId(sym.id);
|
2017-09-22 01:14:57 +00:00
|
|
|
case SymbolKind::Func: {
|
2018-02-10 03:07:45 +00:00
|
|
|
QueryFunc& func = db->GetFunc(sym);
|
2017-10-17 05:44:58 +00:00
|
|
|
if (!func.declarations.empty())
|
2018-02-12 04:22:47 +00:00
|
|
|
return func.declarations[0].file;
|
2018-02-18 07:09:05 +00:00
|
|
|
if (const auto* def = func.AnyDef())
|
|
|
|
return def->file;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SymbolKind::Type: {
|
|
|
|
if (const auto* def = db->GetType(sym).AnyDef())
|
|
|
|
return def->file;
|
2017-09-22 01:14:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SymbolKind::Var: {
|
2018-02-18 07:09:05 +00:00
|
|
|
if (const auto* def = db->GetVar(sym).AnyDef())
|
2018-02-18 05:52:14 +00:00
|
|
|
return def->file;
|
2017-09-22 01:14:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SymbolKind::Invalid: {
|
|
|
|
assert(false && "unexpected");
|
|
|
|
break;
|
|
|
|
}
|
2017-06-15 05:32:23 +00:00
|
|
|
}
|
|
|
|
return nullopt;
|
|
|
|
}
|
|
|
|
|
2018-02-10 20:53:18 +00:00
|
|
|
std::vector<Use> ToUses(QueryDatabase* db,
|
|
|
|
const std::vector<QueryFuncId>& ids) {
|
2018-02-20 21:56:56 +00:00
|
|
|
return ToUsesHelper(db->funcs, ids);
|
2018-02-10 06:51:58 +00:00
|
|
|
}
|
|
|
|
|
2018-02-10 20:53:18 +00:00
|
|
|
std::vector<Use> ToUses(QueryDatabase* db,
|
|
|
|
const std::vector<QueryTypeId>& ids) {
|
2018-02-20 21:56:56 +00:00
|
|
|
return ToUsesHelper(db->types, ids);
|
2018-02-10 06:51:58 +00:00
|
|
|
}
|
|
|
|
|
2018-02-10 20:53:18 +00:00
|
|
|
std::vector<Use> ToUses(QueryDatabase* db, const std::vector<QueryVarId>& ids) {
|
2018-02-20 21:56:56 +00:00
|
|
|
return ToUsesHelper(db->vars, ids);
|
2018-02-10 06:51:58 +00:00
|
|
|
}
|
|
|
|
|
2018-02-10 20:53:18 +00:00
|
|
|
std::vector<Use> GetDeclarationsOfSymbolForGotoDefinition(
|
2017-09-22 01:14:57 +00:00
|
|
|
QueryDatabase* db,
|
2018-02-11 18:25:37 +00:00
|
|
|
SymbolIdx sym) {
|
2018-02-09 17:42:10 +00:00
|
|
|
switch (sym.kind) {
|
2018-02-09 05:11:35 +00:00
|
|
|
case SymbolKind::Func:
|
2018-02-10 01:30:22 +00:00
|
|
|
return db->GetFunc(sym).declarations;
|
2018-02-20 21:56:56 +00:00
|
|
|
case SymbolKind::Type:
|
|
|
|
return db->GetType(sym).declarations;
|
2018-02-09 05:11:35 +00:00
|
|
|
case SymbolKind::Var:
|
2018-02-10 01:30:22 +00:00
|
|
|
return db->GetVar(sym).declarations;
|
2017-09-22 01:14:57 +00:00
|
|
|
default:
|
2018-02-20 21:56:56 +00:00
|
|
|
return {};
|
2017-06-15 05:32:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-19 07:17:38 +00:00
|
|
|
bool HasCallersOnSelfOrBaseOrDerived(QueryDatabase* db, QueryFunc& root) {
|
2018-02-21 01:50:48 +00:00
|
|
|
std::unordered_set<Usr> seen;
|
2018-02-21 04:26:17 +00:00
|
|
|
std::stack<QueryFunc*> stack;
|
2018-02-21 01:50:48 +00:00
|
|
|
seen.insert(root.usr);
|
2018-02-21 04:26:17 +00:00
|
|
|
stack.push(&root);
|
|
|
|
while (!stack.empty()) {
|
|
|
|
QueryFunc& func = *stack.top();
|
|
|
|
stack.pop();
|
2018-02-10 20:53:18 +00:00
|
|
|
if (!func.uses.empty())
|
2017-07-19 07:17:38 +00:00
|
|
|
return true;
|
2018-02-21 01:50:48 +00:00
|
|
|
if (auto* def = func.AnyDef()) {
|
|
|
|
EachDefinedEntity(db->funcs, def->base, [&](QueryFunc& func1) {
|
|
|
|
if (!seen.count(func1.usr)) {
|
|
|
|
seen.insert(func1.usr);
|
2018-02-21 04:26:17 +00:00
|
|
|
stack.push(&func1);
|
2018-02-21 01:50:48 +00:00
|
|
|
}
|
2018-02-04 00:20:14 +00:00
|
|
|
});
|
2018-02-21 01:50:48 +00:00
|
|
|
EachDefinedEntity(db->funcs, func.derived, [&](QueryFunc& func1) {
|
|
|
|
if (!seen.count(func1.usr)) {
|
|
|
|
seen.insert(func1.usr);
|
2018-02-21 04:26:17 +00:00
|
|
|
stack.push(&func1);
|
2018-02-21 01:50:48 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2017-07-19 07:17:38 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-02-10 20:53:18 +00:00
|
|
|
std::vector<Use> GetCallersForAllBaseFunctions(QueryDatabase* db,
|
|
|
|
QueryFunc& root) {
|
|
|
|
std::vector<Use> callers;
|
2018-02-21 04:26:17 +00:00
|
|
|
std::unordered_set<Usr> seen;
|
|
|
|
std::stack<QueryFunc*> stack;
|
|
|
|
seen.insert(root.usr);
|
|
|
|
stack.push(&root);
|
|
|
|
while (!stack.empty()) {
|
|
|
|
QueryFunc& func = *stack.top();
|
|
|
|
stack.pop();
|
2018-02-10 20:53:18 +00:00
|
|
|
AddRange(&callers, func.uses);
|
2018-02-21 04:26:17 +00:00
|
|
|
if (auto* def = func.AnyDef()) {
|
|
|
|
EachDefinedEntity(db->funcs, def->base, [&](QueryFunc& func1) {
|
|
|
|
if (!seen.count(func1.usr)) {
|
|
|
|
seen.insert(func1.usr);
|
|
|
|
stack.push(&func1);
|
|
|
|
}
|
2018-02-04 00:20:14 +00:00
|
|
|
});
|
2018-02-19 03:06:40 +00:00
|
|
|
}
|
2017-06-15 05:32:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return callers;
|
|
|
|
}
|
|
|
|
|
2018-02-10 20:53:18 +00:00
|
|
|
std::vector<Use> GetCallersForAllDerivedFunctions(QueryDatabase* db,
|
|
|
|
QueryFunc& root) {
|
|
|
|
std::vector<Use> callers;
|
2018-02-21 04:26:17 +00:00
|
|
|
std::unordered_set<Usr> seen;
|
|
|
|
std::stack<QueryFunc*> stack;
|
|
|
|
seen.insert(root.usr);
|
|
|
|
stack.push(&root);
|
|
|
|
while (!stack.empty()) {
|
|
|
|
QueryFunc& func = *stack.top();
|
|
|
|
stack.pop();
|
|
|
|
AddRange(&callers, func.uses);
|
2018-02-21 01:50:48 +00:00
|
|
|
EachDefinedEntity(db->funcs, func.derived, [&](QueryFunc& func1) {
|
2018-02-21 04:26:17 +00:00
|
|
|
if (!seen.count(func1.usr)) {
|
|
|
|
seen.insert(func1.usr);
|
|
|
|
stack.push(&func1);
|
|
|
|
}
|
2018-02-04 00:20:14 +00:00
|
|
|
});
|
2017-06-15 05:32:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return callers;
|
|
|
|
}
|
|
|
|
|
2017-09-22 01:14:57 +00:00
|
|
|
optional<lsPosition> GetLsPosition(WorkingFile* working_file,
|
|
|
|
const Position& position) {
|
2017-06-15 05:32:23 +00:00
|
|
|
if (!working_file)
|
2018-01-14 19:39:29 +00:00
|
|
|
return lsPosition(position.line, position.column);
|
2017-06-15 05:32:23 +00:00
|
|
|
|
2018-01-14 22:24:47 +00:00
|
|
|
int column = position.column;
|
2018-02-21 04:26:17 +00:00
|
|
|
if (optional<int> start =
|
|
|
|
working_file->GetBufferPosFromIndexPos(position.line, &column, false))
|
|
|
|
return lsPosition(*start, column);
|
|
|
|
return nullopt;
|
2017-06-15 05:32:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
optional<lsRange> GetLsRange(WorkingFile* working_file, const Range& location) {
|
|
|
|
if (!working_file) {
|
2018-01-30 00:27:43 +00:00
|
|
|
return lsRange(lsPosition(location.start.line, location.start.column),
|
|
|
|
lsPosition(location.end.line, location.end.column));
|
2017-06-15 05:32:23 +00:00
|
|
|
}
|
|
|
|
|
2018-01-14 22:24:47 +00:00
|
|
|
int start_column = location.start.column, end_column = location.end.column;
|
2018-01-30 00:27:43 +00:00
|
|
|
optional<int> start = working_file->GetBufferPosFromIndexPos(
|
|
|
|
location.start.line, &start_column, false);
|
|
|
|
optional<int> end = working_file->GetBufferPosFromIndexPos(location.end.line,
|
|
|
|
&end_column, true);
|
2017-06-15 05:32:23 +00:00
|
|
|
if (!start || !end)
|
|
|
|
return nullopt;
|
|
|
|
|
|
|
|
// If remapping end fails (end can never be < start), just guess that the
|
|
|
|
// final location didn't move. This only screws up the highlighted code
|
|
|
|
// region if we guess wrong, so not a big deal.
|
|
|
|
//
|
|
|
|
// Remapping fails often in C++ since there are a lot of "};" at the end of
|
|
|
|
// class/struct definitions.
|
|
|
|
if (*end < *start)
|
|
|
|
*end = *start + (location.end.line - location.start.line);
|
2018-01-15 06:53:51 +00:00
|
|
|
if (*start == *end && start_column > end_column)
|
|
|
|
end_column = start_column;
|
2017-06-15 05:32:23 +00:00
|
|
|
|
2018-01-14 22:24:47 +00:00
|
|
|
return lsRange(lsPosition(*start, start_column),
|
|
|
|
lsPosition(*end, end_column));
|
2017-06-15 05:32:23 +00:00
|
|
|
}
|
|
|
|
|
2017-09-22 01:14:57 +00:00
|
|
|
lsDocumentUri GetLsDocumentUri(QueryDatabase* db,
|
|
|
|
QueryFileId file_id,
|
|
|
|
std::string* path) {
|
2017-10-17 05:44:58 +00:00
|
|
|
QueryFile& file = db->files[file_id.id];
|
|
|
|
if (file.def) {
|
|
|
|
*path = file.def->path;
|
2017-06-15 05:32:23 +00:00
|
|
|
return lsDocumentUri::FromPath(*path);
|
2017-09-22 01:14:57 +00:00
|
|
|
} else {
|
2017-06-15 05:32:23 +00:00
|
|
|
*path = "";
|
|
|
|
return lsDocumentUri::FromPath("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lsDocumentUri GetLsDocumentUri(QueryDatabase* db, QueryFileId file_id) {
|
2017-10-17 05:44:58 +00:00
|
|
|
QueryFile& file = db->files[file_id.id];
|
|
|
|
if (file.def) {
|
|
|
|
return lsDocumentUri::FromPath(file.def->path);
|
2017-09-22 01:14:57 +00:00
|
|
|
} else {
|
2017-06-15 05:32:23 +00:00
|
|
|
return lsDocumentUri::FromPath("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-22 01:14:57 +00:00
|
|
|
optional<lsLocation> GetLsLocation(QueryDatabase* db,
|
|
|
|
WorkingFiles* working_files,
|
2018-02-12 04:22:47 +00:00
|
|
|
Use use) {
|
2017-06-15 05:32:23 +00:00
|
|
|
std::string path;
|
2018-02-12 04:22:47 +00:00
|
|
|
lsDocumentUri uri = GetLsDocumentUri(db, use.file, &path);
|
2017-09-22 01:14:57 +00:00
|
|
|
optional<lsRange> range =
|
2018-02-12 04:22:47 +00:00
|
|
|
GetLsRange(working_files->GetFileByFilename(path), use.range);
|
2017-06-15 05:32:23 +00:00
|
|
|
if (!range)
|
|
|
|
return nullopt;
|
|
|
|
return lsLocation(uri, *range);
|
|
|
|
}
|
|
|
|
|
2018-02-11 01:50:44 +00:00
|
|
|
optional<lsLocationEx> GetLsLocationEx(QueryDatabase* db,
|
|
|
|
WorkingFiles* working_files,
|
|
|
|
Use use,
|
2018-02-21 04:26:17 +00:00
|
|
|
bool container) {
|
2018-02-11 01:50:44 +00:00
|
|
|
optional<lsLocation> ls_loc = GetLsLocation(db, working_files, use);
|
|
|
|
if (!ls_loc)
|
|
|
|
return nullopt;
|
|
|
|
lsLocationEx ret;
|
|
|
|
ret.lsLocation::operator=(*ls_loc);
|
2018-02-21 04:26:17 +00:00
|
|
|
if (container) {
|
2018-02-21 01:50:48 +00:00
|
|
|
EachEntityDef(db, use, [&](const auto& def) {
|
|
|
|
ret.containerName = std::string_view(def.detailed_name);
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
2018-02-11 01:50:44 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-02-21 04:26:17 +00:00
|
|
|
std::vector<lsLocationEx> GetLsLocationExs(QueryDatabase* db,
|
|
|
|
WorkingFiles* working_files,
|
|
|
|
const std::vector<Use>& uses,
|
|
|
|
bool container,
|
|
|
|
int limit) {
|
|
|
|
std::vector<lsLocationEx> ret;
|
|
|
|
for (Use use : uses)
|
|
|
|
if (auto loc = GetLsLocationEx(db, working_files, use, container))
|
|
|
|
ret.push_back(*loc);
|
2018-02-13 01:15:19 +00:00
|
|
|
std::sort(ret.begin(), ret.end());
|
|
|
|
ret.erase(std::unique(ret.begin(), ret.end()), ret.end());
|
2018-02-20 23:40:31 +00:00
|
|
|
if (ret.size() > limit)
|
|
|
|
ret.resize(limit);
|
2018-02-13 01:15:19 +00:00
|
|
|
return ret;
|
2017-06-15 05:32:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns a symbol. The symbol will have *NOT* have a location assigned.
|
2017-09-22 01:14:57 +00:00
|
|
|
optional<lsSymbolInformation> GetSymbolInfo(QueryDatabase* db,
|
|
|
|
WorkingFiles* working_files,
|
2018-02-11 18:25:37 +00:00
|
|
|
SymbolIdx sym,
|
2017-12-19 05:31:19 +00:00
|
|
|
bool use_short_name) {
|
2018-02-09 17:42:10 +00:00
|
|
|
switch (sym.kind) {
|
2018-02-21 04:26:17 +00:00
|
|
|
case SymbolKind::Invalid:
|
|
|
|
break;
|
2017-09-22 01:14:57 +00:00
|
|
|
case SymbolKind::File: {
|
2018-02-11 18:25:37 +00:00
|
|
|
QueryFile& file = db->GetFile(sym);
|
2017-10-17 05:44:58 +00:00
|
|
|
if (!file.def)
|
2018-02-09 17:42:10 +00:00
|
|
|
break;
|
2017-06-15 05:32:23 +00:00
|
|
|
|
2017-09-22 01:14:57 +00:00
|
|
|
lsSymbolInformation info;
|
2017-10-17 05:44:58 +00:00
|
|
|
info.name = file.def->path;
|
2017-09-22 01:14:57 +00:00
|
|
|
info.kind = lsSymbolKind::File;
|
|
|
|
return info;
|
2017-06-15 05:32:23 +00:00
|
|
|
}
|
2018-02-21 04:26:17 +00:00
|
|
|
default: {
|
2017-09-22 01:14:57 +00:00
|
|
|
lsSymbolInformation info;
|
2018-02-21 04:26:17 +00:00
|
|
|
EachEntityDef(db, sym, [&](const auto& def) {
|
|
|
|
if (use_short_name)
|
|
|
|
info.name = def.ShortName();
|
|
|
|
else
|
|
|
|
info.name = def.detailed_name;
|
|
|
|
info.kind = def.kind;
|
|
|
|
info.containerName = def.detailed_name;
|
|
|
|
return false;
|
|
|
|
});
|
2017-09-22 01:14:57 +00:00
|
|
|
return info;
|
|
|
|
}
|
2018-02-09 17:42:10 +00:00
|
|
|
}
|
2017-06-15 05:32:23 +00:00
|
|
|
|
|
|
|
return nullopt;
|
|
|
|
}
|
|
|
|
|
2018-01-29 04:39:41 +00:00
|
|
|
// TODO Sort only by range length, not |kind| or |idx|
|
2017-09-22 01:14:57 +00:00
|
|
|
std::vector<SymbolRef> FindSymbolsAtLocation(WorkingFile* working_file,
|
|
|
|
QueryFile* file,
|
|
|
|
lsPosition position) {
|
2017-06-15 05:32:23 +00:00
|
|
|
std::vector<SymbolRef> symbols;
|
|
|
|
symbols.reserve(1);
|
|
|
|
|
2018-01-14 19:39:29 +00:00
|
|
|
int target_line = position.line;
|
|
|
|
int target_column = position.character;
|
2017-06-15 05:32:23 +00:00
|
|
|
if (working_file) {
|
2018-01-15 01:16:24 +00:00
|
|
|
optional<int> index_line = working_file->GetIndexPosFromBufferPos(
|
|
|
|
target_line, &target_column, false);
|
2017-06-15 05:32:23 +00:00
|
|
|
if (index_line)
|
|
|
|
target_line = *index_line;
|
|
|
|
}
|
|
|
|
|
2018-02-09 17:42:10 +00:00
|
|
|
for (const SymbolRef& sym : file->def->all_symbols) {
|
|
|
|
if (sym.range.Contains(target_line, target_column))
|
|
|
|
symbols.push_back(sym);
|
2017-06-15 05:32:23 +00:00
|
|
|
}
|
|
|
|
|
2017-06-16 06:43:02 +00:00
|
|
|
// Order shorter ranges first, since they are more detailed/precise. This is
|
|
|
|
// important for macros which generate code so that we can resolving the
|
|
|
|
// macro argument takes priority over the entire macro body.
|
|
|
|
//
|
2017-12-23 16:01:43 +00:00
|
|
|
// Order SymbolKind::Var before SymbolKind::Type. Macro calls are treated as
|
|
|
|
// Var currently. If a macro expands to tokens led by a SymbolKind::Type, the
|
2017-12-18 01:50:19 +00:00
|
|
|
// macro and the Type have the same range. We want to find the macro
|
|
|
|
// definition instead of the Type definition.
|
|
|
|
//
|
|
|
|
// Then order functions before other types, which makes goto definition work
|
2017-06-16 06:43:02 +00:00
|
|
|
// better on constructors.
|
2018-01-30 00:27:43 +00:00
|
|
|
std::sort(symbols.begin(), symbols.end(),
|
|
|
|
[](const SymbolRef& a, const SymbolRef& b) {
|
2018-02-19 03:39:18 +00:00
|
|
|
int t = ComputeRangeSize(a.range) - ComputeRangeSize(b.range);
|
|
|
|
if (t)
|
|
|
|
return t < 0;
|
|
|
|
t = (a.role & Role::Definition) - (b.role & Role::Definition);
|
|
|
|
if (t)
|
|
|
|
return t > 0;
|
2018-01-30 00:27:43 +00:00
|
|
|
// operator> orders Var/Func before Type.
|
2018-02-19 03:39:18 +00:00
|
|
|
t = static_cast<int>(a.kind) - static_cast<int>(b.kind);
|
2018-01-30 00:27:43 +00:00
|
|
|
if (t)
|
|
|
|
return t > 0;
|
2018-02-11 18:25:37 +00:00
|
|
|
return a.id < b.id;
|
2018-01-30 00:27:43 +00:00
|
|
|
});
|
2017-06-15 05:32:23 +00:00
|
|
|
|
|
|
|
return symbols;
|
2017-12-20 06:20:44 +00:00
|
|
|
}
|
2017-12-24 01:30:52 +00:00
|
|
|
|
|
|
|
void EmitDiagnostics(WorkingFiles* working_files,
|
|
|
|
std::string path,
|
|
|
|
std::vector<lsDiagnostic> diagnostics) {
|
|
|
|
// Emit diagnostics.
|
|
|
|
Out_TextDocumentPublishDiagnostics out;
|
|
|
|
out.params.uri = lsDocumentUri::FromPath(path);
|
|
|
|
out.params.diagnostics = diagnostics;
|
|
|
|
QueueManager::WriteStdout(IpcId::TextDocumentPublishDiagnostics, out);
|
|
|
|
|
|
|
|
// Cache diagnostics so we can show fixits.
|
|
|
|
working_files->DoActionOnFile(path, [&](WorkingFile* working_file) {
|
|
|
|
if (working_file)
|
|
|
|
working_file->diagnostics_ = diagnostics;
|
|
|
|
});
|
2018-01-11 07:16:33 +00:00
|
|
|
}
|