Skip to content

Commit a07c821

Browse files
bors[bot]cynecxVeykril
authored
Merge #9047 #9048
9047: fix: proc_macro_srv: temporary abi fix (rust-lang/rust#84717) r=lnicola a=lnicola bors r+ 9048: Add some lint completion tests r=Veykril a=Veykril bors r+ Co-authored-by: cynecx <[email protected]> Co-authored-by: Lukas Wirth <[email protected]>
3 parents 8cd98bd + 6fed8cc + c9598a4 commit a07c821

File tree

6 files changed

+101
-30
lines changed

6 files changed

+101
-30
lines changed

crates/ide_completion/src/completions/attribute.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
//! This module uses a bit of static metadata to provide completions
44
//! for built-in attributes.
55
6-
use std::mem;
7-
86
use once_cell::sync::Lazy;
97
use rustc_hash::{FxHashMap, FxHashSet};
108
use syntax::{ast, AstNode, NodeOrToken, SyntaxKind, T};
@@ -272,27 +270,27 @@ const ATTRIBUTES: &[AttrCompletion] = &[
272270
fn parse_comma_sep_input(derive_input: ast::TokenTree) -> Option<FxHashSet<String>> {
273271
let (l_paren, r_paren) = derive_input.l_paren_token().zip(derive_input.r_paren_token())?;
274272
let mut input_derives = FxHashSet::default();
275-
let mut current_derive = String::new();
276-
for token in derive_input
273+
let mut tokens = derive_input
277274
.syntax()
278275
.children_with_tokens()
279276
.filter_map(NodeOrToken::into_token)
280277
.skip_while(|token| token != &l_paren)
281278
.skip(1)
282279
.take_while(|token| token != &r_paren)
283-
{
284-
if token.kind() == T![,] {
285-
if !current_derive.is_empty() {
286-
input_derives.insert(mem::take(&mut current_derive));
287-
}
288-
} else {
289-
current_derive.push_str(token.text().trim());
280+
.peekable();
281+
let mut input = String::new();
282+
while tokens.peek().is_some() {
283+
for token in tokens.by_ref().take_while(|t| t.kind() != T![,]) {
284+
input.push_str(token.text());
290285
}
291-
}
292286

293-
if !current_derive.is_empty() {
294-
input_derives.insert(current_derive);
287+
if !input.is_empty() {
288+
input_derives.insert(input.trim().to_owned());
289+
}
290+
291+
input.clear();
295292
}
293+
296294
Some(input_derives)
297295
}
298296

crates/ide_completion/src/completions/attribute/derive.rs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub(super) fn complete_derive(
4545
}
4646
}
4747
}
48+
4849
fn get_derive_names_in_scope(ctx: &CompletionContext) -> FxHashSet<String> {
4950
let mut result = FxHashSet::default();
5051
ctx.scope.process_all_names(&mut |name, scope_def| {
@@ -89,12 +90,14 @@ mod tests {
8990
}
9091

9192
#[test]
92-
fn empty_derive_completion() {
93+
fn no_completion_for_incorrect_derive() {
94+
check(r#"#[derive{$0)] struct Test;"#, expect![[]])
95+
}
96+
97+
#[test]
98+
fn empty_derive() {
9399
check(
94-
r#"
95-
#[derive($0)]
96-
struct Test {}
97-
"#,
100+
r#"#[derive($0)] struct Test;"#,
98101
expect![[r#"
99102
at Clone
100103
at Clone, Copy
@@ -110,23 +113,26 @@ struct Test {}
110113
}
111114

112115
#[test]
113-
fn no_completion_for_incorrect_derive() {
116+
fn derive_with_input() {
114117
check(
115-
r#"
116-
#[derive{$0)]
117-
struct Test {}
118-
"#,
119-
expect![[r#""#]],
118+
r#"#[derive(serde::Serialize, PartialEq, $0)] struct Test;"#,
119+
expect![[r#"
120+
at Clone
121+
at Clone, Copy
122+
at Debug
123+
at Default
124+
at Hash
125+
at Eq
126+
at PartialOrd
127+
at Eq, PartialOrd, Ord
128+
"#]],
120129
)
121130
}
122131

123132
#[test]
124-
fn derive_with_input_completion() {
133+
fn derive_with_input2() {
125134
check(
126-
r#"
127-
#[derive(serde::Serialize, PartialEq, $0)]
128-
struct Test {}
129-
"#,
135+
r#"#[derive($0 serde::Serialize, PartialEq)] struct Test;"#,
130136
expect![[r#"
131137
at Clone
132138
at Clone, Copy

crates/ide_completion/src/completions/attribute/lint.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,36 @@ pub(super) const DEFAULT_LINT_COMPLETIONS: &[LintCompletion] = &[
152152
LintCompletion { label: "unconditional_panic", description: r#"operation will cause a panic at runtime"# },
153153
LintCompletion { label: "unknown_crate_types", description: r#"unknown crate type found in `#[crate_type]` directive"# },
154154
];
155+
156+
#[cfg(test)]
157+
mod tests {
158+
159+
use crate::test_utils::check_edit;
160+
161+
#[test]
162+
fn check_empty() {
163+
check_edit(
164+
"deprecated",
165+
r#"#[allow($0)] struct Test;"#,
166+
r#"#[allow(deprecated)] struct Test;"#,
167+
)
168+
}
169+
170+
#[test]
171+
fn check_with_existing() {
172+
check_edit(
173+
"deprecated",
174+
r#"#[allow(keyword_idents, $0)] struct Test;"#,
175+
r#"#[allow(keyword_idents, deprecated)] struct Test;"#,
176+
)
177+
}
178+
179+
#[test]
180+
fn check_qualified() {
181+
check_edit(
182+
"deprecated",
183+
r#"#[allow(keyword_idents, $0)] struct Test;"#,
184+
r#"#[allow(keyword_idents, deprecated)] struct Test;"#,
185+
)
186+
}
187+
}

crates/proc_macro_srv/src/proc_macro/bridge/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ macro_rules! with_api {
112112
Literal {
113113
fn drop($self: $S::Literal);
114114
fn clone($self: &$S::Literal) -> $S::Literal;
115+
fn from_str(s: &str) -> Result<$S::Literal, ()>;
115116
fn debug_kind($self: &$S::Literal) -> String;
116117
fn symbol($self: &$S::Literal) -> String;
117118
fn suffix($self: &$S::Literal) -> Option<String>;
@@ -318,6 +319,19 @@ impl<T: Unmark> Unmark for Option<T> {
318319
}
319320
}
320321

322+
impl<T: Mark, E: Mark> Mark for Result<T, E> {
323+
type Unmarked = Result<T::Unmarked, E::Unmarked>;
324+
fn mark(unmarked: Self::Unmarked) -> Self {
325+
unmarked.map(T::mark).map_err(E::mark)
326+
}
327+
}
328+
impl<T: Unmark, E: Unmark> Unmark for Result<T, E> {
329+
type Unmarked = Result<T::Unmarked, E::Unmarked>;
330+
fn unmark(self) -> Self::Unmarked {
331+
self.map(T::unmark).map_err(E::unmark)
332+
}
333+
}
334+
321335
macro_rules! mark_noop {
322336
($($ty:ty),* $(,)?) => {
323337
$(

crates/proc_macro_srv/src/proc_macro/mod.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ pub struct LexError {
3737
_inner: (),
3838
}
3939

40+
impl LexError {
41+
fn new() -> Self {
42+
LexError { _inner: () }
43+
}
44+
}
45+
4046
impl TokenStream {
4147
/// Returns an empty `TokenStream` containing no token trees.
4248
pub fn new() -> TokenStream {
@@ -925,6 +931,17 @@ impl fmt::Debug for Literal {
925931
}
926932
}
927933

934+
impl FromStr for Literal {
935+
type Err = LexError;
936+
937+
fn from_str(src: &str) -> Result<Self, LexError> {
938+
match bridge::client::Literal::from_str(src) {
939+
Ok(literal) => Ok(Literal(literal)),
940+
Err(()) => Err(LexError::new()),
941+
}
942+
}
943+
}
944+
928945
pub mod tracked_env {
929946
use std::env::{self, VarError};
930947
use std::ffi::OsStr;

crates/proc_macro_srv/src/rustc_server.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,9 @@ impl server::Ident for Rustc {
521521
}
522522

523523
impl server::Literal for Rustc {
524+
fn from_str(&mut self, _s: &str) -> Result<Self::Literal, ()> {
525+
unimplemented!()
526+
}
524527
fn debug_kind(&mut self, _literal: &Self::Literal) -> String {
525528
// r-a: debug_kind and suffix are unsupported; corresponding client code has been changed to not call these.
526529
// They must still be present to be ABI-compatible and work with upstream proc_macro.

0 commit comments

Comments
 (0)