Skip to content

Commit b0d4986

Browse files
committed
Stop ignoring import clauses in non-unit files
Previously there were concerns over breaking IDE features by formatting these sections, but after some testing and reconsideration we have decided that this is a non-issue and it's better to consistently format all import clauses. In `program` files (dpr) RAD Studio will sometimes store some metadata in special comments adjacent to the imports in the `uses` clause. This is apparently an artifact of a time before Delphi had dproj files, where it would indicate whether a unit contains a form only using the comment. Various IDE features depend on 'knowing' what forms are available and what their names are, including 1. opening the form when you open the unit 2. showing the form in the project overview panel 3. being able to inherit from the form using the IDE dialogs 4. being able to open a frame contained within a form In modern Delphi, the IDE also reads the dproj to find out about the contained forms, and in such cases doesn't need the comment at all. What about when it needs to read the comment? Does the formatting break that feature? It doesn't appear that it does. `pasfmt` only changes two things when formatting the uses clause in a dpr file when compared to what the IDE generates. 1. `{$ifdef}` directives are moved all the way left to the margin, and 2. if a unit name is really long, then the `in '...'` part of the import is wrapped to the next line. In our testing all the IDE features continue to work when the dproj doesn't contain the information about the form and the uses clause is formatted by `pasfmt`. A secondary concern to the breakage of form features was the fact that we would be 'fighting' against the formatting that the IDE generates. On reconsideration, this doesn't seem like a compelling reason to skip formatting these sections. It's highly unintuitive that the formatter skips formatting these sections, and it's undesirable when the user is writing actual code in the program file, because they will be manually adding to the import clause for the units they need, and they can't make the formatter format the changes they are making. There will inevitably be some level of flip-flopping of formatting, but if one cares about having all their source files automatically formatted they should have some other process ensuring that is the case. Additionally, this flip-flopping is limited to conditional directives and wrapped `in` expressions, because the style `pasfmt` uses (with default whitespace configuration) is very similar to the style generated by the IDE. In the case of dpk files, we may well make an exception and change our formatting style for the conditional directives for the `IMPLICITBUILD` block (see #166), because the file is completely generated and it's guaranteed to affect every dpk file. This PR should supersede #200.
1 parent 436b9d5 commit b0d4986

File tree

5 files changed

+9
-270
lines changed

5 files changed

+9
-270
lines changed

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
77

88
## [Unreleased]
99

10-
### Fixed
10+
### Changed
1111

12-
- Fixed conditional directives not being ignored between `uses` and import list in non-units.
12+
- Uses, contains, and requires clauses in `program`, `package`, and `library` files are no longer ignored.
13+
Previously there were concerns over breaking IDE features by formatting these sections, but after some
14+
testing and reconsideration we have decided that this is a non-issue and it's better to consistently
15+
format all import clauses.
1316

1417
## [0.4.0-rc2] - 2025-03-12
1518

core/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Removed
11+
12+
- Removed `IgnoreNonUnitImportClauses`; all import clauses are now formatted.
13+
1014
## [0.4.0-rc2] - 2025-03-12
1115

1216
### Changed

core/src/rules/ignore_non_unit_import_clauses.rs

Lines changed: 0 additions & 265 deletions
This file was deleted.

core/src/rules/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ pub mod eof_newline;
33
pub mod formatting_toggle;
44
pub mod generics_consolidator;
55
pub mod ignore_asm_instructions;
6-
pub mod ignore_non_unit_import_clauses;
76
pub mod optimising_line_formatter;
87
pub mod token_spacing;
98

@@ -12,6 +11,5 @@ pub use eof_newline::*;
1211
pub use formatting_toggle::*;
1312
pub use generics_consolidator::*;
1413
pub use ignore_asm_instructions::*;
15-
pub use ignore_non_unit_import_clauses::*;
1614
pub use optimising_line_formatter::*;
1715
pub use token_spacing::*;

front-end/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,6 @@ pub fn make_formatter(config: &FormattingConfig) -> Formatter {
305305
.token_consolidator(DistinguishGenericTypeParamsConsolidator {})
306306
.lines_consolidator(ConditionalDirectiveConsolidator {})
307307
.token_ignorer(FormattingToggler {})
308-
.token_ignorer(IgnoreNonUnitImportClauses {})
309308
.token_ignorer(IgnoreAsmIstructions {})
310309
.file_formatter(TokenSpacing {})
311310
.line_formatter(FormatterSelector::new(

0 commit comments

Comments
 (0)