Code Suggestions Fail to Respect Existing Indentation Levels
<!--IssueSummary start--> <details> <summary> Everyone can contribute. [Help move this issue forward](https://handbook.gitlab.com/handbook/marketing/developer-relations/contributor-success/community-contributors-workflows/#contributor-links) while earning points, leveling up and collecting rewards. </summary> - [Close this issue](https://contributors.gitlab.com/manage-issue?action=close&projectId=278964&issueIid=538933) </details> <!--IssueSummary end--> <!--- Please read this! Before opening a new issue, make sure to search for keywords in the issues filtered by the "regression" or "type::bug" label: - https://gitlab.com/gitlab-org/gitlab/issues?label_name%5B%5D=regression - https://gitlab.com/gitlab-org/gitlab/issues?label_name%5B%5D=type::bug and verify the issue you're about to submit isn't a duplicate. ---> ### Summary Code suggestions inserted by Duo don't maintain proper indentation levels of the surrounding code, causing syntax errors in indentation-sensitive languages like Python. The first line of inserted code begins exactly at cursor position rather than aligning with the proper indentation level. ### Steps to reproduce 1. Open a Python file in the VS Code editor with Code suggestion feature enabled 2. Position cursor within an indented code block (e.g., inside a function or loop) 3. Request a code suggestion from Duo 4. Accept the suggestion for insertion See attached video for illustration. ### Example Project <!-- If possible, please create an example project here on GitLab.com that exhibits the problematic behavior, and link to it here in the bug report. If you are using an older version of GitLab, this will also determine whether the bug is fixed in a more recent version. --> ### What is the current *bug* behavior? The first line of the inserted code begins exactly at the cursor position, ignoring the indentation level of the surrounding code. This breaks Python's syntax requirements and requires manual adjustment after insertion. ### What is the expected *correct* behavior? Code suggestions should automatically detect and respect the indentation level of the surrounding code. When inserted into an indented block, all lines of the suggestion should maintain proper indentation relative to the code context. ### Relevant logs and/or screenshots ![Screen_Recording_2025-05-02_at_12.07.33](/uploads/387f5ed12d249a64670935ddfae9fa51/Screen_Recording_2025-05-02_at_12.07.33.mov) ### Output of checks This bug happens on GitLab.com ``` # GitLab Workflow Diagnostics ## Versions - IDE: Visual Studio Code (1.99.3) - Extension: GitLab Workflow version (6.13.0) - Language Server version: 7.30.0 - GitLab instance version: 18.0.0-pre ## GitLab Duo Code Suggestions (On) ✅ [true] User is authenticated ✅ [true] Code Suggestions are enabled in settings ✅ [true] Code Suggestions API connection is working ✅ [true] The GitLab instance version supports Code Suggestions ✅ [true] Valid GitLab license ✅ [true] GitLab Duo is enabled for the open project(s) ## GitLab Duo Chat (On) ✅ [true] User is authenticated ✅ [true] Chat is enabled in settings ✅ [true] Valid GitLab license ✅ [true] GitLab Duo is enabled for the open project(s) ## Duo workflow settings ### GitLab Duo - Disabled supported languages: None - Additional enabled languages: yaml - [enabled] Duo Code Suggestions - [enabled] Duo Chat - [enabled] Enabled without GitLab project - [enabled] Open files as context - [disabled] Use Docker ### Other - [disabled] Debug ### Custom certificates - Certificate authority: Not configured - Certificate: Not configured - Certificate key: Not configured - [disabled] Ignore certificate errors ### Code security - [disabled] Real-time security scanning - [enabled] Scan file on save ``` ### Possible fixes <!-- If you can, link to the line of code that might be responsible for the problem. --> <!-- If you don't have /label privileges, follow up with an issue comment of `@gitlab-bot label ~"type::bug"` -->
issue