Indentation issues
Before submitting your bug report
- [X] I believe this is a bug. I'll try to join the Continue Discord for questions
- [X] I'm not able to find an open issue that reports the same bug
- [X] I've seen the troubleshooting guide on the Continue Docs
Relevant environment info
- OS: macOS 14.4.1
- Continue: 0.8.23
- IDE: VSCode 1.87.2
- Ollama v0.1.29
Description
I have a problem with indentations, somehow continue breaks indentation when I try to edit / generate code. The model provides correct code but it is not applied correctly. I hope the attached movie explains the issue better than words :)
https://github.com/continuedev/continue/assets/95582824/69883496-4a08-458f-a91b-d568052f8794
I tried adjusting VS code settings regarding indentations, tabulations, paste formatting - nothing helped.
[edit] Changed .mov to .mp4 movie format
To reproduce
- create new python file
- CMD+I (ask Continue to generate new code)
- enter simple prompt "generate fibonacci sequence"
- all "elif" statements and "else" statement are indented too far
Log output
No response
@PawelSzpyt thanks for the clear video! I have a few improvements on the way for cmd+I that should clean this up
I have same bug with v0.9.202 (pre-release) version. it also appears when using "Optimize this Code" shortcut.
I also tried to disable all extensions for workspace and enable back only Continue. Same problem.
BTW, i also check indentation with python code, as @PawelSzpyt did.
@vills what LLM are you using? This seems very much to be a model-specific problem
@sestinj Tried both gpt-4o and gpt-4o mini. Also tried llama3.1 and mistral-nemo through Ollama. And claude sonnet. With all this models indent issue persist.
Seeing this issue on 1.0.1 with Claude, however it seems to be loosing the indent. The resulting code often looks like:
def get_current_directory():
import os
return os.getcwd()
I wonder if this is down to the prompt. I note the prompt reads:
## EXAMPLE QUERY:
<QUERY>
function sum_evens(lim) {
var sum = 0;
for (var i = 0; i < lim; ++i) {
{{FILL_HERE}}
}
return sum;
}
</QUERY>
TASK: Fill the {{FILL_HERE}} hole.
## CORRECT COMPLETION
<COMPLETION>if (i % 2 === 0) {
sum += i;
}</COMPLETION>
Then for the next example:
## EXAMPLE QUERY:
<QUERY>
def sum_list(lst):
total = 0
for x in lst:
{{FILL_HERE}}
return total
print sum_list([1, 2, 3])
</QUERY>
## CORRECT COMPLETION:
<COMPLETION> total += x</COMPLETION>
The {{FILL_HERE}} is of course pre indented for the line it is on. I would suggest that the first completion (i.e. not providing any further indentation for the first line) is correct, and the seccond example (suggesting providing indentation for the first line in the completion) is wrong. If one were to sub in the completion in the seccond example right in place of the {{FILL_HERE}}, it would be over indented, however if pasting the first example over the top, it would be correctly indented.
Summary
- Continue's edit mode fails to apply the correct indentation
- But the API response contains the correct indentation
- -> Bug is NOT caused by LLM
- -> Bug is probably caused by Continue incorrectly parsing the API response
Details
I can reproduce this bug with:
- Continue
v1.1.67 - VSCode
v1.102.1.
In edit mode, Continue does not correctly apply indentation that is correctly returned by the LLM when only the indentation on a line of code must change (i.e. no other character in that line changes). I have confirmed in the Continue Console that the API response does include the correct number of spaces (see screenshot), so the issue must be caused by Continue parsing the response incorrectly.
For a trivial example, when Continue edits the code...
def hello_world():
print("Hello world!")
...with edit-mode instructions to print Hello world! 3 times using a for loop, the Continue Console shows that the API response includes the correct indentation:
But the editor misses the indentation that should be applied to the print statement:
I am taking the liberty to flag @sestinj here because this issue makes the edit functionality practically unusable.
Any solution to this? I have a similar issue.
It seems the more indented the line already is, the more it adds extra indentation.
I currently use the below settings. The "template" was added after a lot of research into this problem, but the result is the same with and without it.
"tabAutocompleteModel": {
"title": "qwen2.5-coder",
"provider": "ollama",
"model": "qwen2.5-7b:latest",
"completionOptions": {
"stop": [
"<|endoftext|>"
]
}
},
"tabAutocompleteOptions": {
"template": "<|fim_prefix|>{{{ prefix }}}<|fim_suffix|>{{{ suffix }}}<|fim_middle|>",
"debounceDelay": 600,
"maxPromptTokens": 4096
},
I have the same issue, any solutions?