ccls/src/messages/workspace_didChangeWatchedFiles.cc

80 lines
2.6 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"
#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-01-26 07:04:07 +00:00
#include "working_files.h"
2018-05-28 00:50:02 +00:00
using namespace ccls;
2018-01-26 07:04:07 +00:00
namespace {
MethodType kMethodType = "workspace/didChangeWatchedFiles";
enum class lsFileChangeType {
Created = 1,
Changed = 2,
Deleted = 3,
};
2018-01-30 00:35:01 +00:00
MAKE_REFLECT_TYPE_PROXY(lsFileChangeType);
struct lsFileEvent {
lsDocumentUri uri;
lsFileChangeType type;
};
MAKE_REFLECT_STRUCT(lsFileEvent, uri, type);
struct lsDidChangeWatchedFilesParams {
std::vector<lsFileEvent> changes;
};
MAKE_REFLECT_STRUCT(lsDidChangeWatchedFilesParams, changes);
2018-03-22 05:01:21 +00:00
struct In_WorkspaceDidChangeWatchedFiles : public NotificationInMessage {
MethodType GetMethodType() const override { return kMethodType; }
lsDidChangeWatchedFilesParams params;
};
MAKE_REFLECT_STRUCT(In_WorkspaceDidChangeWatchedFiles, params);
REGISTER_IN_MESSAGE(In_WorkspaceDidChangeWatchedFiles);
struct Handler_WorkspaceDidChangeWatchedFiles
: BaseMessageHandler<In_WorkspaceDidChangeWatchedFiles> {
MethodType GetMethodType() const override { return kMethodType; }
2018-08-09 17:08:14 +00:00
void Run(In_WorkspaceDidChangeWatchedFiles *request) override {
for (lsFileEvent &event : request->params.changes) {
2018-01-26 07:04:07 +00:00
std::string path = event.uri.GetPath();
2018-09-16 23:32:06 +00:00
IndexMode mode = working_files->GetFileByFilename(path)
? IndexMode::Normal
: IndexMode::NonInteractive;
switch (event.type) {
2018-08-09 17:08:14 +00:00
case lsFileChangeType::Created:
case lsFileChangeType::Changed: {
2018-09-16 23:32:06 +00:00
pipeline::Index(path, {}, mode);
if (mode == IndexMode::Normal)
2018-08-09 17:08:14 +00:00
clang_complete->NotifySave(path);
2018-09-16 23:32:06 +00:00
else
clang_complete->FlushSession(path);
2018-08-09 17:08:14 +00:00
break;
}
case lsFileChangeType::Deleted:
2018-09-16 23:32:06 +00:00
pipeline::Index(path, {}, mode);
clang_complete->FlushSession(path);
2018-08-09 17:08:14 +00:00
break;
}
}
}
};
REGISTER_MESSAGE_HANDLER(Handler_WorkspaceDidChangeWatchedFiles);
2018-08-09 17:08:14 +00:00
} // namespace