Repository navigation
Conversation
…etions and inlay hints The analyser and the workspace each had their own loop that follows the catalog through the statements of a file. The workspace's loop only switched to a new migration section when it reached a statement in it, so completions in the first statement after a down section saw the changes of the down section. Both now use `pgls_analyser::walk_statements`, which also returns the catalog as a statement at the end of the walk sees it. Statements with identifier parameters like `create table :name` taint the catalog instead of being applied with their placeholder names, and only statements that run do so, not the bodies of SQL functions. The analyser still stops typechecking after such a statement.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #965.
The analyser and the workspace each had a loop that follows the catalog through the statements of a file:
Analyser::analysefor lint and typecheck, andWorkspaceServer::walk_statementsfor hover, completions and inlay hints. Onmainthere was a third one,snapshot_before, which ignored sections, unparsable statements and identifier parameters; #956 already moved completions and hover ontowalk_statements. The two remaining loops still differed.What was broken
The workspace's loop only switched to a new migration section when it reached a statement in it. Completions walk up to the start of the statement being completed, so in the first statement after a down section they saw the down section's changes, while lint didn't:
Statements with identifier parameters were handled differently too:
create table :name (...)to the catalog with the placeholder name, so the file then had a tablename. It stopped typechecking right after, so this didn't show in lint, but it is wrong for anything else that reads the catalog.What changed
pgls_analyser::walk_statements(WalkParams, visit)in a newwalk.rsis the only walk. It holds the section handling (each section has its own session and transaction mode, and a down section's changes are dropped afterwards), unparsable statements tainting the catalog, and function bodies not being applied.visitgets each statement with itsAnalysedFileContext.WalkParams::endstops the walk, and the walk returns the catalog that a statement atendsees. The section that containsenddecides which catalog that is, not the last statement walked, and that fixes the completions case above.Analyser::analyseruns the rules invisit.WorkspaceServer::walk_statementscollects the statements that start beforeendand calls the same function. Hover and inlay hints skip statements with identifier parameters in their visitor, like before.may_change_catalogandis_plain_querymoved intowalk.rsand are now private to the crate. They had no other users.Tests
lint_hover_and_completions_see_the_same_catalog(workspace) checks typecheck diagnostics, completions and hover in the same file for three cases: the first statement after a down section, a statement after one that doesn't parse, and a statement aftercreate table :tbl. On #965, the down-section case fails: completions includedown_only. The other two pass there and pin the shared behaviour.pgls_analyser(rules specs, Postgres regression),pgls_workspace(including the memory and edit-churn tests) andpgls_lsppass.Performance
Release build, 5,000-statement dbmate file. Each iteration changes a table name in the middle of the file, then requests hover on the last query, completions at the end, inlay hints over the last 2 KB, and diagnostics. The numbers are averages over 20 keystrokes. Runs alternated between the two branches on a shared machine, so expect about ±15% noise.
Memory tests (release, defaults):
memory_boundsone-document peak 25.7 → 26.0 MiB (the workspace walk now collects the statements before walking them), all-open peak 242.4 MiB and retained 220.7 MiB unchanged.edit_churnretains 32.9 / 36.1 MiB on both.Not covered
Hover and completions still walk every statement before the cursor after each change, about 100 ms at 5,000 statements in release. Caching catalogs at points in the file would fix that, but it is a separate change.