2018-08-21 05:27:52 +00:00
|
|
|
/* Copyright 2017-2018 ccls Authors
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
==============================================================================*/
|
|
|
|
|
2018-02-15 06:41:07 +00:00
|
|
|
#include "message_handler.h"
|
2018-05-28 00:50:02 +00:00
|
|
|
#include "pipeline.hh"
|
2018-02-15 06:41:07 +00:00
|
|
|
#include "query_utils.h"
|
2018-05-28 00:50:02 +00:00
|
|
|
using namespace ccls;
|
2018-02-15 06:41:07 +00:00
|
|
|
|
2018-09-03 02:11:10 +00:00
|
|
|
MAKE_REFLECT_STRUCT(QueryFile::Def, path, args, language, skipped_ranges,
|
|
|
|
dependencies);
|
2018-04-09 07:52:04 +00:00
|
|
|
|
2018-02-15 06:41:07 +00:00
|
|
|
namespace {
|
2018-03-31 03:16:33 +00:00
|
|
|
MethodType kMethodType = "$ccls/fileInfo";
|
2018-03-22 04:05:25 +00:00
|
|
|
|
2018-02-15 06:41:07 +00:00
|
|
|
struct lsDocumentSymbolParams {
|
|
|
|
lsTextDocumentIdentifier textDocument;
|
|
|
|
};
|
|
|
|
MAKE_REFLECT_STRUCT(lsDocumentSymbolParams, textDocument);
|
|
|
|
|
2018-03-31 03:16:33 +00:00
|
|
|
struct In_CclsFileInfo : public RequestInMessage {
|
2018-03-22 04:05:25 +00:00
|
|
|
MethodType GetMethodType() const override { return kMethodType; }
|
2018-02-15 06:41:07 +00:00
|
|
|
lsDocumentSymbolParams params;
|
|
|
|
};
|
2018-03-31 03:16:33 +00:00
|
|
|
MAKE_REFLECT_STRUCT(In_CclsFileInfo, id, params);
|
|
|
|
REGISTER_IN_MESSAGE(In_CclsFileInfo);
|
2018-02-15 06:41:07 +00:00
|
|
|
|
2018-03-31 03:16:33 +00:00
|
|
|
struct Out_CclsFileInfo : public lsOutMessage<Out_CclsFileInfo> {
|
2018-02-15 06:41:07 +00:00
|
|
|
lsRequestId id;
|
|
|
|
QueryFile::Def result;
|
|
|
|
};
|
2018-03-31 03:16:33 +00:00
|
|
|
MAKE_REFLECT_STRUCT(Out_CclsFileInfo, jsonrpc, id, result);
|
2018-02-15 06:41:07 +00:00
|
|
|
|
2018-03-31 03:16:33 +00:00
|
|
|
struct Handler_CclsFileInfo : BaseMessageHandler<In_CclsFileInfo> {
|
2018-03-22 04:05:25 +00:00
|
|
|
MethodType GetMethodType() const override { return kMethodType; }
|
2018-08-09 17:08:14 +00:00
|
|
|
void Run(In_CclsFileInfo *request) override {
|
|
|
|
QueryFile *file;
|
2018-02-15 06:41:07 +00:00
|
|
|
if (!FindFileOrFail(db, project, request->id,
|
|
|
|
request->params.textDocument.uri.GetPath(), &file)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-31 03:16:33 +00:00
|
|
|
Out_CclsFileInfo out;
|
2018-02-15 06:41:07 +00:00
|
|
|
out.id = request->id;
|
|
|
|
// Expose some fields of |QueryFile::Def|.
|
|
|
|
out.result.path = file->def->path;
|
|
|
|
out.result.args = file->def->args;
|
|
|
|
out.result.language = file->def->language;
|
|
|
|
out.result.includes = file->def->includes;
|
2018-07-06 00:53:33 +00:00
|
|
|
out.result.skipped_ranges = file->def->skipped_ranges;
|
2018-05-28 00:50:02 +00:00
|
|
|
pipeline::WriteStdout(kMethodType, out);
|
2018-02-15 06:41:07 +00:00
|
|
|
}
|
|
|
|
};
|
2018-03-31 03:16:33 +00:00
|
|
|
REGISTER_MESSAGE_HANDLER(Handler_CclsFileInfo);
|
2018-08-09 17:08:14 +00:00
|
|
|
} // namespace
|