aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis/src/lib.rs')
-rw-r--r--crates/ra_analysis/src/lib.rs60
1 files changed, 25 insertions, 35 deletions
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs
index 4e4c65f08..0ea9ebee7 100644
--- a/crates/ra_analysis/src/lib.rs
+++ b/crates/ra_analysis/src/lib.rs
@@ -119,18 +119,18 @@ impl AnalysisHost {
119 } 119 }
120} 120}
121 121
122#[derive(Clone, Copy, Debug)]
123pub struct FilePosition {
124 pub file_id: FileId,
125 pub offset: TextUnit,
126}
127
122#[derive(Debug)] 128#[derive(Debug)]
123pub struct SourceChange { 129pub struct SourceChange {
124 pub label: String, 130 pub label: String,
125 pub source_file_edits: Vec<SourceFileEdit>, 131 pub source_file_edits: Vec<SourceFileEdit>,
126 pub file_system_edits: Vec<FileSystemEdit>, 132 pub file_system_edits: Vec<FileSystemEdit>,
127 pub cursor_position: Option<Position>, 133 pub cursor_position: Option<FilePosition>,
128}
129
130#[derive(Debug)]
131pub struct Position {
132 pub file_id: FileId,
133 pub offset: TextUnit,
134} 134}
135 135
136#[derive(Debug)] 136#[derive(Debug)]
@@ -224,18 +224,18 @@ impl Analysis {
224 let file = self.imp.file_syntax(file_id); 224 let file = self.imp.file_syntax(file_id);
225 SourceChange::from_local_edit(file_id, "join lines", ra_editor::join_lines(&file, range)) 225 SourceChange::from_local_edit(file_id, "join lines", ra_editor::join_lines(&file, range))
226 } 226 }
227 pub fn on_enter(&self, file_id: FileId, offset: TextUnit) -> Option<SourceChange> { 227 pub fn on_enter(&self, position: FilePosition) -> Option<SourceChange> {
228 let file = self.imp.file_syntax(file_id); 228 let file = self.imp.file_syntax(position.file_id);
229 let edit = ra_editor::on_enter(&file, offset)?; 229 let edit = ra_editor::on_enter(&file, position.offset)?;
230 let res = SourceChange::from_local_edit(file_id, "on enter", edit); 230 let res = SourceChange::from_local_edit(position.file_id, "on enter", edit);
231 Some(res) 231 Some(res)
232 } 232 }
233 pub fn on_eq_typed(&self, file_id: FileId, offset: TextUnit) -> Option<SourceChange> { 233 pub fn on_eq_typed(&self, position: FilePosition) -> Option<SourceChange> {
234 let file = self.imp.file_syntax(file_id); 234 let file = self.imp.file_syntax(position.file_id);
235 Some(SourceChange::from_local_edit( 235 Some(SourceChange::from_local_edit(
236 file_id, 236 position.file_id,
237 "add semicolon", 237 "add semicolon",
238 ra_editor::on_eq_typed(&file, offset)?, 238 ra_editor::on_eq_typed(&file, position.offset)?,
239 )) 239 ))
240 } 240 }
241 pub fn file_structure(&self, file_id: FileId) -> Vec<StructureNode> { 241 pub fn file_structure(&self, file_id: FileId) -> Vec<StructureNode> {
@@ -251,20 +251,15 @@ impl Analysis {
251 } 251 }
252 pub fn approximately_resolve_symbol( 252 pub fn approximately_resolve_symbol(
253 &self, 253 &self,
254 file_id: FileId, 254 position: FilePosition,
255 offset: TextUnit,
256 ) -> Cancelable<Vec<(FileId, FileSymbol)>> { 255 ) -> Cancelable<Vec<(FileId, FileSymbol)>> {
257 self.imp.approximately_resolve_symbol(file_id, offset) 256 self.imp.approximately_resolve_symbol(position)
258 } 257 }
259 pub fn find_all_refs( 258 pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> {
260 &self, 259 Ok(self.imp.find_all_refs(position))
261 file_id: FileId,
262 offset: TextUnit,
263 ) -> Cancelable<Vec<(FileId, TextRange)>> {
264 Ok(self.imp.find_all_refs(file_id, offset))
265 } 260 }
266 pub fn parent_module(&self, file_id: FileId) -> Cancelable<Vec<(FileId, FileSymbol)>> { 261 pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<(FileId, FileSymbol)>> {
267 self.imp.parent_module(file_id) 262 self.imp.parent_module(position)
268 } 263 }
269 pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> { 264 pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> {
270 self.imp.crate_for(file_id) 265 self.imp.crate_for(file_id)
@@ -280,12 +275,8 @@ impl Analysis {
280 let file = self.imp.file_syntax(file_id); 275 let file = self.imp.file_syntax(file_id);
281 Ok(ra_editor::highlight(&file)) 276 Ok(ra_editor::highlight(&file))
282 } 277 }
283 pub fn completions( 278 pub fn completions(&self, position: FilePosition) -> Cancelable<Option<Vec<CompletionItem>>> {
284 &self, 279 self.imp.completions(position)
285 file_id: FileId,
286 offset: TextUnit,
287 ) -> Cancelable<Option<Vec<CompletionItem>>> {
288 self.imp.completions(file_id, offset)
289 } 280 }
290 pub fn assists(&self, file_id: FileId, range: TextRange) -> Cancelable<Vec<SourceChange>> { 281 pub fn assists(&self, file_id: FileId, range: TextRange) -> Cancelable<Vec<SourceChange>> {
291 Ok(self.imp.assists(file_id, range)) 282 Ok(self.imp.assists(file_id, range))
@@ -295,10 +286,9 @@ impl Analysis {
295 } 286 }
296 pub fn resolve_callable( 287 pub fn resolve_callable(
297 &self, 288 &self,
298 file_id: FileId, 289 position: FilePosition,
299 offset: TextUnit,
300 ) -> Cancelable<Option<(FnDescriptor, Option<usize>)>> { 290 ) -> Cancelable<Option<(FnDescriptor, Option<usize>)>> {
301 self.imp.resolve_callable(file_id, offset) 291 self.imp.resolve_callable(position)
302 } 292 }
303} 293}
304 294