You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-12-31 18:41:20 +00:00
LSP: Rework management of client owned files
This commit is contained in:
@@ -63,29 +63,21 @@ void GDScriptTextDocument::_bind_methods() {
|
||||
}
|
||||
|
||||
void GDScriptTextDocument::didOpen(const Variant &p_param) {
|
||||
LSP::TextDocumentItem doc = load_document_item(p_param);
|
||||
sync_script_content(doc.uri, doc.text);
|
||||
}
|
||||
|
||||
void GDScriptTextDocument::didClose(const Variant &p_param) {
|
||||
// Left empty on purpose. Godot does nothing special on closing a document,
|
||||
// but it satisfies LSP clients that require didClose be implemented.
|
||||
GDScriptLanguageProtocol::get_singleton()->lsp_did_open(p_param);
|
||||
}
|
||||
|
||||
void GDScriptTextDocument::didChange(const Variant &p_param) {
|
||||
LSP::TextDocumentItem doc = load_document_item(p_param);
|
||||
Dictionary dict = p_param;
|
||||
Array contentChanges = dict["contentChanges"];
|
||||
for (int i = 0; i < contentChanges.size(); ++i) {
|
||||
LSP::TextDocumentContentChangeEvent evt;
|
||||
evt.load(contentChanges[i]);
|
||||
doc.text = evt.text;
|
||||
}
|
||||
sync_script_content(doc.uri, doc.text);
|
||||
GDScriptLanguageProtocol::get_singleton()->lsp_did_change(p_param);
|
||||
}
|
||||
|
||||
void GDScriptTextDocument::didClose(const Variant &p_param) {
|
||||
GDScriptLanguageProtocol::get_singleton()->lsp_did_close(p_param);
|
||||
}
|
||||
|
||||
void GDScriptTextDocument::willSaveWaitUntil(const Variant &p_param) {
|
||||
LSP::TextDocumentItem doc = load_document_item(p_param);
|
||||
Dictionary dict = p_param;
|
||||
LSP::TextDocumentIdentifier doc;
|
||||
doc.load(dict["textDocument"]);
|
||||
|
||||
String path = GDScriptLanguageProtocol::get_singleton()->get_workspace()->get_file_path(doc.uri);
|
||||
Ref<Script> scr = ResourceLoader::load(path);
|
||||
@@ -95,12 +87,11 @@ void GDScriptTextDocument::willSaveWaitUntil(const Variant &p_param) {
|
||||
}
|
||||
|
||||
void GDScriptTextDocument::didSave(const Variant &p_param) {
|
||||
LSP::TextDocumentItem doc = load_document_item(p_param);
|
||||
Dictionary dict = p_param;
|
||||
LSP::TextDocumentIdentifier doc;
|
||||
doc.load(dict["textDocument"]);
|
||||
String text = dict["text"];
|
||||
|
||||
sync_script_content(doc.uri, text);
|
||||
|
||||
String path = GDScriptLanguageProtocol::get_singleton()->get_workspace()->get_file_path(doc.uri);
|
||||
Ref<GDScript> scr = ResourceLoader::load(path);
|
||||
if (scr.is_valid() && (scr->load_source_code(path) == OK)) {
|
||||
@@ -126,13 +117,6 @@ void GDScriptTextDocument::reload_script(Ref<GDScript> p_to_reload_script) {
|
||||
ScriptEditor::get_singleton()->trigger_live_script_reload(p_to_reload_script->get_path());
|
||||
}
|
||||
|
||||
LSP::TextDocumentItem GDScriptTextDocument::load_document_item(const Variant &p_param) {
|
||||
LSP::TextDocumentItem doc;
|
||||
Dictionary params = p_param;
|
||||
doc.load(params["textDocument"]);
|
||||
return doc;
|
||||
}
|
||||
|
||||
void GDScriptTextDocument::notify_client_show_symbol(const LSP::DocumentSymbol *symbol) {
|
||||
ERR_FAIL_NULL(symbol);
|
||||
GDScriptLanguageProtocol::get_singleton()->notify_client("gdscript/show_native_symbol", symbol->to_json(true));
|
||||
@@ -172,8 +156,10 @@ Array GDScriptTextDocument::documentSymbol(const Dictionary &p_params) {
|
||||
String uri = params["uri"];
|
||||
String path = GDScriptLanguageProtocol::get_singleton()->get_workspace()->get_file_path(uri);
|
||||
Array arr;
|
||||
if (HashMap<String, ExtendGDScriptParser *>::ConstIterator parser = GDScriptLanguageProtocol::get_singleton()->get_workspace()->scripts.find(path)) {
|
||||
LSP::DocumentSymbol symbol = parser->value->get_symbols();
|
||||
|
||||
ExtendGDScriptParser *parser = GDScriptLanguageProtocol::get_singleton()->get_parse_result(path);
|
||||
if (parser) {
|
||||
LSP::DocumentSymbol symbol = parser->get_symbols();
|
||||
arr.push_back(symbol.to_json(true));
|
||||
}
|
||||
return arr;
|
||||
@@ -324,8 +310,9 @@ Dictionary GDScriptTextDocument::resolve(const Dictionary &p_params) {
|
||||
}
|
||||
|
||||
if (!symbol) {
|
||||
if (HashMap<String, ExtendGDScriptParser *>::ConstIterator E = GDScriptLanguageProtocol::get_singleton()->get_workspace()->scripts.find(class_name)) {
|
||||
symbol = E->value->get_member_symbol(member_name, inner_class_name);
|
||||
ExtendGDScriptParser *parser = GDScriptLanguageProtocol::get_singleton()->get_parse_result(class_name);
|
||||
if (parser) {
|
||||
symbol = parser->get_member_symbol(member_name, inner_class_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -396,7 +383,7 @@ Variant GDScriptTextDocument::hover(const Dictionary &p_params) {
|
||||
Dictionary ret;
|
||||
Array contents;
|
||||
List<const LSP::DocumentSymbol *> list;
|
||||
GDScriptLanguageProtocol::get_singleton()->get_workspace()->resolve_related_symbols(params, list);
|
||||
GDScriptLanguageProtocol::get_singleton()->resolve_related_symbols(params, list);
|
||||
for (const LSP::DocumentSymbol *&E : list) {
|
||||
if (const LSP::DocumentSymbol *s = E) {
|
||||
contents.push_back(s->render().value);
|
||||
@@ -473,11 +460,6 @@ GDScriptTextDocument::GDScriptTextDocument() {
|
||||
file_checker = FileAccess::create(FileAccess::ACCESS_RESOURCES);
|
||||
}
|
||||
|
||||
void GDScriptTextDocument::sync_script_content(const String &p_path, const String &p_content) {
|
||||
String path = GDScriptLanguageProtocol::get_singleton()->get_workspace()->get_file_path(p_path);
|
||||
GDScriptLanguageProtocol::get_singleton()->get_workspace()->parse_script(path, p_content);
|
||||
}
|
||||
|
||||
void GDScriptTextDocument::show_native_symbol_in_editor(const String &p_symbol_id) {
|
||||
callable_mp(ScriptEditor::get_singleton(), &ScriptEditor::goto_help).call_deferred(p_symbol_id);
|
||||
|
||||
@@ -500,7 +482,7 @@ Array GDScriptTextDocument::find_symbols(const LSP::TextDocumentPositionParams &
|
||||
r_list.push_back(symbol);
|
||||
} else if (GDScriptLanguageProtocol::get_singleton()->is_smart_resolve_enabled()) {
|
||||
List<const LSP::DocumentSymbol *> list;
|
||||
GDScriptLanguageProtocol::get_singleton()->get_workspace()->resolve_related_symbols(p_location, list);
|
||||
GDScriptLanguageProtocol::get_singleton()->resolve_related_symbols(p_location, list);
|
||||
for (const LSP::DocumentSymbol *&E : list) {
|
||||
if (const LSP::DocumentSymbol *s = E) {
|
||||
if (!s->uri.is_empty()) {
|
||||
|
||||
Reference in New Issue
Block a user