|
1 | 1 | define("plugins/sourcegraph/package.sourcegraph", [], { |
2 | 2 | "name": "sourcegraph", |
3 | 3 | "description": "Sourcegraph for C9", |
4 | | - "version": "0.0.2", |
| 4 | + "version": "0.0.3", |
5 | 5 | "author": "Sourcegraph", |
6 | 6 | "contributors": [ |
7 | 7 | { |
@@ -52,7 +52,7 @@ define("plugins/sourcegraph/sourcegraph",[], function(require, exports, module) |
52 | 52 | var workspaceDir = imports.c9.workspaceDir |
53 | 53 | var tabs = imports.tabManager |
54 | 54 | var dirname = require('path').dirname |
55 | | - var VERSION = '0.0.1' |
| 55 | + var VERSION = '0.0.3' |
56 | 56 |
|
57 | 57 | var plugin = new Plugin('Ajax.org', main.consumes) |
58 | 58 | var emit = plugin.getEmitter() |
@@ -185,23 +185,37 @@ define("plugins/sourcegraph/sourcegraph",[], function(require, exports, module) |
185 | 185 | function repoInfo(callback) { |
186 | 186 | getRemote(function(err, remotes) { |
187 | 187 | if (err) { |
| 188 | + logError("Unable to resolve getRemote", err) |
188 | 189 | return |
189 | 190 | } |
190 | 191 | var remote = remotes[0] |
191 | 192 | gitRemoteUrl(remote, function(err, remoteUrl) { |
192 | 193 | if (err) { |
| 194 | + logError("Unable to resolve gitRemoteUrl", err) |
193 | 195 | return |
194 | 196 | } |
195 | 197 | getBranch(function(err, branch) { |
196 | 198 | if (err) { |
| 199 | + logError("Unable to resolve getBranch", err) |
197 | 200 | return |
198 | 201 | } |
199 | | - var tab = tabs.focussedTab |
200 | | - var filePath = tab && tab.path |
201 | | - callback({ |
202 | | - remote: remoteUrl, |
203 | | - branch: branch, |
204 | | - file: filePath |
| 202 | + getTopLevel(function(err, topLevel) { |
| 203 | + if (err) { |
| 204 | + logError("Unable to resolve getTopLevel", err) |
| 205 | + return |
| 206 | + } |
| 207 | + var tab = tabs.focussedTab |
| 208 | + if (!tab || !tab.path) { |
| 209 | + logError("Unable to resolve file path", "No tab found.") |
| 210 | + return |
| 211 | + } |
| 212 | + |
| 213 | + var filePath = `${environmentDir || workspaceDir}${tab.path}`.replace(topLevel, '') |
| 214 | + callback({ |
| 215 | + remote: remoteUrl, |
| 216 | + branch: branch, |
| 217 | + file: filePath |
| 218 | + }) |
205 | 219 | }) |
206 | 220 | }) |
207 | 221 | }) |
@@ -250,6 +264,13 @@ define("plugins/sourcegraph/sourcegraph",[], function(require, exports, module) |
250 | 264 | }) |
251 | 265 | } |
252 | 266 |
|
| 267 | + function getTopLevel(callback) { |
| 268 | + git(['rev-parse', '--show-toplevel'], function(err, stdout, stderr) { |
| 269 | + if (err || stderr) return callback(err || stderr) |
| 270 | + callback(null, stdout.trim()) |
| 271 | + }) |
| 272 | + } |
| 273 | + |
253 | 274 | function getRemote(callback) { |
254 | 275 | git(['remote'], function(err, stdout, stderr) { |
255 | 276 | if (err || stderr) return callback(err || stderr) |
@@ -289,6 +310,10 @@ define("plugins/sourcegraph/sourcegraph",[], function(require, exports, module) |
289 | 310 | return { cursor, anchor } |
290 | 311 | } |
291 | 312 |
|
| 313 | + function logError(messsage, err) { |
| 314 | + console.error(`${message}: ${err}\n EnvDir: ${environmentDir}, WorkspaceDir: ${workspaceDir}`) |
| 315 | + } |
| 316 | + |
292 | 317 | plugin.on('load', function() { |
293 | 318 | load() |
294 | 319 | }) |
|
0 commit comments