Skip to content

Commit

Permalink
Add external uri handler
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffpeterson committed Nov 29, 2018
1 parent 69b7943 commit dd931a3
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 16 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
"type": "git"
},
"engines": {
"vscode": "^1.23.0"
"vscode": "^1.29.1"
},
"categories": [
"Other"
],
"activationEvents": [
"onFileSystem:hypermergefs",
"onView:hypermergeExplorer"
"onFileSystem:hypermerge",
"onView:hypermergeExplorer",
"onUri"
],
"main": "./out/src/extension",
"contributes": {
Expand Down Expand Up @@ -138,7 +139,7 @@
"@types/node": "^10.2.0",
"electron-rebuild": "^1.8.2",
"typescript": "^3.1.4",
"vscode": "^1.1.21"
"vscode": "^1.1.22"
},
"dependencies": {
"@hyperswarm/network": "0.0.4",
Expand Down
15 changes: 15 additions & 0 deletions src/HypermergeUriHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { UriHandler, Uri, commands, OutputChannel } from 'vscode'

export default class HypermergeUriHandler implements UriHandler {
output: OutputChannel
constructor(output: OutputChannel) {
this.output = output
output.appendLine("HypermergeUriHandler registered")
}

handleUri(uri: Uri) {
const uriString = uri.path.replace(/^\//, "")
this.output.appendLine(uriString)
commands.executeCommand("hypermergeExplorer.open", uriString)
}
}
20 changes: 14 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,33 @@ import { HypermergeFS } from "./fileSystemProvider";
import { HypermergeExplorer } from "./treeview";
import { HypermergeViewContainer } from "./details";
import { HypermergeWrapper } from "./fauxmerge";
import HypermergeUriHandler from "./HypermergeUriHandler";

export function activate(context: vscode.ExtensionContext) {
console.log("HypermergeFS activated");
const hypermergeWrapper = new HypermergeWrapper();

const output = vscode.window.createOutputChannel("Hypermerge")

const hypermergeFs = new HypermergeFS(hypermergeWrapper);
context.subscriptions.push(
vscode.workspace.registerFileSystemProvider("hypermerge", hypermergeFs, {
isCaseSensitive: true
})
);

vscode.workspace.onDidOpenTextDocument(document => {
if (document.uri.scheme === "hypermerge") {
if (JSON.parse(document.getText())) {
(vscode.languages as any).setTextDocumentLanguage(document, "json");
context.subscriptions.push(
vscode.workspace.onDidOpenTextDocument(document => {
if (document.uri.scheme === "hypermerge") {
if (JSON.parse(document.getText())) {
(vscode.languages as any).setTextDocumentLanguage(document, "json");
}
}
}
});
}));

context.subscriptions.push(
vscode.window.registerUriHandler(new HypermergeUriHandler(output))
)

// self-registers
new HypermergeExplorer(context, hypermergeWrapper);
Expand Down
14 changes: 12 additions & 2 deletions src/treeview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ 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 @@ -72,6 +72,8 @@ export class HypermergeTreeDataProvider
}

public addRoot(uriString: string) {
if (this.roots().has(uriString)) return

const inspectRoots = vscode.workspace
.getConfiguration("hypermergefs")
.inspect<string[]>("roots");
Expand Down Expand Up @@ -188,6 +190,14 @@ export class HypermergeExplorer {
treeDataProvider.refresh()
);

vscode.commands.registerCommand("hypermergeExplorer.open", (uriString: string) => {
if (!this.validateURL(uriString)) {
treeDataProvider.addRoot(uriString);
treeDataProvider.refresh();
vscode.workspace.openTextDocument(vscode.Uri.parse(uriString))
}
});

context.subscriptions.push(
vscode.workspace.onDidChangeConfiguration(e => {
if (e.affectsConfiguration("hypermergefs.roots")) {
Expand Down

0 comments on commit dd931a3

Please sign in to comment.