-
Notifications
You must be signed in to change notification settings - Fork 14
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
Index all assigned variables #620
Conversation
Stopgap until we are in a better position to track the scopes of objects in a document. This causes a first definition to be the symbol of reference. Jumping from a reference to a definition then always moves up.
// Super hacky but let's wait until the typed API to do better | ||
if !lhs_text.starts_with("method(") && !lhs.is_identifier_or_string() { | ||
return Ok(None); | ||
} | ||
|
||
let start = convert_point_to_position(contents, lhs.start_position()); | ||
let end = convert_point_to_position(contents, lhs.end_position()); | ||
|
||
Ok(Some(IndexEntry { | ||
key: lhs_text.clone(), | ||
range: Range { start, end }, | ||
data: IndexEntryData::Variable { name: lhs_text }, | ||
})) |
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.
Seems pretty reasonable even with the hackiness for method(
indexer::IndexEntryData::Variable { name } => { | ||
let completion = match completion_item_from_variable(name) { | ||
Ok(item) => item, | ||
Err(err) => { | ||
log::error!("{err:?}"); | ||
return; | ||
}, | ||
}; | ||
completions.push(completion); | ||
}, |
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.
So this ensures that for the workspace we now add variables to the completion list even if they don't exist yet in the R session. For example in a fresh restart of clock we now get these global constants:
I think that's probably fine, even though sending that to the console will result in an error. I guess its still useful when writing in the editor without loading the package?
However, note that after you load the package, the completion shows up with a different symbol:
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.
I think this will all get cleaned up once we build a stronger model of object scopes.
IndexEntryData::Variable { name } => { | ||
info.push(SymbolInformation { | ||
name: name.clone(), | ||
kind: SymbolKind::VARIABLE, | ||
location: Location { | ||
uri: Url::from_file_path(path).unwrap(), | ||
range: entry.range, | ||
}, | ||
tags: None, | ||
deprecated: None, | ||
container_name: None, | ||
}); | ||
}, |
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.
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.
So I guess workspace symbols are enough to power jump to definition, neat
deprecated: None, | ||
container_name: None, | ||
}); | ||
}, | ||
}; | ||
}); | ||
|
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.
It's somewhat interesting to note that for document symbols, i.e. with @
, we were already tracking all variables due to how document_symbols()
and eventually index_assignment()
works.
It even already worked with method(
calls. We don't check that the LHS is an identifier, we just accept anything. That does lead to some weirdness but its probably ok.
So it was just the following two places where we weren't indexing variables but we do now:
- Workspace level symbols (so
#name
works across files, and so you can jump to defn) - Workspace level static analysis completions (even though we previously did get a completion item already due to runtime completions once the user loaded the package)
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.
oh I hadn't caught up on that, good catch
Quick fix to improve S7 workflow.
Addresses posit-dev/positron#5274
Also a nice improvement all around as you can jump to the definition of e.g. a data frame in a script.
Positron Release Notes
New Features
Bug Fixes