Skip to content

Commit

Permalink
fix not being able to create/initialize projects in empty workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
SpontanCombust committed Jun 15, 2024
1 parent 3c2ed5e commit 9570659
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
6 changes: 2 additions & 4 deletions editors/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,12 @@
{
"command": "witcherscript-ide.projects.init",
"title": "Initialize a WitcherScript project in existing directory...",
"category": "WitcherScript-IDE",
"enablement": "witcherscript-ide.languageServerActive"
"category": "WitcherScript-IDE"
},
{
"command": "witcherscript-ide.projects.create",
"title": "Create a new WitcherScript project...",
"category": "WitcherScript-IDE",
"enablement": "witcherscript-ide.languageServerActive"
"category": "WitcherScript-IDE"
},
{
"command": "witcherscript-ide.scripts.importVanilla",
Expand Down
25 changes: 16 additions & 9 deletions editors/vscode/src/commands/projects.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as vscode from 'vscode';
import * as lsp from 'vscode-languageclient/node';
import * as path from 'path';
import * as fs from 'fs/promises';

Expand All @@ -11,6 +12,12 @@ import { Cmd } from './index'

export function commandInitProject(context: vscode.ExtensionContext): Cmd {
return async () => {
const client = getLanguageClient();
if (client == undefined) {
vscode.window.showErrorMessage("Language Server needs to be active!");
return;
}

const initialDirUri = vscode.workspace.workspaceFolders ? vscode.workspace.workspaceFolders[0].uri : undefined;

const projectDirUri = await vscode.window.showOpenDialog({
Expand Down Expand Up @@ -45,12 +52,18 @@ export function commandInitProject(context: vscode.ExtensionContext): Cmd {
}


await initializeProjectInDirectory(projectDirUri, projectName, context);
await initializeProjectInDirectory(client, projectDirUri, projectName, context);
}
}

export function commandCreateProject(context: vscode.ExtensionContext): Cmd {
return async () => {
const client = getLanguageClient();
if (client == undefined) {
vscode.window.showErrorMessage("Language Server needs to be active!");
return;
}

const projectName = await vscode.window.showInputBox({
prompt: "Enter the name of the project",
ignoreFocusOut: true,
Expand Down Expand Up @@ -89,7 +102,7 @@ export function commandCreateProject(context: vscode.ExtensionContext): Cmd {


const projectDirUri = vscode.Uri.file(projectDir);
await initializeProjectInDirectory(projectDirUri, projectName, context);
await initializeProjectInDirectory(client, projectDirUri, projectName, context);
}
}

Expand All @@ -102,13 +115,7 @@ function validateProjectName(input: string): string | undefined {
}
}

async function initializeProjectInDirectory(projectDirUri: vscode.Uri, projectName: string, context: vscode.ExtensionContext) {
const client = getLanguageClient();
if (client == undefined) {
vscode.window.showErrorMessage("Language Server is not active!");
return;
}

async function initializeProjectInDirectory(client: lsp.LanguageClient, projectDirUri: vscode.Uri, projectName: string, context: vscode.ExtensionContext) {
let manifestUri: vscode.Uri;
try {
const params: requests.projects.create.Parameters = {
Expand Down

0 comments on commit 9570659

Please sign in to comment.