]> git.lizzy.rs Git - rust.git/commit
Fix `cargo watch` code action filtering
authorRyan Cumming <etaoins@gmail.com>
Thu, 27 Jun 2019 11:30:23 +0000 (21:30 +1000)
committerRyan Cumming <etaoins@gmail.com>
Sat, 29 Jun 2019 07:39:36 +0000 (17:39 +1000)
commitabc0784e57610a0cceca63301489918015418df6
tree05aec9fef88f31cee82e3507903a1dbcd6b4d30d
parent0e1912de528b5092c10eedaf94c43c67d5f86f1a
Fix `cargo watch` code action filtering

There are two issues with the implementation of `provideCodeActions`
introduced in #1439:

1. We're returning the code action based on the file its diagnostic is
   in; not the file the suggested fix is in. I'm not sure how often
   fixes are suggested cross-file but it's something we should handle.

2. We're not filtering code actions based on the passed range. The means
   if there is any suggestion in a file we'll show an action for every
   line of the file. I naively thought that VS Code would filter for us
   but that was wrong.

Unfortunately the VS Code `CodeAction` object is very complex - it can
handle edits across multiple files, run commands, etc. This makes it
complex to check them for equality or see if any of their edits
intersects with a specified range.

To make it easier to work with suggestions this introduces a
`SuggestedFix` model object and a `SuggestFixCollection` code action
provider. This is a layer between the raw Rust JSON and VS Code's
`CodeAction`s. I was reluctant to introduce another layer of abstraction
here but my attempt to work directly with VS Code's model objects was
worse.
13 files changed:
editors/code/src/commands/cargo_watch.ts
editors/code/src/test/rust_diagnostics.test.ts [deleted file]
editors/code/src/test/utils/diagnotics/SuggestedFix.test.ts [new file with mode: 0644]
editors/code/src/test/utils/diagnotics/SuggestedFixCollection.test.ts [new file with mode: 0644]
editors/code/src/test/utils/diagnotics/rust.test.ts [new file with mode: 0644]
editors/code/src/test/utils/diagnotics/vscode.test.ts [new file with mode: 0644]
editors/code/src/test/vscode_diagnostics.test.ts [deleted file]
editors/code/src/utils/diagnostics/SuggestedFix.ts [new file with mode: 0644]
editors/code/src/utils/diagnostics/SuggestedFixCollection.ts [new file with mode: 0644]
editors/code/src/utils/diagnostics/rust.ts [new file with mode: 0644]
editors/code/src/utils/diagnostics/vscode.ts [new file with mode: 0644]
editors/code/src/utils/rust_diagnostics.ts [deleted file]
editors/code/src/utils/vscode_diagnostics.ts [deleted file]