Skip to content

Commit 41c0d96

Browse files
authored
Merge pull request #20112 from Veykril/push-ruszuxrqzmvz
Workaround missing none group support in builtin macros
2 parents 6dd8cfe + ba7bdc9 commit 41c0d96

File tree

4 files changed

+22
-40
lines changed

4 files changed

+22
-40
lines changed

src/tools/rust-analyzer/crates/hir-expand/src/builtin/fn_macro.rs

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use intern::{
77
Symbol,
88
sym::{self},
99
};
10+
use itertools::Itertools;
1011
use mbe::{DelimiterKind, expect_fragment};
1112
use span::{Edition, FileId, Span};
1213
use stdx::format_to;
@@ -681,11 +682,19 @@ fn relative_file(
681682
}
682683

683684
fn parse_string(tt: &tt::TopSubtree) -> Result<(Symbol, Span), ExpandError> {
684-
let delimiter = tt.top_subtree().delimiter;
685-
tt.iter()
686-
.next()
687-
.ok_or(delimiter.open.cover(delimiter.close))
688-
.and_then(|tt| match tt {
685+
let mut tt = TtElement::Subtree(tt.top_subtree(), tt.iter());
686+
(|| {
687+
// FIXME: We wrap expression fragments in parentheses which can break this expectation
688+
// here
689+
// Remove this once we handle none delims correctly
690+
while let TtElement::Subtree(sub, tt_iter) = &mut tt
691+
&& let DelimiterKind::Parenthesis | DelimiterKind::Invisible = sub.delimiter.kind
692+
{
693+
tt =
694+
tt_iter.exactly_one().map_err(|_| sub.delimiter.open.cover(sub.delimiter.close))?;
695+
}
696+
697+
match tt {
689698
TtElement::Leaf(tt::Leaf::Literal(tt::Literal {
690699
symbol: text,
691700
span,
@@ -698,35 +707,11 @@ fn parse_string(tt: &tt::TopSubtree) -> Result<(Symbol, Span), ExpandError> {
698707
kind: tt::LitKind::StrRaw(_),
699708
suffix: _,
700709
})) => Ok((text.clone(), *span)),
701-
// FIXME: We wrap expression fragments in parentheses which can break this expectation
702-
// here
703-
// Remove this once we handle none delims correctly
704-
TtElement::Subtree(tt, mut tt_iter)
705-
if tt.delimiter.kind == DelimiterKind::Parenthesis =>
706-
{
707-
tt_iter
708-
.next()
709-
.and_then(|tt| match tt {
710-
TtElement::Leaf(tt::Leaf::Literal(tt::Literal {
711-
symbol: text,
712-
span,
713-
kind: tt::LitKind::Str,
714-
suffix: _,
715-
})) => Some((unescape_symbol(text), *span)),
716-
TtElement::Leaf(tt::Leaf::Literal(tt::Literal {
717-
symbol: text,
718-
span,
719-
kind: tt::LitKind::StrRaw(_),
720-
suffix: _,
721-
})) => Some((text.clone(), *span)),
722-
_ => None,
723-
})
724-
.ok_or(delimiter.open.cover(delimiter.close))
725-
}
726710
TtElement::Leaf(l) => Err(*l.span()),
727711
TtElement::Subtree(tt, _) => Err(tt.delimiter.open.cover(tt.delimiter.close)),
728-
})
729-
.map_err(|span| ExpandError::other(span, "expected string literal"))
712+
}
713+
})()
714+
.map_err(|span| ExpandError::other(span, "expected string literal"))
730715
}
731716

732717
fn include_expand(

src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,7 +1526,7 @@ impl Config {
15261526
CompletionConfig {
15271527
enable_postfix_completions: self.completion_postfix_enable(source_root).to_owned(),
15281528
enable_imports_on_the_fly: self.completion_autoimport_enable(source_root).to_owned()
1529-
&& self.caps.completion_item_edit_resolve(),
1529+
&& self.caps.has_completion_item_resolve_additionalTextEdits(),
15301530
enable_self_on_the_fly: self.completion_autoself_enable(source_root).to_owned(),
15311531
enable_auto_iter: *self.completion_autoIter_enable(source_root),
15321532
enable_auto_await: *self.completion_autoAwait_enable(source_root),
@@ -2355,10 +2355,6 @@ impl Config {
23552355
.and_then(|it| it.version.as_ref())
23562356
}
23572357

2358-
pub fn client_is_helix(&self) -> bool {
2359-
self.client_info.as_ref().map(|it| it.name == "helix").unwrap_or_default()
2360-
}
2361-
23622358
pub fn client_is_neovim(&self) -> bool {
23632359
self.client_info.as_ref().map(|it| it.name == "Neovim").unwrap_or_default()
23642360
}

src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/capabilities.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub fn server_capabilities(config: &Config) -> ServerCapabilities {
4242
hover_provider: Some(HoverProviderCapability::Simple(true)),
4343
completion_provider: Some(CompletionOptions {
4444
resolve_provider: if config.client_is_neovim() {
45-
config.completion_item_edit_resolve().then_some(true)
45+
config.has_completion_item_resolve_additionalTextEdits().then_some(true)
4646
} else {
4747
Some(config.caps().completions_resolve_provider())
4848
},
@@ -207,8 +207,8 @@ impl ClientCapabilities {
207207
serde_json::from_value(self.0.experimental.as_ref()?.get(index)?.clone()).ok()
208208
}
209209

210-
/// Parses client capabilities and returns all completion resolve capabilities rust-analyzer supports.
211-
pub fn completion_item_edit_resolve(&self) -> bool {
210+
#[allow(non_snake_case)]
211+
pub fn has_completion_item_resolve_additionalTextEdits(&self) -> bool {
212212
(|| {
213213
Some(
214214
self.0

src/tools/rust-analyzer/crates/tt/src/iter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ impl<'a, S: Copy> TtIter<'a, S> {
211211
}
212212
}
213213

214+
#[derive(Clone)]
214215
pub enum TtElement<'a, S> {
215216
Leaf(&'a Leaf<S>),
216217
Subtree(&'a Subtree<S>, TtIter<'a, S>),

0 commit comments

Comments
 (0)