-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Code editor auto-completion by schema #1435
Code editor auto-completion by schema #1435
Conversation
Adding ext-language_tools Adding example Start SchemaTextCompleter
simple props primitives - string, number enums
@josdejong - it took a while :-) but now ready for your review. tnx! |
Wow 😎 that looks really promising Meir! I'll review your PR soon. |
I've tried out the autocompletion, it works really nicely! The code looks neat too 👍 A couple of feedbacks:
|
@josdejong 1-3 - good points. will do it. As for 4 - I totally agree - this is a significant downside of the current implementation as the use case of adding new property is very common - also this prevents of adding non-string suggesstions in some cases. However I'm afarid that the solution is a bit complicated than just trying to manipuilate the JSON to be a valid one, because it is also crucial for us to know the exact cursor location in the code editor - this can be influenced by additinal factors such as newlines, tabs, etc. the result of it can be that the completer will 'think' that the cursor is on different location and will provide wrong suggestions - IMO it is worse than no suggestions at all. Currently I am leveraging the Another interesting lib I have noted for myself to check is partial-json-parser but still looks like it just emitting the 'bad' parts so I still not sure about it. In any case, this can be a challenge and require additional research, based on my available time it can take a while and I didnt wanted to delay the entire feature, so my suggestion is to create a new issue for improvmenets and I (or anyone else who is interested) can work on it on my/his/her spare time :-) WDYT? |
Thanks. Yes makes sense to address point (4) separately. It may involve quite some experimentation. So let's finish this PR without (4) first then 👍 I wasn't aware of |
@josdejong I have addressed the items we discussed, pls review when you can. tnx. |
Thanks Meir, I'll review your PR soon, but I'm not sure if I can make it this week. |
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.
Thanks Meir for the updates. I'm happy with the unit tests, that helps preventing regressions in the future.
I made one small inline remark, besides that everything is ready to merge 👌
@meirotstein I just merged your work, thanks again. Testing once more gives an odd issue on my side: the dropdown is displayed way too low. Does the same happen on your computer? |
Hey @josdejong Can you elaborate on your testing? which browser? |
@josdejong correction: working also in Safari (I have rebuilt it again). |
I'm using Windows 11 and tested with the latest Firefox and Chrome, and using Node@16 and npm@8. I did a bit of debugging:
|
I've published v9.9.0 now with the auto-completion feature. Thanks again Meir. I have made a few minor changes: run the linting and fixed code style accordingly, and increment the numbering of the examples, there was an other example added in the meantime. |
Awesome, thanks! |
@josdejong I have created a new issue to address the non-valid JSON limitaion - #1443 |
This PR adds the ability to get an auto-completion suggestions based on a given JSON schema for code editor.
It is related to issue #968 .
This feature was implemented by leveraging the ace editor autocomplete capability, and it is mainly about investigating the schema (including its references), and building a set of suggestions that can be delivered to ace live auto-completeion, based on the current cursor position in the JSON document.
code
modeallowSchemaSuggestions
option totrue
Limitation :
This feature will work only for a valid JSONs, and no suggestion will show if the JSON is not valid.
So, if one wants to get a list of available properties - he/she sould also provide an empty value followed with a comma (when needed) - as can be seen in the short example movie.
autcomplete_example.mov