Skip to content
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

Allow toggling code lens positions #13218

Closed
Kixiron opened this issue Sep 10, 2022 · 3 comments · Fixed by #13221
Closed

Allow toggling code lens positions #13218

Kixiron opened this issue Sep 10, 2022 · 3 comments · Fixed by #13221
Labels
A-config configuration A-ide general IDE features E-has-instructions Issue has some instructions and pointers to code to get started

Comments

@Kixiron
Copy link
Member

Kixiron commented Sep 10, 2022

Currently code lenses are positioned between doc comments/attributes and the item they're decorating, like this

image

But I personally would rather it be above the doc comments and attributes, so an option to toggle their position would be awesome

@Veykril Veykril added A-ide general IDE features A-config configuration labels Sep 10, 2022
@Veykril
Copy link
Member

Veykril commented Sep 10, 2022

Relevant code is here (minus the config part)

fn name_range<T: HasName>(
db: &RootDatabase,
node: InFile<T>,
source_file_id: FileId,
) -> Option<TextRange> {
if let Some(InFile { file_id, value }) = node.original_ast_node(db) {
if file_id == source_file_id.into() {
return value.name().map(|it| it.syntax().text_range());
}
}
None
}

For this new case we should just take the range of the whole node instead of the name, that should make editors place it above the comments and attributes. This should as stated be done with a config flag toggling the behavior, with the current behavior staying the default.

@Veykril Veykril added the E-has-instructions Issue has some instructions and pointers to code to get started label Sep 10, 2022
@mdx97
Copy link
Contributor

mdx97 commented Sep 11, 2022

I'm working on this one but am running into an issue regarding how to configure this feature.

I figured it would be best to add a new enum configuration value. I've called this lens_annotation_location, which now will have values of above_name and above_whole_item (naming can be hashed out in the PR, just giving this information for context).

I'm not exactly sure where to put the Rust enum definition at, however. I need access to this type in both the ide and rust-analyzer crates. But there are problems with either option:

  • I can't really put the type in rust-analyzer because it depends upon the ide crate, which would result in a circular reference between the two crates.
  • Having a config type exist in the ide crate doesn't seem to be a common pattern of the project. I'd have to add serde as a dependency of ide, which feels weird for this one-off scenario.

Does anyone have opinions?

@Veykril
Copy link
Member

Veykril commented Sep 11, 2022

usually we define the enum twice, once in IDE as the actual used thing, and the second time just for deserializing purposes in the config module in rust-analyzer, and then we map between the two. Thre should be some enum in config.rs doing this already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-config configuration A-ide general IDE features E-has-instructions Issue has some instructions and pointers to code to get started
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants