Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@
"strip-ansi": "6.0.0",
"sudo-prompt": "9.2.1",
"titleize": "2.1.0",
"yeoman-environment": "3.19.3"
"yeoman-environment": "3.19.3",
"vscode-uri": "3.1.0"
},
"devDependencies": {
"@types/cheerio": "^0.22.31",
Expand Down
4 changes: 3 additions & 1 deletion packages/backend/src/panels/YeomanUIPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { NpmCommand } from "../utils/npm";
import { Constants } from "../utils/constants";
import { notifyGeneratorsInstallationProgress } from "../utils/generators-installation-progress";
import messages from "../messages";
import { getFileSchemeWorkspaceFolders } from "../utils/workspaceFolders";

export class YeomanUIPanel extends AbstractWebviewPanel {
public static YEOMAN_UI = "Application Wizard";
Expand Down Expand Up @@ -142,7 +143,8 @@ export class YeomanUIPanel extends AbstractWebviewPanel {
}
uri = vscode.Uri.file(currentPath);
} catch (e) {
uri = get(vscode, "workspace.workspaceFolders[0].uri");
const fileSchemeWorkspaces = getFileSchemeWorkspaceFolders();
uri = fileSchemeWorkspaces.length > 0 ? fileSchemeWorkspaces[0].uri : undefined;
if (isNil(uri)) {
uri = vscode.Uri.file(join(homedir()));
}
Expand Down
5 changes: 3 additions & 2 deletions packages/backend/src/utils/vscodeProxy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { set } from "lodash";
import { join } from "path";
import { URI } from "vscode-uri";

export const getVscode = () => {
try {
Expand Down Expand Up @@ -33,10 +34,10 @@ const context = { globalState: globalStateObj, extensionPath: "" };

const Uri = {
file: (path?: string) => {
return { fsPath: path };
return URI.file(path || "");
},
parse: (path?: string) => {
return { fsPath: path };
return URI.parse(path || "");
},
};

Expand Down
32 changes: 32 additions & 0 deletions packages/backend/src/utils/workspaceFolders.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { workspace, WorkspaceFolder } from "vscode";

/**
* Returns an array of WorkspaceFolder objects with 'file' URI scheme.
* Useful when you need the full WorkspaceFolder metadata (name, uri, etc.).
* @returns Array of WorkspaceFolder objects with file scheme, or empty array
*/
export function getFileSchemeWorkspaceFolders(): WorkspaceFolder[] {
return workspace.workspaceFolders
? workspace.workspaceFolders.filter((folder) => folder?.uri?.scheme === "file")
: [];
}

/**
* Returns an array of file system paths for workspace folders with 'file' URI scheme.
* Filters out virtual workspaces (remote, SSH, WSL, etc.) that don't have valid fsPath.
* @returns Array of file system paths, or empty array if no file-scheme workspaces exist
*/
export function getWorkspaceFolders(): string[] {
return getFileSchemeWorkspaceFolders().map((ws) => ws.uri.fsPath);
}

/**
* Returns the first file-scheme workspace path, or fallback if none exist.
* Convenience method for cases where you need a single path with a default.
* @param fallback The fallback path to use if no file-scheme workspaces exist
* @returns The first file-scheme workspace path or the fallback value
*/
export function getFirstWorkspacePath(fallback: string): string {
const paths = getWorkspaceFolders();
return paths.length > 0 ? paths[0] : fallback;
}
10 changes: 6 additions & 4 deletions packages/backend/src/vscode-youi-events.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as vscode from "vscode";
import { isEmpty, size, isNil, set } from "lodash";
import { isEmpty, isNil, set } from "lodash";
import { YouiEvents } from "./youi-events";
import { IRpc } from "@sap-devx/webview-rpc/out.ext/rpc-common";
import { GeneratorOutput } from "./vscode-output";
Expand All @@ -9,6 +9,7 @@ import { getImage } from "./images/messageImages";
import { AppWizard, MessageType, Severity, IBannerProps } from "@sap-devx/yeoman-ui-types";
import { FolderUriConfig, getFolderUri, getValidFolderUri, WorkspaceFile, WsFoldersToAdd } from "./utils/workspaceFile";
import { Constants } from "./utils/constants";
import { getFileSchemeWorkspaceFolders } from "./utils/workspaceFolders";

class YoUiAppWizard extends AppWizard {
constructor(private readonly events: VSCodeYouiEvents) {
Expand Down Expand Up @@ -240,7 +241,7 @@ export class VSCodeYouiEvents implements YouiEvents {
}

private getUniqueProjectName(baseName: string): string {
const existingNames = vscode.workspace.workspaceFolders?.map((folder) => folder.name) || [];
const existingNames = getFileSchemeWorkspaceFolders().map((folder) => folder.name);
if (!existingNames.includes(baseName)) {
return baseName;
}
Expand All @@ -257,8 +258,9 @@ export class VSCodeYouiEvents implements YouiEvents {
}

private addOrCreateProjectWorkspace(wsFoldersToAdd: WsFoldersToAdd) {
const wsFoldersQuantity = size(vscode.workspace.workspaceFolders);
vscode.workspace.updateWorkspaceFolders(wsFoldersQuantity, null, wsFoldersToAdd);
const fileSchemeWorkspaces = getFileSchemeWorkspaceFolders();
const insertPosition = fileSchemeWorkspaces.length;
vscode.workspace.updateWorkspaceFolders(insertPosition, null, wsFoldersToAdd);
}

private getSuccessInfoMessage(selectedWorkspace: string, type: string): string {
Expand Down
5 changes: 2 additions & 3 deletions packages/backend/src/yeomanui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { Questions } from "yeoman-environment/lib/adapter";
import { State } from "./utils/promise";
import { Constants } from "./utils/constants";
import { isUriFlow } from "./utils/workspaceFile";
import { getFirstWorkspacePath } from "./utils/workspaceFolders";

export interface IQuestionsPrompt extends IPrompt {
questions: any[];
Expand Down Expand Up @@ -363,9 +364,7 @@ export class YeomanUI {
return targetFolderConfig;
}

return Constants.IS_IN_BAS
? Constants.HOMEDIR_PROJECTS
: _.get(vscode, "workspace.workspaceFolders[0].uri.fsPath", Constants.HOMEDIR_PROJECTS);
return Constants.IS_IN_BAS ? Constants.HOMEDIR_PROJECTS : getFirstWorkspacePath(Constants.HOMEDIR_PROJECTS);
}

public async showPrompt(questions: Questions<any>): Promise<inquirer.Answers> {
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/test/panels/YeomanUIPanel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ describe("YeomanUIPanel unit test", () => {

it("showOpenDialog - empty path provided, ws folder exists", async () => {
const canSelectFiles = true;
const objWs = [{ uri: { fsPath: "rootFolderPath" } }];
const objWs = [{ uri: { fsPath: "rootFolderPath", scheme: "file" } }];
sandbox.stub(vscode.workspace, "workspaceFolders").value(objWs);
windowMock
.expects("showOpenDialog")
Expand Down
Loading