Skip to content

refactor(workspace): move formatting out of server.rs - #975

Closed
psteinroe wants to merge 2 commits into
fix/workspace-shared-statement-walkfrom
refactor/workspace-formatting
Closed

psteinroe wants to merge 2 commits into
fix/workspace-shared-statement-walkfrom
refactor/workspace-formatting

Conversation

@psteinroe

Copy link
Copy Markdown
Collaborator

Stacked on #974.

Two moves in the workspace server that change no behaviour.

Formatting moves to server/formatting.rs

pull_file_formatting had about 200 lines of formatting inline: it built the FormatConfig, formatted the bodies of SQL functions, and rebuilt the file from the formatted statements and the text between them. collapse_blank_lines and restore_named_parameters sat at the end of server.rs. These now live in server/formatting.rs as format_config and format_document(doc, settings, range, path), together with the two helpers. pull_file_formatting reads the settings and the document, calls format_document, and charges the document caches. The code moved as it was. It reads settings.formatter.x as settings.x and params.range as range, and nothing else changed. server.rs goes from 2,141 to 1,876 lines.

One visitor for the lint and splinter rule selection

LintVisitor and SplinterVisitor in server/analyser.rs were copies of each other with two differences:

  • which configured rules they add when there is no only (as_linter_rules or as_splinter_rules);
  • the lint visitor drops the lint rules when linter.enabled is off, and the typecheck rules when typecheck.enabled is off.

They are now one RuleSelection that collects what only and skip select. AnalyserVisitorBuilder::finish passes in the configured rules and applies the enabled check to the lint rules. The splinter visitor recorded every category, while the lint visitor only recorded the categories of the lint kind. The splinter registry has one category, and declare_category! declares it with kind: Lint, so the shared filter visits the same rules.

Tests

The existing tests cover both: the formatting tests in pgls_workspace (ranges, SQL function bodies, named parameters, blank lines) and recognizes_disabled_linter_rules plus the diagnostics tests with only/skip. cargo test -p pgls_workspace and clippy pass.

pull_file_formatting builds the format config and formats the document in server/formatting.rs, together with collapse_blank_lines and restore_named_parameters. The code is moved as it was.
…ter visitors

LintVisitor and SplinterVisitor only differed in the rules that the configuration enables and disables, and in the check of linter.enabled and typecheck.enabled for the lint rules. Both are now a RuleSelection, and AnalyserVisitorBuilder passes the configured rules and applies the check. The splinter category is of the lint kind, so filtering the categories to lint as LintVisitor did visits the same rules.
@psteinroe

Copy link
Copy Markdown
Collaborator Author

Superseded by #988 (rebuild of the document caches and walk).

@psteinroe psteinroe closed this Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant