From 4a4d0efe89a29f3902a3e4259d1dd31ddc0903ff Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Mon, 29 May 2023 11:43:50 -0700 Subject: [PATCH] aider: Replaced `MarkdownLexer` with `PygmentsLexer` to correctly highlight user input with markdown syntax. # Context: USER: AttributeError: 'MarkdownLexer' object has no attribute 'lex_document' ASSISTANT: I apologize for the confusion. It seems I misunderstood the usage of `MarkdownLexer` with `prompt_toolkit`. Instead, we should use `PygmentsLexer` from `prompt_toolkit.lexers` to wrap the `MarkdownLexer`. Here's the updated change: First, import `PygmentsLexer` from `prompt_toolkit.lexers`: ```python aider/io.py <<<<<<< ORIGINAL from prompt_toolkit.completion import Completer, Completion ======= from prompt_toolkit.completion import Completer, Completion from prompt_toolkit.lexers import PygmentsLexer >>>>>>> UPDATED ``` Then, update the `PromptSession` instantiation in the `get_input` method: ```python aider/io.py <<<<<<< ORIGINAL session_kwargs = { "message": show, "completer": completer_instance, "reserve_space_for_menu": 4, "complete_style": CompleteStyle.MULTI_COLUMN, "input": self.input, "output": self.output, "lexer": MarkdownLexer(), } ======= session_kwargs = { "message": show, "completer": completer_instance, "reserve_space_for_menu": 4, "complete_style": CompleteStyle.MULTI_COLUMN, "input": self.input, "output": self.output, "lexer": PygmentsLexer(MarkdownLexer), } >>>>>>> UPDATED ``` These changes will correctly use the `MarkdownLexer` with `prompt_toolkit` to highlight the user input with markdown syntax. --- aider/io.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/aider/io.py b/aider/io.py index f4de29a79..fc4f32ad5 100644 --- a/aider/io.py +++ b/aider/io.py @@ -5,6 +5,7 @@ from datetime import datetime from pathlib import Path from prompt_toolkit.completion import Completer, Completion +from prompt_toolkit.lexers import PygmentsLexer from prompt_toolkit.history import FileHistory from prompt_toolkit.shortcuts import CompleteStyle, PromptSession, prompt from prompt_toolkit.styles import Style @@ -148,7 +149,7 @@ class InputOutput: "complete_style": CompleteStyle.MULTI_COLUMN, "input": self.input, "output": self.output, - "lexer": MarkdownLexer(), + "lexer": PygmentsLexer(MarkdownLexer), } if style: session_kwargs["style"] = style