Skip to content

Commit 9202f52

Browse files
authored
Merge branch 'master' into i/docs-scroll
2 parents eac6d58 + 3c245a7 commit 9202f52

File tree

6 files changed

+268
-247
lines changed

6 files changed

+268
-247
lines changed

docs/index.html

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -116,20 +116,22 @@
116116
if (this.version !== this.oldVersion) {
117117
const ConfigurationMdUrl =
118118
`https://raw.githubusercontent.com/rust-lang/rustfmt/${this.version}/Configurations.md`;
119+
let res;
119120
try {
120-
const res = await axios.get(ConfigurationMdUrl);
121-
const {
122-
about,
123-
configurationAbout,
124-
configurationDescriptions
125-
} = parseMarkdownAst(res.data);
126-
this.aboutHtml = marked.parser(about);
127-
this.configurationAboutHtml = marked.parser(configurationAbout);
128-
this.configurationDescriptions = configurationDescriptions;
129-
this.oldVersion = this.version;
130-
} catch(error) {
131-
this.aboutHtml = "<p>Failed to get configuration options for this version, please select the version from the dropdown above.</p>";
121+
res = await axios.get(ConfigurationMdUrl).catch(e => { throw e });
122+
} catch(e) {
123+
this.handleReqFailure(e);
124+
return;
132125
}
126+
const {
127+
about,
128+
configurationAbout,
129+
configurationDescriptions
130+
} = parseMarkdownAst(res.data);
131+
this.aboutHtml = marked.parser(about);
132+
this.configurationAboutHtml = marked.parser(configurationAbout);
133+
this.configurationDescriptions = configurationDescriptions;
134+
this.oldVersion = this.version;
133135
}
134136

135137
const ast = this.configurationDescriptions
@@ -172,7 +174,13 @@
172174
}
173175
},
174176
created: async function() {
175-
const {data: tags} = await axios.get(RusfmtTagsUrl);
177+
let tags;
178+
try {
179+
tags = (await axios.get(RusfmtTagsUrl)).data;
180+
} catch(e) {
181+
this.handleReqFailure(e);
182+
return;
183+
}
176184
const reMajorVersion = /v(\d+)/;
177185
const tagOptions = tags
178186
.map(tag => tag.name)
@@ -188,6 +196,30 @@
188196
this.scrolledOnce = true;
189197
}
190198
});
199+
},
200+
methods: {
201+
handleReqFailure(e) {
202+
if (e.response.status === 404) {
203+
this.aboutHtml =
204+
"<p>Failed to get configuration options for this version, please select the version from the dropdown above.</p>";
205+
} else if (
206+
e.response.status === 403 &&
207+
e.response.headers["X-RateLimit-Remaining"] === 0
208+
) {
209+
const resetDate = new Date(
210+
e.response.headers['X-RateLimit-Reset'] * 1000
211+
).toLocaleString();
212+
this.aboutHtml =
213+
`<p>You have hit the GitHub API rate limit; documentation cannot be updated.` +
214+
`<p>The rate limit will be reset at ${resetDate}.</p>`;
215+
} else {
216+
this.aboutHtml =
217+
`<p>Ecountered an error when fetching documentation data:</p>` +
218+
`<pre><code>${e.response.data}</code></pre>` +
219+
`<p>We would appreciate <a href="https://github.com/rust-lang/rustfmt/issues/new?template=bug_report.md">a bug report</a>.` +
220+
`<p>Try refreshing the page.</p>`;
221+
}
222+
}
191223
}
192224
});
193225
const extractDepthOnes = (ast) => {

src/formatting.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ mod vertical;
5757
pub(crate) mod visitor;
5858

5959
pub(crate) mod report;
60-
pub(crate) mod util;
6160

6261
pub(crate) fn format_input_inner(
6362
input: Input,

src/formatting/comment.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::formatting::{
1111
shape::{Indent, Shape},
1212
string::{rewrite_string, StringFormat},
1313
utils::{
14-
count_newlines, first_line_width, last_line_width, tab_to_spaces,
14+
count_newlines, first_line_width, format_code_block, last_line_width, tab_to_spaces,
1515
trim_end_unless_two_whitespaces, trim_left_preserve_layout, unicode_str_width,
1616
},
1717
};
@@ -685,10 +685,7 @@ impl<'a> CommentRewrite<'a> {
685685
let mut config = self.fmt.config.clone();
686686
config.set().wrap_comments(false);
687687
if config.format_code_in_doc_comments() {
688-
if let Some(s) = crate::formatting::util::format_code_block(
689-
&self.code_block_buffer,
690-
&config,
691-
) {
688+
if let Some(s) = format_code_block(&self.code_block_buffer, &config) {
692689
trim_custom_comment_prefix(s.as_ref())
693690
} else {
694691
trim_custom_comment_prefix(&self.code_block_buffer)

src/formatting/macros.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,10 @@ use crate::formatting::{
3333
shape::{Indent, Shape},
3434
source_map::SpanUtils,
3535
spanned::Spanned,
36-
util::{format_code_block, format_snippet},
3736
utils::{
38-
count_newlines, format_visibility, indent_next_line, is_empty_line, mk_sp,
39-
remove_trailing_white_spaces, rewrite_ident, trim_left_preserve_layout, wrap_str,
40-
NodeIdExt,
37+
count_newlines, format_code_block, format_snippet, format_visibility, indent_next_line,
38+
is_empty_line, mk_sp, remove_trailing_white_spaces, rewrite_ident,
39+
trim_left_preserve_layout, wrap_str, NodeIdExt,
4140
},
4241
visitor::FmtVisitor,
4342
};

src/formatting/util.rs

Lines changed: 0 additions & 224 deletions
This file was deleted.

0 commit comments

Comments
 (0)