diff --git a/src/clang_complete.cc b/src/clang_complete.cc index 8c2e5eec..17da7123 100644 --- a/src/clang_complete.cc +++ b/src/clang_complete.cc @@ -417,7 +417,7 @@ void *CompletionMain(void *manager_) { DiagnosticConsumer DC; WorkingFiles::Snapshot snapshot = - manager->wfiles_->AsSnapshot({StripFileType(path)}); + manager->wfiles_->AsSnapshot({StripFileType(path)}); std::vector> Bufs; auto Clang = BuildCompilerInstance(*session, std::move(CI), FS, DC, preamble.get(), snapshot, Bufs); @@ -574,13 +574,11 @@ std::shared_ptr CompletionSession::GetPreamble() { return preamble; } -CompletionManager::CompletionManager(Project *project, - WorkingFiles *wfiles, +CompletionManager::CompletionManager(Project *project, WorkingFiles *wfiles, OnDiagnostic on_diagnostic, OnDropped on_dropped) - : project_(project), wfiles_(wfiles), - on_diagnostic_(on_diagnostic), on_dropped_(on_dropped), - preloads(kMaxPreloadedSessions), + : project_(project), wfiles_(wfiles), on_diagnostic_(on_diagnostic), + on_dropped_(on_dropped), preloads(kMaxPreloadedSessions), sessions(kMaxCompletionSessions), PCH(std::make_shared()) { SpawnThread(ccls::CompletionMain, this); diff --git a/src/messages/ccls_call.cc b/src/messages/ccls_call.cc index f22ee46b..14766d2c 100644 --- a/src/messages/ccls_call.cc +++ b/src/messages/ccls_call.cc @@ -204,8 +204,7 @@ void MessageHandler::ccls_call(Reader &reader, ReplyOnce &reply) { QueryFile *file = FindFile(reply, param.textDocument.uri.GetPath()); if (!file) return; - WorkingFile *working_file = - wfiles->GetFileByFilename(file->def->path); + WorkingFile *working_file = wfiles->GetFileByFilename(file->def->path); for (SymbolRef sym : FindSymbolsAtLocation(working_file, file, param.position)) { if (sym.kind == SymbolKind::Func) { diff --git a/src/messages/ccls_member.cc b/src/messages/ccls_member.cc index c39fe790..45c8fd82 100644 --- a/src/messages/ccls_member.cc +++ b/src/messages/ccls_member.cc @@ -145,13 +145,13 @@ bool Expand(MessageHandler *m, Out_cclsMember *entry, bool qualified, if (def1 && def1->spell) { // The declaration of target type. if (std::optional loc = - GetLsLocation(m->db, m->wfiles, *def1->spell)) + GetLsLocation(m->db, m->wfiles, *def1->spell)) entry1.location = *loc; } else if (def->spell) { // Builtin types have no declaration but the typedef declaration // itself is useful. if (std::optional loc = - GetLsLocation(m->db, m->wfiles, *def->spell)) + GetLsLocation(m->db, m->wfiles, *def->spell)) entry1.location = *loc; } if (def1 && qualified) @@ -172,8 +172,7 @@ bool Expand(MessageHandler *m, Out_cclsMember *entry, bool qualified, Out_cclsMember entry1; entry1.fieldName = def1->Name(false); if (def1->spell) { - if (auto loc = - GetLsLocation(m->db, m->wfiles, *def1->spell)) + if (auto loc = GetLsLocation(m->db, m->wfiles, *def1->spell)) entry1.location = *loc; } else if (func1.declarations.size()) { if (auto loc = GetLsLocation(m->db, m->wfiles, @@ -193,12 +192,11 @@ bool Expand(MessageHandler *m, Out_cclsMember *entry, bool qualified, Out_cclsMember entry1; entry1.fieldName = def1->Name(false); if (def1->spell) { - if (auto loc = - GetLsLocation(m->db, m->wfiles, *def1->spell)) + if (auto loc = GetLsLocation(m->db, m->wfiles, *def1->spell)) entry1.location = *loc; } else if (type1.declarations.size()) { if (auto loc = GetLsLocation(m->db, m->wfiles, - type1.declarations[0])) + type1.declarations[0])) entry1.location = *loc; } entry->children.push_back(std::move(entry1)); diff --git a/src/messages/initialize.cc b/src/messages/initialize.cc index 1d5b7e70..ccc80e9c 100644 --- a/src/messages/initialize.cc +++ b/src/messages/initialize.cc @@ -360,8 +360,7 @@ void *Indexer(void *arg_) { delete arg; std::string name = "indexer" + std::to_string(idx); set_thread_name(name.c_str()); - pipeline::Indexer_Main(h->clang_complete, h->vfs, h->project, - h->wfiles); + pipeline::Indexer_Main(h->clang_complete, h->vfs, h->project, h->wfiles); return nullptr; } } // namespace diff --git a/src/messages/textDocument_hover.cc b/src/messages/textDocument_hover.cc index 044e822b..907de2e2 100644 --- a/src/messages/textDocument_hover.cc +++ b/src/messages/textDocument_hover.cc @@ -101,8 +101,8 @@ void MessageHandler::textDocument_hover(TextDocumentPositionParam ¶m, Hover result; for (SymbolRef sym : FindSymbolsAtLocation(wfile, file, param.position)) { - std::optional ls_range = GetLsRange( - wfiles->GetFileByFilename(file->def->path), sym.range); + std::optional ls_range = + GetLsRange(wfiles->GetFileByFilename(file->def->path), sym.range); if (!ls_range) continue; diff --git a/src/messages/textDocument_rename.cc b/src/messages/textDocument_rename.cc index 84cefa50..836847dd 100644 --- a/src/messages/textDocument_rename.cc +++ b/src/messages/textDocument_rename.cc @@ -18,13 +18,12 @@ limitations under the License. namespace ccls { namespace { -lsWorkspaceEdit BuildWorkspaceEdit(DB *db, WorkingFiles *wfiles, - SymbolRef sym, const std::string &new_text) { +lsWorkspaceEdit BuildWorkspaceEdit(DB *db, WorkingFiles *wfiles, SymbolRef sym, + const std::string &new_text) { std::unordered_map path_to_edit; EachOccurrence(db, sym, true, [&](Use use) { - std::optional ls_location = - GetLsLocation(db, wfiles, use); + std::optional ls_location = GetLsLocation(db, wfiles, use); if (!ls_location) return; diff --git a/src/pipeline.cc b/src/pipeline.cc index 867ccf18..40873b2f 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -400,8 +400,7 @@ void Main_OnIndexed(DB *db, WorkingFiles *wfiles, IndexUpdate *update) { // Update indexed content, skipped ranges, and semantic highlighting. if (update->files_def_update) { auto &def_u = *update->files_def_update; - if (WorkingFile *wfile = - wfiles->GetFileByFilename(def_u.first.path)) { + if (WorkingFile *wfile = wfiles->GetFileByFilename(def_u.first.path)) { // FIXME With index.onChange: true, use buffer_content only for // request.path wfile->SetIndexContent(g_config->index.onChange ? wfile->buffer_content diff --git a/src/pipeline.hh b/src/pipeline.hh index 6bd4d4d4..494f8707 100644 --- a/src/pipeline.hh +++ b/src/pipeline.hh @@ -57,9 +57,6 @@ template void Notify(const char *method, T &result) { } void Reply(lsRequestId id, const std::function &fn); -template void Reply(lsRequestId id, T &result) { - Reply(id, [&](Writer &w) { Reflect(w, result); }); -} void ReplyError(lsRequestId id, const std::function &fn); template void ReplyError(lsRequestId id, T &result) { diff --git a/src/working_files.cc b/src/working_files.cc index 5d6cbaaa..8f793935 100644 --- a/src/working_files.cc +++ b/src/working_files.cc @@ -538,12 +538,13 @@ WorkingFiles::AsSnapshot(const std::vector &filter_paths) { // text documents. // 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. -int GetOffsetForPosition(lsPosition position, std::string_view content) { +int GetOffsetForPosition(lsPosition pos, std::string_view content) { size_t i = 0; - for (; position.line > 0 && i < content.size(); i++) + for (; pos.line > 0 && i < content.size(); i++) if (content[i] == '\n') - position.line--; - for (; position.character > 0 && i < content.size(); position.character--) + pos.line--; + for (; pos.character > 0 && i < content.size() && content[i] != '\n'; + pos.character--) if (uint8_t(content[i++]) >= 128) { // Skip 0b10xxxxxx while (i < content.size() && uint8_t(content[i]) >= 128 && diff --git a/src/working_files.hh b/src/working_files.hh index 52339c9a..0824ecee 100644 --- a/src/working_files.hh +++ b/src/working_files.hh @@ -132,7 +132,7 @@ struct WorkingFiles { 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 content);