mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-24 19:12:55 +00:00
Support c string literals
This commit is contained in:
parent
099b5b3b15
commit
4b577e2bc8
21 changed files with 176 additions and 34 deletions
|
@ -39,7 +39,7 @@ fn try_extend_selection(
|
|||
) -> Option<TextRange> {
|
||||
let range = frange.range;
|
||||
|
||||
let string_kinds = [COMMENT, STRING, BYTE_STRING];
|
||||
let string_kinds = [COMMENT, STRING, BYTE_STRING, C_STRING];
|
||||
let list_kinds = [
|
||||
RECORD_PAT_FIELD_LIST,
|
||||
MATCH_ARM_LIST,
|
||||
|
|
|
@ -16,7 +16,10 @@ mod tests;
|
|||
use hir::{Name, Semantics};
|
||||
use ide_db::{FxHashMap, RootDatabase, SymbolKind};
|
||||
use syntax::{
|
||||
ast, AstNode, AstToken, NodeOrToken, SyntaxKind::*, SyntaxNode, TextRange, WalkEvent, T,
|
||||
ast::{self, IsString},
|
||||
AstNode, AstToken, NodeOrToken,
|
||||
SyntaxKind::*,
|
||||
SyntaxNode, TextRange, WalkEvent, T,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
|
@ -440,7 +443,17 @@ fn traverse(
|
|||
&& ast::ByteString::can_cast(descended_token.kind())
|
||||
{
|
||||
if let Some(byte_string) = ast::ByteString::cast(token) {
|
||||
highlight_escape_string(hl, &byte_string, range.start());
|
||||
if !byte_string.is_raw() {
|
||||
highlight_escape_string(hl, &byte_string, range.start());
|
||||
}
|
||||
}
|
||||
} else if ast::CString::can_cast(token.kind())
|
||||
&& ast::CString::can_cast(descended_token.kind())
|
||||
{
|
||||
if let Some(c_string) = ast::CString::cast(token) {
|
||||
if !c_string.is_raw() {
|
||||
highlight_escape_string(hl, &c_string, range.start());
|
||||
}
|
||||
}
|
||||
} else if ast::Char::can_cast(token.kind())
|
||||
&& ast::Char::can_cast(descended_token.kind())
|
||||
|
|
|
@ -26,7 +26,7 @@ pub(super) fn token(sema: &Semantics<'_, RootDatabase>, token: SyntaxToken) -> O
|
|||
}
|
||||
|
||||
let highlight: Highlight = match token.kind() {
|
||||
STRING | BYTE_STRING => HlTag::StringLiteral.into(),
|
||||
STRING | BYTE_STRING | C_STRING => HlTag::StringLiteral.into(),
|
||||
INT_NUMBER if token.parent_ancestors().nth(1).map(|it| it.kind()) == Some(FIELD_EXPR) => {
|
||||
SymbolKind::Field.into()
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
use ide_db::base_db::{FileId, SourceDatabase};
|
||||
use ide_db::RootDatabase;
|
||||
use ide_db::{
|
||||
base_db::{FileId, SourceDatabase},
|
||||
RootDatabase,
|
||||
};
|
||||
use syntax::{
|
||||
AstNode, NodeOrToken, SourceFile, SyntaxKind::STRING, SyntaxToken, TextRange, TextSize,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue