2018-09-13 07:18:37 +00:00
|
|
|
// Copyright 2017-2018 ccls Authors
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2018-10-28 17:49:31 +00:00
|
|
|
#include "lsp.hh"
|
2018-09-13 07:18:37 +00:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <queue>
|
|
|
|
|
2018-10-28 17:49:31 +00:00
|
|
|
namespace ccls {
|
2018-09-13 07:18:37 +00:00
|
|
|
template <typename Node>
|
2019-01-09 07:19:17 +00:00
|
|
|
std::vector<lsLocation> FlattenHierarchy(const std::optional<Node> &root) {
|
|
|
|
if (!root)
|
|
|
|
return {};
|
|
|
|
std::vector<lsLocation> ret;
|
2018-09-13 07:18:37 +00:00
|
|
|
std::queue<const Node *> q;
|
2019-01-09 07:19:17 +00:00
|
|
|
for (auto &entry : root->children)
|
2018-09-13 07:18:37 +00:00
|
|
|
q.push(&entry);
|
|
|
|
while (q.size()) {
|
|
|
|
auto *entry = q.front();
|
|
|
|
q.pop();
|
|
|
|
if (entry->location.uri.raw_uri.size())
|
2019-01-09 07:19:17 +00:00
|
|
|
ret.push_back({entry->location});
|
2018-09-13 07:18:37 +00:00
|
|
|
for (auto &entry1 : entry->children)
|
|
|
|
q.push(&entry1);
|
|
|
|
}
|
2019-01-09 07:19:17 +00:00
|
|
|
std::sort(ret.begin(), ret.end());
|
|
|
|
ret.erase(std::unique(ret.begin(), ret.end()), ret.end());
|
|
|
|
return ret;
|
2018-09-13 07:18:37 +00:00
|
|
|
}
|
2018-10-28 17:49:31 +00:00
|
|
|
} // namespace ccls
|