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

Commit ac226e5

Browse files
committed
chore: run prettier-config-atomic
1 parent 3078932 commit ac226e5

File tree

10 files changed

+531
-368
lines changed

10 files changed

+531
-368
lines changed

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
target/
3+
pnpm-lock.yaml

README.md

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
11
# IDE-Rust
2+
23
Rust language support for Atom-IDE, powered by [rust-analyzer](https://github.com/rust-analyzer/rust-analyzer).
34

45
## Features
5-
- Auto-completion
6-
- Diagnostics (errors and warnings from `rustc`)
7-
- Document outline
8-
- Go to definition (`ctrl` or `cmd` click)
9-
- Type information and Documentation on hover (hold `ctrl` or `cmd` for more information)
10-
- Find references (`ctrl-alt-shift-f` or `cmd-opt-shift-f` also in context menu)
11-
- Format file with rustfmt (`ctrl-shift-c` or `cmd-shift-c` also in context menu)
12-
- Format on save (disabled by default, see `atom-ide-ui` settings)
13-
- Rustup toolchain update checking at startup & every 6 hours thereafter
14-
- Supports rustup override toolchains
15-
- Rust language snippets
6+
7+
- Auto-completion
8+
- Diagnostics (errors and warnings from `rustc`)
9+
- Document outline
10+
- Go to definition (`ctrl` or `cmd` click)
11+
- Type information and Documentation on hover (hold `ctrl` or `cmd` for more information)
12+
- Find references (`ctrl-alt-shift-f` or `cmd-opt-shift-f` also in context menu)
13+
- Format file with rustfmt (`ctrl-shift-c` or `cmd-shift-c` also in context menu)
14+
- Format on save (disabled by default, see `atom-ide-ui` settings)
15+
- Rustup toolchain update checking at startup & every 6 hours thereafter
16+
- Supports rustup override toolchains
17+
- Rust language snippets
1618

1719
## Install
20+
1821
Install from Settings view by searching for `ide-rust`, or with the command line:
22+
1923
```
2024
$ apm install ide-rust
2125
```
2226

2327
### Prerequisites
28+
2429
**rust-analyzer** must be installed manually, if possible on the PATH _(otherwise configure this in the package settings)_.
2530
See https://rust-analyzer.github.io/manual.html#rust-analyzer-language-server-binary.
2631

@@ -30,20 +35,25 @@ No other packages or manual setup is required as these will be handled with user
3035
However, you may wish to install `rustup` with your OS package manager instead of following prompts to install via [rustup.rs](https://rustup.rs).
3136

3237
## Commands
38+
3339
- `ide-rust:restart-all-language-servers` Restart all currently active Rls processes
3440

3541
## Debugging IDE-Rust
42+
3643
If stuff isn't working you can try **enabling logging** to debug:
37-
* Open the atom console _(ctrl-shift-i)_
38-
* Enter `atom.config.set('core.debugLSP', true)`
39-
* Reload atom _(ctrl-shift-F5)_
44+
45+
- Open the atom console _(ctrl-shift-i)_
46+
- Enter `atom.config.set('core.debugLSP', true)`
47+
- Reload atom _(ctrl-shift-F5)_
4048

4149
This will spit out language server message logging into the atom console. Check if requests/responses are being sent or are incorrect.
4250

4351
## RLS
52+
4453
RLS is no longer supported. To use RLS install a previous version of ide-rust, `apm install [email protected]`.
4554

4655
## Screenshots
56+
4757
**Autocomplete**:
4858

4959
![Autocomplete image](https://user-images.githubusercontent.com/16418197/121962919-01114c80-cd2f-11eb-8136-11ba82ebe543.png)
@@ -60,6 +70,6 @@ RLS is no longer supported. To use RLS install a previous version of ide-rust, `
6070

6171
![Outline image](https://user-images.githubusercontent.com/16418197/121962765-cd362700-cd2e-11eb-92b2-74516cd734db.png)
6272

63-
6473
## License
74+
6575
MIT License. See the [license](LICENSE) for more details.

lib/competition.js

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,46 +16,50 @@ const CONFLICTING_PACKAGES = [
1616

1717
/**
1818
* @param {string} pkg
19-
* @return {boolean}
19+
* @returns {boolean}
2020
*/
2121
function alreadyNotifying(pkg) {
22-
return atom.notifications.getNotifications()
23-
.some(note => note.getOptions()._src == `ide-rust-conflict-${pkg}`)
22+
return atom.notifications.getNotifications().some((note) => note.getOptions()._src == `ide-rust-conflict-${pkg}`)
2423
}
2524

2625
/** Scans current active packages and shows notifications to help handle conflicts */
2726
function showConflictingPackageWarnings() {
2827
for (const pkg of CONFLICTING_PACKAGES) {
2928
if (atom.packages.isPackageActive(pkg) && !alreadyNotifying(pkg)) {
3029
const note = atom.notifications.addInfo("Choose a rust package", {
31-
description: `You have both \`ide-rust\` and \`${pkg}\` enabled, which ` +
30+
description:
31+
`You have both \`ide-rust\` and \`${pkg}\` enabled, which ` +
3232
"include conflicting/duplicate functionality. " +
3333
"To avoid problems disable one of the packages.",
3434
dismissable: true,
3535
_src: `ide-rust-conflict-${pkg}`,
36-
buttons: [{
37-
text: `Disable ${pkg}`,
38-
onDidClick: () => {
39-
atom.packages.disablePackage(pkg)
40-
note.dismiss()
41-
}
42-
}, {
43-
text: "Disable ide-rust",
44-
onDidClick: () => {
45-
atom.notifications.getNotifications()
46-
.filter(note => {
47-
const src = note.getOptions()._src
48-
return src && src.startsWith("ide-rust")
49-
})
50-
.forEach(note => note.dismiss())
51-
atom.packages.disablePackage("ide-rust")
52-
}
53-
}]
36+
buttons: [
37+
{
38+
text: `Disable ${pkg}`,
39+
onDidClick: () => {
40+
atom.packages.disablePackage(pkg)
41+
note.dismiss()
42+
},
43+
},
44+
{
45+
text: "Disable ide-rust",
46+
onDidClick: () => {
47+
atom.notifications
48+
.getNotifications()
49+
.filter((note) => {
50+
const src = note.getOptions()._src
51+
return src && src.startsWith("ide-rust")
52+
})
53+
.forEach((note) => note.dismiss())
54+
atom.packages.disablePackage("ide-rust")
55+
},
56+
},
57+
],
5458
})
5559
}
5660
}
5761
}
5862

5963
module.exports = {
60-
showConflictingPackageWarnings
64+
showConflictingPackageWarnings,
6165
}

lib/dist-fetch.js

Lines changed: 74 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,47 @@
1-
const https = require('https')
2-
const _ = require('underscore-plus')
1+
const https = require("https")
2+
const _ = require("underscore-plus")
33

44
const datedNightlyHasRlsCache = new Map()
55
const DATED_REGEX = /(^[^-]+)-(\d{4,}-\d{2}-\d{2})$/
66

77
/**
8-
* @param {string} manifest toml
9-
* @return {boolean}
8+
* @param {string} manifest Toml
9+
* @returns {boolean}
1010
*/
1111
function manifest_includes_rls(manifest) {
12-
return manifest.includes('rls-preview') && !manifest.includes('[pkg.rls-preview]\nversion = ""')
12+
return manifest.includes("rls-preview") && !manifest.includes('[pkg.rls-preview]\nversion = ""')
1313
}
1414

1515
/**
16-
* @param {Date|string} date
17-
* @param {string=} channel defaults to `nightly`
18-
* @return {Promise<string>} toolchain name
16+
* @param {Date | string} date
17+
* @param {string} [channel] Defaults to `nightly`
18+
* @returns {Promise<string>} Toolchain name
1919
*/
20-
async function checkDatedDistHasRls(date, channel='nightly') {
21-
const dateString = _.isString(date) ? date : date.toISOString().split('T')[0]
20+
async function checkDatedDistHasRls(date, channel = "nightly") {
21+
const dateString = _.isString(date) ? date : date.toISOString().split("T")[0]
2222
const cacheKey = `${channel}-${dateString}`
2323

24-
let fetch = datedNightlyHasRlsCache.get(cacheKey) || new Promise((resolve, reject) => {
25-
https.get(`https://static.rust-lang.org/dist/${dateString}/channel-rust-${channel}.toml`, res => {
26-
if (res.statusCode !== 200) {
27-
return reject(new Error(`Failed, status: ${res.statusCode}`))
28-
}
29-
res.setEncoding("utf8")
30-
let body = ""
31-
res.on("data", data => {
32-
body += data
33-
if (manifest_includes_rls(body)) resolve(cacheKey)
24+
let fetch =
25+
datedNightlyHasRlsCache.get(cacheKey) ||
26+
new Promise((resolve, reject) => {
27+
https
28+
.get(`https://static.rust-lang.org/dist/${dateString}/channel-rust-${channel}.toml`, (res) => {
29+
if (res.statusCode !== 200) {
30+
return reject(new Error(`Failed, status: ${res.statusCode}`))
31+
}
32+
res.setEncoding("utf8")
33+
let body = ""
34+
res.on("data", (data) => {
35+
body += data
36+
if (manifest_includes_rls(body)) resolve(cacheKey)
37+
})
38+
res.on("end", () => reject(new Error("no 'rls-preview'")))
3439
})
35-
res.on("end", () => reject(new Error("no 'rls-preview'")))
36-
})
37-
.on("error", e => {
38-
datedNightlyHasRlsCache.delete(cacheKey)
39-
reject(e)
40-
})
41-
})
40+
.on("error", (e) => {
41+
datedNightlyHasRlsCache.delete(cacheKey)
42+
reject(e)
43+
})
44+
})
4245

4346
if (!datedNightlyHasRlsCache.has(cacheKey)) {
4447
datedNightlyHasRlsCache.set(cacheKey, fetch)
@@ -48,77 +51,80 @@ async function checkDatedDistHasRls(date, channel='nightly') {
4851
}
4952

5053
/**
51-
* @param {string=} channel defaults to `nightly`
52-
* @return {Promise<string>} latest channel dated version with rls-preview
54+
* @param {string} [channel] Defaults to `nightly`
55+
* @returns {Promise<string>} Latest channel dated version with rls-preview
5356
*/
5457
async function fetchLatestDatedDistWithRls(channel) {
5558
const aDayMillis = 24 * 60 * 60 * 1000
5659
const minDate = new Date(Date.now() - 30 * aDayMillis)
5760

58-
const check = day => {
59-
return checkDatedDistHasRls(day, channel)
60-
.catch(e => {
61-
if (e && e.code === 'ENOTFOUND') throw e
61+
const check = (day) => {
62+
return checkDatedDistHasRls(day, channel).catch((e) => {
63+
if (e && e.code === "ENOTFOUND") throw e
6264

63-
const yesterday = new Date(day - aDayMillis)
64-
if (yesterday >= minDate) return check(yesterday)
65-
else throw new Error("No nightly with 'rls-preview'")
66-
})
65+
const yesterday = new Date(day - aDayMillis)
66+
if (yesterday >= minDate) return check(yesterday)
67+
else throw new Error("No nightly with 'rls-preview'")
68+
})
6769
}
6870

6971
return check(new Date())
7072
}
7173

7274
/**
73-
* @param {string} arg.toolchain toolchain to check
74-
* @param {string} [arg.currentVersion] current installed rustc version
75-
* @return {Promise<?string>} new version of update available (falsy otherwise)
75+
* @param {string} arg.toolchain Toolchain to check
76+
* @param {string} [arg.currentVersion] Current installed rustc version
77+
* @returns {Promise<?string>} New version of update available (falsy otherwise)
7678
*/
77-
async function fetchLatestDist({ toolchain, currentVersion="none" }) {
79+
async function fetchLatestDist({ toolchain, currentVersion = "none" }) {
7880
return new Promise((resolve, reject) => {
79-
https.get(`https://static.rust-lang.org/dist/channel-rust-${toolchain}.toml`, res => {
80-
if (res.statusCode !== 200) {
81-
return reject(new Error(`check for toolchain update failed, status: ${res.statusCode}`))
82-
}
81+
https
82+
.get(`https://static.rust-lang.org/dist/channel-rust-${toolchain}.toml`, (res) => {
83+
if (res.statusCode !== 200) {
84+
return reject(new Error(`check for toolchain update failed, status: ${res.statusCode}`))
85+
}
8386

84-
res.setEncoding("utf8")
85-
let body = ""
86-
res.on("data", data => body += data)
87-
res.on("end", () => {
88-
// use a subsection as toml is slow to parse fully
89-
let rustcInfo = body.match(/(\[pkg\.rustc\][^[]*)/m)
90-
if (!rustcInfo) return reject(new Error('could not split channel toml output'))
91-
let rustcVersion = require('toml').parse(rustcInfo[1]).pkg.rustc.version.trim()
92-
resolve(
93-
!currentVersion.trim().endsWith(rustcVersion)
94-
&& manifest_includes_rls(body)
95-
&& `rustc ${rustcVersion}`
96-
)
87+
res.setEncoding("utf8")
88+
let body = ""
89+
res.on("data", (data) => (body += data))
90+
res.on("end", () => {
91+
// use a subsection as toml is slow to parse fully
92+
let rustcInfo = body.match(/(\[pkg\.rustc\][^[]*)/m)
93+
if (!rustcInfo) return reject(new Error("could not split channel toml output"))
94+
let rustcVersion = require("toml").parse(rustcInfo[1]).pkg.rustc.version.trim()
95+
resolve(
96+
!currentVersion.trim().endsWith(rustcVersion) && manifest_includes_rls(body) && `rustc ${rustcVersion}`
97+
)
98+
})
99+
})
100+
.on("error", (e) => {
101+
console.warn("ide-rust: check for updates failed", e)
102+
resolve()
97103
})
98-
})
99-
.on("error", e => {
100-
console.warn("ide-rust: check for updates failed", e)
101-
resolve()
102-
})
103104
})
104105
}
105106

106107
/**
107108
* Check a toolchain has rls, this can be done before installing
109+
*
108110
* @param {string} toolchain
109-
* @return {Promise<boolean>}
111+
* @returns {Promise<boolean>}
110112
*/
111113
async function checkHasRls(toolchain) {
112114
let dated = toolchain.match(DATED_REGEX)
113115
if (dated) {
114-
return checkDatedDistHasRls(dated[2], dated[1]).then(() => true).catch(() => false)
116+
return checkDatedDistHasRls(dated[2], dated[1])
117+
.then(() => true)
118+
.catch(() => false)
115119
}
116-
return fetchLatestDist({ toolchain }).then(v => !!v).catch(() => false)
120+
return fetchLatestDist({ toolchain })
121+
.then((v) => !!v)
122+
.catch(() => false)
117123
}
118124

119125
/**
120-
* @param {string} channel ie nightly, beta, stable
121-
* @return {Promise<string>} latest channel dated version with rls-preview or the channel itself if ok
126+
* @param {string} channel Ie nightly, beta, stable
127+
* @returns {Promise<string>} Latest channel dated version with rls-preview or the channel itself if ok
122128
*/
123129
async function suggestChannelOrDated(channel) {
124130
let latestDatedPromise = fetchLatestDatedDistWithRls(channel)

0 commit comments

Comments
 (0)