2017-03-26 06:47:59 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "language_server_api.h"
|
2017-04-09 19:38:52 +00:00
|
|
|
#include "utils.h"
|
2017-03-26 06:47:59 +00:00
|
|
|
|
2017-03-26 21:40:34 +00:00
|
|
|
#include <clang-c/Index.h>
|
2017-04-16 08:09:12 +00:00
|
|
|
#include <optional.h>
|
2017-03-26 21:40:34 +00:00
|
|
|
|
2017-05-10 04:52:15 +00:00
|
|
|
#include <mutex>
|
2017-03-26 21:40:34 +00:00
|
|
|
#include <string>
|
|
|
|
|
2017-04-16 08:09:12 +00:00
|
|
|
using std::experimental::optional;
|
|
|
|
using std::experimental::nullopt;
|
2017-04-09 19:38:52 +00:00
|
|
|
|
2017-05-29 21:18:35 +00:00
|
|
|
// Utility method to map |position| to an offset inside of |content|.
|
|
|
|
int GetOffsetForPosition(lsPosition position, const std::string& content);
|
|
|
|
// Utility method to find a position for the given character.
|
|
|
|
lsPosition CharPos(const std::string& search, char character, int character_offset = 0);
|
|
|
|
|
2017-04-16 08:09:12 +00:00
|
|
|
struct WorkingFile {
|
2017-04-14 08:21:03 +00:00
|
|
|
int version = 0;
|
2017-03-26 21:40:34 +00:00
|
|
|
std::string filename;
|
|
|
|
|
2017-04-16 08:09:12 +00:00
|
|
|
std::string buffer_content;
|
|
|
|
// Note: This assumes 0-based lines (1-based lines are normally assumed).
|
|
|
|
std::vector<std::string> index_lines;
|
|
|
|
// Note: This assumes 0-based lines (1-based lines are normally assumed).
|
|
|
|
std::vector<std::string> all_buffer_lines;
|
2017-04-19 07:52:48 +00:00
|
|
|
// This map goes from disk-line -> indicies+1 in index_lines.
|
|
|
|
// Note: The items in the value entry are 1-based lines.
|
|
|
|
std::unordered_map<std::string, std::vector<int>> index_lines_lookup;
|
|
|
|
// This map goes from buffer-line -> indices+1 in all_buffer_lines.
|
|
|
|
// Note: The items in the value entry are 1-based liness.
|
|
|
|
std::unordered_map<std::string, std::vector<int>> all_buffer_lines_lookup;
|
2017-05-20 19:31:07 +00:00
|
|
|
// A set of diagnostics that have been reported for this file.
|
|
|
|
std::vector<lsDiagnostic> diagnostics;
|
2017-04-19 07:52:48 +00:00
|
|
|
|
2017-04-16 08:09:12 +00:00
|
|
|
WorkingFile(const std::string& filename, const std::string& buffer_content);
|
2017-04-09 19:38:52 +00:00
|
|
|
|
2017-04-16 08:09:12 +00:00
|
|
|
// This should be called when the indexed content has changed.
|
|
|
|
void SetIndexContent(const std::string& index_content);
|
|
|
|
// This should be called whenever |buffer_content| has changed.
|
|
|
|
void OnBufferContentUpdated();
|
2017-04-09 19:38:52 +00:00
|
|
|
|
2017-04-16 08:09:12 +00:00
|
|
|
// Find the buffer-line which should be shown for |indexed_line|. This
|
|
|
|
// accepts and returns 1-based lines.
|
2017-04-19 07:52:48 +00:00
|
|
|
optional<int> GetBufferLineFromIndexLine(int indexed_line) const;
|
|
|
|
// Find the indexed-line which should be shown for |buffer_line|. This
|
|
|
|
// accepts and returns 1-based lines.
|
|
|
|
optional<int> GetIndexLineFromBufferLine(int buffer_line) const;
|
2017-04-09 19:38:52 +00:00
|
|
|
|
2017-05-21 04:30:59 +00:00
|
|
|
optional<std::string> GetBufferLineContentFromIndexLine(int indexed_line, optional<int>* out_buffer_line) const;
|
|
|
|
|
2017-05-15 07:28:53 +00:00
|
|
|
// Finds the closest 'callable' name prior to position. This is used for
|
|
|
|
// signature help to filter code completion results.
|
|
|
|
//
|
|
|
|
// |completion_position| will be point to a good code completion location to
|
|
|
|
// for fetching signatures.
|
|
|
|
std::string FindClosestCallNameInBuffer(lsPosition position, int* active_parameter, lsPosition* completion_position = nullptr) const;
|
|
|
|
|
2017-05-20 08:07:29 +00:00
|
|
|
// Returns a relatively stable completion position (it jumps back until there
|
|
|
|
// is a non-alphanumeric character).
|
2017-05-26 07:10:55 +00:00
|
|
|
//
|
|
|
|
// The out param |is_global_completion| is set to true if this looks like a
|
|
|
|
// global completion.
|
|
|
|
lsPosition FindStableCompletionSource(lsPosition position, bool* is_global_completion) const;
|
2017-05-20 08:07:29 +00:00
|
|
|
|
2017-04-16 08:09:12 +00:00
|
|
|
CXUnsavedFile AsUnsavedFile() const;
|
2017-03-26 21:40:34 +00:00
|
|
|
};
|
|
|
|
|
2017-03-26 06:47:59 +00:00
|
|
|
struct WorkingFiles {
|
2017-05-10 04:52:15 +00:00
|
|
|
//
|
|
|
|
// :: IMPORTANT :: All methods in this class are guarded by a single lock.
|
|
|
|
//
|
|
|
|
|
2017-03-26 21:40:34 +00:00
|
|
|
// Find the file with the given filename.
|
|
|
|
WorkingFile* GetFileByFilename(const std::string& filename);
|
2017-05-10 04:52:15 +00:00
|
|
|
WorkingFile* GetFileByFilenameNoLock(const std::string& filename);
|
|
|
|
|
2017-04-21 06:32:18 +00:00
|
|
|
WorkingFile* OnOpen(const Ipc_TextDocumentDidOpen::Params& open);
|
2017-03-26 21:40:34 +00:00
|
|
|
void OnChange(const Ipc_TextDocumentDidChange::Params& change);
|
|
|
|
void OnClose(const Ipc_TextDocumentDidClose::Params& close);
|
|
|
|
|
2017-05-10 04:52:15 +00:00
|
|
|
std::vector<CXUnsavedFile> AsUnsavedFiles();
|
2017-03-26 06:47:59 +00:00
|
|
|
|
2017-03-26 21:40:34 +00:00
|
|
|
// Use unique_ptrs so we can handout WorkingFile ptrs and not have them
|
|
|
|
// invalidated if we resize files.
|
|
|
|
std::vector<std::unique_ptr<WorkingFile>> files;
|
2017-05-10 04:52:15 +00:00
|
|
|
std::mutex files_mutex; // Protects |files|.
|
2017-03-26 06:47:59 +00:00
|
|
|
};
|