Remove issue where diagnostics would disappear file saves.

Also allow rebuilding of completion session by closing and reopening a
file.
This commit is contained in:
Jacob Dufault 2017-10-17 11:43:33 -07:00
parent 809a55a351
commit a6807dcb8c
3 changed files with 30 additions and 1 deletions

View File

@ -303,6 +303,12 @@ void EnsureDocumentParsed(ClangCompleteManager* manager,
// Build diagnostics. // Build diagnostics.
if (manager->config_->diagnosticsOnParse && !(*tu)->did_fail) { if (manager->config_->diagnosticsOnParse && !(*tu)->did_fail) {
// If we're emitting diagnostics, do an immedaite reparse, otherwise we will
// emit stale/bad diagnostics.
clang_reparseTranslationUnit(
(*tu)->cx_tu, unsaved.size(), unsaved.data(),
clang_defaultReparseOptions((*tu)->cx_tu));
NonElidedVector<lsDiagnostic> ls_diagnostics; NonElidedVector<lsDiagnostic> ls_diagnostics;
unsigned num_diagnostics = clang_getNumDiagnostics((*tu)->cx_tu); unsigned num_diagnostics = clang_getNumDiagnostics((*tu)->cx_tu);
for (unsigned i = 0; i < num_diagnostics; ++i) { for (unsigned i = 0; i < num_diagnostics; ++i) {
@ -360,9 +366,10 @@ void CompletionQueryMain(ClangCompleteManager* completion_manager) {
completion_manager->TryGetSession(path, true /*create_if_needed*/); completion_manager->TryGetSession(path, true /*create_if_needed*/);
std::lock_guard<std::mutex> lock(session->tu_lock); std::lock_guard<std::mutex> lock(session->tu_lock);
Timer timer;
EnsureDocumentParsed(completion_manager, session, &session->tu, EnsureDocumentParsed(completion_manager, session, &session->tu,
&session->index); &session->index);
Timer timer; timer.ResetAndPrint("[complete] EnsureDocumentParsed");
std::vector<CXUnsavedFile> unsaved = std::vector<CXUnsavedFile> unsaved =
completion_manager->working_files_->AsUnsavedFiles(); completion_manager->working_files_->AsUnsavedFiles();
@ -631,6 +638,23 @@ void ClangCompleteManager::NotifySave(const std::string& filename) {
parse_requests_.PriorityEnqueue(ParseRequest(filename)); parse_requests_.PriorityEnqueue(ParseRequest(filename));
} }
void ClangCompleteManager::NotifyClose(const std::string& filename) {
//
// On close, we clear any existing CompletionSession instance.
//
std::lock_guard<std::mutex> lock(sessions_lock_);
// Take and drop. It's okay if we don't actually drop the file, it'll
// eventually get pushed out of the caches as the user opens other files.
auto view_ptr = view_sessions_.TryTakeEntry(filename);
LOG_IF_S(INFO, !!view_ptr)
<< "Dropped view-based code completion session for " << filename;
auto edit_ptr = edit_sessions_.TryTakeEntry(filename);
LOG_IF_S(INFO, !!edit_ptr)
<< "Dropped edit-based code completion session for " << filename;
}
std::shared_ptr<CompletionSession> ClangCompleteManager::TryGetSession( std::shared_ptr<CompletionSession> ClangCompleteManager::TryGetSession(
const std::string& filename, const std::string& filename,
bool create_if_needed) { bool create_if_needed) {

View File

@ -95,6 +95,9 @@ struct ClangCompleteManager {
// Notify the completion manager that |filename| has been saved. This // Notify the completion manager that |filename| has been saved. This
// triggers a reparse. // triggers a reparse.
void NotifySave(const std::string& filename); void NotifySave(const std::string& filename);
// Notify the completion manager that |filename| has been closed. Any existing
// completion session will be dropped.
void NotifyClose(const std::string& filename);
std::shared_ptr<CompletionSession> TryGetSession(const std::string& filename, std::shared_ptr<CompletionSession> TryGetSession(const std::string& filename,
bool create_if_needed); bool create_if_needed);

View File

@ -1765,6 +1765,7 @@ bool QueryDbMainLoop(Config* config,
case IpcId::TextDocumentDidClose: { case IpcId::TextDocumentDidClose: {
auto msg = message->As<Ipc_TextDocumentDidClose>(); auto msg = message->As<Ipc_TextDocumentDidClose>();
std::string path = msg->params.textDocument.uri.GetPath();
// Clear any diagnostics for the file. // Clear any diagnostics for the file.
Out_TextDocumentPublishDiagnostics diag; Out_TextDocumentPublishDiagnostics diag;
@ -1774,6 +1775,7 @@ bool QueryDbMainLoop(Config* config,
// Remove internal state. // Remove internal state.
working_files->OnClose(msg->params); working_files->OnClose(msg->params);
clang_complete->NotifyClose(path);
break; break;
} }