Skip to content

Fix caret positioning when CLI truncates long source lines - #3292

Open
Mihir-Rabari wants to merge 2 commits into
smithy-lang:mainfrom
Mihir-Rabari:agent/2491-cli-truncation
Open

Mihir-Rabari wants to merge 2 commits into
smithy-lang:mainfrom
Mihir-Rabari:agent/2491-cli-truncation

Conversation

@Mihir-Rabari

Copy link
Copy Markdown

Background

smithy validate truncates long source lines when rendering validation events, but the pointer (caret) was positioned using the raw column of the untruncated line — so on long lines (e.g. wide minified JSON) it rendered far past the … truncation marker, as reported in #2491. While fixing this, I found a second, latent issue: the marker was appended with a length >= allowedSize condition, so lines that exactly fit the available width also got a spurious ….

Testing

  • 5 new CodeFormatterTest cases pinning the behavior: an exactly-fitting line renders fully with the correct caret and no marker; a long line is truncated with the caret inside the visible window under the right character; an error column far past the window clamps the caret exactly onto the … marker (never past it — the acceptance criterion from the issue); carets at column 1 and at the last visible column both position correctly.
  • The pointer is clamped only when a truncation marker is present, so rendering of short/fitting lines is unchanged — the pre-existing formatter tests pass byte-identically.
  • Full module gate: ./gradlew :smithy-cli:build (tests + spotless + spotbugs + javadoc) — BUILD SUCCESSFUL, all 18 tests in CodeFormatterTest and PrettyAnsiValidationFormatterTest green.

Links

Fixes #2491


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Comment on lines +1 to +5
{
"type": "bugfix",
"description": "Fix CLI output when rendering long source lines so that the pointer never goes past the truncation marker. Fixes [#2491](https://github.com/smithy-lang/smithy/issues/2491)",
"pull_requests": []
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Staged changelog entries should have an associated pull request set. Commit this suggestion to associate this changelog entry with this PR.

Suggested change
{
"type": "bugfix",
"description": "Fix CLI output when rendering long source lines so that the pointer never goes past the truncation marker. Fixes [#2491](https://github.com/smithy-lang/smithy/issues/2491)",
"pull_requests": []
}
{
"type": "bugfix",
"description": "Fix CLI output when rendering long source lines so that the pointer never goes past the truncation marker. Fixes [#2491](https://github.com/smithy-lang/smithy/issues/2491)",
"pull_requests": [
"[#3292](https://github.com/smithy-lang/smithy/pull/3292)"
]
}

This branch has not been deployed

No deployments
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.

CLI validate command hates long lines

1 participant