Skip to content

would like to show syntax errors inline with the text #56

Open

Description

@csells

When there are syntax errors, I'd like to be able to show the red squiggles and provide a tooltip over the code with the error message.

This editor is so close to being useful for read code; this feature puts it over the edge!

Activity

  1. added
    enhancement
    on Dec 4, 2024
  2. hommes-doutant commented on Mar 19, 2025

    @hommes-doutant

    The CodeLineEditingController has a spanBuilder parameter that allow you to do just that.

    You just have to build your syntax checker, and using the span builder you can add the red squiggles.

    https://pub.dev/documentation/re_editor/latest/re_editor/CodeLineSpanBuilder.html

  3. LUK3D commented on Mar 19, 2025

    @LUK3D

    I tried to do it this way, but its not showing the TextSpan inside the code editor:

    Image

  4. hommes-doutant commented on Mar 19, 2025

    @hommes-doutant

    It's because it is not used in that way. Here's a small guide :

    1. You set your function as the parameter of the CodeLineEditingController when creating it. And it runs it everytime something changes.
    final controller = CodeLineEditingController(
            codeLines: isEmpty ? 
                CodeLines.fromText('') : 
                CodeLines.fromText(content),
            spanBuilder: _buildSpan, // Add span builder here
          );
    1. You create your buildspan function with the same signature as the doc and return a textspan
    TextSpan _buildSpan({
        required CodeLine codeLine,
        required BuildContext context,
        required int index,
        required TextStyle style,
        required TextSpan textSpan,
      }) {
        final spans = <TextSpan>[];
            spans.add(TextSpan(
              text: text[highlightIndex],
              style: spanStyle.copyWith(
                backgroundColor: Colors.yellow.withOpacity(0.3),
                fontWeight: FontWeight.bold,
              ),
            ));
        return TextSpan(children: spans.isNotEmpty ? spans : [textSpan], style: style);
      }

    P.S. I haven't tested it for syntax error, I've stripped a function from my code since there was a lot of other functions involved. But it should highlight every line in yellow, while keeping syntax highlighting intact.

    If you want to implement the method is to check the position of the characters you want to modify, iterate over the whole text to find them, split their current textspan, change the style, and put everything back together.

  5. csells commented on Mar 23, 2025

    @csells
    Author

    Do you have an example with a syntax checker using LSP?

  6. MegatronKing commented on Mar 23, 2025

    @MegatronKing
    Member

    Do you have an example with a syntax checker using LSP?

    Sorry, there is no need for code syntax analysis in my project. I think you can launch a LSP server, input the code, and build a custom TextSpan after getting the result, ref to #56 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions