-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Conversation
I think this should go in ```rust
let x: u32
```
A let binding for /// A let binding
let x = 10u32; |
Not sure about description: this works for expressions like |
@@ -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)?; |
There was a problem hiding this comment.
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
Oh I see. Sorry. I still think we should expose |
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)? { |
There was a problem hiding this comment.
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
.
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) { |
There was a problem hiding this comment.
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()?
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! |
Build succeeded |
implement #389