Skip to content

Commit

Permalink
Fix LSP completion crashing on sceneless scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Razoric480 committed Aug 6, 2021
1 parent 8db0bd4 commit 6db17a5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
10 changes: 7 additions & 3 deletions modules/gdscript/language_server/gdscript_text_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,13 @@ 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);
script->reload(true);
Error error;
Ref<GDScript> script = ResourceLoader::load(path, "", false, &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) {
Expand Down
28 changes: 15 additions & 13 deletions modules/gdscript/language_server/gdscript_workspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,22 +517,24 @@ void GDScriptWorkspace::completion(const lsp::CompletionParams &p_params, List<S

Array stack;
Node *current = nullptr;
stack.push_back(owner_scene_node);

while (!stack.empty()) {
current = stack.pop_back();
Ref<GDScript> script = current->get_script();
if (script.is_valid() && script->get_path() == path) {
break;
}
for (int i = 0; i < current->get_child_count(); ++i) {
stack.push_back(current->get_child(i));
if (owner_scene_node) {
stack.push_back(owner_scene_node);
while (!stack.empty()) {
current = stack.pop_back();
Ref<GDScript> script = current->get_script();
if (script.is_valid() && script->get_path() == path) {
break;
}
for (int i = 0; i < current->get_child_count(); ++i) {
stack.push_back(current->get_child(i));
}
}
}

Ref<GDScript> script = current->get_script();
if (!script.is_valid() || script->get_path() != path) {
current = owner_scene_node;
Ref<GDScript> script = current->get_script();
if (!script.is_valid() || script->get_path() != path) {
current = owner_scene_node;
}
}

String code = parser->get_text_for_completion(p_params.position);
Expand Down

0 comments on commit 6db17a5

Please sign in to comment.