11//! This module defines `AssistCtx` -- the API surface that is exposed to assists.
22use either:: Either ;
3- use hir:: { db :: HirDatabase , InFile , SourceAnalyzer , SourceBinder } ;
4- use ra_db:: FileRange ;
3+ use hir:: { InFile , SourceAnalyzer , SourceBinder } ;
4+ use ra_db:: { FileRange , SourceDatabase } ;
55use ra_fmt:: { leading_indent, reindent} ;
6+ use ra_ide_db:: RootDatabase ;
67use ra_syntax:: {
78 algo:: { self , find_covering_element, find_node_at_offset} ,
89 AstNode , SourceFile , SyntaxElement , SyntaxKind , SyntaxNode , SyntaxToken , TextRange , TextUnit ,
@@ -49,14 +50,14 @@ pub(crate) enum Assist {
4950/// moment, because the LSP API is pretty awkward in this place, and it's much
5051/// easier to just compute the edit eagerly :-)
5152#[ derive( Debug ) ]
52- pub ( crate ) struct AssistCtx < ' a , DB > {
53- pub ( crate ) db : & ' a DB ,
53+ pub ( crate ) struct AssistCtx < ' a > {
54+ pub ( crate ) db : & ' a RootDatabase ,
5455 pub ( crate ) frange : FileRange ,
5556 source_file : SourceFile ,
5657 should_compute_edit : bool ,
5758}
5859
59- impl < ' a , DB > Clone for AssistCtx < ' a , DB > {
60+ impl < ' a > Clone for AssistCtx < ' a > {
6061 fn clone ( & self ) -> Self {
6162 AssistCtx {
6263 db : self . db ,
@@ -67,17 +68,24 @@ impl<'a, DB> Clone for AssistCtx<'a, DB> {
6768 }
6869}
6970
70- impl < ' a , DB : HirDatabase > AssistCtx < ' a , DB > {
71- pub ( crate ) fn with_ctx < F , T > ( db : & DB , frange : FileRange , should_compute_edit : bool , f : F ) -> T
71+ impl < ' a > AssistCtx < ' a > {
72+ pub ( crate ) fn with_ctx < F , T > (
73+ db : & RootDatabase ,
74+ frange : FileRange ,
75+ should_compute_edit : bool ,
76+ f : F ,
77+ ) -> T
7278 where
73- F : FnOnce ( AssistCtx < DB > ) -> T ,
79+ F : FnOnce ( AssistCtx ) -> T ,
7480 {
7581 let parse = db. parse ( frange. file_id ) ;
7682
7783 let ctx = AssistCtx { db, frange, source_file : parse. tree ( ) , should_compute_edit } ;
7884 f ( ctx)
7985 }
86+ }
8087
88+ impl < ' a > AssistCtx < ' a > {
8189 pub ( crate ) fn add_assist (
8290 self ,
8391 id : AssistId ,
@@ -141,7 +149,7 @@ impl<'a, DB: HirDatabase> AssistCtx<'a, DB> {
141149 pub ( crate ) fn covering_element ( & self ) -> SyntaxElement {
142150 find_covering_element ( self . source_file . syntax ( ) , self . frange . range )
143151 }
144- pub ( crate ) fn source_binder ( & self ) -> SourceBinder < ' a , DB > {
152+ pub ( crate ) fn source_binder ( & self ) -> SourceBinder < ' a , RootDatabase > {
145153 SourceBinder :: new ( self . db )
146154 }
147155 pub ( crate ) fn source_analyzer (
0 commit comments