mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-23 08:05:07 +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
@ -406,7 +406,7 @@ void *CompletionMain(void *manager_) {
|
||||
|
||||
DiagnosticConsumer DC;
|
||||
WorkingFiles::Snapshot snapshot =
|
||||
manager->wfiles_->AsSnapshot({StripFileType(path)});
|
||||
manager->wfiles_->AsSnapshot({StripFileType(path)});
|
||||
std::vector<std::unique_ptr<llvm::MemoryBuffer>> Bufs;
|
||||
auto Clang = BuildCompilerInstance(*session, std::move(CI), FS, DC,
|
||||
preamble.get(), snapshot, Bufs);
|
||||
@ -563,13 +563,11 @@ std::shared_ptr<PreambleData> 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<PCHContainerOperations>()) {
|
||||
SpawnThread(ccls::CompletionMain, this);
|
||||
|
@ -192,8 +192,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) {
|
||||
|
@ -133,13 +133,13 @@ bool Expand(MessageHandler *m, Out_cclsMember *entry, bool qualified,
|
||||
if (def1 && def1->spell) {
|
||||
// The declaration of target type.
|
||||
if (std::optional<lsLocation> 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<lsLocation> loc =
|
||||
GetLsLocation(m->db, m->wfiles, *def->spell))
|
||||
GetLsLocation(m->db, m->wfiles, *def->spell))
|
||||
entry1.location = *loc;
|
||||
}
|
||||
if (def1 && qualified)
|
||||
@ -160,8 +160,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,
|
||||
@ -181,12 +180,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));
|
||||
|
@ -348,8 +348,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
|
||||
|
@ -89,8 +89,8 @@ void MessageHandler::textDocument_hover(TextDocumentPositionParam ¶m,
|
||||
Hover result;
|
||||
|
||||
for (SymbolRef sym : FindSymbolsAtLocation(wfile, file, param.position)) {
|
||||
std::optional<lsRange> ls_range = GetLsRange(
|
||||
wfiles->GetFileByFilename(file->def->path), sym.range);
|
||||
std::optional<lsRange> ls_range =
|
||||
GetLsRange(wfiles->GetFileByFilename(file->def->path), sym.range);
|
||||
if (!ls_range)
|
||||
continue;
|
||||
|
||||
|
@ -6,13 +6,12 @@
|
||||
|
||||
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<int, lsTextDocumentEdit> path_to_edit;
|
||||
|
||||
EachOccurrence(db, sym, true, [&](Use use) {
|
||||
std::optional<lsLocation> ls_location =
|
||||
GetLsLocation(db, wfiles, use);
|
||||
std::optional<lsLocation> ls_location = GetLsLocation(db, wfiles, use);
|
||||
if (!ls_location)
|
||||
return;
|
||||
|
||||
|
@ -388,8 +388,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
|
||||
|
@ -60,9 +60,6 @@ template <typename T> void Notify(const char *method, T &result) {
|
||||
}
|
||||
|
||||
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);
|
||||
template <typename T> void ReplyError(lsRequestId id, T &result) {
|
||||
|
@ -526,12 +526,13 @@ WorkingFiles::AsSnapshot(const std::vector<std::string> &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 &&
|
||||
|
@ -120,7 +120,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);
|
||||
|
Loading…
Reference in New Issue
Block a user