neogen
neogen copied to clipboard
Neogen sync/update [feature request]
Sometimes the source material for a generated annotation might be changed after the annotation has been generated. In these cases, it would be very useful to have a command (neogen.sync()
?) to update an existing annotation. For example:
def foo(bar):
return bar
Run neogen.generate()
:
def foo(bar):
"""
Args:
bar ():
Returns:
"""
return bar
But now suppose I add type annotations so the top line reads:
def foo(bar: int):
Then the hypothetical neogen.sync()
would do this:
def foo(bar: int):
"""
Args:
bar (int):
Returns:
"""
return bar
~~what about just re-doing Neogen command and it does it automatically ? So no need of a sync function?~~
This will not work because it'll override the annotation
Hmm it seems difficult to implement, as how we could retrieve easily the annotation and see if it has been changed
Do you have any ideas ? Maybe with some regex
Really what's needed is a treesitter grammar for the annotations themselves-- so it would be a feature that relatively few languages support, but IMO definitely worth it for popular ones.
I could implement this for Python google-style docstrings.
Really what's needed is a treesitter grammar for the annotations themselves-- so it would be a feature that relatively few languages support, but IMO definitely worth it for popular ones.
You mean creating a grammar for annotations ? That could work indeed, but as of right now, we don't have any.
you could retrieve the old annotation, create the new one, compare the "fields", see where values are set, set the im the new annotation -> profit :)
you could retrieve the old annotation
the problem is: how do you know something is the old annotation ? That's why having a parser for annotations could be a huge benefit, but I don't think it's something easily feasible
you just get the comment about the function and check if it's kinda like the annotations format e.g. ---
in lua
you just get the comment about the function and check if it's kinda like the annotations format e.g.
---
in lua
Even though, this check is not sufficient, take a look:
--- this is not meant to be an annotation
function test()
end
If we allow this type of behavior, this will mean that everything on top of the function, that has ---
will be deleted and replaced with new annotation. I don't think this is a good idea, because the user should be expected to clearly know the result of the command before typing it out.
hmmm
One way to handle this, would be to keep the Information about created annotation (with marks) But that would mean that exiting neovim will lose the informations
For reference, it seems like this is possible with bare luasnip
(at least for the active session, exiting neovim still poses a problem). LuaSnip
's README
shows a GIF of this working, but the source code for the demo even admits that it is ugly and fragile. I'm not sure what the existing neogen
+luasnip
integration looks like, but I'm wondering if some combination of setting history = true
in luasnip
and using restoreNode
would get close?
It would be a great feature, but I think it is not that easy to implement. To implement this, a better way is to parse the generated comments before, and then we can do a sync, which means additional parser should be implemented. A special mark could be a quick (but dirty) way...