Skip to content

Commit 35abf13

Browse files
committed
Small refactoring + docs
1 parent a2a999f commit 35abf13

File tree

4 files changed

+45
-31
lines changed

4 files changed

+45
-31
lines changed

src/librustc_save_analysis/json_api_dumper.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_serialize::json::as_json;
1515
use external_data::*;
1616
use data::{VariableKind, Visibility};
1717
use dump::Dump;
18-
use json_dumper::id_from_def_id;
18+
use id_from_def_id;
1919

2020
use rls_data::{Analysis, Import, ImportKind, Def, DefKind, CratePreludeData};
2121

src/librustc_save_analysis/json_dumper.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
use std::io::Write;
1212

13-
use rustc::hir::def_id::DefId;
1413
use rustc_serialize::json::as_json;
1514

1615
use rls_data::{self, Id, Analysis, Import, ImportKind, Def, DefKind, Ref, RefKind, MacroRef,
@@ -20,6 +19,7 @@ use rls_span::{Column, Row};
2019
use external_data::*;
2120
use data::VariableKind;
2221
use dump::Dump;
22+
use id_from_def_id;
2323

2424
pub struct JsonDumper<O: DumpOutput> {
2525
result: Analysis,
@@ -163,15 +163,6 @@ impl<'b, O: DumpOutput + 'b> Dump for JsonDumper<O> {
163163
// method, but not the supplied method). In both cases, we are currently
164164
// ignoring it.
165165

166-
// DefId::index is a newtype and so the JSON serialisation is ugly. Therefore
167-
// we use our own Id which is the same, but without the newtype.
168-
pub fn id_from_def_id(id: DefId) -> Id {
169-
Id {
170-
krate: id.krate.as_u32(),
171-
index: id.index.as_u32(),
172-
}
173-
}
174-
175166
impl Into<Import> for ExternCrateData {
176167
fn into(self) -> Import {
177168
Import {

src/librustc_save_analysis/lib.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,20 @@ fn escape(s: String) -> String {
10261026

10271027
// Helper function to determine if a span came from a
10281028
// macro expansion or syntax extension.
1029-
pub fn generated_code(span: Span) -> bool {
1029+
fn generated_code(span: Span) -> bool {
10301030
span.ctxt != NO_EXPANSION || span == DUMMY_SP
10311031
}
1032+
1033+
// DefId::index is a newtype and so the JSON serialisation is ugly. Therefore
1034+
// we use our own Id which is the same, but without the newtype.
1035+
fn id_from_def_id(id: DefId) -> rls_data::Id {
1036+
rls_data::Id {
1037+
krate: id.krate.as_u32(),
1038+
index: id.index.as_u32(),
1039+
}
1040+
}
1041+
1042+
fn id_from_node_id(id: NodeId, scx: &SaveContext) -> rls_data::Id {
1043+
let def_id = scx.tcx.hir.local_def_id(id);
1044+
id_from_def_id(def_id)
1045+
}

src/librustc_save_analysis/sig.rs

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,38 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// FIXME? None of these include visibility info.
12-
// Large outstanding things - where clauses, defs/refs for generics
13-
// paresable - each sig ends with `;` of ` {}`
11+
// A signature is a string representation of an item's type signature, excluding
12+
// any body. It also includes ids for any defs or refs in the signature. For
13+
// example:
14+
//
15+
// ```
16+
// fn foo(x: String) {
17+
// println!("{}", x);
18+
// }
19+
// ```
20+
// The signature string is something like "fn foo(x: String) {}" and the signature
21+
// will have defs for `foo` and `x` and a ref for `String`.
22+
//
23+
// All signature text should parse in the correct context (i.e., in a module or
24+
// impl, etc.). Clients may want to trim trailing `{}` or `;`. The text of a
25+
// signature is not guaranteed to be stable (it may improve or change as the
26+
// syntax changes, or whitespace or punctuation may change). It is also likely
27+
// not to be pretty - no attempt is made to prettify the text. It is recommended
28+
// that clients run the text through Rustfmt.
29+
//
30+
// This module generates Signatures for items by walking the AST and looking up
31+
// references.
32+
//
33+
// Signatures do not include visibility info. I'm not sure if this is a feature
34+
// or an ommission (FIXME).
35+
//
36+
// FIXME where clauses need implementing, defs/refs in generics are mostly missing.
1437

15-
use SaveContext;
38+
use {SaveContext, id_from_def_id, id_from_node_id};
1639

17-
use rls_data::{Signature, SigElement, Id};
40+
use rls_data::{Signature, SigElement};
1841

1942
use rustc::hir::def::Def;
20-
use rustc::hir::def_id::DefId;
2143
use syntax::ast::{self, NodeId};
2244
use syntax::print::pprust;
2345

@@ -26,19 +48,6 @@ pub fn item_signature(item: &ast::Item, scx: &SaveContext) -> Option<Signature>
2648
item.make(0, None, scx).ok()
2749
}
2850

29-
// TODO dup from json_dumper
30-
fn id_from_def_id(id: DefId) -> Id {
31-
Id {
32-
krate: id.krate.as_u32(),
33-
index: id.index.as_u32(),
34-
}
35-
}
36-
37-
fn id_from_node_id(id: NodeId, scx: &SaveContext) -> Id {
38-
let def_id = scx.tcx.hir.local_def_id(id);
39-
id_from_def_id(def_id)
40-
}
41-
4251
type Result = ::std::result::Result<Signature, &'static str>;
4352

4453
trait Sig {

0 commit comments

Comments
 (0)