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

Neogen sync/update [feature request] #65

Open
smackesey opened this issue Feb 10, 2022 · 12 comments
Open

Neogen sync/update [feature request] #65

smackesey opened this issue Feb 10, 2022 · 12 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@smackesey
Copy link

smackesey commented Feb 10, 2022

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
@danymat
Copy link
Owner

danymat commented Feb 10, 2022

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

@danymat danymat added enhancement New feature or request help wanted Extra attention is needed labels Feb 10, 2022
@danymat
Copy link
Owner

danymat commented Feb 10, 2022

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

@smackesey
Copy link
Author

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.

@danymat
Copy link
Owner

danymat commented Feb 11, 2022

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.

@max397574
Copy link

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

@danymat
Copy link
Owner

danymat commented Feb 24, 2022

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

@max397574
Copy link

you just get the comment about the function and check if it's kinda like the annotations format e.g. ---in lua

@danymat
Copy link
Owner

danymat commented Feb 24, 2022

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.

@max397574
Copy link

hmmm

@danymat
Copy link
Owner

danymat commented Feb 24, 2022

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

@sputnick1124
Copy link

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?

@tan-wei
Copy link

tan-wei commented Aug 26, 2023

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants