Skip to content

Use one-based line numbers for external text editors #107816

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

Merged

Conversation

Meorge
Copy link
Contributor

@Meorge Meorge commented Jun 21, 2025

Closes #107809 . Closes #100832 . Supercedes #107812 .

The table in #107809 notes that all of the external editors mentioned by the Godot Docs expect line numbers to start at 1. Internally, Godot considers line numbers to start at 0. This PR simply adds 1 to an existing line number before passing it to an external editor, so that the editor highlights the correct line.

As noted in the PR's comment, a better long-term solution may be to have Godot adopt one-based line numbering internally. I chose to take a more conservative approach for now, to avoid breaking other parts of the engine or editor while fixing the problem at hand.

Copy link
Contributor

@kitbdev kitbdev left a comment

Choose a reason for hiding this comment

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

The column should also be 1 indexed.

We can't completely change to a 1 index system internally in the future, it would just cause lots of issues. The lines are stored in a vector which is always going to be 0 indexed, and it would cause compatibility issues if we change TextEdit and CodeEdit methods to be 1 indexed as well. I also doubt those editors all actually use 1 indexed internally, its just the interface.
So there is always going to be conversion between them, we just need to better define where it happens.
We already display line numbers in the editor as starting from 1, and EditorInterface::edit_script looks like it is already 1 indexed.

@Meorge Meorge force-pushed the bugfix/everyone-uses-one-based-line-numbers branch from 3162399 to 5c94b2e Compare June 23, 2025 19:57
Copy link
Contributor

@kitbdev kitbdev left a comment

Choose a reason for hiding this comment

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

Tested on multiple different editors, works as expected.

@Repiteo Repiteo merged commit c157e61 into godotengine:master Jun 24, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Jun 24, 2025

Thanks!

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.

VS Code opens to line before error on selecting stack trace/error/warning External Editor line flag differs in behavior from internal editor
4 participants