ccls/src/messages/textDocument_didSave.cc

56 lines
1.9 KiB
C++
Raw Normal View History

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.
==============================================================================*/
#include "clang_complete.hh"
2017-12-06 03:32:33 +00:00
#include "message_handler.h"
2018-05-28 00:50:02 +00:00
#include "pipeline.hh"
2018-08-09 17:08:14 +00:00
#include "project.h"
2018-05-28 00:50:02 +00:00
using namespace ccls;
2017-12-06 03:32:33 +00:00
namespace {
MethodType kMethodType = "textDocument/didSave";
2018-03-22 05:01:21 +00:00
struct In_TextDocumentDidSave : public NotificationInMessage {
MethodType GetMethodType() const override { return kMethodType; }
2017-12-06 04:39:44 +00:00
struct Params {
// The document that was saved.
lsTextDocumentIdentifier textDocument;
// Optional the content when saved. Depends on the includeText value
// when the save notifcation was requested.
// std::string text;
} params;
2017-12-06 04:39:44 +00:00
};
MAKE_REFLECT_STRUCT(In_TextDocumentDidSave::Params, textDocument);
MAKE_REFLECT_STRUCT(In_TextDocumentDidSave, params);
REGISTER_IN_MESSAGE(In_TextDocumentDidSave);
struct Handler_TextDocumentDidSave
: BaseMessageHandler<In_TextDocumentDidSave> {
MethodType GetMethodType() const override { return kMethodType; }
2017-12-06 04:39:44 +00:00
2018-08-09 17:08:14 +00:00
void Run(In_TextDocumentDidSave *request) override {
const auto &params = request->params;
2018-05-28 00:50:02 +00:00
std::string path = params.textDocument.uri.GetPath();
2017-12-07 01:00:19 +00:00
Project::Entry entry = project->FindCompilationEntryForFile(path);
pipeline::Index(entry.filename, entry.args, IndexMode::Normal);
2017-12-06 03:32:33 +00:00
clang_complete->NotifySave(path);
}
};
REGISTER_MESSAGE_HANDLER(Handler_TextDocumentDidSave);
2018-08-09 17:08:14 +00:00
} // namespace