2017-04-17 01:22:59 +00:00
|
|
|
#include "atomic_object.h"
|
2017-03-26 21:40:34 +00:00
|
|
|
#include "language_server_api.h"
|
|
|
|
#include "libclangmm/Index.h"
|
|
|
|
#include "libclangmm/TranslationUnit.h"
|
|
|
|
#include "project.h"
|
|
|
|
#include "working_files.h"
|
|
|
|
|
|
|
|
#include <clang-c/Index.h>
|
|
|
|
|
2017-04-17 01:22:59 +00:00
|
|
|
#include <functional>
|
2017-05-10 04:52:15 +00:00
|
|
|
#include <mutex>
|
2017-04-17 01:22:59 +00:00
|
|
|
|
2017-05-21 19:51:15 +00:00
|
|
|
// TODO: rename this file to clang_completion.h/cc
|
|
|
|
|
2017-03-26 21:40:34 +00:00
|
|
|
struct CompletionSession {
|
2017-04-20 05:01:36 +00:00
|
|
|
Project::Entry file;
|
2017-05-10 04:52:15 +00:00
|
|
|
WorkingFiles* working_files;
|
|
|
|
|
|
|
|
// Acquired when the session is being used.
|
|
|
|
std::mutex usage_lock;
|
2017-03-26 21:40:34 +00:00
|
|
|
|
|
|
|
// The active translation unit.
|
|
|
|
std::unique_ptr<clang::TranslationUnit> active;
|
|
|
|
std::unique_ptr<clang::Index> active_index;
|
|
|
|
|
|
|
|
// Updated translation unit. If |is_updated_ready| is true, then |updated|
|
|
|
|
// contains more recent state than |active| and the two should be swapped.
|
2017-05-10 04:52:15 +00:00
|
|
|
//
|
2017-03-26 21:40:34 +00:00
|
|
|
// TODO: implement this. Needs changes in Refresh and CodeComplete.
|
|
|
|
//bool is_updated_ready = false;
|
|
|
|
//std::unique_ptr<clang::TranslationUnit> updated;
|
|
|
|
//std::unique_ptr<clang::Index> updated_index;
|
|
|
|
|
2017-04-26 04:03:22 +00:00
|
|
|
CompletionSession(const Project::Entry& file, WorkingFiles* working_files);
|
2017-03-26 21:40:34 +00:00
|
|
|
~CompletionSession();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CompletionManager {
|
|
|
|
std::vector<std::unique_ptr<CompletionSession>> sessions;
|
2017-05-21 19:51:15 +00:00
|
|
|
Config* config;
|
2017-03-26 21:40:34 +00:00
|
|
|
Project* project;
|
|
|
|
WorkingFiles* working_files;
|
|
|
|
|
2017-05-20 06:35:14 +00:00
|
|
|
using OnComplete = std::function<void(NonElidedVector<lsCompletionItem> results, NonElidedVector<lsDiagnostic> diagnostics)>;
|
2017-05-11 06:25:41 +00:00
|
|
|
|
2017-04-17 01:22:59 +00:00
|
|
|
struct CompletionRequest {
|
|
|
|
lsTextDocumentPositionParams location;
|
|
|
|
OnComplete on_complete;
|
|
|
|
};
|
2017-05-10 04:52:15 +00:00
|
|
|
|
2017-04-17 01:22:59 +00:00
|
|
|
AtomicObject<CompletionRequest> completion_request;
|
|
|
|
|
2017-05-11 06:25:41 +00:00
|
|
|
// Request that the given path be reparsed.
|
|
|
|
AtomicObject<std::string> reparse_request;
|
|
|
|
|
2017-05-21 19:51:15 +00:00
|
|
|
CompletionManager(Config* config, Project* project, WorkingFiles* working_files);
|
2017-03-26 21:40:34 +00:00
|
|
|
|
2017-04-17 01:22:59 +00:00
|
|
|
// Start a code completion at the given location. |on_complete| will run when
|
|
|
|
// completion results are available. |on_complete| may run on any thread.
|
|
|
|
void CodeComplete(const lsTextDocumentPositionParams& completion_location, const OnComplete& on_complete);
|
2017-03-26 21:40:34 +00:00
|
|
|
|
|
|
|
CompletionSession* GetOrOpenSession(const std::string& filename);
|
2017-05-11 06:25:41 +00:00
|
|
|
|
|
|
|
// Set the new active session. We will drop clang state for all other
|
|
|
|
// sessions and begin reparsing the session for |filename| to ensure
|
|
|
|
// completions are always fast.
|
|
|
|
void UpdateActiveSession(const std::string& filename);
|
2017-03-26 21:40:34 +00:00
|
|
|
};
|