Fixes for completion of shader preprocessor defines

This commit is contained in:
Chaosus 2026-02-17 19:20:06 +03:00
parent a3e84cc2af
commit cd5f2aa923
4 changed files with 28 additions and 4 deletions

View file

@ -636,13 +636,18 @@ void ShaderPreprocessor::process_if(Tokenizer *p_tokenizer) {
void ShaderPreprocessor::process_ifdef(Tokenizer *p_tokenizer) {
const int line = p_tokenizer->get_line();
bool is_cursor = false;
String label = p_tokenizer->get_identifier();
String label = p_tokenizer->get_identifier(&is_cursor);
if (label.is_empty()) {
set_error(RTR("Invalid macro name."), line);
return;
}
if (is_cursor) {
state->completion_show_defines = true;
}
if (!p_tokenizer->consume_empty_line()) {
set_error(vformat(RTR("Invalid '%s' directive."), "ifdef"), line);
return;
@ -876,6 +881,7 @@ Error ShaderPreprocessor::expand_condition(const String &p_string, int p_line, S
switch (p_string[i]) {
case CURSOR:
state->completion_type = COMPLETION_TYPE_CONDITION;
state->completion_show_defines = true;
break;
case '(':
bracket_start_count++;
@ -1417,6 +1423,13 @@ Error ShaderPreprocessor::preprocess(const String &p_code, const String &p_filen
}
}
if (state->completion_show_defines) {
for (const KeyValue<String, Define *> &E : state->defines) {
ScriptLanguage::CodeCompletionOption option(E.key, ScriptLanguage::CODE_COMPLETION_KIND_CONSTANT);
r_completion_options->push_back(option);
}
}
clear_state();
return err;