yetone/avante.nvim

bug: markdown search and replace code suggestions break when the suggestion contains a code block.

Opened this issue · 0 comments

Describe the bug

While working with a markdown file, the LLM output rendering tends to break when suggesting search/replace blocks that contain code examples such as bash.

This is due to the output not being valid markdown being formatted like this:

```markdown
some text here
```bash
cd ~
```
```

The code suggestions also break as inner markdown code blocks are incorrectly detected as apply able to the current buffer.
image

I have been able to work around this bug by asking the LLM to use ~~~ rather than ` when rendering code blocks.
image

To reproduce

Sample output when working with a markdown file.

---

- Datetime: 2024-11-11 09:16:33

- Model: cody/anthropic/claude-3-5-sonnet-20240620

> improve this markdown with better code examples. change all text to lorelipsum.

Certainly! I'll improve the markdown with better code examples and change all the text to Lorem Ipsum. I'll use *SEARCH/REPLACE* blocks to make these changes. Here's how we'll modify the `readme-9.md` file:

readme-9.md
Replace lines: 1-24
```markdown
# Lorem Ipsum Service

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam euismod, nisi vel consectetur interdum, nisl nunc egestas nunc, vitae tincidunt nisl nunc euismod nunc.

## Exemplum Primum

### Python Example
```python
def lorem_ipsum_generator(words=100):
    lorem_ipsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
    return " ".join([lorem_ipsum for _ in range(words)])[:words * 6].strip() + "."

print(lorem_ipsum_generator(50))
```

## Exemplum Secundum

### JavaScript Example
```javascript
function loremIpsumGenerator(words = 100) {
    const loremIpsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. ";
    return loremIpsum.repeat(words).split(' ').slice(0, words).join(' ') + '.';
}

console.log(loremIpsumGenerator(50));
```

## Exemplum Tertium

### Go Example
```go
package main

import (
    "fmt"
    "strings"
)

func loremIpsumGenerator(words int) string {
    loremIpsum := "Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
    repeated := strings.Repeat(loremIpsum, words)
    return strings.Join(strings.Fields(repeated)[:words], " ") + "."
}

func main() {
    fmt.Println(loremIpsumGenerator(50))
}
```

Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
```

This improved markdown includes:

1. A main title using Lorem Ipsum.
2. An introductory paragraph in Lorem Ipsum.
3. Three sections with different programming language examples (Python, JavaScript, and Go), each generating Lorem Ipsum text.
4. A concluding paragraph in Lorem Ipsum.

The code examples are more substantial and relevant to the Lorem Ipsum theme, demonstrating simple Lorem Ipsum generators in each language. The structure is cleaner and more organized, with proper markdown formatting for headers and code blocks.

**Generation complete!** Please review the code suggestions above.

Expected behavior

LLM output buffer should contain valid markdown output.

Code blocks rendered inside of markdown should not have the apply hint text added to them on hover. only the parent.

Installation method

Use lazy.nvim:

{
  "yetone/avante.nvim",
  event = "VeryLazy",
  lazy = false,
  version = false, -- set this if you want to always pull the latest change
  opts = {
    -- add any opts here
  },
  -- if you want to build from source then do `make BUILD_FROM_SOURCE=true`
  build = "make",
  -- build = "powershell -ExecutionPolicy Bypass -File Build.ps1 -BuildFromSource false" -- for windows
  dependencies = {
    "nvim-treesitter/nvim-treesitter",
    "stevearc/dressing.nvim",
    "nvim-lua/plenary.nvim",
    "MunifTanjim/nui.nvim",
  },
}

Environment

nvim -v

NVIM v0.10.2
Build type: Release
LuaJIT 2.1.1727870382
Run "nvim -V1 -v" for more info

uname -a

Darwin LP4570 24.1.0 Darwin Kernel Version 24.1.0: Thu Oct 10 21:03:15 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T6000 arm64

Repro

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

require("lazy.minit").repro({
  spec = {
    -- add any other plugins here
  },
})