| 112 | } |
| 113 | |
| 114 | PackedStringArray get_code_completion(CompletionKind p_kind, const String &p_script_file) { |
| 115 | PackedStringArray suggestions; |
| 116 | |
| 117 | switch (p_kind) { |
| 118 | case CompletionKind::INPUT_ACTIONS: { |
| 119 | List<PropertyInfo> project_props; |
| 120 | ProjectSettings::get_singleton()->get_property_list(&project_props); |
| 121 | |
| 122 | for (const PropertyInfo &prop : project_props) { |
| 123 | if (!prop.name.begins_with("input/")) { |
| 124 | continue; |
| 125 | } |
| 126 | |
| 127 | String name = prop.name.substr(prop.name.find_char('/') + 1); |
| 128 | suggestions.push_back(quoted(name)); |
| 129 | } |
| 130 | } break; |
| 131 | case CompletionKind::NODE_PATHS: { |
| 132 | { |
| 133 | // Autoloads. |
| 134 | HashMap<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list(); |
| 135 | |
| 136 | for (const KeyValue<StringName, ProjectSettings::AutoloadInfo> &E : autoloads) { |
| 137 | const ProjectSettings::AutoloadInfo &info = E.value; |
| 138 | suggestions.push_back(quoted("/root/" + String(info.name))); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | { |
| 143 | // Current edited scene tree |
| 144 | Ref<Script> script = ResourceLoader::load(p_script_file.simplify_path()); |
| 145 | Node *base = _try_find_owner_node_in_tree(script); |
| 146 | if (base) { |
| 147 | _add_nodes_suggestions(base, base, suggestions); |
| 148 | } |
| 149 | } |
| 150 | } break; |
| 151 | case CompletionKind::RESOURCE_PATHS: { |
| 152 | if (bool(EDITOR_GET("text_editor/completion/complete_file_paths"))) { |
| 153 | _get_directory_contents(EditorFileSystem::get_singleton()->get_filesystem(), suggestions); |
| 154 | } |
| 155 | } break; |
| 156 | case CompletionKind::SCENE_PATHS: { |
| 157 | Ref<DirAccess> dir_access = DirAccess::create(DirAccess::ACCESS_RESOURCES); |
| 158 | List<String> directories; |
| 159 | directories.push_back(dir_access->get_current_dir()); |
| 160 | |
| 161 | while (!directories.is_empty()) { |
| 162 | dir_access->change_dir(directories.back()->get()); |
| 163 | directories.pop_back(); |
| 164 | |
| 165 | dir_access->list_dir_begin(); |
| 166 | String filename = dir_access->get_next(); |
| 167 | |
| 168 | while (!filename.is_empty()) { |
| 169 | if (filename == "." || filename == "..") { |
| 170 | filename = dir_access->get_next(); |
| 171 | continue; |
no test coverage detected