@@ -14,7 +14,7 @@ use proc_macro::{
14
14
} ;
15
15
16
16
mod token_stream;
17
- pub ( crate ) use token_stream:: TokenStream ;
17
+ pub use token_stream:: TokenStream ;
18
18
use token_stream:: TokenStreamBuilder ;
19
19
20
20
mod symbol;
@@ -40,9 +40,9 @@ pub struct SourceFile {
40
40
41
41
pub struct FreeFunctions ;
42
42
43
- #[ derive( Default ) ]
44
43
pub struct RustAnalyzer {
45
44
// FIXME: store span information here.
45
+ pub ( crate ) interner : SymbolInternerRef ,
46
46
}
47
47
48
48
impl server:: Types for RustAnalyzer {
@@ -67,7 +67,7 @@ impl server::FreeFunctions for RustAnalyzer {
67
67
// FIXME: keep track of LitKind and Suffix
68
68
Ok ( bridge:: Literal {
69
69
kind : bridge:: LitKind :: Err ,
70
- symbol : Symbol :: intern ( s) ,
70
+ symbol : Symbol :: intern ( self . interner , s) ,
71
71
suffix : None ,
72
72
span : tt:: TokenId :: unspecified ( ) ,
73
73
} )
@@ -108,7 +108,7 @@ impl server::TokenStream for RustAnalyzer {
108
108
}
109
109
110
110
bridge:: TokenTree :: Ident ( ident) => {
111
- let text = ident. sym . text ( ) ;
111
+ let text = ident. sym . text ( self . interner ) ;
112
112
let text =
113
113
if ident. is_raw { :: tt:: SmolStr :: from_iter ( [ "r#" , & text] ) } else { text } ;
114
114
let ident: tt:: Ident = tt:: Ident { text, span : ident. span } ;
@@ -119,8 +119,9 @@ impl server::TokenStream for RustAnalyzer {
119
119
120
120
bridge:: TokenTree :: Literal ( literal) => {
121
121
let literal = LiteralFormatter ( literal) ;
122
- let text = literal
123
- . with_stringify_parts ( |parts| :: tt:: SmolStr :: from_iter ( parts. iter ( ) . copied ( ) ) ) ;
122
+ let text = literal. with_stringify_parts ( self . interner , |parts| {
123
+ :: tt:: SmolStr :: from_iter ( parts. iter ( ) . copied ( ) )
124
+ } ) ;
124
125
125
126
let literal = tt:: Literal { text, span : literal. 0 . span } ;
126
127
let leaf = tt:: Leaf :: from ( literal) ;
@@ -184,7 +185,7 @@ impl server::TokenStream for RustAnalyzer {
184
185
. map ( |tree| match tree {
185
186
tt:: TokenTree :: Leaf ( tt:: Leaf :: Ident ( ident) ) => {
186
187
bridge:: TokenTree :: Ident ( bridge:: Ident {
187
- sym : Symbol :: intern ( ident. text . trim_start_matches ( "r#" ) ) ,
188
+ sym : Symbol :: intern ( self . interner , ident. text . trim_start_matches ( "r#" ) ) ,
188
189
is_raw : ident. text . starts_with ( "r#" ) ,
189
190
span : ident. span ,
190
191
} )
@@ -193,7 +194,7 @@ impl server::TokenStream for RustAnalyzer {
193
194
bridge:: TokenTree :: Literal ( bridge:: Literal {
194
195
// FIXME: handle literal kinds
195
196
kind : bridge:: LitKind :: Err ,
196
- symbol : Symbol :: intern ( & lit. text ) ,
197
+ symbol : Symbol :: intern ( self . interner , & lit. text ) ,
197
198
// FIXME: handle suffixes
198
199
suffix : None ,
199
200
span : lit. span ,
@@ -351,11 +352,13 @@ impl server::Server for RustAnalyzer {
351
352
}
352
353
353
354
fn intern_symbol ( ident : & str ) -> Self :: Symbol {
354
- Symbol :: intern ( & :: tt:: SmolStr :: from ( ident) )
355
+ // FIXME: should be self.interner once the proc-macro api allows is
356
+ Symbol :: intern ( & SYMBOL_INTERNER , & :: tt:: SmolStr :: from ( ident) )
355
357
}
356
358
357
359
fn with_symbol_string ( symbol : & Self :: Symbol , f : impl FnOnce ( & str ) ) {
358
- f ( symbol. text ( ) . as_str ( ) )
360
+ // FIXME: should be self.interner once the proc-macro api allows is
361
+ f ( symbol. text ( & SYMBOL_INTERNER ) . as_str ( ) )
359
362
}
360
363
}
361
364
@@ -366,7 +369,11 @@ impl LiteralFormatter {
366
369
/// literal's representation. This is done to allow the `ToString` and
367
370
/// `Display` implementations to borrow references to symbol values, and
368
371
/// both be optimized to reduce overhead.
369
- fn with_stringify_parts < R > ( & self , f : impl FnOnce ( & [ & str ] ) -> R ) -> R {
372
+ fn with_stringify_parts < R > (
373
+ & self ,
374
+ interner : SymbolInternerRef ,
375
+ f : impl FnOnce ( & [ & str ] ) -> R ,
376
+ ) -> R {
370
377
/// Returns a string containing exactly `num` '#' characters.
371
378
/// Uses a 256-character source string literal which is always safe to
372
379
/// index with a `u8` index.
@@ -381,7 +388,7 @@ impl LiteralFormatter {
381
388
& HASHES [ ..num as usize ]
382
389
}
383
390
384
- self . with_symbol_and_suffix ( |symbol, suffix| match self . 0 . kind {
391
+ self . with_symbol_and_suffix ( interner , |symbol, suffix| match self . 0 . kind {
385
392
bridge:: LitKind :: Byte => f ( & [ "b'" , symbol, "'" , suffix] ) ,
386
393
bridge:: LitKind :: Char => f ( & [ "'" , symbol, "'" , suffix] ) ,
387
394
bridge:: LitKind :: Str => f ( & [ "\" " , symbol, "\" " , suffix] ) ,
@@ -398,9 +405,13 @@ impl LiteralFormatter {
398
405
} )
399
406
}
400
407
401
- fn with_symbol_and_suffix < R > ( & self , f : impl FnOnce ( & str , & str ) -> R ) -> R {
402
- let symbol = self . 0 . symbol . text ( ) ;
403
- let suffix = self . 0 . suffix . map ( |s| s. text ( ) ) . unwrap_or_default ( ) ;
408
+ fn with_symbol_and_suffix < R > (
409
+ & self ,
410
+ interner : SymbolInternerRef ,
411
+ f : impl FnOnce ( & str , & str ) -> R ,
412
+ ) -> R {
413
+ let symbol = self . 0 . symbol . text ( interner) ;
414
+ let suffix = self . 0 . suffix . map ( |s| s. text ( interner) ) . unwrap_or_default ( ) ;
404
415
f ( symbol. as_str ( ) , suffix. as_str ( ) )
405
416
}
406
417
}
0 commit comments