mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-27 10:02:03 +00:00
Simplify and better compatibility with encodings retaining the feature of low bytes being 1-byte characters
This commit is contained in:
parent
e3a2f1a9a8
commit
ca550720e4
@ -563,13 +563,11 @@ std::shared_ptr<PreambleData> CompletionSession::GetPreamble() {
|
|||||||
return preamble;
|
return preamble;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompletionManager::CompletionManager(Project *project,
|
CompletionManager::CompletionManager(Project *project, WorkingFiles *wfiles,
|
||||||
WorkingFiles *wfiles,
|
|
||||||
OnDiagnostic on_diagnostic,
|
OnDiagnostic on_diagnostic,
|
||||||
OnDropped on_dropped)
|
OnDropped on_dropped)
|
||||||
: project_(project), wfiles_(wfiles),
|
: project_(project), wfiles_(wfiles), on_diagnostic_(on_diagnostic),
|
||||||
on_diagnostic_(on_diagnostic), on_dropped_(on_dropped),
|
on_dropped_(on_dropped), preloads(kMaxPreloadedSessions),
|
||||||
preloads(kMaxPreloadedSessions),
|
|
||||||
sessions(kMaxCompletionSessions),
|
sessions(kMaxCompletionSessions),
|
||||||
PCH(std::make_shared<PCHContainerOperations>()) {
|
PCH(std::make_shared<PCHContainerOperations>()) {
|
||||||
SpawnThread(ccls::CompletionMain, this);
|
SpawnThread(ccls::CompletionMain, this);
|
||||||
|
@ -192,8 +192,7 @@ void MessageHandler::ccls_call(Reader &reader, ReplyOnce &reply) {
|
|||||||
QueryFile *file = FindFile(reply, param.textDocument.uri.GetPath());
|
QueryFile *file = FindFile(reply, param.textDocument.uri.GetPath());
|
||||||
if (!file)
|
if (!file)
|
||||||
return;
|
return;
|
||||||
WorkingFile *working_file =
|
WorkingFile *working_file = wfiles->GetFileByFilename(file->def->path);
|
||||||
wfiles->GetFileByFilename(file->def->path);
|
|
||||||
for (SymbolRef sym :
|
for (SymbolRef sym :
|
||||||
FindSymbolsAtLocation(working_file, file, param.position)) {
|
FindSymbolsAtLocation(working_file, file, param.position)) {
|
||||||
if (sym.kind == SymbolKind::Func) {
|
if (sym.kind == SymbolKind::Func) {
|
||||||
|
@ -160,8 +160,7 @@ bool Expand(MessageHandler *m, Out_cclsMember *entry, bool qualified,
|
|||||||
Out_cclsMember entry1;
|
Out_cclsMember entry1;
|
||||||
entry1.fieldName = def1->Name(false);
|
entry1.fieldName = def1->Name(false);
|
||||||
if (def1->spell) {
|
if (def1->spell) {
|
||||||
if (auto loc =
|
if (auto loc = GetLsLocation(m->db, m->wfiles, *def1->spell))
|
||||||
GetLsLocation(m->db, m->wfiles, *def1->spell))
|
|
||||||
entry1.location = *loc;
|
entry1.location = *loc;
|
||||||
} else if (func1.declarations.size()) {
|
} else if (func1.declarations.size()) {
|
||||||
if (auto loc = GetLsLocation(m->db, m->wfiles,
|
if (auto loc = GetLsLocation(m->db, m->wfiles,
|
||||||
@ -181,8 +180,7 @@ bool Expand(MessageHandler *m, Out_cclsMember *entry, bool qualified,
|
|||||||
Out_cclsMember entry1;
|
Out_cclsMember entry1;
|
||||||
entry1.fieldName = def1->Name(false);
|
entry1.fieldName = def1->Name(false);
|
||||||
if (def1->spell) {
|
if (def1->spell) {
|
||||||
if (auto loc =
|
if (auto loc = GetLsLocation(m->db, m->wfiles, *def1->spell))
|
||||||
GetLsLocation(m->db, m->wfiles, *def1->spell))
|
|
||||||
entry1.location = *loc;
|
entry1.location = *loc;
|
||||||
} else if (type1.declarations.size()) {
|
} else if (type1.declarations.size()) {
|
||||||
if (auto loc = GetLsLocation(m->db, m->wfiles,
|
if (auto loc = GetLsLocation(m->db, m->wfiles,
|
||||||
|
@ -348,8 +348,7 @@ void *Indexer(void *arg_) {
|
|||||||
delete arg;
|
delete arg;
|
||||||
std::string name = "indexer" + std::to_string(idx);
|
std::string name = "indexer" + std::to_string(idx);
|
||||||
set_thread_name(name.c_str());
|
set_thread_name(name.c_str());
|
||||||
pipeline::Indexer_Main(h->clang_complete, h->vfs, h->project,
|
pipeline::Indexer_Main(h->clang_complete, h->vfs, h->project, h->wfiles);
|
||||||
h->wfiles);
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -89,8 +89,8 @@ void MessageHandler::textDocument_hover(TextDocumentPositionParam ¶m,
|
|||||||
Hover result;
|
Hover result;
|
||||||
|
|
||||||
for (SymbolRef sym : FindSymbolsAtLocation(wfile, file, param.position)) {
|
for (SymbolRef sym : FindSymbolsAtLocation(wfile, file, param.position)) {
|
||||||
std::optional<lsRange> ls_range = GetLsRange(
|
std::optional<lsRange> ls_range =
|
||||||
wfiles->GetFileByFilename(file->def->path), sym.range);
|
GetLsRange(wfiles->GetFileByFilename(file->def->path), sym.range);
|
||||||
if (!ls_range)
|
if (!ls_range)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -6,13 +6,12 @@
|
|||||||
|
|
||||||
namespace ccls {
|
namespace ccls {
|
||||||
namespace {
|
namespace {
|
||||||
lsWorkspaceEdit BuildWorkspaceEdit(DB *db, WorkingFiles *wfiles,
|
lsWorkspaceEdit BuildWorkspaceEdit(DB *db, WorkingFiles *wfiles, SymbolRef sym,
|
||||||
SymbolRef sym, const std::string &new_text) {
|
const std::string &new_text) {
|
||||||
std::unordered_map<int, lsTextDocumentEdit> path_to_edit;
|
std::unordered_map<int, lsTextDocumentEdit> path_to_edit;
|
||||||
|
|
||||||
EachOccurrence(db, sym, true, [&](Use use) {
|
EachOccurrence(db, sym, true, [&](Use use) {
|
||||||
std::optional<lsLocation> ls_location =
|
std::optional<lsLocation> ls_location = GetLsLocation(db, wfiles, use);
|
||||||
GetLsLocation(db, wfiles, use);
|
|
||||||
if (!ls_location)
|
if (!ls_location)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -388,8 +388,7 @@ void Main_OnIndexed(DB *db, WorkingFiles *wfiles, IndexUpdate *update) {
|
|||||||
// Update indexed content, skipped ranges, and semantic highlighting.
|
// Update indexed content, skipped ranges, and semantic highlighting.
|
||||||
if (update->files_def_update) {
|
if (update->files_def_update) {
|
||||||
auto &def_u = *update->files_def_update;
|
auto &def_u = *update->files_def_update;
|
||||||
if (WorkingFile *wfile =
|
if (WorkingFile *wfile = wfiles->GetFileByFilename(def_u.first.path)) {
|
||||||
wfiles->GetFileByFilename(def_u.first.path)) {
|
|
||||||
// FIXME With index.onChange: true, use buffer_content only for
|
// FIXME With index.onChange: true, use buffer_content only for
|
||||||
// request.path
|
// request.path
|
||||||
wfile->SetIndexContent(g_config->index.onChange ? wfile->buffer_content
|
wfile->SetIndexContent(g_config->index.onChange ? wfile->buffer_content
|
||||||
|
@ -60,9 +60,6 @@ template <typename T> void Notify(const char *method, T &result) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Reply(lsRequestId id, const std::function<void(Writer &)> &fn);
|
void Reply(lsRequestId id, const std::function<void(Writer &)> &fn);
|
||||||
template <typename T> void Reply(lsRequestId id, T &result) {
|
|
||||||
Reply(id, [&](Writer &w) { Reflect(w, result); });
|
|
||||||
}
|
|
||||||
|
|
||||||
void ReplyError(lsRequestId id, const std::function<void(Writer &)> &fn);
|
void ReplyError(lsRequestId id, const std::function<void(Writer &)> &fn);
|
||||||
template <typename T> void ReplyError(lsRequestId id, T &result) {
|
template <typename T> void ReplyError(lsRequestId id, T &result) {
|
||||||
|
@ -526,12 +526,13 @@ WorkingFiles::AsSnapshot(const std::vector<std::string> &filter_paths) {
|
|||||||
// text documents.
|
// text documents.
|
||||||
// We use a UTF-8 iterator to approximate UTF-16 in the specification (weird).
|
// We use a UTF-8 iterator to approximate UTF-16 in the specification (weird).
|
||||||
// This is good enough and fails only for UTF-16 surrogate pairs.
|
// This is good enough and fails only for UTF-16 surrogate pairs.
|
||||||
int GetOffsetForPosition(lsPosition position, std::string_view content) {
|
int GetOffsetForPosition(lsPosition pos, std::string_view content) {
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
for (; position.line > 0 && i < content.size(); i++)
|
for (; pos.line > 0 && i < content.size(); i++)
|
||||||
if (content[i] == '\n')
|
if (content[i] == '\n')
|
||||||
position.line--;
|
pos.line--;
|
||||||
for (; position.character > 0 && i < content.size(); position.character--)
|
for (; pos.character > 0 && i < content.size() && content[i] != '\n';
|
||||||
|
pos.character--)
|
||||||
if (uint8_t(content[i++]) >= 128) {
|
if (uint8_t(content[i++]) >= 128) {
|
||||||
// Skip 0b10xxxxxx
|
// Skip 0b10xxxxxx
|
||||||
while (i < content.size() && uint8_t(content[i]) >= 128 &&
|
while (i < content.size() && uint8_t(content[i]) >= 128 &&
|
||||||
|
@ -120,7 +120,7 @@ struct WorkingFiles {
|
|||||||
std::mutex files_mutex; // Protects |files|.
|
std::mutex files_mutex; // Protects |files|.
|
||||||
};
|
};
|
||||||
|
|
||||||
int GetOffsetForPosition(lsPosition position, std::string_view content);
|
int GetOffsetForPosition(lsPosition pos, std::string_view content);
|
||||||
|
|
||||||
std::string_view LexIdentifierAroundPos(lsPosition position,
|
std::string_view LexIdentifierAroundPos(lsPosition position,
|
||||||
std::string_view content);
|
std::string_view content);
|
||||||
|
Loading…
Reference in New Issue
Block a user