Fixes for completion of shader preprocessor defines
This commit is contained in:
parent
a3e84cc2af
commit
cd5f2aa923
4 changed files with 28 additions and 4 deletions
|
|
@ -440,9 +440,6 @@ void ShaderTextEditor::_code_complete_script(const String &p_code, List<ScriptLa
|
|||
}
|
||||
return;
|
||||
}
|
||||
for (const ScriptLanguage::CodeCompletionOption &E : pp_defines) {
|
||||
r_options->push_back(E);
|
||||
}
|
||||
|
||||
ShaderLanguage sl;
|
||||
String calltip;
|
||||
|
|
@ -453,6 +450,12 @@ void ShaderTextEditor::_code_complete_script(const String &p_code, List<ScriptLa
|
|||
comp_info.is_include = true;
|
||||
|
||||
sl.complete(code, comp_info, r_options, calltip);
|
||||
if (sl.get_completion_type() == ShaderLanguage::COMPLETION_IDENTIFIER) {
|
||||
for (const ScriptLanguage::CodeCompletionOption &E : pp_defines) {
|
||||
r_options->push_back(E);
|
||||
}
|
||||
}
|
||||
|
||||
get_text_editor()->set_code_hint(calltip);
|
||||
return;
|
||||
}
|
||||
|
|
@ -463,6 +466,12 @@ void ShaderTextEditor::_code_complete_script(const String &p_code, List<ScriptLa
|
|||
comp_info.shader_types = ShaderTypes::get_singleton()->get_types();
|
||||
|
||||
sl.complete(code, comp_info, r_options, calltip);
|
||||
if (sl.get_completion_type() == ShaderLanguage::COMPLETION_IDENTIFIER) {
|
||||
for (const ScriptLanguage::CodeCompletionOption &E : pp_defines) {
|
||||
r_options->push_back(E);
|
||||
}
|
||||
}
|
||||
|
||||
get_text_editor()->set_code_hint(calltip);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1275,6 +1275,7 @@ public:
|
|||
|
||||
String get_error_text();
|
||||
Vector<FilePosition> get_include_positions();
|
||||
CompletionType get_completion_type() const { return completion_type; }
|
||||
int get_error_line();
|
||||
|
||||
ShaderNode *get_shader();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -161,6 +161,7 @@ private:
|
|||
bool disabled = false;
|
||||
CompletionType completion_type = COMPLETION_TYPE_NONE;
|
||||
HashSet<Ref<ShaderInclude>> shader_includes;
|
||||
bool completion_show_defines = false;
|
||||
};
|
||||
|
||||
private:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue