Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Style: Cleanup code using text_editor/completion/use_single_quotes #51642

Merged
merged 1 commit into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions core/input/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ void Input::_bind_methods() {

void Input::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
#ifdef TOOLS_ENABLED

const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", 0) ? "'" : "\"";
const String quote_style = EDITOR_GET("text_editor/completion/use_single_quotes") ? "'" : "\"";

String pf = p_function;
if (p_idx == 0 && (pf == "is_action_pressed" || pf == "action_press" || pf == "action_release" ||
Expand All @@ -180,7 +179,7 @@ void Input::get_argument_options(const StringName &p_function, int p_idx, List<S
}

String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length());
r_options->push_back(quote_style + name + quote_style);
r_options->push_back(name.quote(quote_style));
}
}
#endif
Expand Down
7 changes: 3 additions & 4 deletions editor/plugins/script_text_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1420,10 +1420,11 @@ static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const
}

void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
const String quote_style = EDITOR_GET("text_editor/completion/use_single_quotes") ? "'" : "\"";

Dictionary d = p_data;

CodeEdit *te = code_editor->get_text_editor();

Point2i pos = te->get_line_column_at_pos(p_point);
int row = pos.y;
int col = pos.x;
Expand All @@ -1445,7 +1446,6 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data
}

if (d.has("type") && (String(d["type"]) == "files" || String(d["type"]) == "files_and_dirs")) {
const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", false) ? "'" : "\"";
Array files = d["files"];

String text_to_drop;
Expand Down Expand Up @@ -1489,7 +1489,7 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data
}

String path = sn->get_path_to(node);
text_to_drop += "\"" + path.c_escape() + "\"";
text_to_drop += path.c_escape().quote(quote_style);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wasn't respecting the setting.

}

te->set_caret_line(row);
Expand All @@ -1498,7 +1498,6 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data
}

if (d.has("type") && String(d["type"]) == "obj_property") {
const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", false) ? "'" : "\"";
const String text_to_drop = String(d["property"]).c_escape().quote(quote_style);

te->set_caret_line(row);
Expand Down
26 changes: 12 additions & 14 deletions modules/gdscript/gdscript_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -623,11 +623,11 @@ static String _make_arguments_hint(const GDScriptParser::FunctionNode *p_functio
}

static void _get_directory_contents(EditorFileSystemDirectory *p_dir, Map<String, ScriptCodeCompletionOption> &r_list) {
const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", false) ? "'" : "\"";
const String quote_style = EDITOR_GET("text_editor/completion/use_single_quotes") ? "'" : "\"";

for (int i = 0; i < p_dir->get_file_count(); i++) {
ScriptCodeCompletionOption option(p_dir->get_file_path(i), ScriptCodeCompletionOption::KIND_FILE_PATH);
option.insert_text = quote_style + option.display + quote_style;
option.insert_text = option.display.quote(quote_style);
r_list.insert(option.display, option);
}

Expand All @@ -641,20 +641,20 @@ static void _find_annotation_arguments(const GDScriptParser::AnnotationNode *p_a
if (p_argument == 3 || p_argument == 4) {
// Slider hint.
ScriptCodeCompletionOption slider1("or_greater", ScriptCodeCompletionOption::KIND_PLAIN_TEXT);
slider1.insert_text = p_quote_style + slider1.display + p_quote_style;
slider1.insert_text = slider1.display.quote(p_quote_style);
r_result.insert(slider1.display, slider1);
ScriptCodeCompletionOption slider2("or_lesser", ScriptCodeCompletionOption::KIND_PLAIN_TEXT);
slider2.insert_text = p_quote_style + slider2.display + p_quote_style;
slider2.insert_text = slider2.display.quote(p_quote_style);
r_result.insert(slider2.display, slider2);
}
} else if (p_annotation->name == "@export_exp_easing") {
if (p_argument == 0 || p_argument == 1) {
// Easing hint.
ScriptCodeCompletionOption hint1("attenuation", ScriptCodeCompletionOption::KIND_PLAIN_TEXT);
hint1.insert_text = p_quote_style + hint1.display + p_quote_style;
hint1.insert_text = hint1.display.quote(p_quote_style);
r_result.insert(hint1.display, hint1);
ScriptCodeCompletionOption hint2("inout", ScriptCodeCompletionOption::KIND_PLAIN_TEXT);
hint2.insert_text = p_quote_style + hint2.display + p_quote_style;
hint2.insert_text = hint2.display.quote(p_quote_style);
r_result.insert(hint2.display, hint2);
}
} else if (p_annotation->name == "@export_node_path") {
Expand Down Expand Up @@ -2192,7 +2192,7 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c
Variant base = p_base.value;
GDScriptParser::DataType base_type = p_base.type;

const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", false) ? "'" : "\"";
const String quote_style = EDITOR_GET("text_editor/completion/use_single_quotes") ? "'" : "\"";

while (base_type.is_set() && !base_type.is_variant()) {
switch (base_type.kind) {
Expand Down Expand Up @@ -2254,7 +2254,7 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c
}
String name = s.get_slice("/", 1);
ScriptCodeCompletionOption option("/root/" + name, ScriptCodeCompletionOption::KIND_NODE_PATH);
option.insert_text = quote_style + option.display + quote_style;
option.insert_text = option.display.quote(quote_style);
r_result.insert(option.display, option);
}
}
Expand All @@ -2270,7 +2270,7 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c
}
String name = s.get_slice("/", 1);
ScriptCodeCompletionOption option(name, ScriptCodeCompletionOption::KIND_CONSTANT);
option.insert_text = quote_style + option.display + quote_style;
option.insert_text = option.display.quote(quote_style);
r_result.insert(option.display, option);
}
}
Expand Down Expand Up @@ -2305,8 +2305,6 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c
}

static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, const GDScriptParser::Node *p_call, int p_argidx, Map<String, ScriptCodeCompletionOption> &r_result, bool &r_forced, String &r_arghint) {
const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", false) ? "'" : "\"";

if (p_call->type == GDScriptParser::Node::PRELOAD) {
if (p_argidx == 0 && bool(EditorSettings::get_singleton()->get("text_editor/completion/complete_file_paths"))) {
_get_directory_contents(EditorFileSystem::get_singleton()->get_filesystem(), r_result);
Expand Down Expand Up @@ -2382,7 +2380,7 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c
}

::Error GDScriptLanguage::complete_code(const String &p_code, const String &p_path, Object *p_owner, List<ScriptCodeCompletionOption> *r_options, bool &r_forced, String &r_call_hint) {
const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", false) ? "'" : "\"";
const String quote_style = EDITOR_GET("text_editor/completion/use_single_quotes") ? "'" : "\"";

GDScriptParser parser;
GDScriptAnalyzer analyzer(&parser);
Expand Down Expand Up @@ -2671,8 +2669,8 @@ ::Error GDScriptLanguage::complete_code(const String &p_code, const String &p_pa
Map<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list();

for (Map<StringName, ProjectSettings::AutoloadInfo>::Element *E = autoloads.front(); E; E = E->next()) {
String name = E->key();
ScriptCodeCompletionOption option(quote_style + "/root/" + name + quote_style, ScriptCodeCompletionOption::KIND_NODE_PATH);
String path = "/root/" + E->key();
ScriptCodeCompletionOption option(path.quote(quote_style), ScriptCodeCompletionOption::KIND_NODE_PATH);
Comment on lines +2672 to +2673
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored a bit to be able to use String::quote() like in other calls.

options.insert(option.display, option);
}
}
Expand Down
4 changes: 2 additions & 2 deletions modules/gdscript/language_server/gdscript_text_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ Dictionary GDScriptTextDocument::resolve(const Dictionary &p_params) {
}
} else if (item.kind == lsp::CompletionItemKind::Event) {
if (params.context.triggerKind == lsp::CompletionTriggerKind::TriggerCharacter && (params.context.triggerCharacter == "(")) {
const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", false) ? "'" : "\"";
item.insertText = quote_style + item.label + quote_style;
const String quote_style = EDITOR_GET("text_editor/completion/use_single_quotes") ? "'" : "\"";
item.insertText = item.label.quote(quote_style);
}
}

Expand Down
6 changes: 3 additions & 3 deletions scene/animation/animation_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1493,7 +1493,7 @@ NodePath AnimationPlayer::get_root() const {

void AnimationPlayer::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
#ifdef TOOLS_ENABLED
const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", 0) ? "'" : "\"";
const String quote_style = EDITOR_GET("text_editor/completion/use_single_quotes") ? "'" : "\"";
#else
const String quote_style = "\"";
#endif
Expand All @@ -1502,8 +1502,8 @@ void AnimationPlayer::get_argument_options(const StringName &p_function, int p_i
if (p_idx == 0 && (p_function == "play" || p_function == "play_backwards" || p_function == "remove_animation" || p_function == "has_animation" || p_function == "queue")) {
List<StringName> al;
get_animation_list(&al);
for (const StringName &E : al) {
r_options->push_back(quote_style + String(E) + quote_style);
for (const StringName &name : al) {
r_options->push_back(String(name).quote(quote_style));
}
}
Node::get_argument_options(p_function, p_idx, r_options);
Expand Down
6 changes: 3 additions & 3 deletions scene/gui/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2585,7 +2585,7 @@ bool Control::is_visibility_clip_disabled() const {

void Control::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
#ifdef TOOLS_ENABLED
const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", 0) ? "'" : "\"";
const String quote_style = EDITOR_GET("text_editor/completion/use_single_quotes") ? "'" : "\"";
#else
const String quote_style = "\"";
#endif
Expand All @@ -2608,8 +2608,8 @@ void Control::get_argument_options(const StringName &p_function, int p_idx, List
}

sn.sort_custom<StringName::AlphCompare>();
for (const StringName &E : sn) {
r_options->push_back(quote_style + E + quote_style);
for (const StringName &name : sn) {
r_options->push_back(String(name).quote(quote_style));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions scene/main/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2465,7 +2465,7 @@ NodePath Node::get_import_path() const {

static void _add_nodes_to_options(const Node *p_base, const Node *p_node, List<String> *r_options) {
#ifdef TOOLS_ENABLED
const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", 0) ? "'" : "\"";
const String quote_style = EDITOR_GET("text_editor/completion/use_single_quotes") ? "'" : "\"";
#else
const String quote_style = "\"";
#endif
Expand All @@ -2474,7 +2474,7 @@ static void _add_nodes_to_options(const Node *p_base, const Node *p_node, List<S
return;
}
String n = p_base->get_path_to(p_node);
r_options->push_back(quote_style + n + quote_style);
r_options->push_back(n.quote(quote_style));
for (int i = 0; i < p_node->get_child_count(); i++) {
_add_nodes_to_options(p_base, p_node->get_child(i), r_options);
}
Expand Down
4 changes: 2 additions & 2 deletions scene/resources/material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ void ShaderMaterial::_bind_methods() {

void ShaderMaterial::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
#ifdef TOOLS_ENABLED
const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", 0) ? "'" : "\"";
const String quote_style = EDITOR_GET("text_editor/completion/use_single_quotes") ? "'" : "\"";
#else
const String quote_style = "\"";
#endif
Expand All @@ -279,7 +279,7 @@ void ShaderMaterial::get_argument_options(const StringName &p_function, int p_id
List<PropertyInfo> pl;
shader->get_param_list(&pl);
for (const PropertyInfo &E : pl) {
r_options->push_back(quote_style + E.name.replace_first("shader_param/", "") + quote_style);
r_options->push_back(E.name.replace_first("shader_param/", "").quote(quote_style));
}
}
}
Expand Down