|
4 | 4 | use lsp_types::{
|
5 | 5 | self, CreateFile, DiagnosticSeverity, DocumentChangeOperation, DocumentChanges, Documentation,
|
6 | 6 | Location, LocationLink, MarkupContent, MarkupKind, Position, Range, RenameFile, ResourceOp,
|
7 |
| - SymbolKind, TextDocumentEdit, TextDocumentIdentifier, TextDocumentItem, |
8 |
| - TextDocumentPositionParams, Url, VersionedTextDocumentIdentifier, WorkspaceEdit, |
| 7 | + SemanticTokenModifier, SemanticTokenType, SemanticTokensLegend, SymbolKind, TextDocumentEdit, |
| 8 | + TextDocumentIdentifier, TextDocumentItem, TextDocumentPositionParams, Url, |
| 9 | + VersionedTextDocumentIdentifier, WorkspaceEdit, |
9 | 10 | };
|
10 | 11 | use ra_ide::{
|
11 |
| - translate_offset_with_edit, CompletionItem, CompletionItemKind, FileId, FilePosition, |
| 12 | + tags, translate_offset_with_edit, CompletionItem, CompletionItemKind, FileId, FilePosition, |
12 | 13 | FileRange, FileSystemEdit, Fold, FoldKind, InsertTextFormat, LineCol, LineIndex,
|
13 | 14 | NavigationTarget, RangeInfo, ReferenceAccess, Severity, SourceChange, SourceFileEdit,
|
14 | 15 | };
|
@@ -302,6 +303,104 @@ impl ConvWith<&FoldConvCtx<'_>> for Fold {
|
302 | 303 | }
|
303 | 304 | }
|
304 | 305 |
|
| 306 | +impl ConvWith<&WorldSnapshot> for &'static str { |
| 307 | + type Output = (SemanticTokenType, Vec<SemanticTokenModifier>); |
| 308 | + |
| 309 | + fn conv_with(self, _world: &WorldSnapshot) -> (SemanticTokenType, Vec<SemanticTokenModifier>) { |
| 310 | + match self { |
| 311 | + tags::FIELD => (SemanticTokenType::MEMBER, vec![]), |
| 312 | + tags::FUNCTION => (SemanticTokenType::FUNCTION, vec![]), |
| 313 | + tags::MODULE => (SemanticTokenType::NAMESPACE, vec![]), |
| 314 | + tags::CONSTANT => ( |
| 315 | + SemanticTokenType::VARIABLE, |
| 316 | + vec![SemanticTokenModifier::STATIC, SemanticTokenModifier::READONLY], |
| 317 | + ), |
| 318 | + tags::MACRO => (SemanticTokenType::MACRO, vec![]), |
| 319 | + |
| 320 | + tags::VARIABLE => (SemanticTokenType::VARIABLE, vec![SemanticTokenModifier::READONLY]), |
| 321 | + tags::VARIABLE_MUT => (SemanticTokenType::VARIABLE, vec![]), |
| 322 | + |
| 323 | + tags::TYPE => (SemanticTokenType::TYPE, vec![]), |
| 324 | + tags::TYPE_BUILTIN => (SemanticTokenType::TYPE, vec![]), |
| 325 | + tags::TYPE_SELF => (SemanticTokenType::TYPE, vec![SemanticTokenModifier::REFERENCE]), |
| 326 | + tags::TYPE_PARAM => (SemanticTokenType::TYPE_PARAMETER, vec![]), |
| 327 | + tags::TYPE_LIFETIME => { |
| 328 | + (SemanticTokenType::LABEL, vec![SemanticTokenModifier::REFERENCE]) |
| 329 | + } |
| 330 | + |
| 331 | + tags::LITERAL_BYTE => (SemanticTokenType::NUMBER, vec![]), |
| 332 | + tags::LITERAL_NUMERIC => (SemanticTokenType::NUMBER, vec![]), |
| 333 | + tags::LITERAL_CHAR => (SemanticTokenType::NUMBER, vec![]), |
| 334 | + |
| 335 | + tags::LITERAL_COMMENT => { |
| 336 | + (SemanticTokenType::COMMENT, vec![SemanticTokenModifier::DOCUMENTATION]) |
| 337 | + } |
| 338 | + tags::LITERAL_STRING => (SemanticTokenType::STRING, vec![]), |
| 339 | + tags::LITERAL_ATTRIBUTE => (SemanticTokenType::KEYWORD, vec![]), |
| 340 | + |
| 341 | + tags::KEYWORD => (SemanticTokenType::KEYWORD, vec![]), |
| 342 | + tags::KEYWORD_UNSAFE => (SemanticTokenType::KEYWORD, vec![]), |
| 343 | + tags::KEYWORD_CONTROL => (SemanticTokenType::KEYWORD, vec![]), |
| 344 | + _ => panic!("Unknown"), |
| 345 | + } |
| 346 | + } |
| 347 | +} |
| 348 | + |
| 349 | +impl ConvWith<&WorldSnapshot> for (SemanticTokenType, Vec<SemanticTokenModifier>) { |
| 350 | + type Output = (u32, u32); |
| 351 | + |
| 352 | + fn conv_with(self, _world: &WorldSnapshot) -> (u32, u32) { |
| 353 | + // Should we be matching against a token legend held in world or maybe this should just be a const somewhere? |
| 354 | + // This is just a HACK and copy of what we return in server caps. |
| 355 | + let legend = SemanticTokensLegend { |
| 356 | + token_types: vec![ |
| 357 | + SemanticTokenType::COMMENT, |
| 358 | + SemanticTokenType::KEYWORD, |
| 359 | + SemanticTokenType::STRING, |
| 360 | + SemanticTokenType::NUMBER, |
| 361 | + SemanticTokenType::REGEXP, |
| 362 | + SemanticTokenType::OPERATOR, |
| 363 | + SemanticTokenType::NAMESPACE, |
| 364 | + SemanticTokenType::TYPE, |
| 365 | + SemanticTokenType::STRUCT, |
| 366 | + SemanticTokenType::CLASS, |
| 367 | + SemanticTokenType::INTERFACE, |
| 368 | + SemanticTokenType::ENUM, |
| 369 | + SemanticTokenType::TYPE_PARAMETER, |
| 370 | + SemanticTokenType::FUNCTION, |
| 371 | + SemanticTokenType::MEMBER, |
| 372 | + SemanticTokenType::PROPERTY, |
| 373 | + SemanticTokenType::MACRO, |
| 374 | + SemanticTokenType::VARIABLE, |
| 375 | + SemanticTokenType::PARAMETER, |
| 376 | + SemanticTokenType::LABEL, |
| 377 | + ], |
| 378 | + token_modifiers: vec![ |
| 379 | + SemanticTokenModifier::DOCUMENTATION, |
| 380 | + SemanticTokenModifier::DECLARATION, |
| 381 | + SemanticTokenModifier::DEFINITION, |
| 382 | + SemanticTokenModifier::REFERENCE, |
| 383 | + SemanticTokenModifier::STATIC, |
| 384 | + SemanticTokenModifier::ABSTRACT, |
| 385 | + SemanticTokenModifier::DEPRECATED, |
| 386 | + SemanticTokenModifier::ASYNC, |
| 387 | + SemanticTokenModifier::VOLATILE, |
| 388 | + SemanticTokenModifier::READONLY, |
| 389 | + ], |
| 390 | + }; |
| 391 | + |
| 392 | + // IndexMap for tokens and modifiers? |
| 393 | + let token_index = legend.token_types.iter().position(|it| *it == self.0).unwrap(); |
| 394 | + let mut token_modifier_bitset = 0; |
| 395 | + for modifier in self.1.iter() { |
| 396 | + token_modifier_bitset |= |
| 397 | + legend.token_modifiers.iter().position(|it| it == modifier).unwrap(); |
| 398 | + } |
| 399 | + |
| 400 | + (token_index as u32, token_modifier_bitset as u32) |
| 401 | + } |
| 402 | +} |
| 403 | + |
305 | 404 | impl<T: ConvWith<CTX>, CTX> ConvWith<CTX> for Option<T> {
|
306 | 405 | type Output = Option<T::Output>;
|
307 | 406 |
|
|
0 commit comments