diff --git a/.arclint b/.arclint index ab36a12..10791e7 100644 --- a/.arclint +++ b/.arclint @@ -1,37 +1,37 @@ { "linters": { "chmod": { "type": "chmod" }, "filename": { "type": "filename" }, "generated": { "type": "generated" }, "eslint": { "type": "eslint", "include": "(\\.ts$)", "bin": "./node_modules/.bin/eslint" }, "merge-conflict": { "type": "merge-conflict" }, "nolint": { "type": "nolint" }, "spelling": { "type": "spelling" }, "text": { "type": "text", "text.max-line-length": 120, "severity": { "2": "disabled" } } }, "exclude": [ - "package-lock.json" + "/package-lock.json/" ] } diff --git a/package.json b/package.json index 8bd478f..37270af 100644 --- a/package.json +++ b/package.json @@ -1,87 +1,112 @@ { "name": "arcanist", "displayName": "Arcanist", "description": "Phabricator/Arcanist support for VSCode", "publisher": "avive", "version": "1.0.0", "engines": { "vscode": "^1.46.0" }, "categories": [ "Other" ], "keywords": ["Phabricator"], "license": "MIT", "activationEvents": [ "workspaceContains:**/.arclint", "workspaceContains:**/.arcconfig" ], "main": "./out/extension.js", "contributes": { + "menus": { + "editor/title/context": [ + { + "command": "arc-vscode.browseFile" + } + ], + "editor/title": [ + { + "command": "arc-vscode.browseFile" + } + ], + "explorer/context": [ + { + "command": "arc-vscode.browseFile" + } + ] + }, "commands": [ + { + "command": "arc-vscode.browseFile", + "title": "Browse in Diffusion", + "category": "arc", + "icon": "$(account)" + }, { "command": "arc-vscode.clearLint", - "title": "Clear all arc-lint messages" + "title": "Clear all arc-lint messages", + "category": "arc" }, { "command": "arc-vscode.lintEverything", - "title": "arc lint --everything" + "title": "arc lint --everything", + "category": "arc" } ], "configuration": { "title": "Arcanist", "properties": { "arc-vscode.lint.maxDiagnosticsLevel": { "type": "string", "default": "error", "enum": [ "error", "warning", "info", "hint" ], "description": "The maximum level a lint can appear at." } } }, "languages": [ { "id": "json", "extensions": [ ".arcconfig", ".arclint", ".arcrc", ".arcunit" ] } ] }, "repository": { "type": "git", "url": "https://github.com/avivey/arc-vscode.git" }, "scripts": { "vscode:prepublish": "npm run compile", "compile": "tsc -p ./", "lint": "eslint src --ext ts", "watch": "tsc -watch -p ./", "pretest": "npm run compile && npm run lint", "test": "node ./out/test/runTest.js" }, "devDependencies": { "@types/vscode": "^1.46.0", "@types/glob": "^7.1.1", "@types/mocha": "^7.0.2", "@types/node": "^13.11.0", "eslint": "^6.8.0", "@typescript-eslint/parser": "^2.30.0", "@typescript-eslint/eslint-plugin": "^2.30.0", "glob": "^7.1.6", "mocha": "^7.1.2", "typescript": "^3.8.3", "vscode-test": "^1.3.0" }, "dependencies": { "execa": "^4.0.2" } } diff --git a/src/arc_browse.ts b/src/arc_browse.ts new file mode 100644 index 0000000..1c8368a --- /dev/null +++ b/src/arc_browse.ts @@ -0,0 +1,36 @@ +import * as vscode from 'vscode'; +import * as execa from 'execa'; +import * as path from 'path'; + +var LOG: vscode.OutputChannel; + +export function setup(log: vscode.OutputChannel) { + LOG = log; +} + +export function browseFile(resource: vscode.Uri | undefined) { + if (!resource) { + if (!vscode.window.activeTextEditor) { return; } + + const document = vscode.window.activeTextEditor.document; + resource = document.uri; + } + + if (resource.scheme !== "file") { return; } + + const filename = resource.path; + + function handleExecResult(value: execa.ExecaReturnValue) { + // In the happy case, arc-browse outputs nothing. + if (!value.stdout) { + return; + } + // If it does print something, it's an error message. + vscode.window.showErrorMessage('arc-browse error:' + value.stdout); + } + + execa( + 'arc', ['browse', '--types', 'path', '--', path.basename(filename)], + { cwd: path.dirname(filename) }, + ).then(handleExecResult, handleExecResult); +} diff --git a/src/extension.ts b/src/extension.ts index 1319dbc..0959cde 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,49 +1,53 @@ import * as vscode from 'vscode'; import * as lint from './arc_lint'; +import * as browse from './arc_browse'; export function activate(context: vscode.ExtensionContext) { const log = vscode.window.createOutputChannel("arcanist"); const diagnostics = vscode.languages.createDiagnosticCollection('arc lint'); lint.setup(log); + browse.setup(log); function d(disposable: vscode.Disposable) { context.subscriptions.push(disposable); } d(diagnostics); d(log); + d(vscode.commands.registerCommand("arc-vscode.browseFile", browse.browseFile)); + d(vscode.commands.registerCommand('arc-vscode.clearLint', () => diagnostics.clear())); d(vscode.commands.registerCommand('arc-vscode.lintEverything', () => lint.lintEverything(diagnostics))); d(vscode.workspace.onDidSaveTextDocument(onTextDocumentEvent)); d(vscode.workspace.onDidOpenTextDocument(onTextDocumentEvent)); d(vscode.workspace.onDidChangeConfiguration(onChangeConfig)); if (vscode.window.activeTextEditor) { lint.lintFile(vscode.window.activeTextEditor.document, diagnostics); } d(vscode.window.onDidChangeActiveTextEditor(editor => { if (editor) { lint.lintFile(editor.document, diagnostics); } })); d(vscode.workspace.onDidCloseTextDocument(document => diagnostics.delete(document.uri))); function onTextDocumentEvent(document: vscode.TextDocument) { lint.lintFile(document, diagnostics); } } export function deactivate() { } function onChangeConfig(e: vscode.ConfigurationChangeEvent) { if (!e.affectsConfiguration('arc-vscode.lint')) { return; } lint.updateLintSeverityMap(); }