LSP: Rework management of client owned files
This commit is contained in:
parent
ccf414ecb4
commit
4cc88e5175
11 changed files with 346 additions and 259 deletions
|
|
@ -41,9 +41,15 @@
|
|||
#define LSP_MAX_BUFFER_SIZE 4194304
|
||||
#define LSP_MAX_CLIENTS 8
|
||||
|
||||
#define LSP_NO_CLIENT -1
|
||||
|
||||
class GDScriptLanguageProtocol : public JSONRPC {
|
||||
GDCLASS(GDScriptLanguageProtocol, JSONRPC)
|
||||
|
||||
#ifdef TESTS_ENABLED
|
||||
friend class TestGDScriptLanguageProtocolInitializer;
|
||||
#endif
|
||||
|
||||
private:
|
||||
struct LSPeer : RefCounted {
|
||||
Ref<StreamPeerTCP> connection;
|
||||
|
|
@ -58,6 +64,24 @@ private:
|
|||
|
||||
Error handle_data();
|
||||
Error send_data();
|
||||
|
||||
/**
|
||||
* Tracks all files that the client claimed, however for files deemed not relevant
|
||||
* to the server the `text` might not be persisted.
|
||||
*/
|
||||
HashMap<String, LSP::TextDocumentItem> managed_files;
|
||||
HashMap<String, ExtendGDScriptParser *> parse_results;
|
||||
|
||||
void remove_cached_parser(const String &p_path);
|
||||
ExtendGDScriptParser *parse_script(const String &p_path);
|
||||
|
||||
~LSPeer();
|
||||
|
||||
private:
|
||||
// We can't cache parsers for scripts not managed by the editor since we have
|
||||
// no way to invalidate the cache. We still need to keep track of those parsers
|
||||
// to clean them up properly.
|
||||
HashMap<String, ExtendGDScriptParser *> stale_parsers;
|
||||
};
|
||||
|
||||
enum LSPErrorCode {
|
||||
|
|
@ -69,7 +93,7 @@ private:
|
|||
|
||||
HashMap<int, Ref<LSPeer>> clients;
|
||||
Ref<TCPServer> server;
|
||||
int latest_client_id = 0;
|
||||
int latest_client_id = LSP_NO_CLIENT;
|
||||
int next_client_id = 0;
|
||||
|
||||
int next_server_id = 0;
|
||||
|
|
@ -107,5 +131,27 @@ public:
|
|||
bool is_smart_resolve_enabled() const;
|
||||
bool is_goto_native_symbols_enabled() const;
|
||||
|
||||
// Text Document Synchronization
|
||||
void lsp_did_open(const Dictionary &p_params);
|
||||
void lsp_did_change(const Dictionary &p_params);
|
||||
void lsp_did_close(const Dictionary &p_params);
|
||||
|
||||
/**
|
||||
* Returns a list of symbols that might be related to the document position.
|
||||
*
|
||||
* The result fulfills no semantic guarantees, nor is it guaranteed to be complete.
|
||||
* Should only be used for "smart resolve".
|
||||
*/
|
||||
void resolve_related_symbols(const LSP::TextDocumentPositionParams &p_doc_pos, List<const LSP::DocumentSymbol *> &r_list);
|
||||
|
||||
/**
|
||||
* Returns parse results for the given path, using the cache if available.
|
||||
* If no such file exists, or the file is not a GDScript file a `nullptr` is returned.
|
||||
*/
|
||||
ExtendGDScriptParser *get_parse_result(const String &p_path);
|
||||
|
||||
GDScriptLanguageProtocol();
|
||||
~GDScriptLanguageProtocol() {
|
||||
clients.clear();
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue