1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
13 use rustc_serialize::json::as_json;
17 use rls_data::{Analysis, Import, Def, CratePreludeData, Format, Relation};
20 // A dumper to dump a restricted set of JSON information, designed for use with
21 // libraries distributed without their source. Clients are likely to use type
22 // information here, and (for example) generate Rustdoc URLs, but don't need
23 // information for navigating the source of the crate.
24 // Relative to the regular JSON save-analysis info, this form is filtered to
25 // remove non-visible items.
26 pub struct JsonApiDumper<'b, W: Write + 'b> {
31 impl<'b, W: Write> JsonApiDumper<'b, W> {
32 pub fn new(writer: &'b mut W) -> JsonApiDumper<'b, W> {
33 let mut result = Analysis::new();
34 result.kind = Format::JsonApi;
35 JsonApiDumper { output: writer, result }
39 impl<'b, W: Write> Drop for JsonApiDumper<'b, W> {
41 if let Err(_) = write!(self.output, "{}", as_json(&self.result)) {
42 error!("Error writing output");
47 impl<'b, W: Write + 'b> Dump for JsonApiDumper<'b, W> {
48 fn crate_prelude(&mut self, data: CratePreludeData) {
49 self.result.prelude = Some(data)
52 fn dump_relation(&mut self, data: Relation) {
53 self.result.relations.push(data);
55 fn import(&mut self, public: bool, import: Import) {
57 self.result.imports.push(import);
60 fn dump_def(&mut self, public: bool, mut data: Def) {
62 data.attributes = vec![];
63 self.result.defs.push(data);