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

Support for value format validation #229

Open
omerd-cyera opened this issue Jul 21, 2022 · 4 comments
Open

Support for value format validation #229

omerd-cyera opened this issue Jul 21, 2022 · 4 comments

Comments

@omerd-cyera
Copy link
Contributor

omerd-cyera commented Jul 21, 2022

Hi,
Does this extension currently support body validation?
If not, It could be nice to have json format validation (eg: if you forgot to remove a trailing ,):
image
Currently, the message is sent with bad format.

Also, might be nice to support custom json-schema validations.
image

Would love to hear what you think.
And thanks for the great extension :)

@angelozerr
Copy link
Collaborator

angelozerr commented Jul 22, 2022

Does this extension currently support body validation?

No.

Would love to hear what you think.

Indeed it should be nice, but I fear that it will not an easy task. The first thing to do is to study if we can use https://github.com/microsoft/vscode-json-languageservice to manage partial JSON validation, hover, completion, etc.

@omerd-cyera
Copy link
Contributor Author

Yep, I think we can start with the first suggestion and see how it goes.
Ill update here when i find time to work on this. Thanks :)

@omerd-cyera
Copy link
Contributor Author

Hey,
I finally got to work on this a little, I have a working POC using vscode-json-languageservice in KafkaFileDiagnostics.
Do you think its fine to parse the json section with the json language service on every KafkaFileDiagnostics.doDiagnostics?

Feels like a bad design to me. but not sure whats a better fitting solution looks like.
Maybe we can think about creating another, more specific JSONProducerBlock that caches the parsed JSONDocument.

Also seems like the way to add diagnostics in an embeded document is a little hacky, from what i can tell, I'm supposed to clone the document, and replace all the characters in it with " " except for the embeded part. That way the diagnostics align on the original document. Not sure if you have any experience with this sort of stuff, but would love to know if you have an alternative solution.

@angelozerr
Copy link
Collaborator

angelozerr commented Aug 3, 2022

Thanks so muuch foe studying this super nice feature.

I think we should follow the same idea than vscode html language server which consumes html and CSS vscode language service since html can embedds CSS. I think we should have languages modes (today we will have JSON mode):

For instance for validation, you get all languages mode like html language server does https://github.com/microsoft/vscode/blob/11cea7dfb79b4bcbea2b99f3c955a7636ddeac58/extensions/html-language-features/server/src/htmlServer.ts#L280 and consumes doValidation like https://github.com/microsoft/vscode/blob/11cea7dfb79b4bcbea2b99f3c955a7636ddeac58/extensions/html-language-features/server/src/htmlServer.ts#L286

Here a sample with cssMode doValidation https://github.com/microsoft/vscode/blob/11cea7dfb79b4bcbea2b99f3c955a7636ddeac58/extensions/html-language-features/server/src/modes/cssMode.ts#L20

I suggest that you try to mimic the language mode used in vscode. See https://github.com/microsoft/vscode/blob/main/extensions/html-language-features/server/src/modes/cssMode.ts which support CSS features not only diagnostics but completion etc that we should support too for json

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

No branches or pull requests

2 participants