Skip to content

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

Open
psteinroe wants to merge 1 commit into
mainfrom
refactor/workspace-formatting-rebuild
Open

psteinroe wants to merge 1 commit into
mainfrom
refactor/workspace-formatting-rebuild

Conversation

@psteinroe

Copy link
Copy Markdown
Collaborator

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 and calls format_document. 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,296 to 2,021 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 on the whole workspace pass.

Update: This is #975 again, rebuilt on main as the first PR of the rebuild of the document caches and the walk (#918/#929 and their stacks are closed in favour of it). main has gained the rule that a SQL function body with several statements is left as written (#947) since #975 was opened; that code moved along unchanged. It no longer charges the document caches, which don't exist on main.

The formatting of a document moves to server/formatting.rs as it was, and
the lint and splinter rule selection visitors become one RuleSelection.
No behaviour changes.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant