Re-implement rust string highlighting via tool attribute

This commit is contained in:
Lukas Wirth 2025-01-10 13:49:35 +01:00
parent 897f7e579e
commit bf669dab84
72 changed files with 386 additions and 173 deletions

View file

@ -4,7 +4,7 @@ use either::Either;
use hir::{InFile, Semantics, Type};
use parser::T;
use syntax::{
ast::{self, HasArgList, HasName},
ast::{self, AstChildren, HasArgList, HasAttrs, HasName},
match_ast, AstNode, NodeOrToken, SyntaxToken,
};
@ -37,6 +37,10 @@ impl ActiveParameter {
_ => None,
})
}
pub fn attrs(&self) -> Option<AstChildren<ast::Attr>> {
self.src.as_ref().and_then(|param| Some(param.value.as_ref().right()?.attrs()))
}
}
/// Returns a [`hir::Callable`] this token is a part of and its argument index of said callable.

View file

@ -1330,7 +1330,7 @@ fn check_merge_only_fail(ra_fixture0: &str, ra_fixture1: &str, mb: MergeBehavior
assert_eq!(result.map(|u| u.to_string()), None);
}
fn check_guess(ra_fixture: &str, expected: ImportGranularityGuess) {
fn check_guess(#[rust_analyzer::rust_fixture] ra_fixture: &str, expected: ImportGranularityGuess) {
let syntax = ast::SourceFile::parse(ra_fixture, span::Edition::CURRENT).tree().syntax().clone();
let file = ImportScope::from(syntax).unwrap();
assert_eq!(super::guess_granularity_from_scope(&file), expected);

View file

@ -421,7 +421,7 @@ mod tests {
use super::*;
#[track_caller]
fn check(ra_fixture: &str, expected: &str) {
fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str, expected: &str) {
let (db, file_id, range_or_offset) = RootDatabase::with_range_or_offset(ra_fixture);
let frange = FileRange { file_id, range: range_or_offset.into() };

View file

@ -123,7 +123,9 @@ mod tests {
use crate::RootDatabase;
/// Creates analysis from a multi-file fixture, returns positions marked with $0.
pub(crate) fn position(ra_fixture: &str) -> (RootDatabase, FilePosition) {
pub(crate) fn position(
#[rust_analyzer::rust_fixture] ra_fixture: &str,
) -> (RootDatabase, FilePosition) {
let change_fixture = ChangeFixture::parse(ra_fixture);
let mut database = RootDatabase::default();
database.apply_change(change_fixture.change);
@ -133,7 +135,7 @@ mod tests {
(database, FilePosition { file_id, offset })
}
fn check_trait(ra_fixture: &str, expect: Expect) {
fn check_trait(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) {
let (db, position) = position(ra_fixture);
let sema = Semantics::new(&db);
let file = sema.parse(position.file_id);
@ -147,7 +149,7 @@ mod tests {
expect.assert_eq(&actual);
}
fn check_missing_assoc(ra_fixture: &str, expect: Expect) {
fn check_missing_assoc(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) {
let (db, position) = position(ra_fixture);
let sema = Semantics::new(&db);
let file = sema.parse(position.file_id);