Fix LSP completion crashing on scene-less scripts

This commit is contained in:
Francois Belair 2021-08-06 14:55:05 -04:00
parent 18c5d862e4
commit 070d634966
2 changed files with 22 additions and 16 deletions

View file

@ -431,10 +431,14 @@ void GDScriptTextDocument::sync_script_content(const String &p_path, const Strin
GDScriptLanguageProtocol::get_singleton()->get_workspace()->parse_script(path, p_content);
EditorFileSystem::get_singleton()->update_file(path);
Ref<GDScript> script = ResourceLoader::load(path);
script->load_source_code(path);
Error error;
Ref<GDScript> script = ResourceLoader::load(path, "", ResourceFormatLoader::CACHE_MODE_REUSE, &error);
if (error == OK) {
if (script->load_source_code(path) == OK) {
script->reload(true);
}
}
}
void GDScriptTextDocument::show_native_symbol_in_editor(const String &p_symbol_id) {
ScriptEditor::get_singleton()->call_deferred(SNAME("_help_class_goto"), p_symbol_id);

View file

@ -523,6 +523,7 @@ void GDScriptWorkspace::completion(const lsp::CompletionParams &p_params, List<S
Array stack;
Node *current = nullptr;
if (owner_scene_node != nullptr) {
stack.push_back(owner_scene_node);
while (!stack.is_empty()) {
@ -540,6 +541,7 @@ void GDScriptWorkspace::completion(const lsp::CompletionParams &p_params, List<S
if (!script.is_valid() || script->get_path() != path) {
current = owner_scene_node;
}
}
String code = parser->get_text_for_completion(p_params.position);
GDScriptLanguage::get_singleton()->complete_code(code, path, current, r_options, forced, call_hint);