# Fix indentation issues when generating or transforming code with inline assistant \(\#2961\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/5697a87f4a2968ee6b4530680c2bfe910cf6d769)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 5697a87f4a2968ee6b4530680c2bfe910cf6d769

Requested commit: 5697a87f4a2968ee6b4530680c2bfe910cf6d769

Commit: 5697a87f4a2968ee6b4530680c2bfe910cf6d769

Tree: 804a061aae2ab9ac422e656212bbf5b8b3e896dc

Author: Antonio Scandurra

Committer: GitHub

## Message

```
Fix indentation issues when generating or transforming code with inline assistant (#2961)

This pull request extracts a separate `Codegen` struct that models the
interaction with OpenAI and takes care of diffing, auto-indenting and
reporting regions to highlight.

As part of this refactoring, we're now relying less on the AI model to
indent code. The new logic lets tree-sitter decide how the first line
should be indented. Then, for every subsequent line reported by ChatGPT,
it calculates an indent delta relative to the first reported line and
applies it to the indent level chosen by tree-sitter.

Release Notes:

- Improved auto-indentation when using the inline assistant.
```

## Parents

- [329a0724e0ecdcc117f700e5e5ff5e5720398f5c](https://git.cafe/gitcafe/zed/commit/329a0724e0ecdcc117f700e5e5ff5e5720398f5c?format=markdown)

- [127d03516fb40a16f1cb362d9512653b57fffe67](https://git.cafe/gitcafe/zed/commit/127d03516fb40a16f1cb362d9512653b57fffe67?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/5697a87f4a2968ee6b4530680c2bfe910cf6d769?format=markdown)
