@@ -3,8 +3,8 @@ use ra_db::{FileId, FileRange};
3
3
use ra_ide:: {
4
4
translate_offset_with_edit, Assist , CompletionItem , CompletionItemKind , Documentation ,
5
5
FileSystemEdit , Fold , FoldKind , FunctionSignature , Highlight , HighlightModifier , HighlightTag ,
6
- InlayHint , InlayKind , InsertTextFormat , LineIndex , NavigationTarget , ReferenceAccess , Severity ,
7
- SourceChange , SourceFileEdit ,
6
+ HighlightedRange , InlayHint , InlayKind , InsertTextFormat , LineIndex , NavigationTarget ,
7
+ ReferenceAccess , Severity , SourceChange , SourceFileEdit ,
8
8
} ;
9
9
use ra_syntax:: { SyntaxKind , TextRange , TextSize } ;
10
10
use ra_text_edit:: { Indel , TextEdit } ;
@@ -227,8 +227,30 @@ pub(crate) fn inlay_int(line_index: &LineIndex, inlay_hint: InlayHint) -> req::I
227
227
}
228
228
}
229
229
230
- // TODO: this is wrong
231
- pub ( crate ) fn token_type_index_modifiers_bitself ( highlight : Highlight ) -> ( u32 , u32 ) {
230
+ pub ( crate ) fn semantic_tokens (
231
+ text : & str ,
232
+ line_index : & LineIndex ,
233
+ highlights : Vec < HighlightedRange > ,
234
+ ) -> lsp_types:: SemanticTokens {
235
+ let mut builder = semantic_tokens:: SemanticTokensBuilder :: default ( ) ;
236
+
237
+ for highlight_range in highlights {
238
+ let ( token_index, modifier_bitset) =
239
+ token_type_index_modifiers_bitself ( highlight_range. highlight ) ;
240
+ for mut text_range in line_index. lines ( highlight_range. range ) {
241
+ if text[ text_range] . ends_with ( '\n' ) {
242
+ text_range =
243
+ TextRange :: new ( text_range. start ( ) , text_range. end ( ) - TextSize :: of ( '\n' ) ) ;
244
+ }
245
+ let range = range ( & line_index, text_range) ;
246
+ builder. push ( range, token_index, modifier_bitset) ;
247
+ }
248
+ }
249
+
250
+ builder. build ( )
251
+ }
252
+
253
+ fn token_type_index_modifiers_bitself ( highlight : Highlight ) -> ( u32 , u32 ) {
232
254
let mut mods = semantic_tokens:: ModifierSet :: default ( ) ;
233
255
let type_ = match highlight. tag {
234
256
HighlightTag :: Struct => lsp_types:: SemanticTokenType :: STRUCT ,
0 commit comments