forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#14433 - hecatia-elegua:alias-based-completion…
…, r=Veykril Add doc-alias based completion Closes rust-lang#14406. I adapted the parsing code from the CfgExpr parsing code, maybe there's a better abstraction for both, or attribute parsing in general. It also includes `doc(hidden)`-parsing, which means it could replace the other function. There are a few tests for parsing. `process_all_names` changed the most, I added some docs there to explain what happens. Many call sites just pass an empy vec to `add_path_resolution`'s `doc_aliases`, since either it doesn't make sense to pass anything (e.g. visibility completion) or I don't know where to get them from. Shouldn't really matter, as it will just not show aliases if the vec is empty and we can extend alias completion in these cases later. I added two tests in `special.rs` for struct name completion (which was the main thing I wanted). I also tried function and field names, but these don't work yet. I want to add those in a follow-up PR.
- Loading branch information
Showing
17 changed files
with
334 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//! This module contains tests for doc-expression parsing. | ||
//! Currently, it tests `#[doc(hidden)]` and `#[doc(alias)]`. | ||
|
||
use mbe::syntax_node_to_token_tree; | ||
use syntax::{ast, AstNode}; | ||
|
||
use crate::attr::{DocAtom, DocExpr}; | ||
|
||
fn assert_parse_result(input: &str, expected: DocExpr) { | ||
let (tt, _) = { | ||
let source_file = ast::SourceFile::parse(input).ok().unwrap(); | ||
let tt = source_file.syntax().descendants().find_map(ast::TokenTree::cast).unwrap(); | ||
syntax_node_to_token_tree(tt.syntax()) | ||
}; | ||
let cfg = DocExpr::parse(&tt); | ||
assert_eq!(cfg, expected); | ||
} | ||
|
||
#[test] | ||
fn test_doc_expr_parser() { | ||
assert_parse_result("#![doc(hidden)]", DocAtom::Flag("hidden".into()).into()); | ||
|
||
assert_parse_result( | ||
r#"#![doc(alias = "foo")]"#, | ||
DocAtom::KeyValue { key: "alias".into(), value: "foo".into() }.into(), | ||
); | ||
|
||
assert_parse_result(r#"#![doc(alias("foo"))]"#, DocExpr::Alias(["foo".into()].into())); | ||
assert_parse_result( | ||
r#"#![doc(alias("foo", "bar", "baz"))]"#, | ||
DocExpr::Alias(["foo".into(), "bar".into(), "baz".into()].into()), | ||
); | ||
|
||
assert_parse_result( | ||
r#" | ||
#[doc(alias("Bar", "Qux"))] | ||
struct Foo;"#, | ||
DocExpr::Alias(["Bar".into(), "Qux".into()].into()), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.