Make the run buttons in editor toolbar more context-aware#898
Make the run buttons in editor toolbar more context-aware#898testforstephen merged 6 commits intomasterfrom
Conversation
- 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>
Signed-off-by: Sheng Chen <sheche@microsoft.com>
src/extension.ts
Outdated
| 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); |
There was a problem hiding this comment.
Can we just search the main method from the whole workspace directly instead of limiting to the belonging root?
There was a problem hiding this comment.
yes. if it falls back to run the main from the workspace, adding project name in the list would help.
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)); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
But what if the workspace has multiple folders? calling searchMainMethods() multiple times?
There was a problem hiding this comment.
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.
|
thanks @jdneo |


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