diff options
author | Aleksey Kladov <[email protected]> | 2018-08-29 16:07:56 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-29 16:07:56 +0100 |
commit | 1baba9a2e29b72b0d61b86605f9e63f4ca57799c (patch) | |
tree | 33539019b2948466a45aa910130e9e05f79b6855 /crates/libanalysis/src | |
parent | 2e2c2e62eb6fccddae6bcc2ae22b83f209d05d0c (diff) |
Minor
Diffstat (limited to 'crates/libanalysis/src')
-rw-r--r-- | crates/libanalysis/src/api.rs | 88 |
1 files changed, 41 insertions, 47 deletions
diff --git a/crates/libanalysis/src/api.rs b/crates/libanalysis/src/api.rs index bb4fee398..2872d01e9 100644 --- a/crates/libanalysis/src/api.rs +++ b/crates/libanalysis/src/api.rs | |||
@@ -8,6 +8,45 @@ pub use libeditor::{ | |||
8 | Runnable, RunnableKind, HighlightedRange, CompletionItem | 8 | Runnable, RunnableKind, HighlightedRange, CompletionItem |
9 | }; | 9 | }; |
10 | 10 | ||
11 | #[derive(Debug)] | ||
12 | pub struct SourceChange { | ||
13 | pub label: String, | ||
14 | pub source_file_edits: Vec<SourceFileEdit>, | ||
15 | pub file_system_edits: Vec<FileSystemEdit>, | ||
16 | pub cursor_position: Option<Position>, | ||
17 | } | ||
18 | |||
19 | #[derive(Debug)] | ||
20 | pub struct Position { | ||
21 | pub file_id: FileId, | ||
22 | pub offset: TextUnit, | ||
23 | } | ||
24 | |||
25 | #[derive(Debug)] | ||
26 | pub struct SourceFileEdit { | ||
27 | pub file_id: FileId, | ||
28 | pub edits: Vec<AtomEdit>, | ||
29 | } | ||
30 | |||
31 | #[derive(Debug)] | ||
32 | pub enum FileSystemEdit { | ||
33 | CreateFile { | ||
34 | anchor: FileId, | ||
35 | path: RelativePathBuf, | ||
36 | }, | ||
37 | MoveFile { | ||
38 | file: FileId, | ||
39 | path: RelativePathBuf, | ||
40 | } | ||
41 | } | ||
42 | |||
43 | #[derive(Debug)] | ||
44 | pub struct Diagnostic { | ||
45 | pub message: String, | ||
46 | pub range: TextRange, | ||
47 | pub fix: Option<SourceChange>, | ||
48 | } | ||
49 | |||
11 | #[derive(Clone, Debug)] | 50 | #[derive(Clone, Debug)] |
12 | pub struct Analysis { | 51 | pub struct Analysis { |
13 | pub(crate) imp: World | 52 | pub(crate) imp: World |
@@ -34,17 +73,11 @@ impl Analysis { | |||
34 | } | 73 | } |
35 | pub fn join_lines(&self, file_id: FileId, range: TextRange) -> SourceChange { | 74 | pub fn join_lines(&self, file_id: FileId, range: TextRange) -> SourceChange { |
36 | let file = self.file_syntax(file_id); | 75 | let file = self.file_syntax(file_id); |
37 | SourceChange::from_local_edit( | 76 | SourceChange::from_local_edit(file_id, "join lines", libeditor::join_lines(&file, range)) |
38 | file_id, "join lines", | ||
39 | libeditor::join_lines(&file, range), | ||
40 | ) | ||
41 | } | 77 | } |
42 | pub fn on_eq_typed(&self, file_id: FileId, offset: TextUnit) -> Option<SourceChange> { | 78 | pub fn on_eq_typed(&self, file_id: FileId, offset: TextUnit) -> Option<SourceChange> { |
43 | let file = self.file_syntax(file_id); | 79 | let file = self.file_syntax(file_id); |
44 | Some(SourceChange::from_local_edit( | 80 | Some(SourceChange::from_local_edit(file_id, "add semicolon", libeditor::on_eq_typed(&file, offset)?)) |
45 | file_id, "add semicolon", | ||
46 | libeditor::on_eq_typed(&file, offset)?, | ||
47 | )) | ||
48 | } | 81 | } |
49 | pub fn file_structure(&self, file_id: FileId) -> Vec<StructureNode> { | 82 | pub fn file_structure(&self, file_id: FileId) -> Vec<StructureNode> { |
50 | let file = self.file_syntax(file_id); | 83 | let file = self.file_syntax(file_id); |
@@ -80,45 +113,6 @@ impl Analysis { | |||
80 | } | 113 | } |
81 | } | 114 | } |
82 | 115 | ||
83 | #[derive(Debug)] | ||
84 | pub struct SourceChange { | ||
85 | pub label: String, | ||
86 | pub source_file_edits: Vec<SourceFileEdit>, | ||
87 | pub file_system_edits: Vec<FileSystemEdit>, | ||
88 | pub cursor_position: Option<Position>, | ||
89 | } | ||
90 | |||
91 | #[derive(Debug)] | ||
92 | pub struct Position { | ||
93 | pub file_id: FileId, | ||
94 | pub offset: TextUnit, | ||
95 | } | ||
96 | |||
97 | #[derive(Debug)] | ||
98 | pub struct SourceFileEdit { | ||
99 | pub file_id: FileId, | ||
100 | pub edits: Vec<AtomEdit>, | ||
101 | } | ||
102 | |||
103 | #[derive(Debug)] | ||
104 | pub enum FileSystemEdit { | ||
105 | CreateFile { | ||
106 | anchor: FileId, | ||
107 | path: RelativePathBuf, | ||
108 | }, | ||
109 | MoveFile { | ||
110 | file: FileId, | ||
111 | path: RelativePathBuf, | ||
112 | } | ||
113 | } | ||
114 | |||
115 | #[derive(Debug)] | ||
116 | pub struct Diagnostic { | ||
117 | pub message: String, | ||
118 | pub range: TextRange, | ||
119 | pub fix: Option<SourceChange>, | ||
120 | } | ||
121 | |||
122 | impl SourceChange { | 116 | impl SourceChange { |
123 | pub(crate) fn from_local_edit(file_id: FileId, label: &str, edit: LocalEdit) -> SourceChange { | 117 | pub(crate) fn from_local_edit(file_id: FileId, label: &str, edit: LocalEdit) -> SourceChange { |
124 | let file_edit = SourceFileEdit { | 118 | let file_edit = SourceFileEdit { |