Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit ef3ac14

Browse files
committed
Move rls-analysis crate
Based on rust-dev-tools/rls-analysis@2b811df
1 parent 6ec66af commit ef3ac14

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+2908
-1
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ test = false
2121
path = "rls/src/main.rs"
2222

2323
[dependencies]
24+
rls-analysis = "0.16.12"
25+
2426
cargo = { git = "https://github.com/rust-lang/cargo", rev = "4e74e2fc0908524d17735c768067117d3e84ee9c" }
2527
cargo_metadata = "0.7"
2628
clippy_lints = { git = "https://github.com/rust-lang/rust-clippy", rev = "5725726345039830677a0aeb8389ae78ce01ff97", optional = true }
@@ -36,7 +38,6 @@ num_cpus = "1"
3638
racer = { version = "=2.1.18", default-features = false }
3739
rand = "0.6"
3840
rayon = "1"
39-
rls-analysis = "0.16.12"
4041
rls-blacklist = "0.1.3"
4142
rls-data = { version = "0.18.2", features = ["serialize-serde", "serialize-rustc"] }
4243
rls-rustc = "0.5.0"

rls-analysis/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
target
2+
3+
Cargo.lock

rls-analysis/Cargo.toml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[package]
2+
name = "rls-analysis"
3+
version = "0.16.12"
4+
authors = ["Nick Cameron <[email protected]>"]
5+
description = "Library for processing rustc's save-analysis data for the RLS"
6+
license = "Apache-2.0/MIT"
7+
repository = "https://github.com/rust-dev-tools/rls-analysis"
8+
categories = ["development-tools"]
9+
exclude = [
10+
"test_data/*",
11+
]
12+
13+
[dependencies]
14+
rustc-serialize = "0.3"
15+
log = "0.4"
16+
rls-data = "= 0.18.2"
17+
rls-span = "0.4"
18+
derive-new = "0.5"
19+
fst = { version = "0.3", default-features = false }
20+
itertools = "0.7.3"
21+
json = "0.11.13"
22+
23+
[dev-dependencies]
24+
lazy_static = "1"
25+
env_logger = "0.5"

rls-analysis/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[![Build Status](https://travis-ci.org/nrc/rls-analysis.svg?branch=master)](https://travis-ci.org/nrc/rls-analysis)
2+
3+
# rls-analysis
4+
5+
Library for processing rustc's save-analysis data for the RLS.
6+
7+
[API Documentation](https://docs.rs/rls-analysis/)

rls-analysis/benches/std_api_crate.rs

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// Copyright 2017 The RLS Project Developers.
2+
//
3+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6+
// option. This file may not be copied, modified, or distributed
7+
// except according to those terms.
8+
9+
#![feature(test)]
10+
11+
extern crate rls_analysis;
12+
#[macro_use]
13+
extern crate derive_new;
14+
#[macro_use]
15+
extern crate lazy_static;
16+
extern crate test;
17+
use test::Bencher;
18+
19+
use std::path::{Path, PathBuf};
20+
use std::sync::RwLock;
21+
22+
use rls_analysis::{AnalysisHost, AnalysisLoader, SearchDirectory};
23+
24+
#[derive(Clone, new)]
25+
struct TestAnalysisLoader {
26+
path: PathBuf,
27+
}
28+
29+
impl AnalysisLoader for TestAnalysisLoader {
30+
fn needs_hard_reload(&self, _path_prefix: &Path) -> bool {
31+
true
32+
}
33+
34+
fn fresh_host(&self) -> AnalysisHost<Self> {
35+
AnalysisHost::new_with_loader(self.clone())
36+
}
37+
38+
fn set_path_prefix(&mut self, _path_prefix: &Path) {}
39+
40+
fn abs_path_prefix(&self) -> Option<PathBuf> {
41+
panic!();
42+
}
43+
44+
fn search_directories(&self) -> Vec<SearchDirectory> {
45+
vec![SearchDirectory::new(self.path.clone(), None)]
46+
}
47+
}
48+
49+
lazy_static! {
50+
static ref STDLIB_FILE_PATH: PathBuf = PathBuf::from("/checkout/src/libstd/lib.rs");
51+
static ref STDLIB_DATA_PATH: PathBuf = PathBuf::from("test_data/rust-analysis");
52+
53+
static ref HOST: RwLock<AnalysisHost<TestAnalysisLoader>> = {
54+
let host = AnalysisHost::new_with_loader(TestAnalysisLoader::new(
55+
STDLIB_DATA_PATH.clone(),
56+
));
57+
host.reload(&STDLIB_DATA_PATH, &STDLIB_DATA_PATH).unwrap();
58+
RwLock::new(host)
59+
};
60+
}
61+
62+
#[bench]
63+
fn search_for_id(b: &mut Bencher) {
64+
let host = HOST.read().unwrap();
65+
66+
b.iter(|| {
67+
let _ = host.search_for_id("no_std");
68+
});
69+
}
70+
71+
#[bench]
72+
fn search(b: &mut Bencher) {
73+
let host = HOST.read().unwrap();
74+
b.iter(|| {
75+
let _ = host.search("some_inexistent_symbol");
76+
77+
})
78+
}
79+
80+
#[bench]
81+
fn symbols(b: &mut Bencher) {
82+
let host = HOST.read().unwrap();
83+
b.iter(|| {
84+
let _ = host.symbols(&STDLIB_FILE_PATH);
85+
})
86+
}
87+
88+
#[bench]
89+
fn reload(b: &mut Bencher) {
90+
let host = HOST.write().unwrap();
91+
b.iter(|| {
92+
host.reload(&STDLIB_DATA_PATH, &STDLIB_DATA_PATH).unwrap();
93+
})
94+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
extern crate rls_analysis;
2+
extern crate env_logger;
3+
4+
use rls_analysis::{AnalysisHost, AnalysisLoader, SearchDirectory};
5+
use std::path::{Path, PathBuf};
6+
use std::env;
7+
8+
#[derive(Clone)]
9+
pub struct Loader {
10+
deps_dir: PathBuf,
11+
}
12+
13+
impl Loader {
14+
pub fn new(deps_dir: PathBuf) -> Self {
15+
Self { deps_dir }
16+
}
17+
}
18+
19+
impl AnalysisLoader for Loader {
20+
fn needs_hard_reload(&self, _: &Path) -> bool {
21+
true
22+
}
23+
24+
fn fresh_host(&self) -> AnalysisHost<Self> {
25+
AnalysisHost::new_with_loader(self.clone())
26+
}
27+
28+
fn set_path_prefix(&mut self, _: &Path) {}
29+
30+
fn abs_path_prefix(&self) -> Option<PathBuf> {
31+
None
32+
}
33+
fn search_directories(&self) -> Vec<SearchDirectory> {
34+
vec![SearchDirectory {
35+
path: self.deps_dir.clone(),
36+
prefix_rewrite: None,
37+
}]
38+
}
39+
}
40+
41+
fn main() {
42+
env_logger::init();
43+
if env::args().len() < 2 {
44+
println!("Usage: print-crate-id <save-analysis-dir>");
45+
std::process::exit(1);
46+
}
47+
let loader = Loader::new(PathBuf::from(env::args().nth(1).unwrap()));
48+
let crates = rls_analysis::read_analysis_from_files(&loader, Default::default(), &[]);
49+
50+
for krate in &crates {
51+
println!("Crate {:?} data version {:?}", krate.id, krate.analysis.version);
52+
}
53+
}

0 commit comments

Comments
 (0)