Skip to content

textDocument/hover returns both type name and doc_text #414

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 2 commits into from
Jan 5, 2019

Conversation

h-michael
Copy link
Contributor

implement #389

@DJMcNab
Copy link
Contributor

DJMcNab commented Jan 3, 2019

I think this should go in FileSymbol::description, so you get for example

```rust
let x: u32
```

A let binding

for

/// A let binding
let x = 10u32;

@matklad
Copy link
Member

matklad commented Jan 3, 2019

Not sure about description: this works for expressions like 92, and we probably shouldn't create symbols for local variables.

@@ -525,6 +525,18 @@ pub fn handle_hover(
contents: HoverContents::Scalar(MarkedString::String(result.join("\n\n---\n"))),
range: Some(range),
}));
} else {
let file_id = params.text_document.try_conv_with(&world)?;
Copy link
Member

Choose a reason for hiding this comment

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

Note that we have world.analysis().approximately_resolve_symbol(position)? above, which means that if we fail to resove symbol (if, for example, the cursor is on something which is not an identifier, like +), we return None.

I suggest refactoring impl into two functions: get_doc() -> Option<String> and get_type() -> Option<String> and call then from the main handler, so as to avoid accidental ? problelms

@DJMcNab
Copy link
Contributor

DJMcNab commented Jan 3, 2019

Oh I see. Sorry. I still think we should expose type_of for namerefs too, but this is still a strict upgrade.

@h-michael
Copy link
Contributor Author

Oh, I see. Sorry I'll fix it.

file_id,
range: rr.reference_range,
};
if let Some(type_name) = world.analysis().type_of(file_range)? {
Copy link
Member

Choose a reason for hiding this comment

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

Now we have an opposite problem: if we fail to retrive the type, we won't even try retrieving the docs. These two bits really have to be extracted into two helper functions to be called from handle_hover.

@h-michael h-michael changed the title Return type name when doc_text_for returns nothing textDocument/hover returns both type name and doc_text Jan 5, 2019
@h-michael
Copy link
Contributor Author

fixed

@@ -750,3 +759,17 @@ fn to_diagnostic_severity(severity: Severity) -> DiagnosticSeverity {
WeakWarning => DiagnosticSeverity::Hint,
}
}

fn get_type(world: &ServerWorld, file_range: FileRange) -> Option<String> {
match world.analysis().type_of(file_range) {
Copy link
Contributor

@DJMcNab DJMcNab Jan 5, 2019

Choose a reason for hiding this comment

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

Why do you throw away the Cancelled here?

Edit: This function could also be world.analysis().type_of(file_range).ok()?

@matklad
Copy link
Member

matklad commented Jan 5, 2019

I think this still can be tweaked a little bit, but, as I am refactoring surround code, I am going to merge as is!

bors r+

Thanks!

bors bot added a commit that referenced this pull request Jan 5, 2019
414: textDocument/hover returns both type name and doc_text r=matklad a=h-michael

implement #389

Co-authored-by: Hirokazu Hata <h.hata.ai.t@gmail.com>
@bors
Copy link
Contributor

bors bot commented Jan 5, 2019

Build succeeded

@bors bors bot merged commit 341eb4a into rust-lang:master Jan 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants