mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
Merge #8848
8848: Attach comments to ast::Impl r=Veykril a=Veykril bors r+ Fixes #8847 Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
92abc56bc9
@ -19,14 +19,10 @@ use syntax::{
|
||||
pub(crate) fn matching_brace(file: &SourceFile, offset: TextSize) -> Option<TextSize> {
|
||||
const BRACES: &[SyntaxKind] =
|
||||
&[T!['{'], T!['}'], T!['['], T![']'], T!['('], T![')'], T![<], T![>], T![|], T![|]];
|
||||
let (brace_token, brace_idx) = file
|
||||
.syntax()
|
||||
.token_at_offset(offset)
|
||||
.filter_map(|node| {
|
||||
let idx = BRACES.iter().position(|&brace| brace == node.kind())?;
|
||||
Some((node, idx))
|
||||
})
|
||||
.next()?;
|
||||
let (brace_token, brace_idx) = file.syntax().token_at_offset(offset).find_map(|node| {
|
||||
let idx = BRACES.iter().position(|&brace| brace == node.kind())?;
|
||||
Some((node, idx))
|
||||
})?;
|
||||
let parent = brace_token.parent()?;
|
||||
if brace_token.kind() == T![|] && !ast::ParamList::can_cast(parent.kind()) {
|
||||
cov_mark::hit!(pipes_not_braces);
|
||||
|
@ -1,6 +1,8 @@
|
||||
use hir::Semantics;
|
||||
use ide_db::base_db::{CrateId, FileId, FilePosition};
|
||||
use ide_db::RootDatabase;
|
||||
use ide_db::{
|
||||
base_db::{CrateId, FileId, FilePosition},
|
||||
RootDatabase,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
use syntax::{
|
||||
algo::find_node_at_offset,
|
||||
|
@ -37,13 +37,25 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
||||
|
||||
.unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
|
||||
</style>
|
||||
<pre><code><span class="comment documentation">/// ```</span>
|
||||
<pre><code><span class="comment documentation">//! This is a module to test doc injection.</span>
|
||||
<span class="comment documentation">//! ```</span>
|
||||
<span class="comment documentation">//! </span><span class="keyword injected">fn</span><span class="none injected"> </span><span class="function declaration injected">test</span><span class="parenthesis injected">(</span><span class="parenthesis injected">)</span><span class="none injected"> </span><span class="brace injected">{</span><span class="brace injected">}</span>
|
||||
<span class="comment documentation">//! ```</span>
|
||||
|
||||
<span class="comment documentation">/// ```</span>
|
||||
<span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="none injected"> </span><span class="punctuation injected">_</span><span class="none injected"> </span><span class="operator injected">=</span><span class="none injected"> </span><span class="string_literal injected">"early doctests should not go boom"</span><span class="semicolon injected">;</span>
|
||||
<span class="comment documentation">/// ```</span>
|
||||
<span class="keyword">struct</span> <span class="struct declaration">Foo</span> <span class="brace">{</span>
|
||||
<span class="field declaration">bar</span><span class="colon">:</span> <span class="builtin_type">bool</span><span class="comma">,</span>
|
||||
<span class="brace">}</span>
|
||||
|
||||
<span class="comment documentation">/// This is an impl with a code block.</span>
|
||||
<span class="comment documentation">///</span>
|
||||
<span class="comment documentation">/// ```</span>
|
||||
<span class="comment documentation">/// </span><span class="keyword injected">fn</span><span class="none injected"> </span><span class="function declaration injected">foo</span><span class="parenthesis injected">(</span><span class="parenthesis injected">)</span><span class="none injected"> </span><span class="brace injected">{</span>
|
||||
<span class="comment documentation">///</span>
|
||||
<span class="comment documentation">/// </span><span class="brace injected">}</span>
|
||||
<span class="comment documentation">/// ```</span>
|
||||
<span class="keyword">impl</span> <span class="struct">Foo</span> <span class="brace">{</span>
|
||||
<span class="comment documentation">/// ```</span>
|
||||
<span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="none injected"> </span><span class="punctuation injected">_</span><span class="none injected"> </span><span class="operator injected">=</span><span class="none injected"> </span><span class="string_literal injected">"Call me</span>
|
||||
|
@ -524,6 +524,11 @@ fn main() {
|
||||
fn test_highlight_doc_comment() {
|
||||
check_highlighting(
|
||||
r#"
|
||||
//! This is a module to test doc injection.
|
||||
//! ```
|
||||
//! fn test() {}
|
||||
//! ```
|
||||
|
||||
/// ```
|
||||
/// let _ = "early doctests should not go boom";
|
||||
/// ```
|
||||
@ -531,6 +536,13 @@ struct Foo {
|
||||
bar: bool,
|
||||
}
|
||||
|
||||
/// This is an impl with a code block.
|
||||
///
|
||||
/// ```
|
||||
/// fn foo() {
|
||||
///
|
||||
/// }
|
||||
/// ```
|
||||
impl Foo {
|
||||
/// ```
|
||||
/// let _ = "Call me
|
||||
|
@ -147,8 +147,8 @@ fn n_attached_trivias<'a>(
|
||||
trivias: impl Iterator<Item = (SyntaxKind, &'a str)>,
|
||||
) -> usize {
|
||||
match kind {
|
||||
MACRO_CALL | MACRO_RULES | MACRO_DEF | CONST | TYPE_ALIAS | STRUCT | UNION | ENUM
|
||||
| VARIANT | FN | TRAIT | MODULE | RECORD_FIELD | STATIC | USE => {
|
||||
CONST | ENUM | FN | IMPL | MACRO_CALL | MACRO_DEF | MACRO_RULES | MODULE | RECORD_FIELD
|
||||
| STATIC | STRUCT | TRAIT | TUPLE_FIELD | TYPE_ALIAS | UNION | USE | VARIANT => {
|
||||
let mut res = 0;
|
||||
let mut trivias = trivias.enumerate().peekable();
|
||||
|
||||
|
@ -127,9 +127,9 @@ SOURCE_FILE@0..764
|
||||
WHITESPACE@537..538 "\n"
|
||||
R_CURLY@538..539 "}"
|
||||
WHITESPACE@539..541 "\n\n"
|
||||
COMMENT@541..601 "// https://github.com ..."
|
||||
WHITESPACE@601..602 "\n"
|
||||
IMPL@602..763
|
||||
IMPL@541..763
|
||||
COMMENT@541..601 "// https://github.com ..."
|
||||
WHITESPACE@601..602 "\n"
|
||||
IMPL_KW@602..606 "impl"
|
||||
WHITESPACE@606..607 " "
|
||||
PATH_TYPE@607..615
|
||||
|
Loading…
Reference in New Issue
Block a user