Skip to content

Commit

Permalink
fix: Smarter labeling for multi-root situations
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkMcCulloh committed Jan 8, 2022
1 parent 55e7755 commit 058c135
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 16 deletions.
33 changes: 19 additions & 14 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,22 @@ export async function activate(context: vscode.ExtensionContext) {
return;
}

const projects = (
await Promise.all(
vscode.workspace.workspaceFolders.map((f) => {
return findProjectInFolder(f);
let projects: ProjenInfo[] = [];
for (const folder of vscode.workspace.workspaceFolders) {
const folderProjects = await findProjectInFolder(folder);
const filteredProjects = folderProjects
.filter((f) => {
if (projects.some((p) => p.projectRoot.path === f.path)) {
return false;
} else {
return true;
}
})
)
)
.flat()
.map((r) => new ProjenInfo(r));
.map((p) => new ProjenInfo(folder, p));

projects.push(...filteredProjects);
}
projects.sort((a, b) => a.label.localeCompare(b.label));

const singleProject = projects.length === 1;

Expand All @@ -57,17 +64,17 @@ export async function activate(context: vscode.ExtensionContext) {
return projects[0];
}
const selection = await vscode.window.showQuickPick(
projects.map((t) => t.projectRoot.path),
projects.map((t) => t.label),
{ placeHolder: "Select projent project" }
);

return projects.find((p) => p.projectRoot.path === selection)!;
return projects.find((p) => p.label === selection)!;
}

function newOrActiveTerminal(projenInfo: ProjenInfo) {
const terminalName = singleProject
? `[projen]`
: `[projen][${projenInfo.projectRoot.path}]`;
: `[projen][${projenInfo.label}]`;

let terminal = vscode.window.terminals.find((t) => t.name === terminalName);
if (!terminal) {
Expand All @@ -91,9 +98,7 @@ export async function activate(context: vscode.ExtensionContext) {
) {
args.unshift("projen");

const taskName = singleProject
? name
: `${name} [${projenInfo.projectRoot.path}]`;
const taskName = singleProject ? name : `${name} [${projenInfo.label}]`;

return new vscode.Task(
{ type: "projen", task: taskName },
Expand Down
15 changes: 14 additions & 1 deletion src/projen_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,22 @@ export class ProjenInfo {
public tasks: ProjenTask[] = [];
public dependencies: ProjenDependency[] = [];
public rcFile?: vscode.Uri;
public label: string;
decorator: GeneratedFileDecorationProvider;

constructor(public projectRoot: vscode.Uri) {
constructor(
public workspaceFolder: vscode.WorkspaceFolder,
public projectRoot: vscode.Uri
) {
this.label = projectRoot.path.replace(workspaceFolder.uri.path, "");
if (this.label.startsWith("/")) {
this.label = this.label.slice(1);
}
if (this.label === "") {
this.label = projectRoot.path.slice(
projectRoot.path.lastIndexOf("/") + 1
);
}
this.decorator = new GeneratedFileDecorationProvider();
vscode.window.registerFileDecorationProvider(this.decorator);
}
Expand Down
2 changes: 1 addition & 1 deletion src/projen_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class File extends BaseTreeItem {

class Project extends BaseTreeItem {
constructor(info: ProjenInfo) {
super(info, info.projectRoot, vscode.TreeItemCollapsibleState.Collapsed);
super(info, info.label, vscode.TreeItemCollapsibleState.Collapsed);

this.iconPath = vscode.ThemeIcon.Folder;
}
Expand Down

0 comments on commit 058c135

Please sign in to comment.