Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New runnables #4710

Merged
merged 3 commits into from
Jun 2, 2020
Merged

New runnables #4710

merged 3 commits into from
Jun 2, 2020

Conversation

matklad
Copy link
Member

@matklad matklad commented Jun 2, 2020

bors d=@vsrs

@bors
Copy link
Contributor

bors bot commented Jun 2, 2020

✌️ vsrs can now approve this pull request. To approve and merge a pull request, simply reply with bors r+. More detailed instructions are available here.

}
```

rust-analyzer supports only one `kind`, `"cargo"`. The `args` for `"cargo"` look like this:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it makes sense to distinguish different cargo commands?
I believe test targets, binaries and utility commands like 'check' should be different things. Anyway on the client side we have to filter them here and there.

export interface BinaryArgs { /*...*/ }
export interface TestArgs { /*...*/ }
export interface CheckArgs { /*...*/ }
export interface ExpandArgs { /*...*/ }

export interface Runnable {
    label: string;
    location?: lc.LocationLink;
    kind: "cargo";
    workspaceRoot?: string;
    args: BinaryArgs | TestArgs | CheckArgs | ExpandArgs;
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve thought about this, but decided that looking at the cargoArgs[0] is probably good enough

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me the main benefit of having different XXXArg kinds is that it would be easier and less error prone to get, for example, test id or expandable function name, etc. No need to parse raw string array and write client side tests :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better use a discriminated union with kind discriminator. Types are our friends, not enemies...
any is generally bad practice and lsp has it just because it is legacy (e.g. unknown is called to replace it), bear with me...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can't be a discritimated union, because it needs to be open. We'll use unknown once the LSP spec uses unknown.

I've though about it, and I see how for Cargo case we might want to use BinaryArgs | TestArgs in principle, but:

  • it seems like we don't need those right now
  • it seems like when we add support for non-cargo based build systems, the specific layout here will change.

So, I think I'd stick with the simplest possible thing for now.

```typescript
interface RunnablesParams {
textDocument: TextDocumentIdentifier;
/// If null, compute runnables for the whole file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// If null, compute runnables for the whole file.
/// If not present, compute runnables for the whole file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you intended for it to possibly be null, then it better be position?: null | Position;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe protocol is using | null for semantcially similar cases.

}
```

rust-analyzer supports only one `kind`, `"cargo"`. The `args` for `"cargo"` look like this:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better use a discriminated union with kind discriminator. Types are our friends, not enemies...
any is generally bad practice and lsp has it just because it is legacy (e.g. unknown is called to replace it), bear with me...

@matklad
Copy link
Member Author

matklad commented Jun 2, 2020

bors r+

@bors
Copy link
Contributor

bors bot commented Jun 2, 2020

@bors bors bot merged commit 2f6ab77 into rust-lang:master Jun 2, 2020
@matklad matklad deleted the new-runnables branch June 3, 2020 07:28
@vsrs vsrs mentioned this pull request Jun 6, 2020
bors bot added a commit that referenced this pull request Jun 6, 2020
4769: Fix Run lens. r=matklad a=vsrs

This PR fixes a bug introduced in #4710: second and all subsequent clicks on the Run lens produce invalid commands:

1. `cargo test --package ra_ide --lib -- hover::tests::test_hover_enum_has_impl_action --exact --nocapture`
2. `cargo test --package ra_ide --lib -- hover::tests::test_hover_enum_has_impl_action --exact --nocapture` **`-- hover::tests::test_hover_enum_has_impl_action --exact --nocapture`**
3. `cargo test --package ra_ide --lib -- hover::tests::test_hover_enum_has_impl_action --exact --nocapture` **`-- hover::tests::test_hover_enum_has_impl_action --exact --nocapture -- hover::tests::test_hover_enum_has_impl_action --exact --nocapture`**

Co-authored-by: vsrs <vit@conrlab.com>
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.

None yet

3 participants