Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(autoedits): Correctly produce decorations for files that use Tab indentation #6617

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

umpox
Copy link
Contributor

@umpox umpox commented Jan 13, 2025

Description

closes https://linear.app/sourcegraph/issue/CODY-4651/fix-uneven-spacing-in-suffix-decorations

Our suffix decorations were broken in a number of ways for files that used Tab indentation:

  1. We would assume that the line.range.end.character matched the column position where we want to render the decoration. This is not correct, and the more tabs on a line the more out of position the decoration would be come. We ran into a similar issue with our command hint decorations.
  2. We would attempt to render an incoming change without fully converting it to space based indentation. This is problematic because VS Code doesn't correctly render tabs in decorations.

This PR:

  • Fixes the issue with the replacerCol by taking into account the space/tab based indentation and the indentation amount
  • Fixes the issue with the decoration content, by ensuring we always replace the indentation prefix with the correct equivalent of unicode spaces
  • Updates blockify logic so we're not longer modifying the existing data structure (hard to understand if this could trigger side effects) and instead we return a new structure
  • Adds more tests for blockify

Before

image

After

image

Test plan

  1. Visual E2E tests
  2. Manual testing on files that use space indentation and tab indentation

Comment on lines 46 to 50
const text = blockify(mockSpacesDocument, mockAddedLines).map(({ lineText }) => lineText).join('\n')
expect(text).toMatchInlineSnapshot(`
"hello world      
    goodbye world"
`)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kinda wish GitHub rendered special characters differently... these tests are a lot nicer like this:

image

@umpox umpox marked this pull request as ready for review January 13, 2025 14:59
@valerybugakov
Copy link
Member

Updates blockify logic so we're not longer modifying the existing data structure (hard to understand if this could trigger side effects) and instead we return a new structure

💜

Copy link
Member

@valerybugakov valerybugakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great find!


export const UNICODE_SPACE = '\u00A0'

export function blockify(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a doc string comment with a simple input -> output example explaining what this function does? I understand it from looking at the test cases, but it's still an obscure function name. It should help us with reading this code later.

import { blockify } from './blockify'
import type { AddedLinesDecorationInfo } from './default-decorator'

describe('blockify', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙌

}

// For files using tab-based indentation, we need special handling.
// VSCode's Range API doesn't account for tab display width
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it mean that if tabs are used, the column number we get is lower because it counts every tab for one char instead of tabSize?

private renderAddedLinesDecorations(
addedLinesInfo: AddedLinesDecorationInfo[],
_addedLinesInfo: AddedLinesDecorationInfo[],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we want to prefix with _ here?

@@ -231,6 +231,20 @@ test('autoedits: triggers inline decorations when multiple separate insertions a
})
})

test('autoedits: triggers a suffix decoration and renders correctly in files that use tab based indentation', async ({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:letsgoooooooo:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants