Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit 3ce98f5

Browse files
authored
Warn about conflicting atom packages (#84)
1 parent eb944f0 commit 3ce98f5

File tree

2 files changed

+62
-4
lines changed

2 files changed

+62
-4
lines changed

lib/competition.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
const CONFLICTING_PACKAGES = [
2+
// other language server clients - should only use one
3+
"languageserver-rust",
4+
"tokamak",
5+
// rls provides lints
6+
"linter-rust",
7+
// rls provides rustfmt functionality
8+
"rustfmt",
9+
// rls provides racer completion
10+
"racer",
11+
]
12+
13+
/**
14+
* @param {string} pkg
15+
* @return {boolean}
16+
*/
17+
function alreadyNotifying(pkg) {
18+
return atom.notifications.getNotifications()
19+
.some(note => note.getOptions()._src == `ide-rust-conflict-${pkg}`)
20+
}
21+
22+
/** Scans current active packages and shows notifications to help handle conflicts */
23+
function showConflictingPackageWarnings() {
24+
for (const pkg of CONFLICTING_PACKAGES) {
25+
if (atom.packages.isPackageActive(pkg) && !alreadyNotifying(pkg)) {
26+
const note = atom.notifications.addInfo("Choose a rust package", {
27+
description: `You have both \`ide-rust\` and \`${pkg}\` enabled, which ` +
28+
"include conflicting/duplicate functionality. " +
29+
"To avoid problems disable one of the packages.",
30+
dismissable: true,
31+
_src: `ide-rust-conflict-${pkg}`,
32+
buttons: [{
33+
text: `Disable ${pkg}`,
34+
onDidClick: () => {
35+
atom.packages.disablePackage(pkg)
36+
note.dismiss()
37+
}
38+
}, {
39+
text: "Disable ide-rust",
40+
onDidClick: () => {
41+
atom.notifications.getNotifications()
42+
.filter(note => note.getOptions()._src.startsWith("ide-rust"))
43+
.forEach(note => note.dismiss())
44+
atom.packages.disablePackage("ide-rust")
45+
}
46+
}]
47+
})
48+
}
49+
}
50+
}
51+
52+
module.exports = {
53+
showConflictingPackageWarnings
54+
}

lib/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
const cp = require("child_process")
22
const os = require("os")
33
const path = require("path")
4-
const _ = require('underscore-plus')
5-
const { CompositeDisposable, Disposable } = require('atom')
4+
const _ = require("underscore-plus")
5+
const { CompositeDisposable, Disposable } = require("atom")
66
const { AutoLanguageClient } = require("atom-languageclient")
7-
const RlsProject = require('./rls-project.js')
7+
const RlsProject = require("./rls-project.js")
88
const {
99
fetchLatestDist,
1010
checkHasRls,
1111
suggestChannelOrDated,
1212
DATED_REGEX,
13-
} = require('./dist-fetch')
13+
} = require("./dist-fetch")
14+
const { showConflictingPackageWarnings } = require("./competition.js")
1415

1516
/** @type {number} interval between toolchain update checks, milliseconds */
1617
const PERIODIC_UPDATE_CHECK_MILLIS = 6 * 60 * 60 * 1000
@@ -525,6 +526,9 @@ class RustLanguageClient extends AutoLanguageClient {
525526
'ide-rust:restart-all-language-servers',
526527
() => this._restartLanguageServers('Rust language servers restarted')
527528
))
529+
530+
showConflictingPackageWarnings()
531+
this.disposables.add(atom.packages.onDidActivatePackage(showConflictingPackageWarnings))
528532
}
529533

530534
deactivate() {

0 commit comments

Comments
 (0)