Skip to content
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

Better locations for URL strings #6031

Open
wants to merge 6 commits into
base: next
Choose a base branch
from
Open

Conversation

dylan-apollo
Copy link
Member

This fixes error locations within multiline/triple-quote URL strings, and sets up utilities so we can do the same within JSONSelection!
Screenshot 2024-09-19 at 5 36 52 PM

There's also a significant refactor to reduce the amount of things we pass between functions, since I just added one more thing ™️

@@ -3984,6 +3985,12 @@ dependencies = [
"vcpkg",
]

[[package]]
name = "line-col"

Choose a reason for hiding this comment

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

I'm a little wary of an unstable dependency that hasn't been updated in four years - how much value is this providing? It looks like a very small amount of code.

/// Get the raw string value of this GraphQL string literal
///
/// Returns `None` if the value was not a string literal or if location data is messed up
pub fn new(value: &'schema Node<Value>, sources: &'schema SourceMap) -> Option<Self> {

Choose a reason for hiding this comment

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

Nitpick: idiomatically, this seems more like a Result than an Option, since the "messed up" cases would be an error. All callers also use ok_or... to convert to a Result.


pub(super) struct SchemaInfo<'schema> {
pub(crate) schema: &'schema Schema,
pub(crate) lookup: LineColLookup<'schema>,

Choose a reason for hiding this comment

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

I'm wary of including dependencies in public API (even pub(crate)) as it makes it more difficult to remove or update the dependency. Especially in this case, where there is really only a single method on the dependency type, this would be very easy to just wrap with a method on this struct rather than exposing the LineColLookup directly. Then pass around SchemaInfo instead of the lookup field.

let start_offset = self.offset + substring_location.start;
let end_offset = self.offset + substring_location.end;

let (line, column) = lookup.get(start_offset);

Choose a reason for hiding this comment

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

This call panics if the offset is incorrect, which is very worrisome. You need to either document this in a # Panics rustdoc on this method, or you could validate the offsets within this method with a fallible Result. But really this is making me question this dependency even more.

&self,
substring_location: Range<usize>,
lookup: &LineColLookup,
) -> Option<Range<LineColumn>> {

Choose a reason for hiding this comment

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

This appears to be infallible, why the Option?

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.

2 participants