Skip to content

Conversation

@acao
Copy link
Collaborator

@acao acao commented Jul 28, 2023

this allows us to:

  • automatically complete the json5 string based on the type of quotes or lack thereof that the user is using
  • prefers the schema.default over other guesses
  • fixes an apparent bug where guessed solutions are overwritten

I tested this with packageJson.types, which is the only value in the schema that has a default

@changeset-bot
Copy link

changeset-bot bot commented Jul 28, 2023

⚠️ No Changeset found

Latest commit: a138f76

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@netlify
Copy link

netlify bot commented Jul 28, 2023

Deploy Preview for codemirror-json-schema ready!

Name Link
🔨 Latest commit a138f76
🔍 Latest deploy log https://app.netlify.com/sites/codemirror-json-schema/deploys/64cf531b167c350008597d4c
😎 Deploy Preview https://deploy-preview-48--codemirror-json-schema.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

}
}
if (!value || nValueProposals > 1) {
if (!value || nValueProposals < 1) {
Copy link
Collaborator Author

@acao acao Jul 28, 2023

Choose a reason for hiding this comment

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

I wasn't sure what the intention was here, so I reversed the logic

in the case of packageJson.types we have two value proposals I think - one from default, and another because it was an enum

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the idea is that if there are multiple possible values, we don't assume a value for the user

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think in this case, a schema has both default and enum. in my opinion, we should just guess with default and forego the other snippet guessing logic then, instead of counting? what do you think?

Copy link
Collaborator Author

@acao acao Jul 29, 2023

Choose a reason for hiding this comment

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

@imolorhe I have pushed another commit here where i reverted to the original logic for more than 1 proposal, but made it so that if default is provided, only the default value is proposed, how does that sound?

}

const currentWord = getWord(ctx.state.doc, node);
const rawWord = getWord(ctx.state.doc, node, false);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this logic is only needed for json5 really, so we can guess how to insert the completion text based on quotation types or lack thereof

}

type JSONCompletionOptions = {
mode?: "json" | "json5";
Copy link
Collaborator Author

@acao acao Jul 28, 2023

Choose a reason for hiding this comment

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

unfortunately, CompletionContext nor EditorState give us metadata about which parser has parsed the editor state, so we must rely on configuration

@acao acao force-pushed the json5-inserttext-defaults branch from 1c590e5 to 6b17074 Compare July 28, 2023 17:52
propertySchema.examples[0],
""
);
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The tests will make us more confident with these type of changes!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

indeed! i will add tests for all of these cases before merging this PR

@acao acao force-pushed the json5-inserttext-defaults branch from 04a569e to 039344c Compare July 30, 2023 10:02
@acao
Copy link
Collaborator Author

acao commented Jul 30, 2023

@imolorhe so now we are at a much more comprehensive level of coverage, but I would like this to be 95%+ before making this change

image

Here are several regressions I noticed, I will check to see if they are on main branch as well:
json4-regression

json4-regression-2

as you can see, with double quotes it's fine, but I think something related to the modified json5 logic has it working wrong
json4-fine-double

@acao acao mentioned this pull request Jul 30, 2023
@acao acao force-pushed the json5-inserttext-defaults branch from 039344c to 4ac9268 Compare August 3, 2023 18:24
@acao
Copy link
Collaborator Author

acao commented Aug 5, 2023

@imolorhe i see you approved this but I have noted a few regressions, I'm not sure if they came before or after this PR! Should I just merge and we can work out the bugs after that?

@imolorhe
Copy link
Collaborator

imolorhe commented Aug 5, 2023

oh we can fix it then

@acao
Copy link
Collaborator Author

acao commented Aug 6, 2023

ok, confirmed with tests that the regression is not caused by this PR. we can go ahead and merge this, and check out #54 to fix this bug

@acao acao merged commit befabe9 into main Aug 6, 2023
@acao acao deleted the json5-inserttext-defaults branch August 6, 2023 08:05
acao added a commit that referenced this pull request Aug 12, 2023
this allows us to:

- automatically complete the json5 string based on the type of quotes or
lack thereof that the user is using
- prefers the schema.default over other guesses
- fixes an apparent bug where guessed solutions are overwritten

I tested this with `packageJson.types`, which is the only value in the
schema that has a default
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.

3 participants