| 2200 | } |
| 2201 | |
| 2202 | void CodeEdit::request_code_completion(bool p_force) { |
| 2203 | if (GDVIRTUAL_CALL(_request_code_completion, p_force)) { |
| 2204 | return; |
| 2205 | } |
| 2206 | |
| 2207 | /* Don't re-query if all existing options are quoted types, eg path, signal. */ |
| 2208 | bool ignored = code_completion_active && !code_completion_options.is_empty(); |
| 2209 | if (ignored) { |
| 2210 | ScriptLanguage::CodeCompletionKind kind = ScriptLanguage::CODE_COMPLETION_KIND_PLAIN_TEXT; |
| 2211 | const ScriptLanguage::CodeCompletionOption *previous_option = nullptr; |
| 2212 | for (int i = 0; i < code_completion_options.size(); i++) { |
| 2213 | const ScriptLanguage::CodeCompletionOption ¤t_option = code_completion_options[i]; |
| 2214 | if (!previous_option) { |
| 2215 | previous_option = ¤t_option; |
| 2216 | kind = current_option.kind; |
| 2217 | } |
| 2218 | if (previous_option->kind != current_option.kind) { |
| 2219 | ignored = false; |
| 2220 | break; |
| 2221 | } |
| 2222 | } |
| 2223 | ignored = ignored && (kind == ScriptLanguage::CODE_COMPLETION_KIND_FILE_PATH || kind == ScriptLanguage::CODE_COMPLETION_KIND_NODE_PATH || kind == ScriptLanguage::CODE_COMPLETION_KIND_SIGNAL); |
| 2224 | } |
| 2225 | |
| 2226 | if (ignored) { |
| 2227 | return; |
| 2228 | } |
| 2229 | |
| 2230 | if (p_force) { |
| 2231 | emit_signal(SNAME("code_completion_requested")); |
| 2232 | return; |
| 2233 | } |
| 2234 | |
| 2235 | String line = get_line(get_caret_line()); |
| 2236 | int ofs = CLAMP(get_caret_column(), 0, line.length()); |
| 2237 | |
| 2238 | if (ofs > 0 && (is_in_string(get_caret_line(), ofs) != -1 || !is_symbol(line[ofs - 1]) || code_completion_prefixes.has(line[ofs - 1]))) { |
| 2239 | emit_signal(SNAME("code_completion_requested")); |
| 2240 | } else if (ofs > 1 && line[ofs - 1] == ' ' && code_completion_prefixes.has(line[ofs - 2])) { |
| 2241 | emit_signal(SNAME("code_completion_requested")); |
| 2242 | } |
| 2243 | } |
| 2244 | |
| 2245 | void CodeEdit::add_code_completion_option(CodeCompletionKind p_type, const String &p_display_text, const String &p_insert_text, const Color &p_text_color, const Ref<Resource> &p_icon, const Variant &p_value, int p_location) { |
| 2246 | ScriptLanguage::CodeCompletionOption completion_option; |
no test coverage detected