-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b091db
commit 808ea90
Showing
6 changed files
with
279 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
// Place your settings in this file to overwrite default and user settings. | ||
{ | ||
"files.exclude": { | ||
"out": false // set this to true to hide the "out" folder with the compiled JS files | ||
"out": false, // set this to true to hide the "out" folder with the compiled JS files | ||
"node_modules": true | ||
}, | ||
"search.exclude": { | ||
"out": true // set this to false to include "out" folder in search results | ||
"out": true, // set this to false to include "out" folder in search results | ||
"node_modules": true | ||
}, | ||
"typescript.tsdk": "./node_modules/typescript/lib" // we want to use the TS server from our node_modules folder to control its version | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import { TreeDataProvider, EventEmitter, Event, TreeItemCollapsibleState, TreeItem, ProviderResult } from 'vscode'; | ||
|
||
// A map from namespace => var => boolean | ||
// true if the running the test was successful. | ||
type Results = { | ||
[key: string]: { | ||
[key: string]: boolean | ||
} | ||
} | ||
|
||
type NamespaceNode = { | ||
type: 'ns' | ||
ns: string | ||
} | ||
|
||
type VarNode = { | ||
type: 'var' | ||
varName: string | ||
nsName: string | ||
} | ||
|
||
// The test result tree-view has 2 type of node: | ||
// Namespace nodes and var nodes. | ||
// The (root) contains NamespaceNodes, which have VarNodes as children. | ||
type TestNode = NamespaceNode | VarNode | ||
|
||
export interface TestListener { | ||
onTestResult(ns: string, varName: string, success: boolean): void; | ||
} | ||
|
||
class ClojureTestDataProvider implements TreeDataProvider<TestNode>, TestListener { | ||
|
||
onTestResult(ns: string, varName: string, success: boolean): void { | ||
|
||
console.log(ns, varName, success); | ||
|
||
// Make a copy of result with the new result assoc'ed in. | ||
this.results = { | ||
...this.results, | ||
[ns]: { | ||
...this.results[ns], | ||
[varName]: success | ||
} | ||
} | ||
|
||
this.testsChanged.fire(); // Trigger the UI to update. | ||
} | ||
|
||
private testsChanged: EventEmitter<TestNode> = new EventEmitter<TestNode>(); | ||
readonly onDidChangeTreeData: Event<TestNode | undefined | null> = this.testsChanged.event; | ||
|
||
private results: Results = {} | ||
|
||
getNamespaceItem(element: NamespaceNode): TreeItem { | ||
return { | ||
label: element.ns, | ||
collapsibleState: TreeItemCollapsibleState.Expanded | ||
}; | ||
} | ||
|
||
getVarItem(element: VarNode): TreeItem { | ||
const passed: boolean = this.results[element.nsName][element.varName]; | ||
return { | ||
label: (passed ? "✅ " : "❌ ") + element.varName, | ||
collapsibleState: TreeItemCollapsibleState.None | ||
}; | ||
} | ||
|
||
getTreeItem(element: TestNode): TreeItem | Thenable<TreeItem> { | ||
switch (element.type) { | ||
case 'ns': return this.getNamespaceItem(element); | ||
case 'var': return this.getVarItem(element); | ||
} | ||
} | ||
|
||
getChildren(element?: TestNode): ProviderResult<TestNode[]> { | ||
|
||
if (!element) { | ||
return Object.keys(this.results).map((ns) => { | ||
const node: NamespaceNode = { | ||
type: 'ns', | ||
ns: ns | ||
}; | ||
return node; | ||
}); | ||
|
||
} | ||
|
||
switch (element.type) { | ||
case 'ns': { | ||
const vars = Object.keys(this.results[element.ns]); | ||
|
||
return vars.map((varName) => { | ||
const node: VarNode = { | ||
type: 'var', | ||
nsName: element.ns, | ||
varName: varName | ||
}; | ||
return node; | ||
}); | ||
} | ||
} | ||
return null; | ||
} | ||
} | ||
|
||
export const buildTestProvider = function (): ClojureTestDataProvider { | ||
return new ClojureTestDataProvider(); | ||
}; |