diff options
author | George Marques <george@gmarqu.es> | 2018-05-29 23:16:58 -0300 |
---|---|---|
committer | George Marques <george@gmarqu.es> | 2018-07-20 21:55:17 -0300 |
commit | 95351ac867228774d455fe1e3de27d08d1f4f83a (patch) | |
tree | aa742b8dc8f266cbd20c4c3c0f13739d79f71d80 /modules/gdscript/editor | |
parent | e3d72d14ff27af2b396397065ddc38f87685c694 (diff) |
Add syntax highlighting to type hints
Diffstat (limited to 'modules/gdscript/editor')
-rw-r--r-- | modules/gdscript/editor/gdscript_highlighter.cpp | 30 | ||||
-rw-r--r-- | modules/gdscript/editor/gdscript_highlighter.h | 4 |
2 files changed, 33 insertions, 1 deletions
diff --git a/modules/gdscript/editor/gdscript_highlighter.cpp b/modules/gdscript/editor/gdscript_highlighter.cpp index fedc510f01..f2a1a5b50c 100644 --- a/modules/gdscript/editor/gdscript_highlighter.cpp +++ b/modules/gdscript/editor/gdscript_highlighter.cpp @@ -75,9 +75,11 @@ Map<int, TextEdit::HighlighterInfo> GDScriptSyntaxHighlighter::_get_line_syntax_ bool in_keyword = false; bool in_word = false; bool in_function_name = false; + bool in_variable_declaration = false; bool in_member_variable = false; bool in_node_path = false; bool is_hex_notation = false; + bool expect_type = false; Color keyword_color; Color color; @@ -205,6 +207,8 @@ Map<int, TextEdit::HighlighterInfo> GDScriptSyntaxHighlighter::_get_line_syntax_ if (str[k] == '(') { in_function_name = true; + } else if (previous_text == GDScriptTokenizer::get_token_name(GDScriptTokenizer::TK_PR_VAR)) { + in_variable_declaration = true; } } @@ -222,6 +226,28 @@ Map<int, TextEdit::HighlighterInfo> GDScriptSyntaxHighlighter::_get_line_syntax_ if (is_symbol) { in_function_name = false; in_member_variable = false; + + if (expect_type && str[j] != ' ' && str[j] != '\t' && str[j] != ':') { + expect_type = false; + } + if (j > 0 && str[j] == '>' && str[j - 1] == '-') { + expect_type = true; + } + + if (in_variable_declaration || previous_text == "(" || previous_text == ",") { + int k = j; + // Skip space + while (k < str.length() && (str[k] == '\t' || str[k] == ' ')) { + k++; + } + + if (str[k] == ':') { + // has type hint + expect_type = true; + } + } + + in_variable_declaration = false; } if (!in_node_path && in_region == -1 && str[j] == '$') { @@ -256,6 +282,9 @@ Map<int, TextEdit::HighlighterInfo> GDScriptSyntaxHighlighter::_get_line_syntax_ } else if (is_number) { next_type = NUMBER; color = number_color; + } else if (expect_type) { + next_type = TYPE; + color = type_color; } else { next_type = IDENTIFIER; } @@ -330,6 +359,7 @@ void GDScriptSyntaxHighlighter::_update_cache() { function_definition_color = EDITOR_GET("text_editor/highlighting/gdscript/function_definition_color"); node_path_color = EDITOR_GET("text_editor/highlighting/gdscript/node_path_color"); + type_color = EDITOR_GET("text_editor/highlighting/base_type_color"); } SyntaxHighlighter *GDScriptSyntaxHighlighter::create() { diff --git a/modules/gdscript/editor/gdscript_highlighter.h b/modules/gdscript/editor/gdscript_highlighter.h index 0296ab7652..b8cb4a65e9 100644 --- a/modules/gdscript/editor/gdscript_highlighter.h +++ b/modules/gdscript/editor/gdscript_highlighter.h @@ -44,7 +44,8 @@ private: FUNCTION, KEYWORD, MEMBER, - IDENTIFIER + IDENTIFIER, + TYPE, }; // colours @@ -56,6 +57,7 @@ private: Color number_color; Color member_color; Color node_path_color; + Color type_color; public: static SyntaxHighlighter *create(); |