Skip to content

Conversation

pratik-m
Copy link

Fix indentation loss when markdown rendering is disabled

Problem

When chat.disableMarkdownRendering is set to true, Python code blocks lose one space per indentation level. Single indentation shows as 3 spaces instead of 4, and double indentation shows as 7 spaces instead of 8.

Root Cause

The fallback function in parse.rs was skipping spaces at column 1, which was intended for markdown formatting but caused indentation loss when markdown was disabled.

Solution

  • Modified the condition to preserve all characters (including leading spaces) when markdown is disabled
  • Added regression test to prevent future issues
  • Maintained backward compatibility when markdown is enabled

Q is used to get this issue fixed

Testing

  • ✅ Code compiles successfully
  • ✅ New test case markdown_disabled_indentation_preserved added
  • ✅ Backward compatibility verified

Before/After

Before:

def fibonacci(n):
   if n <= 1:
       return n
   return fibonacci(n-1) + fibonacci(n-2)

After:

def fibonacci(n):
    if n <= 1:
        return n
    return fibonacci(n-1) + fibonacci(n-2)

Files Changed

  • crates/chat-cli/src/cli/chat/parse.rs - Fixed indentation logic and added test

- Preserve leading spaces in code blocks when markdown is disabled
- Add regression test for indentation preservation
- Maintain backward compatibility when markdown is enabled

Fixes issue where Python code indentation showed 3 spaces instead of 4
when chat.disableMarkdownRendering was set to true.
@nirajchowdhary
Copy link
Contributor

Just to confirm have you run the following?
To run tests: cargo test.
To run lints: cargo clippy.
To format rust files: cargo +nightly fmt. ?

@pratik-m
Copy link
Author

I did run the cargo test, let me run the other two commands and update the PR.

@pratik-m
Copy link
Author

hmm, when I run the cargo test I get the below error. I did not encounter this error last night..
I even tried pulling the latest from git, but still same results.

Compiling chat_cli v1.16.3 (/Users/pmunot/stuff/amazon-q-developer-cli/crates/chat-cli)
error[E0063]: missing field `title` in initializer of `PromptArgument`
    --> crates/chat-cli/src/cli/chat/cli/prompts.rs:2466:17
     |
2466 |                 PromptArgument {
     |                 ^^^^^^^^^^^^^^ missing `title`

error[E0063]: missing field `title` in initializer of `PromptArgument`
    --> crates/chat-cli/src/cli/chat/cli/prompts.rs:2471:17
     |
2471 |                 PromptArgument {
     |                 ^^^^^^^^^^^^^^ missing `title`

error[E0063]: missing fields `icons` and `title` in initializer of `rmcp::model::Prompt`
    --> crates/chat-cli/src/cli/chat/cli/prompts.rs:2462:23
     |
2462 |         let prompt1 = rmcp::model::Prompt {
     |                       ^^^^^^^^^^^^^^^^^^^ missing `icons` and `title`

error[E0063]: missing fields `icons` and `title` in initializer of `rmcp::model::Prompt`
    --> crates/chat-cli/src/cli/chat/tool_manager.rs:2113:22
     |
2113 |         let prompt = rmcp::model::Prompt {
     |                      ^^^^^^^^^^^^^^^^^^^ missing `icons` and `title`

cargo clippy

➜  amazon-q-developer-cli git:(preserve-indentation-markdown-disabled) ✗ cargo clippy
   Compiling chat_cli v1.16.3 (/Users/pmunot/stuff/amazon-q-developer-cli/crates/chat-cli)
    Checking semantic_search_client v1.16.3 (/Users/pmunot/stuff/amazon-q-developer-cli/crates/semantic-search-client)
    Checking amzn-toolkit-telemetry-client v1.0.0 (/Users/pmunot/stuff/amazon-q-developer-cli/crates/amzn-toolkit-telemetry-client)
    Checking amzn-codewhisperer-client v0.1.10613 (/Users/pmunot/stuff/amazon-q-developer-cli/crates/amzn-codewhisperer-client)
    Checking amzn-codewhisperer-streaming-client v0.1.10613 (/Users/pmunot/stuff/amazon-q-developer-cli/crates/amzn-codewhisperer-streaming-client)
    Checking amzn-qdeveloper-streaming-client v0.1.10613 (/Users/pmunot/stuff/amazon-q-developer-cli/crates/amzn-qdeveloper-streaming-client)
    Checking amzn-consolas-client v0.1.10613 (/Users/pmunot/stuff/amazon-q-developer-cli/crates/amzn-consolas-client)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 26.34s
mise WARN  Config files in ~/stuff/amazon-q-developer-cli/.mise.toml are not trusted.
Trust them with `mise trust`. See https://mise.jdx.dev/cli/trust.html for more information.

cargo +nightly fmt

info: syncing channel updates for 'nightly-aarch64-apple-darwin'
info: latest update on 2025-09-29, rust version 1.92.0-nightly (c8905eaa6 2025-09-28)
info: downloading component 'cargo'
info: downloading component 'clippy'
info: downloading component 'rust-docs'
info: downloading component 'rust-std'
info: downloading component 'rustc'
info: downloading component 'rustfmt'
info: installing component 'cargo'
info: installing component 'clippy'
info: installing component 'rust-docs'
info: installing component 'rust-std'
info: installing component 'rustc'
info: installing component 'rustfmt'
mise WARN  Config files in ~/stuff/amazon-q-developer-cli/.mise.toml are not trusted.
Trust them with `mise trust`. See https://mise.jdx.dev/cli/trust.html for more information.

the parse.rs is already formatted and linted. Let me know how to proceed on this.

➜  amazon-q-developer-cli git:(preserve-indentation-markdown-disabled) ✗ git status
On branch preserve-indentation-markdown-disabled
Your branch is up to date with 'origin/preserve-indentation-markdown-disabled'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   crates/chat-cli/src/cli/chat/cli/reply.rs

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        .amazonq/
        convo

no changes added to commit (use "git add" and/or "git commit -a")
mise WARN  Config files in ~/stuff/amazon-q-developer-cli/.mise.toml are not trusted.
Trust them with `mise trust`. See https://mise.jdx.dev/cli/trust.html for more information.

Thanks!

@nirajchowdhary
Copy link
Contributor

@pratik-m you should sync your work and perform git pull, there was a recent merge from maintainers to fix the cargo test failure

Update test macro to support non-trimmed assertions and add test case
for preserving leading whitespace when markdown is disabled.
@pratik-m
Copy link
Author

Hi @nirajchowdhary - I pulled the changes and I needed to tweak the tests as well..Enhanced test macro to support non-trimmed assertions and added regression test for indentation preservation when markdown is disabled.

cargo test

test result: ok. 294 passed; 0 failed; 13 ignored; 0 measured; 0 filtered out; finished in 6.73s

   Doc-tests chat_cli

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

mise WARN  Config files in ~/stuff/amazon-q-developer-cli/.mise.toml are not trusted.
Trust them with `mise trust`. See https://mise.jdx.dev/cli/trust.html for more information.

cargo clippy

➜  amazon-q-developer-cli git:(preserve-indentation-markdown-disabled) ✗ cargo clippy
   Compiling chat_cli v1.16.3 (/Users/pmunot/stuff/amazon-q-developer-cli/crates/chat-cli)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 11.78s
mise WARN  Config files in ~/stuff/amazon-q-developer-cli/.mise.toml are not trusted.
Trust them with `mise trust`. See https://mise.jdx.dev/cli/trust.html for more information.

cargo +nightly fmt

➜  amazon-q-developer-cli git:(preserve-indentation-markdown-disabled) ✗ cargo +nightly fmt
mise WARN  Config files in ~/stuff/amazon-q-developer-cli/.mise.toml are not trusted.
Trust them with `mise trust`. See https://mise.jdx.dev/cli/trust.html for more information.

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