diff options
Diffstat (limited to 'crates/ra_assists/src/assist_ctx.rs')
-rw-r--r-- | crates/ra_assists/src/assist_ctx.rs | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/crates/ra_assists/src/assist_ctx.rs b/crates/ra_assists/src/assist_ctx.rs index 2ab65ab99..f32072dbd 100644 --- a/crates/ra_assists/src/assist_ctx.rs +++ b/crates/ra_assists/src/assist_ctx.rs | |||
@@ -1,8 +1,9 @@ | |||
1 | //! This module defines `AssistCtx` -- the API surface that is exposed to assists. | 1 | //! This module defines `AssistCtx` -- the API surface that is exposed to assists. |
2 | use either::Either; | 2 | use either::Either; |
3 | use hir::{db::HirDatabase, InFile, SourceAnalyzer, SourceBinder}; | 3 | use hir::{InFile, SourceAnalyzer, SourceBinder}; |
4 | use ra_db::FileRange; | 4 | use ra_db::{FileRange, SourceDatabase}; |
5 | use ra_fmt::{leading_indent, reindent}; | 5 | use ra_fmt::{leading_indent, reindent}; |
6 | use ra_ide_db::RootDatabase; | ||
6 | use ra_syntax::{ | 7 | use ra_syntax::{ |
7 | algo::{self, find_covering_element, find_node_at_offset}, | 8 | algo::{self, find_covering_element, find_node_at_offset}, |
8 | AstNode, SourceFile, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextUnit, | 9 | AstNode, SourceFile, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextUnit, |
@@ -49,14 +50,14 @@ pub(crate) enum Assist { | |||
49 | /// moment, because the LSP API is pretty awkward in this place, and it's much | 50 | /// moment, because the LSP API is pretty awkward in this place, and it's much |
50 | /// easier to just compute the edit eagerly :-) | 51 | /// easier to just compute the edit eagerly :-) |
51 | #[derive(Debug)] | 52 | #[derive(Debug)] |
52 | pub(crate) struct AssistCtx<'a, DB> { | 53 | pub(crate) struct AssistCtx<'a> { |
53 | pub(crate) db: &'a DB, | 54 | pub(crate) db: &'a RootDatabase, |
54 | pub(crate) frange: FileRange, | 55 | pub(crate) frange: FileRange, |
55 | source_file: SourceFile, | 56 | source_file: SourceFile, |
56 | should_compute_edit: bool, | 57 | should_compute_edit: bool, |
57 | } | 58 | } |
58 | 59 | ||
59 | impl<'a, DB> Clone for AssistCtx<'a, DB> { | 60 | impl<'a> Clone for AssistCtx<'a> { |
60 | fn clone(&self) -> Self { | 61 | fn clone(&self) -> Self { |
61 | AssistCtx { | 62 | AssistCtx { |
62 | db: self.db, | 63 | db: self.db, |
@@ -67,17 +68,24 @@ impl<'a, DB> Clone for AssistCtx<'a, DB> { | |||
67 | } | 68 | } |
68 | } | 69 | } |
69 | 70 | ||
70 | impl<'a, DB: HirDatabase> AssistCtx<'a, DB> { | 71 | impl<'a> AssistCtx<'a> { |
71 | pub(crate) fn with_ctx<F, T>(db: &DB, frange: FileRange, should_compute_edit: bool, f: F) -> T | 72 | pub(crate) fn with_ctx<F, T>( |
73 | db: &RootDatabase, | ||
74 | frange: FileRange, | ||
75 | should_compute_edit: bool, | ||
76 | f: F, | ||
77 | ) -> T | ||
72 | where | 78 | where |
73 | F: FnOnce(AssistCtx<DB>) -> T, | 79 | F: FnOnce(AssistCtx) -> T, |
74 | { | 80 | { |
75 | let parse = db.parse(frange.file_id); | 81 | let parse = db.parse(frange.file_id); |
76 | 82 | ||
77 | let ctx = AssistCtx { db, frange, source_file: parse.tree(), should_compute_edit }; | 83 | let ctx = AssistCtx { db, frange, source_file: parse.tree(), should_compute_edit }; |
78 | f(ctx) | 84 | f(ctx) |
79 | } | 85 | } |
86 | } | ||
80 | 87 | ||
88 | impl<'a> AssistCtx<'a> { | ||
81 | pub(crate) fn add_assist( | 89 | pub(crate) fn add_assist( |
82 | self, | 90 | self, |
83 | id: AssistId, | 91 | id: AssistId, |
@@ -141,7 +149,7 @@ impl<'a, DB: HirDatabase> AssistCtx<'a, DB> { | |||
141 | pub(crate) fn covering_element(&self) -> SyntaxElement { | 149 | pub(crate) fn covering_element(&self) -> SyntaxElement { |
142 | find_covering_element(self.source_file.syntax(), self.frange.range) | 150 | find_covering_element(self.source_file.syntax(), self.frange.range) |
143 | } | 151 | } |
144 | pub(crate) fn source_binder(&self) -> SourceBinder<'a, DB> { | 152 | pub(crate) fn source_binder(&self) -> SourceBinder<'a, RootDatabase> { |
145 | SourceBinder::new(self.db) | 153 | SourceBinder::new(self.db) |
146 | } | 154 | } |
147 | pub(crate) fn source_analyzer( | 155 | pub(crate) fn source_analyzer( |