pyjson5 icon indicating copy to clipboard operation
pyjson5 copied to clipboard

preserving comments

Open wmtorode opened this issue 5 years ago • 5 comments

Is there a way to preserve comments so that if I edit a file the comments it contained are still there?

wmtorode avatar Aug 16 '19 03:08 wmtorode

Unfortunately, no, not currently.

In order to do that you need to preserve the whole parse tree, which certainly doesn't work inside the existing simple load/dump API.

I would like to support this, though, it's something of a challenging problem. I've never seen an API for doing something like that and so it's a bit unclear what a good API would look like.

dpranke avatar Aug 16 '19 20:08 dpranke

Thanks, I figured that would be the answer. It would be great if this could be supported even if it's through a different API than the current load and dump.

wmtorode avatar Aug 16 '19 21:08 wmtorode

Agreed. (Sorry for not responding sooner. I'm still mulling over what an API like this might look like.)

dpranke avatar Jan 14 '20 17:01 dpranke

This npm package is doing it (or claiming to): https://www.npmjs.com/package/comment-json

qneill avatar Jul 17 '20 17:07 qneill

@qneill Thanks for the pointer. I'm looking at that now, and it does seem to be at least reasonable well-worked out.

dpranke avatar Jul 21 '20 20:07 dpranke