diff options
-rw-r--r-- | editor/plugins/shader_editor_plugin.cpp | 6 | ||||
-rw-r--r-- | servers/rendering/shader_preprocessor.cpp | 10 | ||||
-rw-r--r-- | servers/rendering/shader_preprocessor.h | 2 |
3 files changed, 14 insertions, 4 deletions
diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp index ae3c578eaa..13aba0a884 100644 --- a/editor/plugins/shader_editor_plugin.cpp +++ b/editor/plugins/shader_editor_plugin.cpp @@ -385,13 +385,14 @@ static void _complete_include_paths(List<ScriptLanguage::CodeCompletionOption> * void ShaderTextEditor::_code_complete_script(const String &p_code, List<ScriptLanguage::CodeCompletionOption> *r_options) { List<ScriptLanguage::CodeCompletionOption> pp_options; + List<ScriptLanguage::CodeCompletionOption> pp_defines; ShaderPreprocessor preprocessor; String code; complete_from_path = (shader.is_valid() ? shader->get_path() : shader_inc->get_path()).get_base_dir(); if (!complete_from_path.ends_with("/")) { complete_from_path += "/"; } - preprocessor.preprocess(p_code, "", code, nullptr, nullptr, nullptr, nullptr, &pp_options, _complete_include_paths); + preprocessor.preprocess(p_code, "", code, nullptr, nullptr, nullptr, nullptr, &pp_options, &pp_defines, _complete_include_paths); complete_from_path = String(); if (pp_options.size()) { for (const ScriptLanguage::CodeCompletionOption &E : pp_options) { @@ -399,6 +400,9 @@ 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; diff --git a/servers/rendering/shader_preprocessor.cpp b/servers/rendering/shader_preprocessor.cpp index 3766477070..46e76fbe92 100644 --- a/servers/rendering/shader_preprocessor.cpp +++ b/servers/rendering/shader_preprocessor.cpp @@ -1176,7 +1176,7 @@ Error ShaderPreprocessor::preprocess(State *p_state, const String &p_code, Strin return OK; } -Error ShaderPreprocessor::preprocess(const String &p_code, const String &p_filename, String &r_result, String *r_error_text, List<FilePosition> *r_error_position, List<Region> *r_regions, HashSet<Ref<ShaderInclude>> *r_includes, List<ScriptLanguage::CodeCompletionOption> *r_completion_options, IncludeCompletionFunction p_include_completion_func) { +Error ShaderPreprocessor::preprocess(const String &p_code, const String &p_filename, String &r_result, String *r_error_text, List<FilePosition> *r_error_position, List<Region> *r_regions, HashSet<Ref<ShaderInclude>> *r_includes, List<ScriptLanguage::CodeCompletionOption> *r_completion_options, List<ScriptLanguage::CodeCompletionOption> *r_completion_defines, IncludeCompletionFunction p_include_completion_func) { State pp_state; if (!p_filename.is_empty()) { pp_state.current_filename = p_filename; @@ -1198,6 +1198,13 @@ Error ShaderPreprocessor::preprocess(const String &p_code, const String &p_filen *r_includes = pp_state.shader_includes; } + if (r_completion_defines) { + for (const KeyValue<String, Define *> &E : state->defines) { + ScriptLanguage::CodeCompletionOption option(E.key, ScriptLanguage::CODE_COMPLETION_KIND_CONSTANT); + r_completion_defines->push_back(option); + } + } + if (r_completion_options) { switch (pp_state.completion_type) { case COMPLETION_TYPE_DIRECTIVE: { @@ -1212,7 +1219,6 @@ Error ShaderPreprocessor::preprocess(const String &p_code, const String &p_filen } break; case COMPLETION_TYPE_PRAGMA: { List<String> options; - ShaderPreprocessor::get_pragma_list(&options); for (const String &E : options) { diff --git a/servers/rendering/shader_preprocessor.h b/servers/rendering/shader_preprocessor.h index b4e7c7199f..f1b2876891 100644 --- a/servers/rendering/shader_preprocessor.h +++ b/servers/rendering/shader_preprocessor.h @@ -218,7 +218,7 @@ private: public: typedef void (*IncludeCompletionFunction)(List<ScriptLanguage::CodeCompletionOption> *); - Error preprocess(const String &p_code, const String &p_filename, String &r_result, String *r_error_text = nullptr, List<FilePosition> *r_error_position = nullptr, List<Region> *r_regions = nullptr, HashSet<Ref<ShaderInclude>> *r_includes = nullptr, List<ScriptLanguage::CodeCompletionOption> *r_completion_options = nullptr, IncludeCompletionFunction p_include_completion_func = nullptr); + Error preprocess(const String &p_code, const String &p_filename, String &r_result, String *r_error_text = nullptr, List<FilePosition> *r_error_position = nullptr, List<Region> *r_regions = nullptr, HashSet<Ref<ShaderInclude>> *r_includes = nullptr, List<ScriptLanguage::CodeCompletionOption> *r_completion_options = nullptr, List<ScriptLanguage::CodeCompletionOption> *r_completion_defines = nullptr, IncludeCompletionFunction p_include_completion_func = nullptr); static void get_keyword_list(List<String> *r_keywords, bool p_include_shader_keywords, bool p_ignore_context_keywords = false); static void get_pragma_list(List<String> *r_pragmas); |