Skip to content

Commit 8677311

Browse files
authored
fix(cdk): address more C9 edge-cases #2662
1 parent 63203c6 commit 8677311

File tree

5 files changed

+30
-8
lines changed

5 files changed

+30
-8
lines changed

src/awsexplorer/localExplorer.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { cdkNode } from '../cdk/explorer/rootNode'
99
import { ResourceTreeDataProvider, TreeNode } from '../shared/treeview/resourceTreeDataProvider'
1010
import { once } from '../shared/utilities/functionUtils'
1111
import { AppNode } from '../cdk/explorer/nodes/appNode'
12+
import { isCloud9 } from '../shared/extensionUtilities'
1213

1314
export interface RootNode extends TreeNode {
1415
canShow?(): Promise<boolean> | boolean
@@ -55,5 +56,12 @@ export function createLocalExplorerView(): vscode.TreeView<TreeNode> {
5556
// Legacy CDK behavior. Mostly useful for C9 as they do not have inline buttons.
5657
view.onDidChangeVisibility(({ visible }) => visible && cdkNode.refresh())
5758

59+
// Cloud9 will only refresh when refreshing the entire tree
60+
if (isCloud9()) {
61+
roots.forEach(node => {
62+
node.onDidChangeChildren?.(() => treeDataProvider.refresh())
63+
})
64+
}
65+
5866
return view
5967
}

src/cdk/explorer/detectCdkProjects.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export async function detectCdkProjects(
2323

2424
projects.forEach(p => results.set(p.cdkJsonUri.toString(), p))
2525

26-
return Array.from(projects.values())
26+
return Array.from(results.values())
2727
}
2828

2929
async function detectCdkProjectsFromWorkspaceFolder(

src/cdk/explorer/nodes/appNode.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { createPlaceholderItem } from '../../../shared/treeview/utils'
1919
* Existence of apps is determined by the presence of `cdk.json` in a workspace folder
2020
*/
2121
export class AppNode implements TreeNode {
22-
public readonly id = this.makeId()
22+
public readonly id = this.location.cdkJsonUri.toString()
2323
public readonly resource = this.location
2424
public readonly treeItem: vscode.TreeItem
2525

@@ -59,12 +59,6 @@ export class AppNode implements TreeNode {
5959
}
6060
}
6161

62-
private makeId() {
63-
const rootUri = vscode.Uri.joinPath(this.location.cdkJsonUri, '..')
64-
65-
return vscode.workspace.asRelativePath(rootUri)
66-
}
67-
6862
private createTreeItem() {
6963
const item = new vscode.TreeItem(this.location.cdkJsonUri, vscode.TreeItemCollapsibleState.Collapsed)
7064
item.contextValue = 'awsCdkAppNode'

src/test/cdk/detectCdkProjects.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,20 @@ describe('detectCdkProjects', function () {
8585
assert.strictEqual(actual.length, 0)
8686
})
8787

88+
it('de-dupes identical projects`', async function () {
89+
workspaceFolders.push(workspaceFolders[0])
90+
91+
try {
92+
const cdkJsonUri = vscode.Uri.joinPath(workspaceFolders[0].uri, 'cdk.json')
93+
await saveCdkJson(cdkJsonUri.fsPath)
94+
95+
const actual = await detectCdkProjects(workspaceFolders)
96+
assert.strictEqual(actual.length, 1)
97+
} finally {
98+
workspaceFolders.pop()
99+
}
100+
})
101+
88102
it('takes into account `output` from cdk.json to build tree.json path', async function () {
89103
const cdkJsonUri = vscode.Uri.joinPath(workspaceFolders[0].uri, 'cdk.json')
90104
await writeJSON(cdkJsonUri.fsPath, { app: 'npx ts-node bin/demo-nov7.ts', output: 'build/cdk.out' })

src/test/cdk/explorer/appNode.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ describe('AppNode', function () {
2323
const cdkJsonPath = path.join(getTestWorkspaceFolder(), workspaceFolderName, 'cdk.json')
2424
const treePath = path.join(cdkJsonPath, '..', 'cdk.out', 'tree.json')
2525

26+
it('uses the `cdk.json` uri as its id', async function () {
27+
const testNode = getTestNode()
28+
29+
assert.strictEqual(testNode.id, vscode.Uri.file(cdkJsonPath).toString())
30+
})
31+
2632
it('initializes label and tooltip', async function () {
2733
const testNode = getTestNode()
2834

0 commit comments

Comments
 (0)