Skip to content

Comments

Make the run buttons in editor toolbar more context-aware#898

Merged
testforstephen merged 6 commits intomasterfrom
cs/editor-toolbar
Oct 30, 2020
Merged

Make the run buttons in editor toolbar more context-aware#898
testforstephen merged 6 commits intomasterfrom
cs/editor-toolbar

Conversation

@jdneo
Copy link
Member

@jdneo jdneo commented Oct 28, 2020

  • If the file has a main() method, run it
  • If the file is a test file, delegate to Test Runner
  • If neither has a main() method nor is a test file, try to launch as a project
  • If both has a main() method and is a test file, let the user to choose

Signed-off-by: Sheng Chen sheche@microsoft.com

- If the file has a main() method, run it
- If the file is a test file, delegate to Test Runner
- If neither has a main() method nor is a test file, try to launch as a
project
- If both has a main() method and is a test file, let the user to
choose

Signed-off-by: Sheng Chen <sheche@microsoft.com>
@jdneo jdneo requested a review from testforstephen October 28, 2020 08:19
Signed-off-by: Sheng Chen <sheche@microsoft.com>
src/extension.ts Outdated
Comment on lines 271 to 276
const workspaceFolder: vscode.WorkspaceFolder | undefined = vscode.workspace.getWorkspaceFolder(uri);
if (!workspaceFolder) {
vscode.window.showErrorMessage(`Failed to run the project because the file: ${uri.fsPath} does not belongs to the current workspace.`);
return;
}
const mainClasses: IMainClassOption[] = await utility.searchMainMethods(workspaceFolder.uri);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we just search the main method from the whole workspace directly instead of limiting to the belonging root?

Copy link
Member Author

Choose a reason for hiding this comment

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

Update the utility method to make it possible to search all main classes in the workspace. Another question, do you think we need to differentiate the "mains" by appending the belonging project name in the list?

image

Copy link
Contributor

Choose a reason for hiding this comment

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

yes. if it falls back to run the main from the workspace, adding project name in the list would help.

Copy link
Member Author

Choose a reason for hiding this comment

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

New look:

WeChat Screenshot_20201030135941

jdneo added 2 commits October 30, 2020 11:09
Signed-off-by: Sheng Chen <sheche@microsoft.com>
Signed-off-by: Sheng Chen <sheche@microsoft.com>
src/utility.ts Outdated
}
const mainClasses: IMainClassOption[] = [];
for (const uri of uris) {
mainClasses.push(...await resolveMainClass(uri));
Copy link
Contributor

Choose a reason for hiding this comment

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

Calling search engine multiple times is not efficient. In current PR, i didn't see there is requirement to search for multiple uris at one time. I suggest to keep passing at most 1 uri in this method. If there is requirement in future to search for multiple uris, we can improve the Java side logic for that.

Copy link
Member Author

Choose a reason for hiding this comment

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

But what if the workspace has multiple folders? calling searchMainMethods() multiple times?

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 didn't pass uri in this method, it means searching in all folders.

If you look at the Java implementation, what it did is searching all results first. and if there is a uri given, then filter the result with the uri, otherwise, return all.

Copy link
Contributor

Choose a reason for hiding this comment

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

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 see

@testforstephen testforstephen merged commit ce265cb into master Oct 30, 2020
@testforstephen
Copy link
Contributor

thanks @jdneo

@testforstephen testforstephen deleted the cs/editor-toolbar branch October 30, 2020 07:40
@testforstephen testforstephen added this to the 0.30.0 milestone Nov 2, 2020
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.

2 participants