-
Notifications
You must be signed in to change notification settings - Fork 256
Support visualization of scopes, borrows and moves #387
Changes from all commits
e92b10b
a01276b
fe723de
34a9774
15d1c5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -435,6 +435,35 @@ impl ActionHandler { | |
} | ||
} | ||
|
||
pub fn borrow_info<O: Output>(&self, id: usize, params: TextDocumentPositionParams, out: O) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you prefer another name? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. name seems fine |
||
let t = thread::current(); | ||
let span = self.convert_pos_to_span(¶ms.text_document, params.position); | ||
|
||
trace!("borrow_info: {:?}", span); | ||
|
||
let analysis = self.analysis.clone(); | ||
let rustw_handle = thread::spawn(move || { | ||
let bi = analysis.borrow_info(&span); | ||
t.unpark(); | ||
bi.map(|b| b.into()) | ||
}); | ||
|
||
thread::park_timeout(Duration::from_millis(::COMPILER_TIMEOUT)); | ||
|
||
let result = rustw_handle.join(); | ||
match result { | ||
Ok(Ok(r)) => { | ||
out.success(id, ResponseData::BorrowInfo(r)); | ||
}, | ||
Ok(Err(e)) => { | ||
out.failure(id, &format!("BorrowInfo not available for that location: {:?}", e)[..]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm betting this is not the way to handle a "nothing to see here" type of message. How should I fix this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably be able to return something morally equivalent to |
||
} | ||
Err(_) => { | ||
out.failure(id, "BorrowInfo failed to complete successfully"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Other code wasn't logging errors. Should we start to do that? Is there a file we can write to in case writing to stderr interferes with the IDEs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should I output the object in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've been trying to output the error in the |
||
} | ||
} | ||
} | ||
|
||
pub fn execute_command<O: Output>(&self, id: usize, params: ExecuteCommandParams, out: O) { | ||
match &*params.command { | ||
"rls.applySuggestion" => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
use lsp_data::Range; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the language server types crate seemed to only be for types that are part of the spec, this seemed to be the best place for these structs. Are there any concerns with this setup? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not clear what the difference between these types and the rls-data types is? Ideally we'd just use one set of types. If that is not possible, then this setup seems fine. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I remember correctly it's the serialization derives. One is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We ought to be able to derive both if we need to (I think we have feature gates for that, or maybe that is span and we could add them for data) |
||
use lsp_data::ls_util::rls_to_range; | ||
use std::convert::From; | ||
use analysis; | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct BorrowData { | ||
pub scopes: Vec<Scope>, | ||
pub loans: Vec<Loan>, | ||
pub moves: Vec<Move>, | ||
} | ||
|
||
impl From<analysis::BorrowData> for BorrowData { | ||
fn from(borrows: analysis::BorrowData) -> BorrowData { | ||
BorrowData { | ||
scopes: borrows.scopes.into_iter().map(|a| a.into()).collect(), | ||
moves: borrows.moves.into_iter().map(|m| m.into()).collect(), | ||
loans: borrows.loans.into_iter().map(|l| l.into()).collect(), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub enum BorrowKind { | ||
ImmBorrow, | ||
MutBorrow, | ||
} | ||
|
||
impl From<analysis::BorrowKind> for BorrowKind { | ||
fn from(kind: analysis::BorrowKind) -> BorrowKind { | ||
match kind { | ||
analysis::BorrowKind::ImmBorrow => BorrowKind::ImmBorrow, | ||
analysis::BorrowKind::MutBorrow => BorrowKind::MutBorrow, | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct Loan { | ||
pub kind: BorrowKind, | ||
pub range: Range, | ||
} | ||
|
||
impl From<analysis::Loan> for Loan { | ||
fn from(loan: analysis::Loan) -> Loan { | ||
Loan { | ||
kind: loan.kind.into(), | ||
range: rls_to_range(loan.span.range), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct Move { | ||
pub range: Range, | ||
} | ||
|
||
impl From<analysis::Move> for Move { | ||
fn from(mov: analysis::Move) -> Move { | ||
Move { | ||
range: rls_to_range(mov.span.range), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct Scope { | ||
pub range: Range, | ||
} | ||
|
||
impl From<analysis::Scope> for Scope { | ||
fn from(scope: analysis::Scope) -> Scope { | ||
Scope { | ||
range: rls_to_range(scope.span.range), | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,7 @@ mod cmd; | |
mod config; | ||
mod lsp_data; | ||
mod server; | ||
mod custom_types; | ||
|
||
#[cfg(test)] | ||
mod test; | ||
|
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.
Pending dependency updates mentioned in top-level comment.