Highlight control flow keywords with a different color
This makes them easier to distinguish from other keywords.
This commit is contained in:
parent
758bccf364
commit
e905e8f145
20 changed files with 115 additions and 9 deletions
|
|
@ -1289,6 +1289,10 @@ void NativeScriptLanguage::finish() {
|
|||
void NativeScriptLanguage::get_reserved_words(List<String> *p_words) const {
|
||||
}
|
||||
|
||||
bool NativeScriptLanguage::is_control_flow_keyword(String p_keyword) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
void NativeScriptLanguage::get_comment_delimiters(List<String> *p_delimiters) const {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -336,6 +336,7 @@ public:
|
|||
virtual Error execute_file(const String &p_path);
|
||||
virtual void finish();
|
||||
virtual void get_reserved_words(List<String> *p_words) const;
|
||||
virtual bool is_control_flow_keyword(String p_keyword) const;
|
||||
virtual void get_comment_delimiters(List<String> *p_delimiters) const;
|
||||
virtual void get_string_delimiters(List<String> *p_delimiters) const;
|
||||
virtual Ref<Script> get_template(const String &p_class_name, const String &p_base_class_name) const;
|
||||
|
|
|
|||
|
|
@ -77,6 +77,10 @@ void PluginScriptLanguage::get_reserved_words(List<String> *p_words) const {
|
|||
}
|
||||
}
|
||||
|
||||
bool PluginScriptLanguage::is_control_flow_keyword(String p_keyword) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
void PluginScriptLanguage::get_comment_delimiters(List<String> *p_delimiters) const {
|
||||
if (_desc.comment_delimiters) {
|
||||
const char **w = _desc.comment_delimiters;
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ public:
|
|||
|
||||
/* EDITOR FUNCTIONS */
|
||||
virtual void get_reserved_words(List<String> *p_words) const;
|
||||
virtual bool is_control_flow_keyword(String p_keyword) const;
|
||||
virtual void get_comment_delimiters(List<String> *p_delimiters) const;
|
||||
virtual void get_string_delimiters(List<String> *p_delimiters) const;
|
||||
virtual Ref<Script> get_template(const String &p_class_name, const String &p_base_class_name) const;
|
||||
|
|
|
|||
|
|
@ -485,10 +485,15 @@ void GDScriptSyntaxHighlighter::_update_cache() {
|
|||
|
||||
/* Reserved words. */
|
||||
const Color keyword_color = EDITOR_GET("text_editor/highlighting/keyword_color");
|
||||
const Color control_flow_keyword_color = EDITOR_GET("text_editor/highlighting/control_flow_keyword_color");
|
||||
List<String> keyword_list;
|
||||
gdscript->get_reserved_words(&keyword_list);
|
||||
for (List<String>::Element *E = keyword_list.front(); E; E = E->next()) {
|
||||
keywords[E->get()] = keyword_color;
|
||||
if (gdscript->is_control_flow_keyword(E->get())) {
|
||||
keywords[E->get()] = control_flow_keyword_color;
|
||||
} else {
|
||||
keywords[E->get()] = keyword_color;
|
||||
}
|
||||
}
|
||||
|
||||
/* Comments */
|
||||
|
|
|
|||
|
|
@ -2135,6 +2135,19 @@ void GDScriptLanguage::get_reserved_words(List<String> *p_words) const {
|
|||
}
|
||||
}
|
||||
|
||||
bool GDScriptLanguage::is_control_flow_keyword(String p_keyword) const {
|
||||
return p_keyword == "break" ||
|
||||
p_keyword == "continue" ||
|
||||
p_keyword == "elif" ||
|
||||
p_keyword == "else" ||
|
||||
p_keyword == "if" ||
|
||||
p_keyword == "for" ||
|
||||
p_keyword == "match" ||
|
||||
p_keyword == "pass" ||
|
||||
p_keyword == "return" ||
|
||||
p_keyword == "while";
|
||||
}
|
||||
|
||||
bool GDScriptLanguage::handles_global_class_type(const String &p_type) const {
|
||||
return p_type == "GDScript";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -461,6 +461,7 @@ public:
|
|||
|
||||
/* EDITOR FUNCTIONS */
|
||||
virtual void get_reserved_words(List<String> *p_words) const;
|
||||
virtual bool is_control_flow_keyword(String p_keywords) const;
|
||||
virtual void get_comment_delimiters(List<String> *p_delimiters) const;
|
||||
virtual void get_string_delimiters(List<String> *p_delimiters) const;
|
||||
virtual String _get_processed_template(const String &p_template, const String &p_base_class_name) const;
|
||||
|
|
|
|||
|
|
@ -304,6 +304,26 @@ void CSharpLanguage::get_reserved_words(List<String> *p_words) const {
|
|||
}
|
||||
}
|
||||
|
||||
bool CSharpLanguage::is_control_flow_keyword(String p_keyword) const {
|
||||
return p_keyword == "break" ||
|
||||
p_keyword == "case" ||
|
||||
p_keyword == "catch" ||
|
||||
p_keyword == "continue" ||
|
||||
p_keyword == "default" ||
|
||||
p_keyword == "do" ||
|
||||
p_keyword == "else" ||
|
||||
p_keyword == "finally" ||
|
||||
p_keyword == "for" ||
|
||||
p_keyword == "foreach" ||
|
||||
p_keyword == "goto" ||
|
||||
p_keyword == "if" ||
|
||||
p_keyword == "return" ||
|
||||
p_keyword == "switch" ||
|
||||
p_keyword == "throw" ||
|
||||
p_keyword == "try" ||
|
||||
p_keyword == "while";
|
||||
}
|
||||
|
||||
void CSharpLanguage::get_comment_delimiters(List<String> *p_delimiters) const {
|
||||
p_delimiters->push_back("//"); // single-line comment
|
||||
p_delimiters->push_back("/* */"); // delimited comment
|
||||
|
|
|
|||
|
|
@ -470,6 +470,7 @@ public:
|
|||
|
||||
/* EDITOR FUNCTIONS */
|
||||
void get_reserved_words(List<String> *p_words) const override;
|
||||
bool is_control_flow_keyword(String p_keyword) const;
|
||||
void get_comment_delimiters(List<String> *p_delimiters) const override;
|
||||
void get_string_delimiters(List<String> *p_delimiters) const override;
|
||||
Ref<Script> get_template(const String &p_class_name, const String &p_base_class_name) const override;
|
||||
|
|
|
|||
|
|
@ -2336,6 +2336,10 @@ void VisualScriptLanguage::finish() {
|
|||
void VisualScriptLanguage::get_reserved_words(List<String> *p_words) const {
|
||||
}
|
||||
|
||||
bool VisualScriptLanguage::is_control_flow_keyword(String p_keyword) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
void VisualScriptLanguage::get_comment_delimiters(List<String> *p_delimiters) const {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -586,6 +586,7 @@ public:
|
|||
|
||||
/* EDITOR FUNCTIONS */
|
||||
virtual void get_reserved_words(List<String> *p_words) const;
|
||||
virtual bool is_control_flow_keyword(String p_keyword) const;
|
||||
virtual void get_comment_delimiters(List<String> *p_delimiters) const;
|
||||
virtual void get_string_delimiters(List<String> *p_delimiters) const;
|
||||
virtual Ref<Script> get_template(const String &p_class_name, const String &p_base_class_name) const;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue