diff options
Diffstat (limited to 'crates/libanalysis/src/api.rs')
-rw-r--r-- | crates/libanalysis/src/api.rs | 142 |
1 files changed, 0 insertions, 142 deletions
diff --git a/crates/libanalysis/src/api.rs b/crates/libanalysis/src/api.rs deleted file mode 100644 index ded88cd15..000000000 --- a/crates/libanalysis/src/api.rs +++ /dev/null | |||
@@ -1,142 +0,0 @@ | |||
1 | use relative_path::{RelativePath, RelativePathBuf}; | ||
2 | use libsyntax2::{File, TextRange, TextUnit, AtomEdit}; | ||
3 | use libeditor; | ||
4 | use {imp::{AnalysisImpl, AnalysisHostImpl}, Query}; | ||
5 | |||
6 | pub use libeditor::{ | ||
7 | LocalEdit, StructureNode, LineIndex, FileSymbol, | ||
8 | Runnable, RunnableKind, HighlightedRange, CompletionItem | ||
9 | }; | ||
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 | |||
50 | #[derive(Clone, Debug)] | ||
51 | pub struct Analysis { | ||
52 | pub(crate) imp: AnalysisImpl | ||
53 | } | ||
54 | |||
55 | impl Analysis { | ||
56 | pub fn file_syntax(&self, file_id: FileId) -> File { | ||
57 | self.imp.file_syntax(file_id) | ||
58 | } | ||
59 | pub fn file_line_index(&self, file_id: FileId) -> LineIndex { | ||
60 | self.imp.file_line_index(file_id) | ||
61 | } | ||
62 | pub fn extend_selection(&self, file: &File, range: TextRange) -> TextRange { | ||
63 | libeditor::extend_selection(file, range).unwrap_or(range) | ||
64 | } | ||
65 | pub fn matching_brace(&self, file: &File, offset: TextUnit) -> Option<TextUnit> { | ||
66 | libeditor::matching_brace(file, offset) | ||
67 | } | ||
68 | pub fn syntax_tree(&self, file_id: FileId) -> String { | ||
69 | let file = self.file_syntax(file_id); | ||
70 | libeditor::syntax_tree(&file) | ||
71 | } | ||
72 | pub fn join_lines(&self, file_id: FileId, range: TextRange) -> SourceChange { | ||
73 | let file = self.file_syntax(file_id); | ||
74 | SourceChange::from_local_edit(file_id, "join lines", libeditor::join_lines(&file, range)) | ||
75 | } | ||
76 | pub fn on_eq_typed(&self, file_id: FileId, offset: TextUnit) -> Option<SourceChange> { | ||
77 | let file = self.file_syntax(file_id); | ||
78 | Some(SourceChange::from_local_edit(file_id, "add semicolon", libeditor::on_eq_typed(&file, offset)?)) | ||
79 | } | ||
80 | pub fn file_structure(&self, file_id: FileId) -> Vec<StructureNode> { | ||
81 | let file = self.file_syntax(file_id); | ||
82 | libeditor::file_structure(&file) | ||
83 | } | ||
84 | pub fn symbol_search(&self, query: Query) -> Vec<(FileId, FileSymbol)> { | ||
85 | self.imp.world_symbols(query) | ||
86 | } | ||
87 | pub fn approximately_resolve_symbol(&self, file_id: FileId, offset: TextUnit) -> Vec<(FileId, FileSymbol)> { | ||
88 | self.imp.approximately_resolve_symbol(file_id, offset) | ||
89 | } | ||
90 | pub fn parent_module(&self, file_id: FileId) -> Vec<(FileId, FileSymbol)> { | ||
91 | self.imp.parent_module(file_id) | ||
92 | } | ||
93 | pub fn runnables(&self, file_id: FileId) -> Vec<Runnable> { | ||
94 | let file = self.file_syntax(file_id); | ||
95 | libeditor::runnables(&file) | ||
96 | } | ||
97 | pub fn highlight(&self, file_id: FileId) -> Vec<HighlightedRange> { | ||
98 | let file = self.file_syntax(file_id); | ||
99 | libeditor::highlight(&file) | ||
100 | } | ||
101 | pub fn completions(&self, file_id: FileId, offset: TextUnit) -> Option<Vec<CompletionItem>> { | ||
102 | let file = self.file_syntax(file_id); | ||
103 | libeditor::scope_completion(&file, offset) | ||
104 | } | ||
105 | pub fn assists(&self, file_id: FileId, offset: TextUnit) -> Vec<SourceChange> { | ||
106 | self.imp.assists(file_id, offset) | ||
107 | } | ||
108 | pub fn diagnostics(&self, file_id: FileId) -> Vec<Diagnostic> { | ||
109 | self.imp.diagnostics(file_id) | ||
110 | } | ||
111 | } | ||
112 | |||
113 | pub trait FileResolver: Send + Sync + 'static { | ||
114 | fn file_stem(&self, id: FileId) -> String; | ||
115 | fn resolve(&self, id: FileId, path: &RelativePath) -> Option<FileId>; | ||
116 | } | ||
117 | |||
118 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
119 | pub struct FileId(pub u32); | ||
120 | |||
121 | #[derive(Debug)] | ||
122 | pub struct AnalysisHost { | ||
123 | pub(crate) imp: AnalysisHostImpl | ||
124 | } | ||
125 | |||
126 | impl AnalysisHost { | ||
127 | pub fn new() -> AnalysisHost { | ||
128 | AnalysisHost { imp: AnalysisHostImpl::new() } | ||
129 | } | ||
130 | |||
131 | pub fn analysis(&self, file_resolver: impl FileResolver) -> Analysis { | ||
132 | Analysis { imp: self.imp.analysis(file_resolver) } | ||
133 | } | ||
134 | |||
135 | pub fn change_file(&mut self, file_id: FileId, text: Option<String>) { | ||
136 | self.change_files(::std::iter::once((file_id, text))); | ||
137 | } | ||
138 | |||
139 | pub fn change_files(&mut self, changes: impl Iterator<Item=(FileId, Option<String>)>) { | ||
140 | self.imp.change_files(changes) | ||
141 | } | ||
142 | } | ||