Skip to content

feat: Add doc-alias based completion #14433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 5, 2023

Conversation

hecatia-elegua
Copy link
Contributor

@hecatia-elegua hecatia-elegua commented Mar 29, 2023

Closes #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.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 29, 2023
@hecatia-elegua
Copy link
Contributor Author

hecatia-elegua commented Mar 29, 2023

btw. does CI not abort after a newer commit got pushed in?
Also, shouldn't cargo test check that there are no errors possible on CI? I mean, tidy helped, but now it's still red with errors I haven't seen lol

@Veykril
Copy link
Member

Veykril commented Mar 29, 2023

CI runs with unreachable-pub which is a lint that is allowed by default in Rust (there is no nice way for us to deny it project wide atm I think)

@hecatia-elegua
Copy link
Contributor Author

hecatia-elegua commented Mar 29, 2023

It looks like the other render_ functions would profit from having a call to some common function with ctx, before item.build() gets called. Maybe just pre_build or post_render or render_common (I like that one). But I will have to think about that more, as of course this could expand indefinitely.

Comment on lines 241 to 247
pub fn doc_exprs(&self) -> Vec<DocExpr> {
self.by_key("doc").tt_values().map(DocExpr::parse).collect()
}

pub fn doc_aliases(&self) -> Vec<SmolStr> {
self.doc_exprs().into_iter().flat_map(|doc_expr| doc_expr.aliases()).collect()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn doc_exprs(&self) -> Vec<DocExpr> {
self.by_key("doc").tt_values().map(DocExpr::parse).collect()
}
pub fn doc_aliases(&self) -> Vec<SmolStr> {
self.doc_exprs().into_iter().flat_map(|doc_expr| doc_expr.aliases()).collect()
}
pub fn doc_exprs(&self) -> impl Iterator<Item = DocExpr> {
self.by_key("doc").tt_values().map(DocExpr::parse)
}
pub fn doc_aliases(&self) -> impl Iterator<Item = SmolStr>{
self.doc_exprs().flat_map(|doc_expr| doc_expr.aliases())
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, since aliases now returns &[SmolStr], how do I make this compile?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

impl Iterator<Item = &SmolStr> should work

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
nope, aliases().to_vec() works but copies

Comment on lines 429 to 430
} else if let Some(doc_aliases) = self.doc_aliases {
label = SmolStr::from(format!("{label} (alias {doc_aliases})"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is something we should do differently. I think we should split the completions according to their aliases up, that is for each alias we copy the item but change the label and lookup to thing (alias <the alias>) + the final one without its alias. This should be done in to_proto.rs similar to how we handle the CompletionItem::ref_match field.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll comprehend this later today, but I played around some more with the code and setting lookup here works better.
If you mean there should be one CompletionItem per alias, that sounds worse than just having e.g. Label (alias A, B, C).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well if setting lookup with multiple aliases somehow works out then sure, but I feel like it won't. Do try it out thought since it would simplify things 👍

@hecatia-elegua
Copy link
Contributor Author

We can further discuss about the new changes. I can get the iterators further outside, right? tbh I should study iterators some more

@Veykril
Copy link
Member

Veykril commented Apr 5, 2023

@bors r+

I fear this might not work in at least VSCode yet because of one quirk it has in regards to the text edit having to start with what source_range points to, but we'll see whether that is the case or not. If we do run into this we'll have to make use of additional text edits somehow.

@bors
Copy link
Contributor

bors commented Apr 5, 2023

📌 Commit 170822b has been approved by Veykril

It is now in the queue for this repository.

@Veykril Veykril changed the title Add doc-alias based completion feat: Add doc-alias based completion Apr 5, 2023
@bors
Copy link
Contributor

bors commented Apr 5, 2023

⌛ Testing commit 170822b with merge 265f830...

@bors
Copy link
Contributor

bors commented Apr 5, 2023

☀️ Test successful - checks-actions
Approved by: Veykril
Pushing 265f830 to master...

@bors bors merged commit 265f830 into rust-lang:master Apr 5, 2023
bors added a commit that referenced this pull request Apr 24, 2023
doc(alias)-based completion round 2

Follow-up on #14433
We can now complete fields, functions and some use/mods.
Flyimports don't behave, I don't really have the time to understand the structure there either.
While reading the flyimport code, I removed one method only used there, the closure-tree was a bit confusing, I can revert that if you want.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support doc(alias)-based completion
4 participants