continue icon indicating copy to clipboard operation
continue copied to clipboard

Indentation issues

Open PawelSzpyt opened this issue 1 year ago • 4 comments

Before submitting your bug report

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

  1. create new python file
  2. CMD+I (ask Continue to generate new code)
  3. enter simple prompt "generate fibonacci sequence"
  4. all "elif" statements and "else" statement are indented too far

Log output

No response

PawelSzpyt avatar Mar 27 '24 13:03 PawelSzpyt

@PawelSzpyt thanks for the clear video! I have a few improvements on the way for cmd+I that should clean this up

sestinj avatar Mar 28 '24 00:03 sestinj

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 avatar Aug 30 '24 19:08 vills

@vills what LLM are you using? This seems very much to be a model-specific problem

sestinj avatar Sep 01 '24 05:09 sestinj

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

vills avatar Sep 01 '24 07:09 vills

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.

bdavj avatar Feb 27 '25 10:02 bdavj

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:

Image

But the editor misses the indentation that should be applied to the print statement:

Image

I am taking the liberty to flag @sestinj here because this issue makes the edit functionality practically unusable.

kevin-pw avatar Jul 24 '25 22:07 kevin-pw

Any solution to this? I have a similar issue.

Image Image

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
  },

medimachina avatar Aug 08 '25 09:08 medimachina

I have the same issue, any solutions?

zhanghm1995 avatar Sep 08 '25 12:09 zhanghm1995