mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 13:48:50 +00:00
Fix metrics
This commit is contained in:
parent
c0b2b15123
commit
cdddd205f6
1 changed files with 20 additions and 10 deletions
|
@ -29,8 +29,7 @@ pub fn run_metrics() -> Result<()> {
|
||||||
run!("git -c user.name=Bot -c user.email=dummy@example.com commit --message 📈")?;
|
run!("git -c user.name=Bot -c user.email=dummy@example.com commit --message 📈")?;
|
||||||
run!("git push origin master")?;
|
run!("git push origin master")?;
|
||||||
}
|
}
|
||||||
eprintln!("{:#?}\n", metrics);
|
eprintln!("{:#?}", metrics);
|
||||||
eprintln!("{}", metrics.json());
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,26 +151,32 @@ impl Host {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct State {
|
||||||
|
obj: bool,
|
||||||
|
first: bool,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct Json {
|
struct Json {
|
||||||
object_comma: bool,
|
stack: Vec<State>,
|
||||||
array_comma: bool,
|
|
||||||
buf: String,
|
buf: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Json {
|
impl Json {
|
||||||
fn begin_object(&mut self) {
|
fn begin_object(&mut self) {
|
||||||
self.object_comma = false;
|
self.stack.push(State { obj: true, first: true });
|
||||||
self.buf.push('{');
|
self.buf.push('{');
|
||||||
}
|
}
|
||||||
fn end_object(&mut self) {
|
fn end_object(&mut self) {
|
||||||
|
self.stack.pop();
|
||||||
self.buf.push('}')
|
self.buf.push('}')
|
||||||
}
|
}
|
||||||
fn begin_array(&mut self) {
|
fn begin_array(&mut self) {
|
||||||
self.array_comma = false;
|
self.stack.push(State { obj: false, first: true });
|
||||||
self.buf.push('[');
|
self.buf.push('[');
|
||||||
}
|
}
|
||||||
fn end_array(&mut self) {
|
fn end_array(&mut self) {
|
||||||
|
self.stack.pop();
|
||||||
self.buf.push(']')
|
self.buf.push(']')
|
||||||
}
|
}
|
||||||
fn field(&mut self, name: &str) {
|
fn field(&mut self, name: &str) {
|
||||||
|
@ -194,17 +199,22 @@ impl Json {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn array_comma(&mut self) {
|
fn array_comma(&mut self) {
|
||||||
if self.array_comma {
|
let state = self.stack.last_mut().unwrap();
|
||||||
|
if state.obj {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if !state.first {
|
||||||
self.buf.push(',');
|
self.buf.push(',');
|
||||||
}
|
}
|
||||||
self.array_comma = true;
|
state.first = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn object_comma(&mut self) {
|
fn object_comma(&mut self) {
|
||||||
if self.object_comma {
|
let state = self.stack.last_mut().unwrap();
|
||||||
|
if !state.first {
|
||||||
self.buf.push(',');
|
self.buf.push(',');
|
||||||
}
|
}
|
||||||
self.object_comma = true;
|
state.first = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue