Skip to content

refactor(workspace): move the code actions into their own module - #990

Open
psteinroe wants to merge 1 commit into
mainfrom
refactor/code-actions-module
Open

psteinroe wants to merge 1 commit into
mainfrom
refactor/code-actions-module

Conversation

@psteinroe

Copy link
Copy Markdown
Collaborator

Follow-up to the review of #920 ("maybe we should split code actions into their own module now that we have expand star and execute statement") and #932 ("Shouldn't this be in server/features/expand_star?").

features/code_actions.rs only held the request and result types. The logic of the actions was spread over workspace/server.rs (lint fixes, suppressions, fix_file, the execute and invalidate actions), workspace/server/expand_star.rs and workspace/server/statement_execution.rs. This moves it into one module, with a file per action:

  • features/code_actions.rs: the types shared by all actions (CodeActionsParams, CodeAction, CodeActionKind, EditAction, TextEdit, ...), and re-exports of the types below, so features::code_actions::ExecuteStatementParams etc. keep working.
  • code_actions/lint.rs: FixFileParams/FixFileMode/FixFileResult, the quick fixes and suppressions at the cursor, suppression_edit, and the fix loop of fix_file.
  • code_actions/expand_star.rs: moved unchanged from workspace/server/.
  • code_actions/execute_statement.rs: the execute statement types, the "Execute Statement" actions, and execute_statement/execution.rs, the execution against the database (moved unchanged from workspace/server/statement_execution.rs).
  • code_actions/schema_cache.rs: the "Invalidate Schema Cache" action.

WorkspaceServer still gathers the inputs, i.e. the document, settings, snapshot and connection, which are private to the server, and calls the functions of the module with them. pull_code_actions now reads as a list: lint actions, refactors, execute statement, invalidate schema cache, in the same order as before.

This is a move only. No behaviour changes, and the TS bindings and docs/schema.json stay the same (just gen-lint leaves the tree clean).

Tests

cargo test -p pgls_workspace (195 passed, including the code action, expand star and fix-file tests) and cargo test -p pgls_lsp pass unchanged. cargo clippy --workspace --all-targets -- -D warnings is clean.

features/code_actions.rs only held the request and result types, while the
logic of each action lived in workspace/server.rs, server/expand_star.rs
and server/statement_execution.rs. Each action now has a submodule:

- lint: the fixes and suppressions of lint diagnostics, and fix_file
- expand_star: moved from workspace/server
- execute_statement: its types, the "Execute Statement" actions, and the
  execution against the database (moved from server/statement_execution)
- schema_cache: the "Invalidate Schema Cache" action

The server keeps gathering the inputs (documents, settings, snapshot,
connection) and calls into the module. The types are re-exported from
features::code_actions, so the public API is unchanged. No behaviour
change.

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