Files
oak-gpui/crates
Artur Rodrigues 5ad3c6b6dc inline_assistant: Respect tabs when selection first row is not indented (#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](https://github.com/zed-industries/zed/issues/14885)).

<img width="942" alt="image"
src="https://github.com/user-attachments/assets/f2c5d7e9-e8bc-400b-bd6f-09e4a89d22c1">
2024-07-24 16:31:16 +03:00
..
2024-07-23 15:01:05 -07:00
2024-05-29 18:06:45 -07:00
2024-07-23 15:01:05 -07:00
2024-07-23 15:01:05 -07:00
2024-07-23 15:01:05 -07:00
2024-07-23 15:01:05 -07:00
2024-07-23 15:01:05 -07:00
2024-07-23 15:01:05 -07:00
2024-07-23 15:01:05 -07:00
2024-05-29 18:06:45 -07:00
2024-07-23 17:59:55 -04:00
2024-06-12 23:22:52 +03:00
2024-07-23 15:01:05 -07:00
2024-07-23 15:01:05 -07:00
2024-07-23 21:05:11 -06:00
2024-07-23 15:01:05 -07:00
2024-07-23 15:01:05 -07:00
2024-07-15 17:04:15 -06:00
2024-07-23 15:01:05 -07:00
2024-07-23 21:38:47 +02:00
2024-06-21 16:32:32 -07:00
2024-07-23 15:01:05 -07:00
2024-07-23 15:01:05 -07:00
2024-07-23 15:01:05 -07:00
2024-07-23 15:01:05 -07:00
2024-07-23 15:01:05 -07:00