Skip to content

Commit

Permalink
code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziya SARIKAYA committed Dec 9, 2016
1 parent 79fd1b0 commit 9b1a1f4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
"search.exclude": {
"out": true
}
,
"typescript.check.workspaceVersion": false
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Open in GitHub / Bitbucket / VisualStudio.com !",
"description": "Jump to a source code line in Github / Bitbucket / VisualStudio.com !",
"icon": "images/icon_200.png",
"version": "1.2.1",
"version": "1.2.3",
"publisher": "ziyasal",
"license": "SEE LICENSE IN LICENSE.md",
"galleryBanner": {
Expand Down
29 changes: 15 additions & 14 deletions src/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var findParentDir = require('find-parent-dir');

const gitProvider = require('./gitProvider');

function getGitHubLink(cb, fileFsPath, line) {
function getGitProviderLink(cb, fileFsPath, line) {
var cwd = workspace.rootPath;
var repoDir = findParentDir.sync(workspace.rootPath, '.git') || cwd;

Expand Down Expand Up @@ -49,46 +49,47 @@ function getGitHubLink(cb, fileFsPath, line) {
});
}

function getGitHubLinkForFile(fileFsPath, cb) {
getGitHubLink(cb, fileFsPath);
function getGitProviderLinkForFile(fileFsPath, cb) {
getGitProviderLink(cb, fileFsPath);
}

function getGitHubLinkForCurrentEditorLine(cb) {
function getGitProviderLinkForCurrentEditorLine(cb) {
var editor = Window.activeTextEditor;
if (editor) {
var lineIndex = editor.selection.active.line + 1;
var fileFsPath = editor.document.uri.fsPath;
getGitHubLink(cb, fileFsPath, lineIndex);
getGitProviderLink(cb, fileFsPath, lineIndex);
}
}

function getGitHubLinkForRepo(cb) {
getGitHubLink(cb);
function getGitProviderLinkForRepo(cb) {
getGitProviderLink(cb);
}

function branchOnCallingContext(args, cb) {
if (args && args.fsPath) {
getGitHubLinkForFile(args.fsPath, cb);
getGitProviderLinkForFile(args.fsPath, cb);
}
else if (Window.activeTextEditor) {
getGitHubLinkForCurrentEditorLine(cb);
getGitProviderLinkForCurrentEditorLine(cb);
}
else {
getGitHubLinkForRepo(cb);
getGitProviderLinkForRepo(cb);
}
}

function openInGitHub(args) {
function openInGitProvider(args) {
branchOnCallingContext(args, open);
}

function copyGitHubLinkToClipboard(args) {
function copyGitProviderLinkToClipboard(args) {
branchOnCallingContext(args, copy);
}

//TODO: rename openInGitHub to openInGitProvider
function activate(context) {
context.subscriptions.push(commands.registerCommand('extension.openInGitHub', openInGitHub));
context.subscriptions.push(commands.registerCommand('extension.copyGitHubLinkToClipboard', copyGitHubLinkToClipboard));
context.subscriptions.push(commands.registerCommand('extension.openInGitHub', openInGitProvider));
context.subscriptions.push(commands.registerCommand('extension.copyGitHubLinkToClipboard', copyGitProviderLinkToClipboard));
}

exports.activate = activate;

0 comments on commit 9b1a1f4

Please sign in to comment.