Skip to content

Commit 297273b

Browse files
authored
Add error logging and get repo top level (#2)
1 parent ba15a8f commit 297273b

File tree

5 files changed

+68
-18
lines changed

5 files changed

+68
-18
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ if (services.c9.workspaceId.match("{username}/{workspacename}")) {
1313
// call plugin manager with a list of plugins you want to load
1414
// this takes either url, or a path on your vm
1515
services.pluginManager.loadPackage([
16-
"https://cdn.rawgit.com/sourcegraph/sourcegraph-c9/v0.0.2/sourcegraph/c9build/package.sourcegraph.js",
16+
"https://cdn.rawgit.com/sourcegraph/sourcegraph-c9/v0.0.3/sourcegraph/c9build/package.sourcegraph.js",
1717
])
1818
}
1919
```

sourcegraph/c9build/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "sourcegraph",
33
"description": "Sourcegraph for C9",
4-
"version": "0.0.2",
4+
"version": "0.0.3",
55
"author": "Sourcegraph",
66
"contributors": [
77
{

sourcegraph/c9build/package.sourcegraph.js

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
define("plugins/sourcegraph/package.sourcegraph", [], {
22
"name": "sourcegraph",
33
"description": "Sourcegraph for C9",
4-
"version": "0.0.2",
4+
"version": "0.0.3",
55
"author": "Sourcegraph",
66
"contributors": [
77
{
@@ -52,7 +52,7 @@ define("plugins/sourcegraph/sourcegraph",[], function(require, exports, module)
5252
var workspaceDir = imports.c9.workspaceDir
5353
var tabs = imports.tabManager
5454
var dirname = require('path').dirname
55-
var VERSION = '0.0.1'
55+
var VERSION = '0.0.3'
5656

5757
var plugin = new Plugin('Ajax.org', main.consumes)
5858
var emit = plugin.getEmitter()
@@ -185,23 +185,37 @@ define("plugins/sourcegraph/sourcegraph",[], function(require, exports, module)
185185
function repoInfo(callback) {
186186
getRemote(function(err, remotes) {
187187
if (err) {
188+
logError("Unable to resolve getRemote", err)
188189
return
189190
}
190191
var remote = remotes[0]
191192
gitRemoteUrl(remote, function(err, remoteUrl) {
192193
if (err) {
194+
logError("Unable to resolve gitRemoteUrl", err)
193195
return
194196
}
195197
getBranch(function(err, branch) {
196198
if (err) {
199+
logError("Unable to resolve getBranch", err)
197200
return
198201
}
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+
})
205219
})
206220
})
207221
})
@@ -250,6 +264,13 @@ define("plugins/sourcegraph/sourcegraph",[], function(require, exports, module)
250264
})
251265
}
252266

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+
253274
function getRemote(callback) {
254275
git(['remote'], function(err, stdout, stderr) {
255276
if (err || stderr) return callback(err || stderr)
@@ -289,6 +310,10 @@ define("plugins/sourcegraph/sourcegraph",[], function(require, exports, module)
289310
return { cursor, anchor }
290311
}
291312

313+
function logError(messsage, err) {
314+
console.error(`${message}: ${err}\n EnvDir: ${environmentDir}, WorkspaceDir: ${workspaceDir}`)
315+
}
316+
292317
plugin.on('load', function() {
293318
load()
294319
})

sourcegraph/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "sourcegraph",
33
"description": "Sourcegraph for C9",
4-
"version": "0.0.2",
4+
"version": "0.0.3",
55
"author": "Sourcegraph",
66
"contributors": [
77
{

sourcegraph/sourcegraph.js

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ define(function(require, exports, module) {
2121
var workspaceDir = imports.c9.workspaceDir
2222
var tabs = imports.tabManager
2323
var dirname = require('path').dirname
24-
var VERSION = '0.0.1'
24+
var VERSION = '0.0.3'
2525

2626
/***** Initialization *****/
2727

@@ -160,23 +160,37 @@ define(function(require, exports, module) {
160160
function repoInfo(callback) {
161161
getRemote(function(err, remotes) {
162162
if (err) {
163+
logError("Unable to resolve getRemote", err)
163164
return
164165
}
165166
var remote = remotes[0]
166167
gitRemoteUrl(remote, function(err, remoteUrl) {
167168
if (err) {
169+
logError("Unable to resolve gitRemoteUrl", err)
168170
return
169171
}
170172
getBranch(function(err, branch) {
171173
if (err) {
174+
logError("Unable to resolve getBranch", err)
172175
return
173176
}
174-
var tab = tabs.focussedTab
175-
var filePath = tab && tab.path
176-
callback({
177-
remote: remoteUrl,
178-
branch: branch,
179-
file: filePath
177+
getTopLevel(function(err, topLevel) {
178+
if (err) {
179+
logError("Unable to resolve getTopLevel", err)
180+
return
181+
}
182+
var tab = tabs.focussedTab
183+
if (!tab || !tab.path) {
184+
logError("Unable to resolve file path", "No tab found.")
185+
return
186+
}
187+
188+
var filePath = `${environmentDir || workspaceDir}${tab.path}`.replace(topLevel, '')
189+
callback({
190+
remote: remoteUrl,
191+
branch: branch,
192+
file: filePath
193+
})
180194
})
181195
})
182196
})
@@ -225,6 +239,13 @@ define(function(require, exports, module) {
225239
})
226240
}
227241

242+
function getTopLevel(callback) {
243+
git(['rev-parse', '--show-toplevel'], function(err, stdout, stderr) {
244+
if (err || stderr) return callback(err || stderr)
245+
callback(null, stdout.trim())
246+
})
247+
}
248+
228249
function getRemote(callback) {
229250
git(['remote'], function(err, stdout, stderr) {
230251
if (err || stderr) return callback(err || stderr)
@@ -266,6 +287,10 @@ define(function(require, exports, module) {
266287
return { cursor, anchor }
267288
}
268289

290+
function logError(messsage, err) {
291+
console.error(`${message}: ${err}\n EnvDir: ${environmentDir}, WorkspaceDir: ${workspaceDir}`)
292+
}
293+
269294
/***** Lifecycle *****/
270295

271296
plugin.on('load', function() {

0 commit comments

Comments
 (0)