-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Fix incorrectly using 0-indexed number where 1-indexed number is expected #3397
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 1d988c1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@u9g thanks, this also fixes a bug in |
I added a changeset for Fix incorrect loop condition, should I add a changeset for fix error range handling bug too if it only fixed bugs in the test as far as I know? |
huh. seeing the change you made to the language service makes me want to check for regressions in |
from what i can tell, this is a breaking change, so we need to give the graphql-language-service a major bump |
yeah, looks from the e2e tests that youll need to handle the breaking change in |
I actually took another look at my though process and remade this pr, take a look at the pr description for why I made the changes. |
@@ -94,8 +97,9 @@ export class GraphQLWorker { | |||
range: toMonacoRange( | |||
getRange( | |||
{ | |||
column: graphQLPosition.character, | |||
line: graphQLPosition.line, | |||
// we add one here because `getRange()` expects a 1-indexed position |
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.
just a nit but this would be very useful to have in this file as toMonacoPosition()
in ./utils
? I think this is the only place where we need to invoke it, but that could change. Aside from hover, the rest of the language services we currently implement and will implement tend to use ranges.
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.
to improve human clarity
* happy svelte parsing * test range * refactor tag parsing for readability & perf tweaks
Co-authored-by: Ted Thibodeau Jr <[email protected]>
Co-authored-by: Ted Thibodeau Jr <[email protected]>
This pr causes console spam in our case for when we hover a comment on the first line. See obi1kenobi/trustfall#285 for more context.
What does this pr do?
Fixes an off-by-one bug that caused console spam when hovering things in the first line of a graphql file. This occurs because monaco's
toGraphQLPosition()
frommonaco-graphql
returns 0-based line/col numbers andgetRange()
fromgraphql-language-service
expects 1-based line/col numbers.Why is this the right fix?
We have a 0-indexed row/col. To see this for myself, I put a
console.log()
after this line. I then hovered the first character on the first line. I see 0,0 printed, and this is after we subtract 1 from both line/col intoGraphQLPosition()
, so we definitely have a 0-indexed number.getRange()
takes in aSourceLocation
, however that's an interface, so it's not really obvious whether the line/col is 0-based or 1-based. However, there is a functiongetLocation()
that returns aSourceLocation
declared in the samelocation.d.ts
from within thegraphql/language
repo. So taking a look at theirgetLocation()
function, it looks like this:When I saw that, it became clear that this line is 1-indexed, and the
+ 1
in the column leads me to believe this number is 1-based too. (if this isn't, please tell me!)