Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
inline_assistant: Respect tabs when selection first row is not indent…
…ed (#14886) When using the inline assistant with a language such as Go that uses tabs, if the user selects a block of text that is correctly formatted and where the first line has no indentation, the `suggested_line_indent` variable ends up with `IndentSize { len: 0, kind: Space }`. That's because `suggested_line_indent` current relies on `BufferSnapshot::suggested_indents` suggestion for the first line on the selection, but since it is already correctly indented, there are no suggestions and `MultiBufferSnapshot::indent_size_for_line` is used instead. https://github.com/zed-industries/zed/blob/2d96bba61fd9e60951ecfcf697707a974475c1b2/crates/assistant/src/inline_assistant.rs#L2124-L2128 In this patch, we also take a look at the rest of the selection and detect tabs. If one is encountered, we assume that tabs should always be used. I suppose this isn't perfect, especially if the original file had a mix of spaces and tabs, however it seems better than the status quo. I considered using `BufferSnapshot::language_indent_size_at`, but I imagine tabs should be preserved even when a specific language isn't being used. See screenshot below of the original prompt with this patch. Tests: * New unit test * I've also manually tested with a few other cases: selection where all lines are indented and file that only use spaces. Release Notes: - Fixed 'inline_assistant: tabs are overwritten with space characters when first line in selection has no indentation' ([#14885](#14885)). <img width="942" alt="image" src="https://github.com/user-attachments/assets/f2c5d7e9-e8bc-400b-bd6f-09e4a89d22c1">
- Loading branch information