Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoVogel committed Nov 1, 2022
1 parent 6a8359d commit dc4e155
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { GlobalConfigurationStore } from '@nx-console/vscode/configuration';
import { revealNxProject } from '@nx-console/vscode/nx-workspace';
import { CliTaskProvider } from '@nx-console/vscode/tasks';
import { AbstractTreeProvider } from '@nx-console/vscode/utils';
import { commands, ExtensionContext, ProviderResult } from 'vscode';
import { commands, ExtensionContext, ProviderResult, TreeItem } from 'vscode';
import {
NxFolderTreeItem,
NxListViewItem,
Expand Down Expand Up @@ -51,7 +51,7 @@ export class NxProjectTreeProvider extends AbstractTreeProvider<NxTreeItem> {
return null;
}

getChildren(element?: NxTreeItem) {
getChildren(element?: TreeItem) {
if (this.isListViewElement(element)) {
return this.listView.getChildren(element);
}
Expand Down Expand Up @@ -109,3 +109,7 @@ export class NxProjectTreeProvider extends AbstractTreeProvider<NxTreeItem> {
this.refresh();
}
}

class NxTreeItem extends TreeItem {
constructor(public readonly type: string)
}
19 changes: 17 additions & 2 deletions libs/vscode/nx-project-view/src/lib/views/nx-project-base-view.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ProjectConfiguration, TargetConfiguration } from '@nrwl/devkit';
import { CliTaskProvider } from '@nx-console/vscode/tasks';
import { getOutputChannel } from '@nx-console/vscode/utils';
import { TreeDataProvider, TreeItemCollapsibleState } from 'vscode';
import { type } from 'os';
import {
NxProject,
NxProjectTreeItem,
Expand All @@ -12,8 +12,23 @@ export type ProjectViewStrategy<T> = Required<
Pick<TreeDataProvider<T>, 'getChildren'>
>;

export type ViewDataProvider = Pick<CliTaskProvider, 'getWorkspacePath' | 'getProjects'>

export type Collapsible = 'none' | 'collapsed' | 'expanded'

export type ViewItem = FolderViewItem

export interface FolderViewItem {
contextValue: 'folder';
path: string;
resource: string;
label: string
collapsible: Collapsible
}


export abstract class BaseView {
constructor(protected readonly cliTaskProvider: CliTaskProvider) {}
constructor(protected readonly cliTaskProvider: ViewDataProvider) { }

createProjectTreeItem([projectName, { root, name, targets }]: [
projectName: string,
Expand Down
126 changes: 126 additions & 0 deletions libs/vscode/nx-project-view/src/lib/views/nx-project-tree-view.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import { ViewDataProvider } from './nx-project-base-view'
import { createTreeViewStrategy } from './nx-project-tree-view'

describe('Project View: TreeView', () => {
describe('nx workspace', () => {
it('should find root directories', async () => {
const viewProvider = createMockViewDataProvider(nxExample.workspacePath, nxExample.project)
const treeView = createTreeViewStrategy(viewProvider)

const rootElements = await treeView.getChildren();
expect(rootElements).toHaveLength(2)
const paths = rootElements?.map((e) => e.label)
expect(paths).toEqual(['apps', 'libs'])
})
})
})

type MockDataGetWorkspacePath = ReturnType<ViewDataProvider['getWorkspacePath']>
type MockDataGetProjects = Awaited<ReturnType<ViewDataProvider['getProjects']>>

function createMockViewDataProvider(workspacePath: MockDataGetWorkspacePath, projects: unknown): ViewDataProvider {
return {
getWorkspacePath: () => workspacePath,
getProjects: () => new Promise(resolve => setTimeout(() => resolve(projects as MockDataGetProjects)))
}
}

// Result of cliTaskProvider.getProjects() for apps/vscode-e2e/testworkspaces/testworkspace-nx
const nxExample = {
workspacePath: '/git/nx-console/apps/vscode-e2e/testworkspaces/testworkspace-nx',
project: {
"app1": {
"targets": {
"build": {
"executor": "@nrwl/webpack:webpack",
"configurations": {
"production": {

}
},
"dependsOn": [
"^build"
],
"inputs": [
"production",
"^production"
]
},
"test": {
"executor": "@nrwl/jest:jest"
}
},
"root": "apps/app1",
"tags": [

],
"files": [
{
"file": "apps/app1/app1.js",
"hash": "fda9bc547f3d044be11c43ba8df3b8f387f29532",
"deps": [
"lib1",
"lib2"
]
},
{
"file": "apps/app1/project.json",
"hash": "5b8dd29636672949793a788e40c9f39b75aadc99"
}
]
},
"lib1": {
"targets": {
"test": {
"executor": "@nrwl/jest:jest"
}
},
"root": "libs/lib1",
"tags": [

],
"files": [
{
"file": "libs/lib1/project.json",
"hash": "929b00c99a39f3bb085b2487fed80d8e8421aea7"
},
{
"file": "libs/lib1/src/index.ts",
"hash": "56e2812af30c82f0f15bb726f98a27321363e5ca"
},
{
"file": "libs/lib1/src/lib/lib1.js",
"hash": "f63c731f25f9ac8efaaee3420cac1e7f08185169"
}
]
},
"lib2": {
"targets": {
"test": {
"executor": "@nrwl/jest:jest"
},
"weird": {

}
},
"root": "libs/lib2",
"tags": [

],
"files": [
{
"file": "libs/lib2/project.json",
"hash": "157a68f9115ba2aeb01e074404066c7aef10c34b"
},
{
"file": "libs/lib2/src/index.js",
"hash": "9aeaf007321d35731cf3a05e937f966216376c95"
},
{
"file": "libs/lib2/src/lib/lib2.js",
"hash": "fcc28489c736ebac8fe0b1b4f3c2aa3041a0de8e"
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import { ProjectConfiguration } from '@nrwl/devkit';
import { CliTaskProvider } from '@nx-console/vscode/tasks';
import { getOutputChannel } from '@nx-console/vscode/utils';
import { TreeItemCollapsibleState } from 'vscode';
import {
NxFolderTreeItem,
NxProjectTreeItem,
NxTreeViewItem,
} from '../nx-project-tree-item';
import { BaseView, ProjectViewStrategy } from './nx-project-base-view';
import { BaseView, ProjectViewStrategy, ViewDataProvider } from './nx-project-base-view';
import { isDefined, PathHelper } from './nx-project-util';

export type TreeViewStrategy = ProjectViewStrategy<NxTreeViewItem>;
type TreeViewMap = Map<string, [string, ProjectConfiguration][]>;

export function createTreeViewStrategy(
cliTaskProvider: CliTaskProvider
cliTaskProvider: ViewDataProvider
): TreeViewStrategy {
const listView = new TreeView(cliTaskProvider);
return {
Expand All @@ -25,7 +23,7 @@ export function createTreeViewStrategy(
class TreeView extends BaseView {
private pathHelper = new PathHelper();

constructor(cliTaskProvider: CliTaskProvider) {
constructor(cliTaskProvider: ViewDataProvider) {
super(cliTaskProvider);
}

Expand Down

0 comments on commit dc4e155

Please sign in to comment.