mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-24 08:35:08 +00:00
Add ReplyOnce::NotReady and error if didOpen is not seen
Use IgnoringDiagConsumer to override default TextDiagnosticPrinter
This commit is contained in:
parent
ab48663ca0
commit
872d7c5de9
@ -98,7 +98,8 @@ BuildCompilerInvocation(std::vector<const char *> args,
|
|||||||
std::string save = "-resource-dir=" + g_config->clang.resourceDir;
|
std::string save = "-resource-dir=" + g_config->clang.resourceDir;
|
||||||
args.push_back(save.c_str());
|
args.push_back(save.c_str());
|
||||||
IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
|
IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
|
||||||
CompilerInstance::createDiagnostics(new DiagnosticOptions));
|
CompilerInstance::createDiagnostics(new DiagnosticOptions,
|
||||||
|
new IgnoringDiagConsumer, true));
|
||||||
std::unique_ptr<CompilerInvocation> CI =
|
std::unique_ptr<CompilerInvocation> CI =
|
||||||
createInvocationFromCommandLine(args, Diags, VFS);
|
createInvocationFromCommandLine(args, Diags, VFS);
|
||||||
if (CI) {
|
if (CI) {
|
||||||
|
@ -107,6 +107,13 @@ struct ScanLineEvent {
|
|||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
void ReplyOnce::NotReady(bool file) {
|
||||||
|
if (file)
|
||||||
|
Error(ErrorCode::InvalidRequest, "not opened");
|
||||||
|
else
|
||||||
|
Error(ErrorCode::InternalError, "not indexed");
|
||||||
|
}
|
||||||
|
|
||||||
void MessageHandler::Bind(const char *method, void (MessageHandler::*handler)(Reader &)) {
|
void MessageHandler::Bind(const char *method, void (MessageHandler::*handler)(Reader &)) {
|
||||||
method2notification[method] = [this, handler](Reader &reader) {
|
method2notification[method] = [this, handler](Reader &reader) {
|
||||||
(this->*handler)(reader);
|
(this->*handler)(reader);
|
||||||
@ -220,14 +227,14 @@ void MessageHandler::Run(InMessage &msg) {
|
|||||||
try {
|
try {
|
||||||
it->second(reader);
|
it->second(reader);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
LOG_S(ERROR) << "failed to process " << msg.method;
|
ShowMessageParam param{MessageType::Error,
|
||||||
|
std::string("failed to process ") + msg.method};
|
||||||
|
pipeline::Notify(window_showMessage, param);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QueryFile *MessageHandler::FindFile(ReplyOnce &reply,
|
QueryFile *MessageHandler::FindFile(const std::string &path, int *out_file_id) {
|
||||||
const std::string &path,
|
|
||||||
int *out_file_id) {
|
|
||||||
QueryFile *ret = nullptr;
|
QueryFile *ret = nullptr;
|
||||||
auto it = db->name2file_id.find(LowerPathIfInsensitive(path));
|
auto it = db->name2file_id.find(LowerPathIfInsensitive(path));
|
||||||
if (it != db->name2file_id.end()) {
|
if (it != db->name2file_id.end()) {
|
||||||
@ -239,24 +246,8 @@ QueryFile *MessageHandler::FindFile(ReplyOnce &reply,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (out_file_id)
|
if (out_file_id)
|
||||||
*out_file_id = -1;
|
*out_file_id = -1;
|
||||||
|
|
||||||
if (reply.id.Valid()) {
|
|
||||||
bool has_entry = false;
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> lock(project->mutex_);
|
|
||||||
for (auto &[root, folder] : project->root2folder)
|
|
||||||
has_entry |= folder.path2entry_index.count(path);
|
|
||||||
}
|
|
||||||
ResponseError err;
|
|
||||||
if (has_entry)
|
|
||||||
reply.Error(ErrorCode::ServerNotInitialized, path + " is being indexed");
|
|
||||||
else
|
|
||||||
reply.Error(ErrorCode::InternalError, "unable to find " + path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,6 +202,7 @@ struct ReplyOnce {
|
|||||||
if (id.Valid())
|
if (id.Valid())
|
||||||
pipeline::ReplyError(id, [&](Writer &w) { Reflect(w, err); });
|
pipeline::ReplyError(id, [&](Writer &w) { Reflect(w, err); });
|
||||||
}
|
}
|
||||||
|
void NotReady(bool file);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MessageHandler {
|
struct MessageHandler {
|
||||||
@ -217,8 +218,7 @@ struct MessageHandler {
|
|||||||
|
|
||||||
MessageHandler();
|
MessageHandler();
|
||||||
void Run(InMessage &msg);
|
void Run(InMessage &msg);
|
||||||
QueryFile *FindFile(ReplyOnce &reply, const std::string &path,
|
QueryFile *FindFile(const std::string &path, int *out_file_id = nullptr);
|
||||||
int *out_file_id = nullptr);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Bind(const char *method, void (MessageHandler::*handler)(Reader &));
|
void Bind(const char *method, void (MessageHandler::*handler)(Reader &));
|
||||||
|
@ -200,7 +200,7 @@ void MessageHandler::ccls_call(Reader &reader, ReplyOnce &reply) {
|
|||||||
Expand(this, &*result, param.callee, param.callType, param.qualified,
|
Expand(this, &*result, param.callee, param.callType, param.qualified,
|
||||||
param.levels);
|
param.levels);
|
||||||
} else {
|
} else {
|
||||||
QueryFile *file = FindFile(reply, param.textDocument.uri.GetPath());
|
QueryFile *file = FindFile(param.textDocument.uri.GetPath());
|
||||||
WorkingFile *wf = file ? wfiles->GetFile(file->def->path) : nullptr;
|
WorkingFile *wf = file ? wfiles->GetFile(file->def->path) : nullptr;
|
||||||
if (!wf)
|
if (!wf)
|
||||||
return;
|
return;
|
||||||
|
@ -54,7 +54,7 @@ void MessageHandler::ccls_info(EmptyParam &, ReplyOnce &reply) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MessageHandler::ccls_fileInfo(TextDocumentParam ¶m, ReplyOnce &reply) {
|
void MessageHandler::ccls_fileInfo(TextDocumentParam ¶m, ReplyOnce &reply) {
|
||||||
QueryFile *file = FindFile(reply, param.textDocument.uri.GetPath());
|
QueryFile *file = FindFile(param.textDocument.uri.GetPath());
|
||||||
if (!file)
|
if (!file)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ void Inheritance(MessageHandler *m, Param ¶m, ReplyOnce &reply) {
|
|||||||
Expand(m, &*result, param.derived, param.qualified, param.levels)))
|
Expand(m, &*result, param.derived, param.qualified, param.levels)))
|
||||||
result.reset();
|
result.reset();
|
||||||
} else {
|
} else {
|
||||||
QueryFile *file = m->FindFile(reply, param.textDocument.uri.GetPath());
|
QueryFile *file = m->FindFile(param.textDocument.uri.GetPath());
|
||||||
if (!file)
|
if (!file)
|
||||||
return;
|
return;
|
||||||
WorkingFile *wf = m->wfiles->GetFile(file->def->path);
|
WorkingFile *wf = m->wfiles->GetFile(file->def->path);
|
||||||
|
@ -281,10 +281,12 @@ void MessageHandler::ccls_member(Reader &reader, ReplyOnce &reply) {
|
|||||||
param.levels, param.kind)))
|
param.levels, param.kind)))
|
||||||
result.reset();
|
result.reset();
|
||||||
} else {
|
} else {
|
||||||
QueryFile *file = FindFile(reply, param.textDocument.uri.GetPath());
|
QueryFile *file = FindFile(param.textDocument.uri.GetPath());
|
||||||
WorkingFile *wf = file ? wfiles->GetFile(file->def->path) : nullptr;
|
WorkingFile *wf = file ? wfiles->GetFile(file->def->path) : nullptr;
|
||||||
if (!wf)
|
if (!wf) {
|
||||||
|
reply.NotReady(file);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
for (SymbolRef sym : FindSymbolsAtLocation(wf, file, param.position)) {
|
for (SymbolRef sym : FindSymbolsAtLocation(wf, file, param.position)) {
|
||||||
switch (sym.kind) {
|
switch (sym.kind) {
|
||||||
case Kind::Func:
|
case Kind::Func:
|
||||||
|
@ -42,10 +42,12 @@ void MessageHandler::ccls_navigate(Reader &reader,
|
|||||||
ReplyOnce &reply) {
|
ReplyOnce &reply) {
|
||||||
Param param;
|
Param param;
|
||||||
Reflect(reader, param);
|
Reflect(reader, param);
|
||||||
QueryFile *file = FindFile(reply, param.textDocument.uri.GetPath());
|
QueryFile *file = FindFile(param.textDocument.uri.GetPath());
|
||||||
WorkingFile *wf = file ? wfiles->GetFile(file->def->path) : nullptr;
|
WorkingFile *wf = file ? wfiles->GetFile(file->def->path) : nullptr;
|
||||||
if (!wf)
|
if (!wf) {
|
||||||
|
reply.NotReady(file);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
Position ls_pos = param.position;
|
Position ls_pos = param.position;
|
||||||
if (wf->index_lines.size())
|
if (wf->index_lines.size())
|
||||||
if (auto line =
|
if (auto line =
|
||||||
|
@ -31,10 +31,12 @@ MAKE_REFLECT_STRUCT(Param, textDocument, position, kind);
|
|||||||
void MessageHandler::ccls_vars(Reader &reader, ReplyOnce &reply) {
|
void MessageHandler::ccls_vars(Reader &reader, ReplyOnce &reply) {
|
||||||
Param param;
|
Param param;
|
||||||
Reflect(reader, param);
|
Reflect(reader, param);
|
||||||
QueryFile *file = FindFile(reply, param.textDocument.uri.GetPath());
|
QueryFile *file = FindFile(param.textDocument.uri.GetPath());
|
||||||
WorkingFile *wf = file ? wfiles->GetFile(file->def->path) : nullptr;
|
WorkingFile *wf = file ? wfiles->GetFile(file->def->path) : nullptr;
|
||||||
if (!wf)
|
if (!wf) {
|
||||||
|
reply.NotReady(file);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<Location> result;
|
std::vector<Location> result;
|
||||||
for (SymbolRef sym : FindSymbolsAtLocation(wf, file, param.position)) {
|
for (SymbolRef sym : FindSymbolsAtLocation(wf, file, param.position)) {
|
||||||
|
@ -34,8 +34,10 @@ MAKE_REFLECT_STRUCT(CodeAction, title, kind, edit);
|
|||||||
void MessageHandler::textDocument_codeAction(CodeActionParam ¶m,
|
void MessageHandler::textDocument_codeAction(CodeActionParam ¶m,
|
||||||
ReplyOnce &reply) {
|
ReplyOnce &reply) {
|
||||||
WorkingFile *wf = wfiles->GetFile(param.textDocument.uri.GetPath());
|
WorkingFile *wf = wfiles->GetFile(param.textDocument.uri.GetPath());
|
||||||
if (!wf)
|
if (!wf) {
|
||||||
|
reply.NotReady(true);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
std::vector<CodeAction> result;
|
std::vector<CodeAction> result;
|
||||||
std::vector<Diagnostic> diagnostics;
|
std::vector<Diagnostic> diagnostics;
|
||||||
wfiles->WithLock([&]() { diagnostics = wf->diagnostics; });
|
wfiles->WithLock([&]() { diagnostics = wf->diagnostics; });
|
||||||
@ -92,15 +94,14 @@ struct CommonCodeLensParams {
|
|||||||
|
|
||||||
void MessageHandler::textDocument_codeLens(TextDocumentParam ¶m,
|
void MessageHandler::textDocument_codeLens(TextDocumentParam ¶m,
|
||||||
ReplyOnce &reply) {
|
ReplyOnce &reply) {
|
||||||
std::vector<CodeLens> result;
|
QueryFile *file = FindFile(param.textDocument.uri.GetPath());
|
||||||
std::string path = param.textDocument.uri.GetPath();
|
|
||||||
|
|
||||||
QueryFile *file = FindFile(reply, path);
|
|
||||||
WorkingFile *wf = file ? wfiles->GetFile(file->def->path) : nullptr;
|
WorkingFile *wf = file ? wfiles->GetFile(file->def->path) : nullptr;
|
||||||
if (!wf) {
|
if (!wf) {
|
||||||
|
reply.NotReady(file);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<CodeLens> result;
|
||||||
auto Add = [&](const char *singular, Cmd_xref show, Range range, int num,
|
auto Add = [&](const char *singular, Cmd_xref show, Range range, int num,
|
||||||
bool force_display = false) {
|
bool force_display = false) {
|
||||||
if (!num && !force_display)
|
if (!num && !force_display)
|
||||||
|
@ -449,13 +449,15 @@ public:
|
|||||||
void MessageHandler::textDocument_completion(CompletionParam ¶m,
|
void MessageHandler::textDocument_completion(CompletionParam ¶m,
|
||||||
ReplyOnce &reply) {
|
ReplyOnce &reply) {
|
||||||
static CompleteConsumerCache<std::vector<CompletionItem>> cache;
|
static CompleteConsumerCache<std::vector<CompletionItem>> cache;
|
||||||
CompletionList result;
|
|
||||||
std::string path = param.textDocument.uri.GetPath();
|
std::string path = param.textDocument.uri.GetPath();
|
||||||
WorkingFile *file = wfiles->GetFile(path);
|
WorkingFile *file = wfiles->GetFile(path);
|
||||||
if (!file) {
|
if (!file) {
|
||||||
|
reply.NotReady(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CompletionList result;
|
||||||
|
|
||||||
// It shouldn't be possible, but sometimes vscode will send queries out
|
// It shouldn't be possible, but sometimes vscode will send queries out
|
||||||
// of order, ie, we get completion request before buffer content update.
|
// of order, ie, we get completion request before buffer content update.
|
||||||
std::string buffer_line;
|
std::string buffer_line;
|
||||||
|
@ -48,10 +48,12 @@ std::vector<DeclRef> GetNonDefDeclarationTargets(DB *db, SymbolRef sym) {
|
|||||||
void MessageHandler::textDocument_definition(TextDocumentPositionParam ¶m,
|
void MessageHandler::textDocument_definition(TextDocumentPositionParam ¶m,
|
||||||
ReplyOnce &reply) {
|
ReplyOnce &reply) {
|
||||||
int file_id;
|
int file_id;
|
||||||
QueryFile *file = FindFile(reply, param.textDocument.uri.GetPath(), &file_id);
|
QueryFile *file = FindFile(param.textDocument.uri.GetPath(), &file_id);
|
||||||
WorkingFile *wf = file ? wfiles->GetFile(file->def->path) : nullptr;
|
WorkingFile *wf = file ? wfiles->GetFile(file->def->path) : nullptr;
|
||||||
if (!wf)
|
if (!wf) {
|
||||||
|
reply.NotReady(file);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<Location> result;
|
std::vector<Location> result;
|
||||||
Maybe<Use> on_def;
|
Maybe<Use> on_def;
|
||||||
@ -169,10 +171,12 @@ void MessageHandler::textDocument_definition(TextDocumentPositionParam ¶m,
|
|||||||
|
|
||||||
void MessageHandler::textDocument_typeDefinition(
|
void MessageHandler::textDocument_typeDefinition(
|
||||||
TextDocumentPositionParam ¶m, ReplyOnce &reply) {
|
TextDocumentPositionParam ¶m, ReplyOnce &reply) {
|
||||||
QueryFile *file = FindFile(reply, param.textDocument.uri.GetPath());
|
QueryFile *file = FindFile(param.textDocument.uri.GetPath());
|
||||||
if (!file)
|
WorkingFile *wf = file ? wfiles->GetFile(file->def->path) : nullptr;
|
||||||
|
if (!file) {
|
||||||
|
reply.NotReady(file);
|
||||||
return;
|
return;
|
||||||
WorkingFile *working_file = wfiles->GetFile(file->def->path);
|
}
|
||||||
|
|
||||||
std::vector<Location> result;
|
std::vector<Location> result;
|
||||||
auto Add = [&](const QueryType &type) {
|
auto Add = [&](const QueryType &type) {
|
||||||
@ -186,8 +190,7 @@ void MessageHandler::textDocument_typeDefinition(
|
|||||||
if (auto ls_loc = GetLsLocation(db, wfiles, dr))
|
if (auto ls_loc = GetLsLocation(db, wfiles, dr))
|
||||||
result.push_back(*ls_loc);
|
result.push_back(*ls_loc);
|
||||||
};
|
};
|
||||||
for (SymbolRef sym :
|
for (SymbolRef sym : FindSymbolsAtLocation(wf, file, param.position)) {
|
||||||
FindSymbolsAtLocation(working_file, file, param.position)) {
|
|
||||||
switch (sym.kind) {
|
switch (sym.kind) {
|
||||||
case Kind::Var: {
|
case Kind::Var: {
|
||||||
const QueryVar::Def *def = db->GetVar(sym).AnyDef();
|
const QueryVar::Def *def = db->GetVar(sym).AnyDef();
|
||||||
|
@ -44,8 +44,7 @@ void MessageHandler::textDocument_didOpen(DidOpenTextDocumentParam ¶m) {
|
|||||||
pipeline::LoadIndexedContent(path))
|
pipeline::LoadIndexedContent(path))
|
||||||
wf->SetIndexContent(*cached_file_contents);
|
wf->SetIndexContent(*cached_file_contents);
|
||||||
|
|
||||||
ReplyOnce reply;
|
QueryFile *file = FindFile(path);
|
||||||
QueryFile *file = FindFile(reply, path);
|
|
||||||
if (file) {
|
if (file) {
|
||||||
EmitSkippedRanges(wf, *file);
|
EmitSkippedRanges(wf, *file);
|
||||||
EmitSemanticHighlight(db, wf, *file);
|
EmitSemanticHighlight(db, wf, *file);
|
||||||
|
@ -44,10 +44,12 @@ MAKE_REFLECT_STRUCT(DocumentHighlight, range, kind, role);
|
|||||||
void MessageHandler::textDocument_documentHighlight(
|
void MessageHandler::textDocument_documentHighlight(
|
||||||
TextDocumentPositionParam ¶m, ReplyOnce &reply) {
|
TextDocumentPositionParam ¶m, ReplyOnce &reply) {
|
||||||
int file_id;
|
int file_id;
|
||||||
QueryFile *file = FindFile(reply, param.textDocument.uri.GetPath(), &file_id);
|
QueryFile *file = FindFile(param.textDocument.uri.GetPath(), &file_id);
|
||||||
WorkingFile *wf = file ? wfiles->GetFile(file->def->path) : nullptr;
|
WorkingFile *wf = file ? wfiles->GetFile(file->def->path) : nullptr;
|
||||||
if (!wf)
|
if (!wf) {
|
||||||
|
reply.NotReady(file);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<DocumentHighlight> result;
|
std::vector<DocumentHighlight> result;
|
||||||
std::vector<SymbolRef> syms =
|
std::vector<SymbolRef> syms =
|
||||||
@ -88,10 +90,10 @@ MAKE_REFLECT_STRUCT(DocumentLink, range, target);
|
|||||||
|
|
||||||
void MessageHandler::textDocument_documentLink(TextDocumentParam ¶m,
|
void MessageHandler::textDocument_documentLink(TextDocumentParam ¶m,
|
||||||
ReplyOnce &reply) {
|
ReplyOnce &reply) {
|
||||||
QueryFile *file = FindFile(reply, param.textDocument.uri.GetPath());
|
QueryFile *file = FindFile(param.textDocument.uri.GetPath());
|
||||||
WorkingFile *wf = file ? wfiles->GetFile(file->def->path) : nullptr;
|
WorkingFile *wf = file ? wfiles->GetFile(file->def->path) : nullptr;
|
||||||
if (!wf) {
|
if (!wf) {
|
||||||
reply.Error(ErrorCode::InternalError, "not opened");
|
reply.NotReady(file);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,10 +165,12 @@ void MessageHandler::textDocument_documentSymbol(Reader &reader,
|
|||||||
Reflect(reader, param);
|
Reflect(reader, param);
|
||||||
|
|
||||||
int file_id;
|
int file_id;
|
||||||
QueryFile *file = FindFile(reply, param.textDocument.uri.GetPath(), &file_id);
|
QueryFile *file = FindFile(param.textDocument.uri.GetPath(), &file_id);
|
||||||
WorkingFile *wf = file ? wfiles->GetFile(file->def->path) : nullptr;
|
WorkingFile *wf = file ? wfiles->GetFile(file->def->path) : nullptr;
|
||||||
if (!wf)
|
if (!wf) {
|
||||||
|
reply.NotReady(file);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (param.startLine >= 0) {
|
if (param.startLine >= 0) {
|
||||||
std::vector<lsRange> result;
|
std::vector<lsRange> result;
|
||||||
|
@ -31,19 +31,19 @@ MAKE_REFLECT_STRUCT(FoldingRange, startLine, startCharacter, endLine,
|
|||||||
|
|
||||||
void MessageHandler::textDocument_foldingRange(TextDocumentParam ¶m,
|
void MessageHandler::textDocument_foldingRange(TextDocumentParam ¶m,
|
||||||
ReplyOnce &reply) {
|
ReplyOnce &reply) {
|
||||||
QueryFile *file = FindFile(reply, param.textDocument.uri.GetPath());
|
QueryFile *file = FindFile(param.textDocument.uri.GetPath());
|
||||||
if (!file)
|
WorkingFile *wf = file ? wfiles->GetFile(file->def->path) : nullptr;
|
||||||
return;
|
if (!wf) {
|
||||||
WorkingFile *wfile = wfiles->GetFile(file->def->path);
|
reply.NotReady(file);
|
||||||
if (!wfile)
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
std::vector<FoldingRange> result;
|
std::vector<FoldingRange> result;
|
||||||
std::optional<lsRange> ls_range;
|
std::optional<lsRange> ls_range;
|
||||||
|
|
||||||
for (auto [sym, refcnt] : file->symbol2refcnt)
|
for (auto [sym, refcnt] : file->symbol2refcnt)
|
||||||
if (refcnt > 0 && sym.extent.Valid() &&
|
if (refcnt > 0 && sym.extent.Valid() &&
|
||||||
(sym.kind == Kind::Func || sym.kind == Kind::Type) &&
|
(sym.kind == Kind::Func || sym.kind == Kind::Type) &&
|
||||||
(ls_range = GetLsRange(wfile, sym.extent))) {
|
(ls_range = GetLsRange(wf, sym.extent))) {
|
||||||
FoldingRange &fold = result.emplace_back();
|
FoldingRange &fold = result.emplace_back();
|
||||||
fold.startLine = ls_range->start.line;
|
fold.startLine = ls_range->start.line;
|
||||||
fold.startCharacter = ls_range->start.character;
|
fold.startCharacter = ls_range->start.character;
|
||||||
|
@ -80,19 +80,23 @@ void Format(ReplyOnce &reply, WorkingFile *wfile, tooling::Range range) {
|
|||||||
|
|
||||||
void MessageHandler::textDocument_formatting(DocumentFormattingParam ¶m,
|
void MessageHandler::textDocument_formatting(DocumentFormattingParam ¶m,
|
||||||
ReplyOnce &reply) {
|
ReplyOnce &reply) {
|
||||||
QueryFile *file = FindFile(reply, param.textDocument.uri.GetPath());
|
QueryFile *file = FindFile(param.textDocument.uri.GetPath());
|
||||||
WorkingFile *wf = file ? wfiles->GetFile(file->def->path) : nullptr;
|
WorkingFile *wf = file ? wfiles->GetFile(file->def->path) : nullptr;
|
||||||
if (!wf)
|
if (!wf) {
|
||||||
|
reply.NotReady(file);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
Format(reply, wf, {0, (unsigned)wf->buffer_content.size()});
|
Format(reply, wf, {0, (unsigned)wf->buffer_content.size()});
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageHandler::textDocument_onTypeFormatting(
|
void MessageHandler::textDocument_onTypeFormatting(
|
||||||
DocumentOnTypeFormattingParam ¶m, ReplyOnce &reply) {
|
DocumentOnTypeFormattingParam ¶m, ReplyOnce &reply) {
|
||||||
QueryFile *file = FindFile(reply, param.textDocument.uri.GetPath());
|
QueryFile *file = FindFile(param.textDocument.uri.GetPath());
|
||||||
WorkingFile *wf = file ? wfiles->GetFile(file->def->path) : nullptr;
|
WorkingFile *wf = file ? wfiles->GetFile(file->def->path) : nullptr;
|
||||||
if (!wf)
|
if (!wf) {
|
||||||
|
reply.NotReady(file);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
std::string_view code = wf->buffer_content;
|
std::string_view code = wf->buffer_content;
|
||||||
int pos = GetOffsetForPosition(param.position, code);
|
int pos = GetOffsetForPosition(param.position, code);
|
||||||
auto lbrace = code.find_last_of('{', pos);
|
auto lbrace = code.find_last_of('{', pos);
|
||||||
@ -103,10 +107,12 @@ void MessageHandler::textDocument_onTypeFormatting(
|
|||||||
|
|
||||||
void MessageHandler::textDocument_rangeFormatting(
|
void MessageHandler::textDocument_rangeFormatting(
|
||||||
DocumentRangeFormattingParam ¶m, ReplyOnce &reply) {
|
DocumentRangeFormattingParam ¶m, ReplyOnce &reply) {
|
||||||
QueryFile *file = FindFile(reply, param.textDocument.uri.GetPath());
|
QueryFile *file = FindFile(param.textDocument.uri.GetPath());
|
||||||
WorkingFile *wf = file ? wfiles->GetFile(file->def->path) : nullptr;
|
WorkingFile *wf = file ? wfiles->GetFile(file->def->path) : nullptr;
|
||||||
if (!wf)
|
if (!wf) {
|
||||||
|
reply.NotReady(file);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
std::string_view code = wf->buffer_content;
|
std::string_view code = wf->buffer_content;
|
||||||
int begin = GetOffsetForPosition(param.range.start, code),
|
int begin = GetOffsetForPosition(param.range.start, code),
|
||||||
end = GetOffsetForPosition(param.range.end, code);
|
end = GetOffsetForPosition(param.range.end, code);
|
||||||
|
@ -93,12 +93,14 @@ GetHover(DB *db, LanguageId lang, SymbolRef sym, int file_id) {
|
|||||||
|
|
||||||
void MessageHandler::textDocument_hover(TextDocumentPositionParam ¶m,
|
void MessageHandler::textDocument_hover(TextDocumentPositionParam ¶m,
|
||||||
ReplyOnce &reply) {
|
ReplyOnce &reply) {
|
||||||
QueryFile *file = FindFile(reply, param.textDocument.uri.GetPath());
|
QueryFile *file = FindFile(param.textDocument.uri.GetPath());
|
||||||
WorkingFile *wf = file ? wfiles->GetFile(file->def->path) : nullptr;
|
WorkingFile *wf = file ? wfiles->GetFile(file->def->path) : nullptr;
|
||||||
if (!wf)
|
if (!wf) {
|
||||||
|
reply.NotReady(file);
|
||||||
return;
|
return;
|
||||||
Hover result;
|
}
|
||||||
|
|
||||||
|
Hover result;
|
||||||
for (SymbolRef sym : FindSymbolsAtLocation(wf, file, param.position)) {
|
for (SymbolRef sym : FindSymbolsAtLocation(wf, file, param.position)) {
|
||||||
std::optional<lsRange> ls_range =
|
std::optional<lsRange> ls_range =
|
||||||
GetLsRange(wfiles->GetFile(file->def->path), sym.range);
|
GetLsRange(wfiles->GetFile(file->def->path), sym.range);
|
||||||
|
@ -44,10 +44,13 @@ MAKE_REFLECT_STRUCT(ReferenceParam, textDocument, position, context, folders,
|
|||||||
void MessageHandler::textDocument_references(Reader &reader, ReplyOnce &reply) {
|
void MessageHandler::textDocument_references(Reader &reader, ReplyOnce &reply) {
|
||||||
ReferenceParam param;
|
ReferenceParam param;
|
||||||
Reflect(reader, param);
|
Reflect(reader, param);
|
||||||
QueryFile *file = FindFile(reply, param.textDocument.uri.GetPath());
|
QueryFile *file = FindFile(param.textDocument.uri.GetPath());
|
||||||
WorkingFile *wf = file ? wfiles->GetFile(file->def->path) : nullptr;
|
WorkingFile *wf = file ? wfiles->GetFile(file->def->path) : nullptr;
|
||||||
if (!wf)
|
if (!wf) {
|
||||||
|
reply.NotReady(file);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (auto &folder : param.folders)
|
for (auto &folder : param.folders)
|
||||||
EnsureEndsInSlash(folder);
|
EnsureEndsInSlash(folder);
|
||||||
std::vector<uint8_t> file_set = db->GetFileSet(param.folders);
|
std::vector<uint8_t> file_set = db->GetFileSet(param.folders);
|
||||||
|
@ -38,9 +38,9 @@ WorkspaceEdit BuildWorkspaceEdit(DB *db, WorkingFiles *wfiles, SymbolRef sym,
|
|||||||
const std::string &path = file.def->path;
|
const std::string &path = file.def->path;
|
||||||
path_to_edit[file_id].textDocument.uri = DocumentUri::FromPath(path);
|
path_to_edit[file_id].textDocument.uri = DocumentUri::FromPath(path);
|
||||||
|
|
||||||
WorkingFile *working_file = wfiles->GetFile(path);
|
WorkingFile *wf = wfiles->GetFile(path);
|
||||||
if (working_file)
|
if (wf)
|
||||||
path_to_edit[file_id].textDocument.version = working_file->version;
|
path_to_edit[file_id].textDocument.version = wf->version;
|
||||||
}
|
}
|
||||||
|
|
||||||
TextEdit &edit = path_to_edit[file_id].edits.emplace_back();
|
TextEdit &edit = path_to_edit[file_id].edits.emplace_back();
|
||||||
@ -56,10 +56,12 @@ WorkspaceEdit BuildWorkspaceEdit(DB *db, WorkingFiles *wfiles, SymbolRef sym,
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void MessageHandler::textDocument_rename(RenameParam ¶m, ReplyOnce &reply) {
|
void MessageHandler::textDocument_rename(RenameParam ¶m, ReplyOnce &reply) {
|
||||||
QueryFile *file = FindFile(reply, param.textDocument.uri.GetPath());
|
QueryFile *file = FindFile(param.textDocument.uri.GetPath());
|
||||||
WorkingFile *wf = file ? wfiles->GetFile(file->def->path) : nullptr;
|
WorkingFile *wf = file ? wfiles->GetFile(file->def->path) : nullptr;
|
||||||
if (!wf)
|
if (!wf) {
|
||||||
|
reply.NotReady(file);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
WorkspaceEdit result;
|
WorkspaceEdit result;
|
||||||
for (SymbolRef sym : FindSymbolsAtLocation(wf, file, param.position)) {
|
for (SymbolRef sym : FindSymbolsAtLocation(wf, file, param.position)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user