Conversation
`GraphTest::source_of(definition_id)` returns the source code for the definition.
| let def = self.graph.definitions().get(definition_id).unwrap(); | ||
| let uri = self.graph.documents().get(def.uri_id()).unwrap().uri(); | ||
| let source = self.source(uri); | ||
| &source[def.offset().start() as usize..def.offset().end() as usize] |
|
We won't need this test helper if the dealiase returns |
| #[must_use] | ||
| pub fn source_of(&self, definition_id: &DefinitionId) -> &str { | ||
| let def = self.graph.definitions().get(definition_id).unwrap(); | ||
| let uri = self.graph.documents().get(def.uri_id()).unwrap().uri(); |
There was a problem hiding this comment.
Can this method work with definitions coming from built_in.rs? They have uri but don't have document AFAIK. So it'll probably panic on this line?
There was a problem hiding this comment.
Absolutely. But I think we can easily avoid testing with builtins...
There was a problem hiding this comment.
I don't think we'll intentionally test against the built in definitions. What could happen is that we build other helpers on top of this method, which takes a declaration and get all the sources of it. In that case it'd be reasonable to pass Object etc to it and then it'd explode.
We can likely prevent it by checking if the definition is a built in before invoking this.
| } | ||
|
|
||
| pub fn delete_uri(&mut self, uri: &str) { | ||
| self.graph.delete_document(uri); |
There was a problem hiding this comment.
Should we also update sources when we remove a uri?
|
The test utility is not used. Closing this PR for this time. Reopen if we need it in future. |
Add
GraphTest::source_of(definition_id), which the source code for the definition. The tests in #697 use these helpers.Extracted from #697.