vscode-kafka icon indicating copy to clipboard operation
vscode-kafka copied to clipboard

Support for value format validation

Open omerd-cyera opened this issue 2 years ago • 4 comments

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 :)

omerd-cyera avatar Jul 21 '22 09:07 omerd-cyera

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.

angelozerr avatar Jul 22 '22 08:07 angelozerr

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 avatar Jul 24 '22 06:07 omerd-cyera

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.

omerd-cyera avatar Aug 03 '22 09:08 omerd-cyera

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

angelozerr avatar Aug 03 '22 12:08 angelozerr