Skip to content

Commit 8d9acda

Browse files
committed
(174) Begin file_cache refactor, create file_controller sub-module
1 parent 1d1fd33 commit 8d9acda

File tree

4 files changed

+71
-52
lines changed

4 files changed

+71
-52
lines changed

src/file_cache.rs renamed to src/file_controller/mod.rs

Lines changed: 10 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ use super::highlight;
2121
// FIXME maximum size and evication policy
2222
// FIXME keep timestamps and check on every read. Then don't empty on build.
2323

24+
mod results;
25+
use file_controller::results::{
26+
SearchResult,
27+
DefResult,
28+
FileResult,
29+
LineResult,
30+
FindResult,
31+
SymbolResult
32+
};
33+
2434
pub struct Cache {
2535
files: Vfs<VfsUserData>,
2636
analysis: AnalysisHost,
@@ -29,56 +39,6 @@ pub struct Cache {
2939

3040
type Span = span::Span<span::ZeroIndexed>;
3141

32-
#[derive(Serialize, Debug, Clone)]
33-
pub struct SearchResult {
34-
pub defs: Vec<DefResult>,
35-
}
36-
37-
#[derive(Serialize, Debug, Clone)]
38-
pub struct DefResult {
39-
pub file: String,
40-
pub line: LineResult,
41-
pub refs: Vec<FileResult>,
42-
}
43-
44-
#[derive(Serialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd)]
45-
pub struct FileResult {
46-
pub file_name: String,
47-
pub lines: Vec<LineResult>,
48-
}
49-
50-
#[derive(Serialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd)]
51-
pub struct LineResult {
52-
pub line_start: u32,
53-
pub column_start: u32,
54-
pub column_end: u32,
55-
pub line: String,
56-
}
57-
58-
impl LineResult {
59-
fn new(span: &Span, line: String) -> LineResult {
60-
LineResult {
61-
line_start: span.range.row_start.one_indexed().0,
62-
column_start: span.range.col_start.one_indexed().0,
63-
column_end: span.range.col_end.one_indexed().0,
64-
line: line,
65-
}
66-
}
67-
}
68-
69-
#[derive(Serialize, Debug, Clone)]
70-
pub struct FindResult {
71-
pub results: Vec<FileResult>,
72-
}
73-
74-
#[derive(Serialize, Debug, Clone)]
75-
pub struct SymbolResult {
76-
pub id: String,
77-
pub name: String,
78-
pub file_name: String,
79-
pub line_start: u32,
80-
}
81-
8242
// Our data which we attach to files in the VFS.
8343
struct VfsUserData {
8444
highlighted_lines: Vec<String>,

src/file_controller/results.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright 2016 The Rustw 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+
use super::Span;
10+
11+
#[derive(Serialize, Debug, Clone)]
12+
pub struct SearchResult {
13+
pub defs: Vec<DefResult>,
14+
}
15+
16+
#[derive(Serialize, Debug, Clone)]
17+
pub struct DefResult {
18+
pub file: String,
19+
pub line: LineResult,
20+
pub refs: Vec<FileResult>,
21+
}
22+
23+
#[derive(Serialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd)]
24+
pub struct FileResult {
25+
pub file_name: String,
26+
pub lines: Vec<LineResult>,
27+
}
28+
29+
#[derive(Serialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd)]
30+
pub struct LineResult {
31+
pub line_start: u32,
32+
pub column_start: u32,
33+
pub column_end: u32,
34+
pub line: String,
35+
}
36+
37+
impl LineResult {
38+
pub fn new(span: &Span, line: String) -> LineResult {
39+
LineResult {
40+
line_start: span.range.row_start.one_indexed().0,
41+
column_start: span.range.col_start.one_indexed().0,
42+
column_end: span.range.col_end.one_indexed().0,
43+
line: line,
44+
}
45+
}
46+
}
47+
48+
#[derive(Serialize, Debug, Clone)]
49+
pub struct FindResult {
50+
pub results: Vec<FileResult>,
51+
}
52+
53+
#[derive(Serialize, Debug, Clone)]
54+
pub struct SymbolResult {
55+
pub id: String,
56+
pub name: String,
57+
pub file_name: String,
58+
pub line_start: u32,
59+
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub use build::BuildArgs;
4343

4444
mod build;
4545
pub mod config;
46-
mod file_cache;
46+
mod file_controller;
4747
mod listings;
4848
mod highlight;
4949
mod server;

src/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use analysis;
1010
use build::{self, BuildArgs};
1111
use config::Config;
12-
use file_cache::Cache;
12+
use file_controller::Cache;
1313
use listings::{Listing, DirectoryListing};
1414
use futures;
1515
use futures::Future;

0 commit comments

Comments
 (0)