Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion crates/ra_ide/src/completion/complete_keyword.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! FIXME: write short doc here

use ra_syntax::ast;
use ra_syntax::{ast, SyntaxKind};

use crate::completion::{
CompletionContext, CompletionItem, CompletionItemKind, CompletionKind, Completions,
Expand Down Expand Up @@ -37,6 +37,10 @@ pub(super) fn complete_use_tree_keyword(acc: &mut Completions, ctx: &CompletionC
}

pub(super) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionContext) {
if ctx.token.kind() == SyntaxKind::COMMENT {
return;
}

let has_trait_or_impl_parent = ctx.has_impl_parent || ctx.has_trait_parent;
if ctx.trait_as_prev_sibling || ctx.impl_as_prev_sibling {
add_keyword(ctx, acc, "where", "where ");
Expand Down
50 changes: 50 additions & 0 deletions crates/ra_ide/src/completion/presentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1516,4 +1516,54 @@ mod tests {
"###
);
}

#[test]
fn no_keyword_autocompletion_on_line_comments() {
assert_debug_snapshot!(
do_completion(
r"
fn test() {
let x = 2; // A comment<|>
}
",
CompletionKind::Keyword
),
@r###"
[]
"###
);
}

#[test]
fn no_keyword_autocompletion_on_multi_line_comments() {
assert_debug_snapshot!(
do_completion(
r"
/*
Some multi-line comment<|>
*/
",
CompletionKind::Keyword
),
@r###"
[]
"###
);
}

#[test]
fn no_keyword_autocompletion_on_doc_comments() {
assert_debug_snapshot!(
do_completion(
r"
/// Some doc comment
/// let test<|> = 1
",
CompletionKind::Keyword
),
@r###"
[]
"###
);
}
}