Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor
Browse files Browse the repository at this point in the history
larshp committed Oct 26, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent a414172 commit 5f5898f
Showing 2 changed files with 28 additions and 32 deletions.
34 changes: 19 additions & 15 deletions src/web/artifacts.ts
Original file line number Diff line number Diff line change
@@ -2,18 +2,18 @@ import * as vscode from 'vscode';
import { Utils } from 'vscode-uri';
import { abapGit } from './abapgit';

export type SubFiles = {name: string, file: vscode.Uri}[];

export type ArtifactInformation = {
abapType: string,
abapName: string,
export interface AnyArtifact {
name: string,
description: string,
mainFile: vscode.Uri,
subFiles: SubFiles;
file: vscode.Uri,

sub: AnyArtifact[];
};

export async function findArtifacts(): Promise<ArtifactInformation[]> {
const ret: ArtifactInformation[] = [];
/////////////////////////

export async function findArtifacts(): Promise<AnyArtifact[]> {
const ret: AnyArtifact[] = [];

for (const folder of vscode.workspace.workspaceFolders || []) {
// todo: use folder.name as top level in artifact tree
@@ -35,16 +35,20 @@ export async function findArtifacts(): Promise<ArtifactInformation[]> {

const type = split[1].toUpperCase();
const name = split[0].toUpperCase();
const found = ret.find((r) => r.abapType === type && r.abapName === name);
const found = ret.find((r) => r.name === name && r.description === type);
if (found) {
found.subFiles.push({name: Utils.basename(filename), file: filename});
found.sub.push({
name: Utils.basename(filename),
description: "",
sub: [],
file: filename,
});
} else {
ret.push({
abapType: type,
abapName: name,
name: name,
description: type,
mainFile: filename,
subFiles: [],
file: filename,
sub: [],
});
}
}
26 changes: 9 additions & 17 deletions src/web/artifacts_tree_provider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as vscode from "vscode";
import { ArtifactInformation, SubFiles, findArtifacts } from "./artifacts";
import { AnyArtifact, findArtifacts } from "./artifacts";

export class ArtifactsTreeProvider implements vscode.TreeDataProvider<ArtifactTreeItem> {

@@ -10,14 +10,8 @@ export class ArtifactsTreeProvider implements vscode.TreeDataProvider<ArtifactTr
public async getChildren(parent?: ArtifactTreeItem): Promise<ArtifactTreeItem[]> {
const treeItems: ArtifactTreeItem[] = [];
if (parent !== undefined) {
for (const sub of parent.subFiles) {
treeItems.push(new ArtifactTreeItem({
abapType: "",
abapName: sub.name,
description: "",
mainFile: sub.file,
subFiles: [],
}));
for (const sub of parent.sub) {
treeItems.push(new ArtifactTreeItem(sub));
}
} else {
const items = await findArtifacts();
@@ -31,21 +25,19 @@ export class ArtifactsTreeProvider implements vscode.TreeDataProvider<ArtifactTr
}

export class ArtifactTreeItem extends vscode.TreeItem {
public readonly subFiles: SubFiles;
public readonly sub: AnyArtifact[];

public constructor(info: ArtifactInformation) {
public constructor(info: AnyArtifact) {
let state = vscode.TreeItemCollapsibleState.None;
if (info.subFiles.length > 0) {
if (info.sub.length > 0) {
state = vscode.TreeItemCollapsibleState.Collapsed;
}

super(info.abapName, state);
this.tooltip = info.abapType;
this.subFiles = info.subFiles;
super(info.name, state);
this.iconPath = vscode.ThemeIcon.File;
this.description = info.description;
this.resourceUri = info.mainFile;

this.resourceUri = info.file;
this.sub = info.sub;

this.command = {
command: "vscode.open",

0 comments on commit 5f5898f

Please sign in to comment.