Skip to content
This repository was archived by the owner on May 7, 2021. It is now read-only.

Commit 9d2f1e5

Browse files
committed
Allow go-plus-update-tools command to be filtered
- Add callback to close gocode when gocode is updated
1 parent 9fb5e3f commit 9d2f1e5

File tree

2 files changed

+59
-7
lines changed

2 files changed

+59
-7
lines changed

Diff for: lib/get/get-manager.js

+14-5
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ class GetManager {
1414
this.subscriptions.add(atom.commands.add(atom.views.getView(atom.workspace), 'golang:get-package', () => {
1515
this.getPackage()
1616
}))
17-
this.subscriptions.add(atom.commands.add(atom.views.getView(atom.workspace), 'golang:update-tools', () => {
17+
this.subscriptions.add(atom.commands.add(atom.views.getView(atom.workspace), 'golang:update-tools', (event) => {
1818
const progress = atom.notifications.addInfo('Updating Tools...', {dismissable: true})
19-
this.updateTools().then((outcome) => {
19+
let filter = false
20+
if (event && event.detail && Array.isArray(event.detail)) {
21+
filter = event.detail
22+
}
23+
this.updateTools(filter).then((outcome) => {
2024
progress.dismiss()
2125
if (!outcome) {
2226
return
@@ -72,14 +76,19 @@ class GetManager {
7276
})
7377
}
7478

75-
updateTools () {
79+
updateTools (filter) {
7680
if (!this.packages || this.packages.size === 0) {
7781
return Promise.resolve()
7882
}
79-
return this.performGet([...this.packages.keys()]).then((outcome) => {
83+
84+
let packs = [...this.packages.keys()]
85+
if (filter && Array.isArray(filter) && filter.length > 0) {
86+
packs = filter
87+
}
88+
return this.performGet(packs).then((outcome) => {
8089
if (this.onDidUpdateTools) {
8190
for (const cb of this.onDidUpdateTools) {
82-
cb(outcome)
91+
cb(outcome, packs)
8392
}
8493
}
8594
return outcome

Diff for: lib/package-manager.js

+45-2
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,12 @@ class PackageManager {
205205
return
206206
}
207207
for (const [key, value] of goTools) {
208+
const packagePath = value
208209
if (key === 'gometalinter') {
209-
this.subscriptions.add(this.goget.register(value, () => {
210+
this.subscriptions.add(this.goget.register(packagePath, (outcome, packs) => {
211+
if (!packs.includes(packagePath)) {
212+
return
213+
}
210214
this.goconfig.locator.findTool('gometalinter').then((cmd) => {
211215
if (!cmd) {
212216
return
@@ -241,8 +245,47 @@ class PackageManager {
241245
})
242246
})
243247
}))
248+
} else if (key === 'gocode') {
249+
this.subscriptions.add(this.goget.register(packagePath, (outcome, packs) => {
250+
if (!packs.includes(packagePath)) {
251+
return
252+
}
253+
this.goconfig.locator.findTool('gocode').then((cmd) => {
254+
if (!cmd) {
255+
return
256+
}
257+
const notification = atom.notifications.addInfo('gocode', {
258+
dismissable: true,
259+
icon: 'cloud-download',
260+
description: 'Running `gocode close` to ensure a new gocode binary is used.'
261+
})
262+
return this.goconfig.executor.exec(cmd, ['close'], 'project').then((r) => {
263+
notification.dismiss()
264+
const detail = r.stdout + os.EOL + r.stderr
265+
266+
if (r.exitcode !== 0) {
267+
atom.notifications.addWarning('gocode', {
268+
dismissable: true,
269+
icon: 'sync',
270+
detail: detail.trim()
271+
})
272+
return r
273+
}
274+
if (r.stderr && r.stderr.trim() !== '') {
275+
console.log('go-plus: (stderr) ' + r.stderr)
276+
}
277+
atom.notifications.addSuccess('gocode', {
278+
dismissable: true,
279+
icon: 'sync',
280+
detail: detail.trim(),
281+
description: 'The `gocode` daemon has been closed to ensure you are using the latest `gocode` binary.'
282+
})
283+
return r
284+
})
285+
})
286+
}))
244287
} else {
245-
this.subscriptions.add(this.goget.register(value))
288+
this.subscriptions.add(this.goget.register(packagePath))
246289
}
247290
}
248291
}

0 commit comments

Comments
 (0)