fix: Support creating new project when no workspace folder (#1163)

This commit is contained in:
Shi Chen 2022-01-24 17:15:37 +08:00 коммит произвёл GitHub
Родитель b63118547a
Коммит 058fe3e484
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 11 добавлений и 12 удалений

Просмотреть файл

@ -38,7 +38,8 @@
"workspaceContains:build.gradle",
"workspaceContains:settings.gradle",
"workspaceContains:build.gradle.kts",
"workspaceContains:settings.gradle.kts"
"workspaceContains:settings.gradle.kts",
"onCommand:gradle.createProject"
],
"main": "./dist/index.js",
"contributes": {
@ -479,11 +480,7 @@
},
{
"command": "gradle.createProject",
"when": "gradle:extensionActivated && !java:projectManagerActivated"
},
{
"command": "gradle.createProjectAdvanced",
"when": "gradle:extensionActivated"
"when": "!java:projectManagerActivated"
}
],
"view/title": [

Просмотреть файл

@ -240,7 +240,7 @@ export class Extension {
private async activate(): Promise<void> {
const activated = !!(await this.rootProjectsStore.getProjectRoots()).length;
if (activated && !this.server.isReady()) {
if (!this.server.isReady()) {
await this.server.start();
}
await vscode.commands.executeCommand("setContext", "gradle:activated", activated);

Просмотреть файл

@ -47,7 +47,7 @@ export class CreateProjectCommand extends Command {
const success = await this.runSteps(metadata);
if (success) {
await this.createProject(metadata);
const openInNewWindow = !(folders && folders.length);
const openInNewWindow = folders !== undefined;
vscode.commands.executeCommand(
"vscode.openFolder",
vscode.Uri.file(metadata.targetFolder),

Просмотреть файл

@ -71,10 +71,12 @@ public class GradleLanguageServer implements LanguageServer, LanguageClientAware
Map<?, ?> initOptions = new Gson().fromJson((JsonElement) params.getInitializationOptions(), Map.class);
// TODO: support multiple workspace folders
List<WorkspaceFolder> workspaceFolders = params.getWorkspaceFolders();
for (WorkspaceFolder folder : workspaceFolders) {
URI uri = URI.create(folder.getUri());
this.gradleServices.getLibraryResolver().setWorkspacePath(Paths.get(uri));
break;
if (workspaceFolders != null) {
for (WorkspaceFolder folder : workspaceFolders) {
URI uri = URI.create(folder.getUri());
this.gradleServices.getLibraryResolver().setWorkspacePath(Paths.get(uri));
break;
}
}
Object settings = initOptions.get("settings");
this.gradleServices.applySetting(settings);