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

Change displayBuildTarget to listBuildTargets #893

Merged
merged 1 commit into from
Feb 25, 2022

Conversation

Arthurm1
Copy link
Contributor

see scalameta/metals#3649

This shifts the burden of quickpicking from Metals onto the client

@Arthurm1
Copy link
Contributor Author

Needs scalameta/metals-languageclient#419 to pass checks

Copy link
Contributor

@tgodzik tgodzik left a comment

Choose a reason for hiding this comment

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

Looks good! Just one small suggestion in regards to parsing, but it can be ignored.

Otherwise, let's bump the language client and default metals server version once the PR in metals is merged (which I will do in a sec.)

src/extension.ts Outdated
if (args.length > 0) {
// get build target name from treeview uri of the form "projects:file:/root/metals/.mtags/?id=mtags3!/_root_/,"
const treeViewUri = args[0] as string;
const buildTargetRegEx = new RegExp("projects:.*?id=(.*)!.*", "g");
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we instead parse it as an URI and get the query parameters?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would still only get us halfway there.

A URI example from the treeview would be...
projects:file:/root/metals/.mtags/?id=mtags3!/_root_/

Using URLSearchParams(uri).get("id") would give...
mtags3!/_root_/

So I'd still need to parse for ! to get mtags3

I can do that if you want?

Copy link
Contributor

Choose a reason for hiding this comment

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

We could then just do split("!") so maybe it's a bit clrearer than a regex?

Copy link
Member

Choose a reason for hiding this comment

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

This splitting part seems too much for me.
IMO in this case regex is simpler and with the proper example in the comment (exists) isn't also that hard to understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm easy. Ideally the treeviewuri would be in the format we already want but it's used to work out how to drill down into classes/methods so I wasn't going to change it. I tried to extract the target name with URLSearchParams but it doesn't like our URI so converts the whole thing to a single query param which is no help. I guess URI != URL

Copy link
Contributor

Choose a reason for hiding this comment

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

ok then, for me whichever is fine

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've changed to split + split. Does the job. 🤷

src/extension.ts Outdated
Comment on lines 594 to 605
client
.sendRequest(ExecuteCommandRequest.type, {
command: ServerCommands.ListBuildTargets,
})
.then(async (...args: any[]) => {
const targets = args?.[0] as string[];
window.showQuickPick(targets).then((target) => {
if (target) {
displayBuildTarget(target);
}
});
});
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
client
.sendRequest(ExecuteCommandRequest.type, {
command: ServerCommands.ListBuildTargets,
})
.then(async (...args: any[]) => {
const targets = args?.[0] as string[];
window.showQuickPick(targets).then((target) => {
if (target) {
displayBuildTarget(target);
}
});
});
const targets = await client.sendRequest(ExecuteCommandRequest.type, {
command: ServerCommands.ListBuildTargets,
});
const picked = await window.showQuickPick(targets);
if (picked) {
displayBuildTarget(picked);
}

Should work the same and, at least for me, it's more readable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've made the change. Works for me. I don't know typescript well enough to know the implications.

Copy link
Contributor

@tgodzik tgodzik left a comment

Choose a reason for hiding this comment

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

LGTM!

@tgodzik tgodzik merged commit 2eae95e into scalameta:main Feb 25, 2022
@Arthurm1 Arthurm1 deleted the list_build_target branch February 25, 2022 10:53
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