Skip to content

Commit

Permalink
Add support for workspace-defined roots
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffpeterson committed Nov 22, 2018
1 parent b8d0599 commit ef55727
Showing 1 changed file with 37 additions and 18 deletions.
55 changes: 37 additions & 18 deletions src/treeview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@ function vscodeURItoCaseSensitiveString(uri: vscode.Uri): string {
return `hypermerge://${uri.authority}/`;
}

interface RootDetails {
user: Set<string>
workspace: Set<string>
default: Set<string>
}

export class HypermergeTreeDataProvider
implements vscode.TreeDataProvider<HypermergeNodeKey> {
private _onDidChangeTreeData: vscode.EventEmitter<
HypermergeNodeKey | undefined
> = new vscode.EventEmitter<HypermergeNodeKey | undefined>();
> = new vscode.EventEmitter<HypermergeNodeKey | undefined>();
readonly onDidChangeTreeData: vscode.Event<
HypermergeNodeKey | undefined
> = this._onDidChangeTreeData.event;
> = this._onDidChangeTreeData.event;

constructor(private readonly hypermergeWrapper: HypermergeWrapper) {
this.hypermergeWrapper = hypermergeWrapper;
Expand Down Expand Up @@ -69,10 +75,13 @@ export class HypermergeTreeDataProvider
}

public addRoot(uriString: string) {
const roots =
const inspectRoots =
vscode.workspace
.getConfiguration("hypermergefs")
.get<string[]>("roots") || [];
.inspect<string[]>("roots");

const roots = inspectRoots && inspectRoots.globalValue || []

vscode.workspace
.getConfiguration("hypermergefs")
.update(
Expand All @@ -83,27 +92,37 @@ export class HypermergeTreeDataProvider
}

public removeRoot(uriString: string) {
const roots =
vscode.workspace
.getConfiguration("hypermergefs")
.get<string[]>("roots") || [];
const roots = this.inspectRoots().user

roots.delete(uriString)

vscode.workspace
.getConfiguration("hypermergefs")
.update(
"roots",
roots.filter(uri => uri !== uriString),
[...roots],
vscode.ConfigurationTarget.Global
);
}

private roots(): Thenable<HypermergeNodeKey[]> {
return new Promise(resolve => {
const roots =
vscode.workspace
.getConfiguration("hypermergefs")
.get<string[]>("roots") || [];
resolve(roots);
});
private roots(): Set<HypermergeNodeKey> {
const details = this.inspectRoots()

return new Set([...details.user, ...details.workspace, ...details.default]);
}

private inspectRoots(): RootDetails {
const insp =
vscode.workspace
.getConfiguration("hypermergefs")
.inspect<string[]>("roots") || <any>{};


return {
user: new Set(insp.globalValue),
workspace: new Set(insp.workspaceValue),
default: new Set(insp.defaultValue)
}
}

private getDocumentChildren(
Expand Down Expand Up @@ -144,7 +163,7 @@ export class HypermergeTreeDataProvider
public getChildren(
element?: HypermergeNodeKey
): HypermergeNodeKey[] | Thenable<HypermergeNodeKey[]> {
return element ? this.getDocumentChildren(element) : this.roots();
return element ? this.getDocumentChildren(element) : [...this.roots()];
}

public getParent(element: HypermergeNodeKey): HypermergeNodeKey | null {
Expand Down

0 comments on commit ef55727

Please sign in to comment.