2018-10-24 03:48:12 +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-10-28 17:49:31 +00:00
|
|
|
#include "message_handler.hh"
|
2018-10-24 03:48:12 +00:00
|
|
|
#include "pipeline.hh"
|
2018-10-28 17:49:31 +00:00
|
|
|
#include "project.hh"
|
2018-11-27 06:29:28 +00:00
|
|
|
#include "query.hh"
|
2018-10-29 04:21:21 +00:00
|
|
|
#include "working_files.hh"
|
2018-10-24 03:48:12 +00:00
|
|
|
|
|
|
|
namespace ccls {
|
|
|
|
namespace {
|
|
|
|
struct FoldingRange {
|
|
|
|
int startLine, startCharacter, endLine, endCharacter;
|
|
|
|
std::string kind = "region";
|
|
|
|
};
|
2018-10-28 17:49:31 +00:00
|
|
|
MAKE_REFLECT_STRUCT(FoldingRange, startLine, startCharacter, endLine,
|
|
|
|
endCharacter, kind);
|
2018-10-24 03:48:12 +00:00
|
|
|
} // namespace
|
2018-10-28 17:49:31 +00:00
|
|
|
|
|
|
|
void MessageHandler::textDocument_foldingRange(TextDocumentParam ¶m,
|
|
|
|
ReplyOnce &reply) {
|
|
|
|
QueryFile *file = FindFile(reply, param.textDocument.uri.GetPath());
|
|
|
|
if (!file)
|
|
|
|
return;
|
2018-12-01 06:44:52 +00:00
|
|
|
WorkingFile *wfile = wfiles->GetFile(file->def->path);
|
2018-10-28 17:49:31 +00:00
|
|
|
if (!wfile)
|
|
|
|
return;
|
|
|
|
std::vector<FoldingRange> result;
|
|
|
|
std::optional<lsRange> ls_range;
|
|
|
|
|
|
|
|
for (auto [sym, refcnt] : file->symbol2refcnt)
|
|
|
|
if (refcnt > 0 && sym.extent.Valid() &&
|
2018-11-03 20:52:43 +00:00
|
|
|
(sym.kind == Kind::Func || sym.kind == Kind::Type) &&
|
2018-10-28 17:49:31 +00:00
|
|
|
(ls_range = GetLsRange(wfile, sym.extent))) {
|
|
|
|
FoldingRange &fold = result.emplace_back();
|
|
|
|
fold.startLine = ls_range->start.line;
|
|
|
|
fold.startCharacter = ls_range->start.character;
|
|
|
|
fold.endLine = ls_range->end.line;
|
|
|
|
fold.endCharacter = ls_range->end.character;
|
|
|
|
}
|
|
|
|
reply(result);
|
|
|
|
}
|
2018-10-24 03:48:12 +00:00
|
|
|
} // namespace ccls
|