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

Implemented {project} placeholder for external dotnet editor #81847

Merged
merged 1 commit into from
Sep 20, 2023

Conversation

crazyStewie
Copy link
Contributor

This PR fixes #81845 , by mimicking the implementation at

String project_path = ProjectSettings::get_singleton()->get_resource_path();
flags = flags.replacen("{line}", itos(p_line > 0 ? p_line : 0));
flags = flags.replacen("{col}", itos(p_col));
flags = flags.strip_edges().replace("\\\\", "\\");
int from = 0;
int num_chars = 0;
bool inside_quotes = false;
for (int i = 0; i < flags.size(); i++) {
if (flags[i] == '"' && (!i || flags[i - 1] != '\\')) {
if (!inside_quotes) {
from++;
}
inside_quotes = !inside_quotes;
} else if (flags[i] == '\0' || (!inside_quotes && flags[i] == ' ')) {
String arg = flags.substr(from, num_chars);
if (arg.contains("{file}")) {
has_file_flag = true;
}
// do path replacement here, else there will be issues with spaces and quotes
arg = arg.replacen("{project}", project_path);
arg = arg.replacen("{file}", script_path);

As the function ProjectSettings::get_singleton()->get_resource_path() isn't exposed in the godot API, this solution instead makes use of ProjectSettings.GlobalizePath("res://"), which, on editor builds, returns ProjectSettings.resource_path + "/", according to its implementation at

String ProjectSettings::globalize_path(const String &p_path) const {
if (p_path.begins_with("res://")) {
if (!resource_path.is_empty()) {
return p_path.replace("res:/", resource_path);
}
return p_path.replace("res://", "");
} else if (p_path.begins_with("user://")) {
String data_dir = OS::get_singleton()->get_user_data_dir();
if (!data_dir.is_empty()) {
return p_path.replace("user:/", data_dir);
}
return p_path.replace("user://", "");
}
return p_path;
}

@crazyStewie crazyStewie requested a review from a team as a code owner September 18, 2023 04:30
@raulsntos raulsntos added enhancement topic:editor topic:dotnet cherrypick:4.1 Considered for cherry-picking into a future 4.1.x release labels Sep 18, 2023
Copy link
Member

@raulsntos raulsntos left a comment

Choose a reason for hiding this comment

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

Thanks for contributing to the .NET module! The changes look good, they're pretty much the same changes requested by @RedworkDE in #74517 (comment).

@raulsntos raulsntos added this to the 4.x milestone Sep 19, 2023
Copy link
Member

@raulsntos raulsntos left a comment

Choose a reason for hiding this comment

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

Looks good to me already. Since you are a new contributor, make sure to read CONTRIBUTING.md and the contributing documentation if you haven't already.

You'll need to squash the commits before this PR can be merged. The contributing documentation contains information about squashing in case you need it.

Feel free to reach out in the development chat if you need help.

@crazyStewie crazyStewie force-pushed the dotnet_editor_project_fix branch 2 times, most recently from 79cd98e to d756c26 Compare September 19, 2023 21:52
@akien-mga akien-mga modified the milestones: 4.x, 4.2 Sep 19, 2023
Implements the {project} placeholder, available when setting an external editor
in the project settings, via Editor > Editor Settings > Text Editor > External
for the c# external editor, under Editor > Editor Settings > Dotnet > Editor,

This allows passing the project folder as a command line argument when using a
custom external editor that isn't one of the available options.

Fixes godotengine#81845
@crazyStewie crazyStewie force-pushed the dotnet_editor_project_fix branch from d756c26 to c01a478 Compare September 20, 2023 13:20
@akien-mga akien-mga merged commit 5fd8506 into godotengine:master Sep 20, 2023
15 checks passed
@akien-mga
Copy link
Member

akien-mga commented Sep 20, 2023

Thanks! And congrats for your first merged Godot contribution 🎉

@akien-mga akien-mga changed the title Implemented {project} placeholder for external dotnet editor Implemented {project} placeholder for external dotnet editor Oct 3, 2023
@YuriSizov YuriSizov removed the cherrypick:4.1 Considered for cherry-picking into a future 4.1.x release label Jan 23, 2024
@YuriSizov
Copy link
Contributor

Cherry-picked for 4.1.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

{project} Placeholder not implemented for custom external dotnet editor
5 participants