Merge pull request #18183 from Paulb23/gdscript_highlighter_inital_changes
GDScript function definition and get_node shortcut syntax highlighting
This commit is contained in:
commit
919d802e66
6 changed files with 101 additions and 8 deletions
|
@ -596,6 +596,10 @@ void EditorSettings::_load_default_text_editor_theme() {
|
||||||
_initial_set("text_editor/highlighting/word_highlighted_color", Color(0.8, 0.9, 0.9, 0.15));
|
_initial_set("text_editor/highlighting/word_highlighted_color", Color(0.8, 0.9, 0.9, 0.15));
|
||||||
_initial_set("text_editor/highlighting/search_result_color", Color(0.05, 0.25, 0.05, 1));
|
_initial_set("text_editor/highlighting/search_result_color", Color(0.05, 0.25, 0.05, 1));
|
||||||
_initial_set("text_editor/highlighting/search_result_border_color", Color(0.1, 0.45, 0.1, 1));
|
_initial_set("text_editor/highlighting/search_result_border_color", Color(0.1, 0.45, 0.1, 1));
|
||||||
|
|
||||||
|
// GDScript highlighter
|
||||||
|
_initial_set("text_editor/highlighting/gdscript/function_definition_color", Color::html("#01e1ff"));
|
||||||
|
_initial_set("text_editor/highlighting/gdscript/node_path_color", Color::html("#64c15a"));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EditorSettings::_save_text_editor_theme(String p_file) {
|
bool EditorSettings::_save_text_editor_theme(String p_file) {
|
||||||
|
@ -632,6 +636,10 @@ bool EditorSettings::_save_text_editor_theme(String p_file) {
|
||||||
cf->set_value(theme_section, "search_result_color", ((Color)get("text_editor/highlighting/search_result_color")).to_html());
|
cf->set_value(theme_section, "search_result_color", ((Color)get("text_editor/highlighting/search_result_color")).to_html());
|
||||||
cf->set_value(theme_section, "search_result_border_color", ((Color)get("text_editor/highlighting/search_result_border_color")).to_html());
|
cf->set_value(theme_section, "search_result_border_color", ((Color)get("text_editor/highlighting/search_result_border_color")).to_html());
|
||||||
|
|
||||||
|
//GDScript highlighter
|
||||||
|
cf->set_value(theme_section, "gdscript/function_definition_color", ((Color)get("text_editor/highlighting/gdscript/function_definition_color")).to_html());
|
||||||
|
cf->set_value(theme_section, "gdscript/node_path_color", ((Color)get("text_editor/highlighting/gdscript/node_path_color")).to_html());
|
||||||
|
|
||||||
Error err = cf->save(p_file);
|
Error err = cf->save(p_file);
|
||||||
|
|
||||||
if (err == OK) {
|
if (err == OK) {
|
||||||
|
|
|
@ -1047,6 +1047,9 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
|
||||||
const Color comment_color = dim_color;
|
const Color comment_color = dim_color;
|
||||||
const Color string_color = Color::html(dark_theme ? "#ffd942" : "#ffd118").linear_interpolate(mono_color, dark_theme ? 0.5 : 0.3);
|
const Color string_color = Color::html(dark_theme ? "#ffd942" : "#ffd118").linear_interpolate(mono_color, dark_theme ? 0.5 : 0.3);
|
||||||
|
|
||||||
|
const Color function_definition_color = Color::html(dark_theme ? "#01e1ff" : "#00a5ba");
|
||||||
|
const Color node_path_color = Color::html(dark_theme ? "64c15a" : "#518b4b");
|
||||||
|
|
||||||
const Color te_background_color = Color(0, 0, 0, 0);
|
const Color te_background_color = Color(0, 0, 0, 0);
|
||||||
const Color completion_background_color = base_color;
|
const Color completion_background_color = base_color;
|
||||||
const Color completion_selected_color = alpha1;
|
const Color completion_selected_color = alpha1;
|
||||||
|
@ -1105,6 +1108,9 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
|
||||||
setting->set_initial_value("text_editor/highlighting/code_folding_color", code_folding_color, true);
|
setting->set_initial_value("text_editor/highlighting/code_folding_color", code_folding_color, true);
|
||||||
setting->set_initial_value("text_editor/highlighting/search_result_color", search_result_color, true);
|
setting->set_initial_value("text_editor/highlighting/search_result_color", search_result_color, true);
|
||||||
setting->set_initial_value("text_editor/highlighting/search_result_border_color", search_result_border_color, true);
|
setting->set_initial_value("text_editor/highlighting/search_result_border_color", search_result_border_color, true);
|
||||||
|
|
||||||
|
setting->set_initial_value("text_editor/highlighting/gdscript/function_definition_color", function_definition_color, true);
|
||||||
|
setting->set_initial_value("text_editor/highlighting/gdscript/node_path_color", node_path_color, true);
|
||||||
} else if (text_editor_color_theme == "Default") {
|
} else if (text_editor_color_theme == "Default") {
|
||||||
setting->set_initial_value("text_editor/highlighting/symbol_color", Color::html("badfff"), true);
|
setting->set_initial_value("text_editor/highlighting/symbol_color", Color::html("badfff"), true);
|
||||||
setting->set_initial_value("text_editor/highlighting/keyword_color", Color::html("ffffb3"), true);
|
setting->set_initial_value("text_editor/highlighting/keyword_color", Color::html("ffffb3"), true);
|
||||||
|
@ -1136,6 +1142,9 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
|
||||||
setting->set_initial_value("text_editor/highlighting/code_folding_color", Color(0.8, 0.8, 0.8, 0.8), true);
|
setting->set_initial_value("text_editor/highlighting/code_folding_color", Color(0.8, 0.8, 0.8, 0.8), true);
|
||||||
setting->set_initial_value("text_editor/highlighting/search_result_color", Color(0.05, 0.25, 0.05, 1), true);
|
setting->set_initial_value("text_editor/highlighting/search_result_color", Color(0.05, 0.25, 0.05, 1), true);
|
||||||
setting->set_initial_value("text_editor/highlighting/search_result_border_color", Color(0.1, 0.45, 0.1, 1), true);
|
setting->set_initial_value("text_editor/highlighting/search_result_border_color", Color(0.1, 0.45, 0.1, 1), true);
|
||||||
|
|
||||||
|
setting->set_initial_value("text_editor/highlighting/gdscript/function_definition_color", Color::html("#01e1ff"), true);
|
||||||
|
setting->set_initial_value("text_editor/highlighting/gdscript/node_path_color", Color::html("#64c15a"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return theme;
|
return theme;
|
||||||
|
|
|
@ -7,4 +7,7 @@ env_gdscript = env_modules.Clone()
|
||||||
|
|
||||||
env_gdscript.add_source_files(env.modules_sources, "*.cpp")
|
env_gdscript.add_source_files(env.modules_sources, "*.cpp")
|
||||||
|
|
||||||
|
if env['tools']:
|
||||||
|
env_gdscript.add_source_files(env.modules_sources, "./editor/*.cpp")
|
||||||
|
|
||||||
Export('env')
|
Export('env')
|
||||||
|
|
|
@ -29,6 +29,8 @@
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
|
|
||||||
#include "gdscript_highlighter.h"
|
#include "gdscript_highlighter.h"
|
||||||
|
#include "../gdscript_tokenizer.h"
|
||||||
|
#include "editor/editor_settings.h"
|
||||||
#include "scene/gui/text_edit.h"
|
#include "scene/gui/text_edit.h"
|
||||||
|
|
||||||
inline bool _is_symbol(CharType c) {
|
inline bool _is_symbol(CharType c) {
|
||||||
|
@ -61,12 +63,20 @@ static bool _is_hex_symbol(CharType c) {
|
||||||
Map<int, TextEdit::HighlighterInfo> GDScriptSyntaxHighlighter::_get_line_syntax_highlighting(int p_line) {
|
Map<int, TextEdit::HighlighterInfo> GDScriptSyntaxHighlighter::_get_line_syntax_highlighting(int p_line) {
|
||||||
Map<int, TextEdit::HighlighterInfo> color_map;
|
Map<int, TextEdit::HighlighterInfo> color_map;
|
||||||
|
|
||||||
|
Type next_type = NONE;
|
||||||
|
Type current_type = NONE;
|
||||||
|
Type previous_type = NONE;
|
||||||
|
|
||||||
|
String previous_text = "";
|
||||||
|
int previous_column = 0;
|
||||||
|
|
||||||
bool prev_is_char = false;
|
bool prev_is_char = false;
|
||||||
bool prev_is_number = false;
|
bool prev_is_number = false;
|
||||||
bool in_keyword = false;
|
bool in_keyword = false;
|
||||||
bool in_word = false;
|
bool in_word = false;
|
||||||
bool in_function_name = false;
|
bool in_function_name = false;
|
||||||
bool in_member_variable = false;
|
bool in_member_variable = false;
|
||||||
|
bool in_node_path = false;
|
||||||
bool is_hex_notation = false;
|
bool is_hex_notation = false;
|
||||||
Color keyword_color;
|
Color keyword_color;
|
||||||
Color color;
|
Color color;
|
||||||
|
@ -214,18 +224,64 @@ Map<int, TextEdit::HighlighterInfo> GDScriptSyntaxHighlighter::_get_line_syntax_
|
||||||
in_member_variable = false;
|
in_member_variable = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_region >= 0)
|
if (!in_node_path && in_region == -1 && str[j] == '$') {
|
||||||
|
in_node_path = true;
|
||||||
|
} else if (in_region != -1 || (is_symbol && str[j] != '/')) {
|
||||||
|
in_node_path = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_region >= 0) {
|
||||||
|
next_type = REGION;
|
||||||
color = text_editor->_get_color_region(in_region).color;
|
color = text_editor->_get_color_region(in_region).color;
|
||||||
else if (in_keyword)
|
} else if (in_node_path) {
|
||||||
|
next_type = NODE_PATH;
|
||||||
|
color = node_path_color;
|
||||||
|
} else if (in_keyword) {
|
||||||
|
next_type = KEYWORD;
|
||||||
color = keyword_color;
|
color = keyword_color;
|
||||||
else if (in_member_variable)
|
} else if (in_member_variable) {
|
||||||
|
next_type = MEMBER;
|
||||||
color = member_color;
|
color = member_color;
|
||||||
else if (in_function_name)
|
} else if (in_function_name) {
|
||||||
color = function_color;
|
next_type = FUNCTION;
|
||||||
else if (is_symbol)
|
|
||||||
|
if (previous_text == GDScriptTokenizer::get_token_name(GDScriptTokenizer::TK_PR_FUNCTION)) {
|
||||||
|
color = function_definition_color;
|
||||||
|
} else {
|
||||||
|
color = function_color;
|
||||||
|
}
|
||||||
|
} else if (is_symbol) {
|
||||||
|
next_type = SYMBOL;
|
||||||
color = symbol_color;
|
color = symbol_color;
|
||||||
else if (is_number)
|
} else if (is_number) {
|
||||||
|
next_type = NUMBER;
|
||||||
color = number_color;
|
color = number_color;
|
||||||
|
} else {
|
||||||
|
next_type = IDENTIFIER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (next_type != current_type) {
|
||||||
|
if (current_type == NONE) {
|
||||||
|
current_type = next_type;
|
||||||
|
} else {
|
||||||
|
previous_type = current_type;
|
||||||
|
current_type = next_type;
|
||||||
|
|
||||||
|
// no need to store regions...
|
||||||
|
if (previous_type == REGION) {
|
||||||
|
previous_text = "";
|
||||||
|
previous_column = j;
|
||||||
|
} else {
|
||||||
|
String text = str.substr(previous_column, j - previous_column).strip_edges();
|
||||||
|
previous_column = j;
|
||||||
|
|
||||||
|
// ignore if just whitespace
|
||||||
|
if (text != "") {
|
||||||
|
previous_text = text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
prev_is_char = is_char;
|
prev_is_char = is_char;
|
||||||
prev_is_number = is_number;
|
prev_is_number = is_number;
|
||||||
|
@ -255,6 +311,9 @@ void GDScriptSyntaxHighlighter::_update_cache() {
|
||||||
function_color = text_editor->get_color("function_color");
|
function_color = text_editor->get_color("function_color");
|
||||||
number_color = text_editor->get_color("number_color");
|
number_color = text_editor->get_color("number_color");
|
||||||
member_color = text_editor->get_color("member_variable_color");
|
member_color = text_editor->get_color("member_variable_color");
|
||||||
|
|
||||||
|
function_definition_color = EDITOR_DEF("text_editor/highlighting/gdscript/function_definition_color", Color::html("#01e1ff"));
|
||||||
|
node_path_color = EDITOR_DEF("text_editor/highlighting/gdscript/node_path_color", Color::html("#64c15a"));
|
||||||
}
|
}
|
||||||
|
|
||||||
SyntaxHighlighter *GDScriptSyntaxHighlighter::create() {
|
SyntaxHighlighter *GDScriptSyntaxHighlighter::create() {
|
|
@ -35,13 +35,27 @@
|
||||||
|
|
||||||
class GDScriptSyntaxHighlighter : public SyntaxHighlighter {
|
class GDScriptSyntaxHighlighter : public SyntaxHighlighter {
|
||||||
private:
|
private:
|
||||||
|
enum Type {
|
||||||
|
NONE,
|
||||||
|
REGION,
|
||||||
|
NODE_PATH,
|
||||||
|
SYMBOL,
|
||||||
|
NUMBER,
|
||||||
|
FUNCTION,
|
||||||
|
KEYWORD,
|
||||||
|
MEMBER,
|
||||||
|
IDENTIFIER
|
||||||
|
};
|
||||||
|
|
||||||
// colours
|
// colours
|
||||||
Color font_color;
|
Color font_color;
|
||||||
Color symbol_color;
|
Color symbol_color;
|
||||||
Color function_color;
|
Color function_color;
|
||||||
|
Color function_definition_color;
|
||||||
Color built_in_type_color;
|
Color built_in_type_color;
|
||||||
Color number_color;
|
Color number_color;
|
||||||
Color member_color;
|
Color member_color;
|
||||||
|
Color node_path_color;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static SyntaxHighlighter *create();
|
static SyntaxHighlighter *create();
|
|
@ -30,8 +30,8 @@
|
||||||
|
|
||||||
#include "register_types.h"
|
#include "register_types.h"
|
||||||
|
|
||||||
|
#include "editor/gdscript_highlighter.h"
|
||||||
#include "gdscript.h"
|
#include "gdscript.h"
|
||||||
#include "gdscript_highlighter.h"
|
|
||||||
#include "gdscript_tokenizer.h"
|
#include "gdscript_tokenizer.h"
|
||||||
#include "io/file_access_encrypted.h"
|
#include "io/file_access_encrypted.h"
|
||||||
#include "io/resource_loader.h"
|
#include "io/resource_loader.h"
|
||||||
|
|
Loading…
Reference in a new issue