diff options
-rw-r--r-- | .github/workflows/release.yaml | 3 | ||||
-rw-r--r-- | crates/ra_hir_def/src/body/scope.rs | 2 | ||||
-rw-r--r-- | crates/ra_project_model/src/sysroot.rs | 3 | ||||
-rw-r--r-- | crates/ra_text_edit/src/lib.rs | 4 | ||||
-rw-r--r-- | crates/ra_text_edit/src/text_edit.rs | 6 | ||||
-rw-r--r-- | docs/dev/README.md | 11 | ||||
-rw-r--r-- | docs/user/README.md | 78 | ||||
-rw-r--r-- | editors/code/src/installation/language_server.ts | 16 | ||||
-rw-r--r-- | xtask/src/cmd.rs | 9 | ||||
-rw-r--r-- | xtask/src/install.rs | 36 | ||||
-rw-r--r-- | xtask/src/lib.rs | 43 | ||||
-rw-r--r-- | xtask/src/main.rs | 6 | ||||
-rw-r--r-- | xtask/src/pre_commit.rs | 2 |
13 files changed, 157 insertions, 62 deletions
diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 77c92512a..4103e46c2 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml | |||
@@ -95,9 +95,6 @@ jobs: | |||
95 | - name: Copy vscode extension | 95 | - name: Copy vscode extension |
96 | run: mkdir -p ./dist/code && cp ./editors/code/*.vsix ./dist/ | 96 | run: mkdir -p ./dist/code && cp ./editors/code/*.vsix ./dist/ |
97 | 97 | ||
98 | - name: Copy emacs mode | ||
99 | run: cp ./editors/emacs/rust-analyzer.el ./dist/rust-analyzer.el | ||
100 | |||
101 | - name: Upload artifacts | 98 | - name: Upload artifacts |
102 | uses: actions/upload-artifact@v1 | 99 | uses: actions/upload-artifact@v1 |
103 | with: | 100 | with: |
diff --git a/crates/ra_hir_def/src/body/scope.rs b/crates/ra_hir_def/src/body/scope.rs index 32c924acc..a58a7b21f 100644 --- a/crates/ra_hir_def/src/body/scope.rs +++ b/crates/ra_hir_def/src/body/scope.rs | |||
@@ -192,7 +192,7 @@ mod tests { | |||
192 | let (off, code) = extract_offset(code); | 192 | let (off, code) = extract_offset(code); |
193 | let code = { | 193 | let code = { |
194 | let mut buf = String::new(); | 194 | let mut buf = String::new(); |
195 | let off = u32::from(off) as usize; | 195 | let off = off.to_usize(); |
196 | buf.push_str(&code[..off]); | 196 | buf.push_str(&code[..off]); |
197 | buf.push_str("marker"); | 197 | buf.push_str("marker"); |
198 | buf.push_str(&code[off..]); | 198 | buf.push_str(&code[off..]); |
diff --git a/crates/ra_project_model/src/sysroot.rs b/crates/ra_project_model/src/sysroot.rs index 34d066b1e..a23265fc0 100644 --- a/crates/ra_project_model/src/sysroot.rs +++ b/crates/ra_project_model/src/sysroot.rs | |||
@@ -99,7 +99,8 @@ fn try_find_src_path(cargo_toml: &Path) -> Result<PathBuf> { | |||
99 | let rustc_output = Command::new("rustc") | 99 | let rustc_output = Command::new("rustc") |
100 | .current_dir(cargo_toml.parent().unwrap()) | 100 | .current_dir(cargo_toml.parent().unwrap()) |
101 | .args(&["--print", "sysroot"]) | 101 | .args(&["--print", "sysroot"]) |
102 | .output()?; | 102 | .output() |
103 | .map_err(|e| format!("rustc --print sysroot failed: {}", e))?; | ||
103 | if !rustc_output.status.success() { | 104 | if !rustc_output.status.success() { |
104 | Err("failed to locate sysroot")?; | 105 | Err("failed to locate sysroot")?; |
105 | } | 106 | } |
diff --git a/crates/ra_text_edit/src/lib.rs b/crates/ra_text_edit/src/lib.rs index 5f1b12222..37f23d043 100644 --- a/crates/ra_text_edit/src/lib.rs +++ b/crates/ra_text_edit/src/lib.rs | |||
@@ -29,8 +29,8 @@ impl AtomTextEdit { | |||
29 | } | 29 | } |
30 | 30 | ||
31 | pub fn apply(&self, mut text: String) -> String { | 31 | pub fn apply(&self, mut text: String) -> String { |
32 | let start = u32::from(self.delete.start()) as usize; | 32 | let start = self.delete.start().to_usize(); |
33 | let end = u32::from(self.delete.end()) as usize; | 33 | let end = self.delete.end().to_usize(); |
34 | text.replace_range(start..end, &self.insert); | 34 | text.replace_range(start..end, &self.insert); |
35 | text | 35 | text |
36 | } | 36 | } |
diff --git a/crates/ra_text_edit/src/text_edit.rs b/crates/ra_text_edit/src/text_edit.rs index 413c7d782..3291ada42 100644 --- a/crates/ra_text_edit/src/text_edit.rs +++ b/crates/ra_text_edit/src/text_edit.rs | |||
@@ -66,13 +66,13 @@ impl TextEdit { | |||
66 | let mut total_len = text.len(); | 66 | let mut total_len = text.len(); |
67 | for atom in self.atoms.iter() { | 67 | for atom in self.atoms.iter() { |
68 | total_len += atom.insert.len(); | 68 | total_len += atom.insert.len(); |
69 | total_len -= u32::from(atom.delete.end() - atom.delete.start()) as usize; | 69 | total_len -= (atom.delete.end() - atom.delete.start()).to_usize(); |
70 | } | 70 | } |
71 | let mut buf = String::with_capacity(total_len); | 71 | let mut buf = String::with_capacity(total_len); |
72 | let mut prev = 0; | 72 | let mut prev = 0; |
73 | for atom in self.atoms.iter() { | 73 | for atom in self.atoms.iter() { |
74 | let start = u32::from(atom.delete.start()) as usize; | 74 | let start = atom.delete.start().to_usize(); |
75 | let end = u32::from(atom.delete.end()) as usize; | 75 | let end = atom.delete.end().to_usize(); |
76 | if start > prev { | 76 | if start > prev { |
77 | buf.push_str(&text[prev..start]); | 77 | buf.push_str(&text[prev..start]); |
78 | } | 78 | } |
diff --git a/docs/dev/README.md b/docs/dev/README.md index 732e4bdd3..991deaf90 100644 --- a/docs/dev/README.md +++ b/docs/dev/README.md | |||
@@ -74,7 +74,7 @@ relevant test and execute it (VS Code includes an action for running a single | |||
74 | test). | 74 | test). |
75 | 75 | ||
76 | However, launching a VS Code instance with locally build language server is | 76 | However, launching a VS Code instance with locally build language server is |
77 | possible. There's "Run Extension (Dev Server)" launch configuration for this. | 77 | possible. There's **"Run Extension (Dev Server)"** launch configuration for this. |
78 | 78 | ||
79 | In general, I use one of the following workflows for fixing bugs and | 79 | In general, I use one of the following workflows for fixing bugs and |
80 | implementing features. | 80 | implementing features. |
@@ -88,7 +88,14 @@ Code to sanity check that the thing works as I expect. | |||
88 | 88 | ||
89 | If the problem concerns only the VS Code extension, I use **Run Extension** | 89 | If the problem concerns only the VS Code extension, I use **Run Extension** |
90 | launch configuration from `launch.json`. Notably, this uses the usual | 90 | launch configuration from `launch.json`. Notably, this uses the usual |
91 | `ra_lsp_server` binary from `PATH`. After I am done with the fix, I use `cargo | 91 | `ra_lsp_server` binary from `PATH`. For this it is important to have the following |
92 | in `setting.json` file: | ||
93 | ```json | ||
94 | { | ||
95 | "rust-analyzer.raLspServerPath": "ra_lsp_server" | ||
96 | } | ||
97 | ``` | ||
98 | After I am done with the fix, I use `cargo | ||
92 | xtask install --client-code` to try the new extension for real. | 99 | xtask install --client-code` to try the new extension for real. |
93 | 100 | ||
94 | If I need to fix something in the `ra_lsp_server` crate, I feel sad because it's | 101 | If I need to fix something in the `ra_lsp_server` crate, I feel sad because it's |
diff --git a/docs/user/README.md b/docs/user/README.md index 3da30a193..14ca6fd64 100644 --- a/docs/user/README.md +++ b/docs/user/README.md | |||
@@ -1,16 +1,26 @@ | |||
1 | [github-releases]: https://github.com/rust-analyzer/rust-analyzer/releases | ||
2 | |||
1 | The main interface to rust-analyzer is the | 3 | The main interface to rust-analyzer is the |
2 | [LSP](https://microsoft.github.io/language-server-protocol/) implementation. To | 4 | [LSP](https://microsoft.github.io/language-server-protocol/) implementation. To |
3 | install lsp server, clone the repository and then run `cargo xtask install | 5 | install lsp server, you have three options: |
4 | --server` (which is shorthand for `cargo install --path | 6 | |
5 | ./crates/ra_lsp_server`). This will produce a binary named `ra_lsp_server` which | 7 | * **Preferred and default:** install the plugin/extension for your IDE and it will ask your permission to automatically download the latest lsp server for you from [GitHub releases][github-releases]. (See docs to find out whether this is implemented for your editor below). |
6 | you should be able to use it with any LSP-compatible editor. We use custom | 8 | * Manually download prebuilt binaries from [GitHub releases][github-releases] |
7 | extensions to LSP, so special client-side support is required to take full | 9 | * `ra_lsp_server-linux` for Linux |
8 | advantage of rust-analyzer. This repository contains support code for VS Code. | 10 | * `ra_lsp_server-mac` for Mac |
9 | 11 | * `ra_lsp_server-windows.exe` for Windows | |
10 | ``` | 12 | * Clone the repository and build from sources |
13 | ```bash | ||
11 | $ git clone [email protected]:rust-analyzer/rust-analyzer && cd rust-analyzer | 14 | $ git clone [email protected]:rust-analyzer/rust-analyzer && cd rust-analyzer |
12 | $ cargo xtask install --server | 15 | $ cargo xtask install --server # or cargo install --path ./crates/ra_lsp_server |
13 | ``` | 16 | ``` |
17 | |||
18 | This way you will get a binary named `ra_lsp_server` (with os suffix for prebuilt binaries) | ||
19 | which you should be able to use with any LSP-compatible editor. | ||
20 | |||
21 | We make use of custom extensions to LSP, so special client-side support is required to take full | ||
22 | advantage of rust-analyzer. This repository contains support code for VS Code. | ||
23 | |||
14 | Rust Analyzer needs sources of rust standard library to work, so | 24 | Rust Analyzer needs sources of rust standard library to work, so |
15 | you might also need to execute | 25 | you might also need to execute |
16 | 26 | ||
@@ -22,30 +32,34 @@ See [./features.md](./features.md) document for a list of features that are avai | |||
22 | 32 | ||
23 | ## VS Code | 33 | ## VS Code |
24 | 34 | ||
25 | Prerequisites: | 35 | ### Prerequisites |
26 | |||
27 | In order to build the VS Code plugin, you need to have node.js and npm with | ||
28 | a minimum version of 10 installed. Please refer to | ||
29 | [node.js and npm documentation](https://nodejs.org) for installation instructions. | ||
30 | 36 | ||
31 | You will also need the most recent version of VS Code: we don't try to | 37 | You will need the most recent version of VS Code: we don't try to |
32 | maintain compatibility with older versions yet. | 38 | maintain compatibility with older versions yet. |
33 | 39 | ||
34 | ### Installation from prebuilt binaries | 40 | ### Installation from prebuilt binaries |
35 | 41 | ||
36 | We ship prebuilt binaries for Linux, Mac and Windows via | 42 | We ship prebuilt binaries for Linux, Mac and Windows via |
37 | [GitHub releases](https://github.com/rust-analyzer/rust-analyzer/releases). | 43 | [GitHub releases][github-releases]. |
38 | In order to use them you need to install the client VSCode extension. | 44 | In order to use them you need to install the client VSCode extension. |
39 | 45 | ||
40 | Publishing to VSCode marketplace is currently WIP. Thus, you need to clone the repository and install **only** the client extension via | 46 | Publishing to VS Code marketplace is currently WIP. Thus, you need to manually download |
47 | `rust-analyzer-0.1.0.vsix` file from latest [GitHub release][github-releases]. | ||
48 | |||
49 | After you downloaded the `.vsix` file you can install it from the terminal | ||
50 | |||
41 | ``` | 51 | ``` |
42 | $ git clone https://github.com/rust-analyzer/rust-analyzer.git --depth 1 | 52 | $ code --install-extension rust-analyzer-0.1.0.vsix |
43 | $ cd rust-analyzer | ||
44 | $ cargo xtask install --client-code | ||
45 | ``` | 53 | ``` |
46 | Then open VSCode (or reload the window if it was already running), open some Rust project and you should | ||
47 | see an info message pop-up. | ||
48 | 54 | ||
55 | Or open VS Code, press <kbd>Ctrl+Shift+P</kbd>, and search for the following command: | ||
56 | |||
57 | <img width="500px" alt="Install from VSIX command" src="https://user-images.githubusercontent.com/36276403/74108225-c0c11d80-4b80-11ea-9b2a-0a43f09e29af.png"> | ||
58 | |||
59 | Press <kbd>Enter</kbd> and go to `rust-analyzer-0.1.0.vsix` file through the file explorer. | ||
60 | |||
61 | Then open some Rust project and you should | ||
62 | see an info message pop-up. | ||
49 | 63 | ||
50 | <img height="140px" src="https://user-images.githubusercontent.com/36276403/74103174-a40df100-4b52-11ea-81f4-372c70797924.png" alt="Download now message"/> | 64 | <img height="140px" src="https://user-images.githubusercontent.com/36276403/74103174-a40df100-4b52-11ea-81f4-372c70797924.png" alt="Download now message"/> |
51 | 65 | ||
@@ -57,11 +71,15 @@ For updates you need to remove installed binary | |||
57 | rm -rf ${HOME}/.config/Code/User/globalStorage/matklad.rust-analyzer | 71 | rm -rf ${HOME}/.config/Code/User/globalStorage/matklad.rust-analyzer |
58 | ``` | 72 | ``` |
59 | 73 | ||
60 | `"Donwload latest language server"` command for VSCode and automatic updates detection is currently WIP. | 74 | `"Download latest language server"` command for VSCode and automatic updates detection is currently WIP. |
61 | 75 | ||
62 | 76 | ||
63 | ### Installation from sources | 77 | ### Installation from sources |
64 | 78 | ||
79 | In order to build the VS Code plugin from sources, you need to have node.js and npm with | ||
80 | a minimum version of 12 installed. Please refer to | ||
81 | [node.js and npm documentation](https://nodejs.org) for installation instructions. | ||
82 | |||
65 | The experimental VS Code plugin can be built and installed by executing the | 83 | The experimental VS Code plugin can be built and installed by executing the |
66 | following commands: | 84 | following commands: |
67 | 85 | ||
@@ -71,6 +89,16 @@ $ cd rust-analyzer | |||
71 | $ cargo xtask install | 89 | $ cargo xtask install |
72 | ``` | 90 | ``` |
73 | 91 | ||
92 | After that you need to amend your `settings.json` file to explicitly specify the | ||
93 | path to `ra_lsp_server` that you've just built. | ||
94 | ```json | ||
95 | { | ||
96 | "rust-analyzer.raLspServerPath": "ra_lsp_server" | ||
97 | } | ||
98 | ``` | ||
99 | This should work on all platforms, otherwise if installed `ra_lsp_server` is not available through your `$PATH` then see how to configure it [here](#setting-up-the-PATH-variable). | ||
100 | |||
101 | |||
74 | The automatic installation is expected to *just work* for common cases, if it | 102 | The automatic installation is expected to *just work* for common cases, if it |
75 | doesn't, report bugs! | 103 | doesn't, report bugs! |
76 | 104 | ||
@@ -127,7 +155,7 @@ host. | |||
127 | As an example, [Pale Fire](https://github.com/matklad/pale-fire/) color scheme tweaks rust colors. | 155 | As an example, [Pale Fire](https://github.com/matklad/pale-fire/) color scheme tweaks rust colors. |
128 | * `rust-analyzer.enableEnhancedTyping`: by default, rust-analyzer intercepts the | 156 | * `rust-analyzer.enableEnhancedTyping`: by default, rust-analyzer intercepts the |
129 | `Enter` key to make it easier to continue comments. Note that it may conflict with VIM emulation plugin. | 157 | `Enter` key to make it easier to continue comments. Note that it may conflict with VIM emulation plugin. |
130 | * `rust-analyzer.raLspServerPath`: path to `ra_lsp_server` executable | 158 | * `rust-analyzer.raLspServerPath`: path to `ra_lsp_server` executable, when absent or `null` defaults to prebuilt binary path |
131 | * `rust-analyzer.enableCargoWatchOnStartup`: prompt to install & enable `cargo | 159 | * `rust-analyzer.enableCargoWatchOnStartup`: prompt to install & enable `cargo |
132 | watch` for live error highlighting (note, this **does not** use rust-analyzer) | 160 | watch` for live error highlighting (note, this **does not** use rust-analyzer) |
133 | * `rust-analyzer.excludeGlobs`: a list of glob-patterns for exclusion (see globset [docs](https://docs.rs/globset) for syntax). | 161 | * `rust-analyzer.excludeGlobs`: a list of glob-patterns for exclusion (see globset [docs](https://docs.rs/globset) for syntax). |
@@ -232,6 +260,8 @@ Installation: | |||
232 | 260 | ||
233 | * You can now invoke the command palette and type LSP enable to locally/globally enable the rust-analyzer LSP (type LSP enable, then choose either locally or globally, then select rust-analyzer) | 261 | * You can now invoke the command palette and type LSP enable to locally/globally enable the rust-analyzer LSP (type LSP enable, then choose either locally or globally, then select rust-analyzer) |
234 | 262 | ||
263 | |||
264 | <!-- Update links to this header when changing it! --> | ||
235 | ### Setting up the `PATH` variable | 265 | ### Setting up the `PATH` variable |
236 | 266 | ||
237 | On Unix systems, `rustup` adds `~/.cargo/bin` to `PATH` by modifying the shell's | 267 | On Unix systems, `rustup` adds `~/.cargo/bin` to `PATH` by modifying the shell's |
diff --git a/editors/code/src/installation/language_server.ts b/editors/code/src/installation/language_server.ts index 1ce67b8b2..3510f9178 100644 --- a/editors/code/src/installation/language_server.ts +++ b/editors/code/src/installation/language_server.ts | |||
@@ -100,15 +100,21 @@ export async function ensureLanguageServerBinary( | |||
100 | try { | 100 | try { |
101 | await downloadLatestLanguageServer(langServerSource); | 101 | await downloadLatestLanguageServer(langServerSource); |
102 | } catch (err) { | 102 | } catch (err) { |
103 | await vscode.window.showErrorMessage( | 103 | vscode.window.showErrorMessage( |
104 | `Failed to download language server from ${langServerSource.repo.name} ` + | 104 | `Failed to download language server from ${langServerSource.repo.name} ` + |
105 | `GitHub repository: ${err.message}` | 105 | `GitHub repository: ${err.message}` |
106 | ); | 106 | ); |
107 | 107 | ||
108 | await dns.resolve('www.google.com').catch(err => { | 108 | dns.resolve('example.com').then( |
109 | console.error("DNS resolution failed, there might be an issue with Internet availability"); | 109 | addrs => console.log("DNS resolution for example.com was successful", addrs), |
110 | console.error(err); | 110 | err => { |
111 | }); | 111 | console.error( |
112 | "DNS resolution for example.com failed, " + | ||
113 | "there might be an issue with Internet availability" | ||
114 | ); | ||
115 | console.error(err); | ||
116 | } | ||
117 | ); | ||
112 | 118 | ||
113 | return null; | 119 | return null; |
114 | } | 120 | } |
diff --git a/xtask/src/cmd.rs b/xtask/src/cmd.rs index 2027f4893..37497fb74 100644 --- a/xtask/src/cmd.rs +++ b/xtask/src/cmd.rs | |||
@@ -18,7 +18,7 @@ impl Cmd<'_> { | |||
18 | run(self.unix, self.work_dir) | 18 | run(self.unix, self.work_dir) |
19 | } | 19 | } |
20 | } | 20 | } |
21 | pub fn run_with_output(self) -> Result<Output> { | 21 | pub fn run_with_output(self) -> Result<String> { |
22 | if cfg!(windows) { | 22 | if cfg!(windows) { |
23 | run_with_output(self.windows, self.work_dir) | 23 | run_with_output(self.windows, self.work_dir) |
24 | } else { | 24 | } else { |
@@ -34,8 +34,11 @@ pub fn run(cmdline: &str, dir: &str) -> Result<()> { | |||
34 | .map(|_| ()) | 34 | .map(|_| ()) |
35 | } | 35 | } |
36 | 36 | ||
37 | pub fn run_with_output(cmdline: &str, dir: &str) -> Result<Output> { | 37 | pub fn run_with_output(cmdline: &str, dir: &str) -> Result<String> { |
38 | do_run(cmdline, dir, &mut |_| {}) | 38 | let output = do_run(cmdline, dir, &mut |_| {})?; |
39 | let stdout = String::from_utf8(output.stdout)?; | ||
40 | let stdout = stdout.trim().to_string(); | ||
41 | Ok(stdout) | ||
39 | } | 42 | } |
40 | 43 | ||
41 | fn do_run(cmdline: &str, dir: &str, f: &mut dyn FnMut(&mut Command)) -> Result<Output> { | 44 | fn do_run(cmdline: &str, dir: &str, f: &mut dyn FnMut(&mut Command)) -> Result<Output> { |
diff --git a/xtask/src/install.rs b/xtask/src/install.rs index 8c65b51e3..99e1eddb1 100644 --- a/xtask/src/install.rs +++ b/xtask/src/install.rs | |||
@@ -24,6 +24,7 @@ pub struct ServerOpt { | |||
24 | 24 | ||
25 | impl InstallCmd { | 25 | impl InstallCmd { |
26 | pub fn run(self) -> Result<()> { | 26 | pub fn run(self) -> Result<()> { |
27 | let both = self.server.is_some() && self.client.is_some(); | ||
27 | if cfg!(target_os = "macos") { | 28 | if cfg!(target_os = "macos") { |
28 | fix_path_for_mac().context("Fix path for mac")? | 29 | fix_path_for_mac().context("Fix path for mac")? |
29 | } | 30 | } |
@@ -33,6 +34,16 @@ impl InstallCmd { | |||
33 | if let Some(client) = self.client { | 34 | if let Some(client) = self.client { |
34 | install_client(client).context("install client")?; | 35 | install_client(client).context("install client")?; |
35 | } | 36 | } |
37 | if both { | ||
38 | eprintln!( | ||
39 | " | ||
40 | Installation complete. | ||
41 | |||
42 | Add `\"rust-analyzer.raLspServerPath\": \"ra_lsp_server\",` to VS Code settings, | ||
43 | otherwise it will use the latest release from GitHub. | ||
44 | " | ||
45 | ) | ||
46 | } | ||
36 | Ok(()) | 47 | Ok(()) |
37 | } | 48 | } |
38 | } | 49 | } |
@@ -116,15 +127,12 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> { | |||
116 | } | 127 | } |
117 | .run()?; | 128 | .run()?; |
118 | 129 | ||
119 | let installed_extensions = { | 130 | let installed_extensions = Cmd { |
120 | let output = Cmd { | 131 | unix: &format!(r"{} --list-extensions", code_binary), |
121 | unix: &format!(r"{} --list-extensions", code_binary), | 132 | windows: &format!(r"cmd.exe /c {}.cmd --list-extensions", code_binary), |
122 | windows: &format!(r"cmd.exe /c {}.cmd --list-extensions", code_binary), | 133 | work_dir: ".", |
123 | work_dir: ".", | 134 | } |
124 | } | 135 | .run_with_output()?; |
125 | .run_with_output()?; | ||
126 | String::from_utf8(output.stdout)? | ||
127 | }; | ||
128 | 136 | ||
129 | if !installed_extensions.contains("rust-analyzer") { | 137 | if !installed_extensions.contains("rust-analyzer") { |
130 | anyhow::bail!( | 138 | anyhow::bail!( |
@@ -150,12 +158,10 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> { | |||
150 | 158 | ||
151 | fn install_server(opts: ServerOpt) -> Result<()> { | 159 | fn install_server(opts: ServerOpt) -> Result<()> { |
152 | let mut old_rust = false; | 160 | let mut old_rust = false; |
153 | if let Ok(output) = run_with_output("cargo --version", ".") { | 161 | if let Ok(stdout) = run_with_output("cargo --version", ".") { |
154 | if let Ok(stdout) = String::from_utf8(output.stdout) { | 162 | println!("{}", stdout); |
155 | println!("{}", stdout); | 163 | if !check_version(&stdout, REQUIRED_RUST_VERSION) { |
156 | if !check_version(&stdout, REQUIRED_RUST_VERSION) { | 164 | old_rust = true; |
157 | old_rust = true; | ||
158 | } | ||
159 | } | 165 | } |
160 | } | 166 | } |
161 | 167 | ||
diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs index 8fdf43e4a..1bb1882b0 100644 --- a/xtask/src/lib.rs +++ b/xtask/src/lib.rs | |||
@@ -15,7 +15,10 @@ use std::{ | |||
15 | process::{Command, Stdio}, | 15 | process::{Command, Stdio}, |
16 | }; | 16 | }; |
17 | 17 | ||
18 | use crate::{cmd::run, codegen::Mode}; | 18 | use crate::{ |
19 | cmd::{run, run_with_output}, | ||
20 | codegen::Mode, | ||
21 | }; | ||
19 | 22 | ||
20 | pub use anyhow::Result; | 23 | pub use anyhow::Result; |
21 | 24 | ||
@@ -156,3 +159,41 @@ fn rm_rf(path: &Path) -> Result<()> { | |||
156 | if path.is_file() { fs::remove_file(path) } else { fs::remove_dir_all(path) } | 159 | if path.is_file() { fs::remove_file(path) } else { fs::remove_dir_all(path) } |
157 | .with_context(|| format!("failed to remove {:?}", path)) | 160 | .with_context(|| format!("failed to remove {:?}", path)) |
158 | } | 161 | } |
162 | |||
163 | pub fn run_release() -> Result<()> { | ||
164 | run("git switch release", ".")?; | ||
165 | run("git fetch upstream", ".")?; | ||
166 | run("git reset --hard upstream/master", ".")?; | ||
167 | run("git push", ".")?; | ||
168 | |||
169 | let changelog_dir = project_root().join("../rust-analyzer.github.io/thisweek/_posts"); | ||
170 | |||
171 | let today = run_with_output("date --iso", ".")?; | ||
172 | let commit = run_with_output("git rev-parse HEAD", ".")?; | ||
173 | let changelog_n = fs::read_dir(changelog_dir.as_path())?.count(); | ||
174 | |||
175 | let contents = format!( | ||
176 | "\ | ||
177 | = Changelog #{} | ||
178 | :sectanchors: | ||
179 | :page-layout: post | ||
180 | |||
181 | Commit: commit:{}[] + | ||
182 | Release: release:{}[] | ||
183 | |||
184 | == New Features | ||
185 | |||
186 | * pr:[] . | ||
187 | |||
188 | == Fixes | ||
189 | |||
190 | == Internal Improvements | ||
191 | ", | ||
192 | changelog_n, commit, today | ||
193 | ); | ||
194 | |||
195 | let path = changelog_dir.join(format!("{}-changelog-{}.adoc", today, changelog_n)); | ||
196 | fs::write(&path, &contents)?; | ||
197 | |||
198 | Ok(()) | ||
199 | } | ||
diff --git a/xtask/src/main.rs b/xtask/src/main.rs index c347de9ab..7ca727bde 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs | |||
@@ -14,7 +14,7 @@ use pico_args::Arguments; | |||
14 | use xtask::{ | 14 | use xtask::{ |
15 | codegen::{self, Mode}, | 15 | codegen::{self, Mode}, |
16 | install::{ClientOpt, InstallCmd, ServerOpt}, | 16 | install::{ClientOpt, InstallCmd, ServerOpt}, |
17 | pre_commit, run_clippy, run_fuzzer, run_pre_cache, run_rustfmt, Result, | 17 | pre_commit, run_clippy, run_fuzzer, run_pre_cache, run_release, run_rustfmt, Result, |
18 | }; | 18 | }; |
19 | 19 | ||
20 | fn main() -> Result<()> { | 20 | fn main() -> Result<()> { |
@@ -92,6 +92,10 @@ FLAGS: | |||
92 | args.finish()?; | 92 | args.finish()?; |
93 | run_pre_cache() | 93 | run_pre_cache() |
94 | } | 94 | } |
95 | "release" => { | ||
96 | args.finish()?; | ||
97 | run_release() | ||
98 | } | ||
95 | _ => { | 99 | _ => { |
96 | eprintln!( | 100 | eprintln!( |
97 | "\ | 101 | "\ |
diff --git a/xtask/src/pre_commit.rs b/xtask/src/pre_commit.rs index 88e868ca6..1533f64dc 100644 --- a/xtask/src/pre_commit.rs +++ b/xtask/src/pre_commit.rs | |||
@@ -14,7 +14,7 @@ pub fn run_hook() -> Result<()> { | |||
14 | let diff = run_with_output("git diff --diff-filter=MAR --name-only --cached", ".")?; | 14 | let diff = run_with_output("git diff --diff-filter=MAR --name-only --cached", ".")?; |
15 | 15 | ||
16 | let root = project_root(); | 16 | let root = project_root(); |
17 | for line in String::from_utf8(diff.stdout)?.lines() { | 17 | for line in diff.lines() { |
18 | run(&format!("git update-index --add {}", root.join(line).to_string_lossy()), ".")?; | 18 | run(&format!("git update-index --add {}", root.join(line).to_string_lossy()), ".")?; |
19 | } | 19 | } |
20 | 20 | ||