Generate code should honor the context

The generate code feature should take into account the code surrounding it when it generates new code

As is the feature is not useful for coding because it generates irrelevant code whenever I ask it

Four example I had code that uses the python pathlib module and I wanted to generate code to check if files already exist but it kept using the os module instead clearly violating the intent expressed in the surrounding code. When I put the cursor in front of an expression that generates a value and tell it to assign this to a variable it does not understand what I want.

2 Likes

You are asking too much from an AI. Try to use ghostwriter and be more specific. But assume that AI will give you an idea and example, often wrong, not the final code.

4 Likes

Try using ChatGPT maybe?

1 Like

That is the same. Copilot is a bit better is properly instructed. Tabnine is maybe better bur for autocomplete on few lines only.
Everybody needs to realise that AI does not really understand and write code. It is more of an interpolation of things resulting in something that could help (not a solution)

4 Likes

I agree that it is an interpolation of things but the point of my post is exactly that it doesn’t interpolate what was already there but only from the text input, from the prompt. It’s not conditioned on the surrounding context at all unless I specify that by selecting it manually. Just putting the surrounding 10 lines or so in the context should help the model generate more relevant ideas.

If my understanding is correct this is not happening at all right now with the generate code feature but would make it so much better!

2 Likes

The chat mode does interact with your files but you need to mention the file (or is the one open in the other pane) and i would expect that the extent is limited to what the chat can do (500 words or so). Also and again, AI is not magic and has limitation in terms of what it can do, how many lines it can get as input and alike. It does not read, it takes text, turn it into some form of number data and tries to extrapolate something.

2 Likes