2018-09-28 05:16:42 +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-29 04:21:21 +00:00
|
|
|
#include "include_complete.hh"
|
2018-10-28 17:49:31 +00:00
|
|
|
#include "message_handler.hh"
|
2018-09-28 05:16:42 +00:00
|
|
|
#include "pipeline.hh"
|
2018-10-28 17:49:31 +00:00
|
|
|
#include "project.hh"
|
2018-12-01 06:44:52 +00:00
|
|
|
#include "sema_manager.hh"
|
2018-10-29 04:21:21 +00:00
|
|
|
#include "working_files.hh"
|
2018-09-28 05:16:42 +00:00
|
|
|
|
2018-10-28 17:49:31 +00:00
|
|
|
namespace ccls {
|
|
|
|
void MessageHandler::textDocument_didChange(TextDocumentDidChangeParam ¶m) {
|
|
|
|
std::string path = param.textDocument.uri.GetPath();
|
2018-10-29 04:21:21 +00:00
|
|
|
wfiles->OnChange(param);
|
2018-10-28 17:49:31 +00:00
|
|
|
if (g_config->index.onChange)
|
2018-12-21 04:53:50 +00:00
|
|
|
pipeline::Index(path, {}, IndexMode::OnChange, true);
|
2018-12-01 06:44:52 +00:00
|
|
|
manager->OnView(path);
|
2018-10-28 17:49:31 +00:00
|
|
|
if (g_config->diagnostics.onChange >= 0)
|
2018-12-01 06:44:52 +00:00
|
|
|
manager->ScheduleDiag(path, g_config->diagnostics.onChange);
|
2018-10-28 17:49:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MessageHandler::textDocument_didClose(TextDocumentParam ¶m) {
|
|
|
|
std::string path = param.textDocument.uri.GetPath();
|
2018-12-01 06:44:52 +00:00
|
|
|
wfiles->OnClose(path);
|
|
|
|
manager->OnClose(path);
|
2018-10-28 17:49:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MessageHandler::textDocument_didOpen(DidOpenTextDocumentParam ¶m) {
|
|
|
|
std::string path = param.textDocument.uri.GetPath();
|
2018-12-01 06:44:52 +00:00
|
|
|
WorkingFile *wf = wfiles->OnOpen(param.textDocument);
|
2018-10-28 17:49:31 +00:00
|
|
|
if (std::optional<std::string> cached_file_contents =
|
|
|
|
pipeline::LoadIndexedContent(path))
|
2018-12-01 06:44:52 +00:00
|
|
|
wf->SetIndexContent(*cached_file_contents);
|
2018-10-28 17:49:31 +00:00
|
|
|
|
2018-12-02 00:55:51 +00:00
|
|
|
QueryFile *file = FindFile(path);
|
2018-10-28 17:49:31 +00:00
|
|
|
if (file) {
|
2018-12-01 06:44:52 +00:00
|
|
|
EmitSkippedRanges(wf, *file);
|
|
|
|
EmitSemanticHighlight(db, wf, *file);
|
2018-09-28 05:16:42 +00:00
|
|
|
}
|
2018-12-01 06:44:52 +00:00
|
|
|
include_complete->AddFile(wf->filename);
|
2018-09-28 05:16:42 +00:00
|
|
|
|
2018-10-28 17:49:31 +00:00
|
|
|
// Submit new index request if it is not a header file or there is no
|
|
|
|
// pending index request.
|
2018-12-28 20:30:15 +00:00
|
|
|
auto [lang, header] = lookupExtension(path);
|
|
|
|
if ((lang != LanguageId::Unknown && !header) ||
|
2018-10-28 17:49:31 +00:00
|
|
|
!pipeline::pending_index_requests)
|
2018-12-21 04:53:50 +00:00
|
|
|
pipeline::Index(path, {}, IndexMode::Normal, false);
|
2018-12-28 20:30:15 +00:00
|
|
|
if (header)
|
|
|
|
project->IndexRelated(path);
|
2018-09-28 05:16:42 +00:00
|
|
|
|
2018-12-01 06:44:52 +00:00
|
|
|
manager->OnView(path);
|
2018-10-28 17:49:31 +00:00
|
|
|
}
|
2018-09-28 05:16:42 +00:00
|
|
|
|
2018-10-28 17:49:31 +00:00
|
|
|
void MessageHandler::textDocument_didSave(TextDocumentParam ¶m) {
|
|
|
|
const std::string &path = param.textDocument.uri.GetPath();
|
2018-12-21 04:53:50 +00:00
|
|
|
pipeline::Index(path, {}, IndexMode::Normal, false);
|
2018-12-01 06:44:52 +00:00
|
|
|
manager->OnSave(path);
|
2018-10-28 17:49:31 +00:00
|
|
|
}
|
|
|
|
} // namespace ccls
|