Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect bracket matching and broken syntax highlighting with this chunk of C code #5177

Closed
creikey opened this issue Dec 15, 2022 · 3 comments · Fixed by #7242
Closed

Incorrect bracket matching and broken syntax highlighting with this chunk of C code #5177

creikey opened this issue Dec 15, 2022 · 3 comments · Fixed by #7242
Labels
A-language-support Area: Support for programming/text languages C-bug Category: This is a bug upstream

Comments

@creikey
Copy link

creikey commented Dec 15, 2022

Summary

Typing mm to go to matching bracket on the top bracket goes to the wrong one, and fiddeling with the file changing the grammar of things (e.g transform_scope => transform_scope()) fixes it. So does removing any line inside of the pipeline_scope.

When the highlighting on the outermost scope is colored blue as in the first screenshot:
image

That means it's broken as seen in the incorrectly highlighted bracket, and when it's green that means it's working as shown below:
image

Reproduction Steps

Open helix and paste this buffer of C code into the file, saving it as tmp.c or something so it recognizes it as C:

{
  transform_scope
  {
    pipeline_scope(goodpixel_pipeline)
    {
      sgp_set_image(0, image_rightclick);
      cpVect draw_at = cpvadd(entity_pos(b), cpv(BOX_SIZE, 0));
      rotate_at(-entity_rotation(b) - rotangle(b->compass_rotation), draw_at.x, draw_at.y);
      draw_texture_centered(draw_at, BOX_SIZE + sin(exec_time * 5.0) * BOX_SIZE * 0.1);
      sgp_reset_image(0);
    }
  }
}

Helix log

~/.cache/helix/helix.log
2022-12-15T14:05:58.168 helix_lsp::transport [ERROR] err <- "I[14:05:58.168] --> reply:textDocument/signatureHelp(25) 18 ms\r\n"
2022-12-15T14:05:58.205 helix_lsp::transport [ERROR] err <- "I[14:05:58.205] ASTWorker building file C:\\Users\\Cameron\\Documents\\flight\\tmp.c version 75 with command inferred from C:/Users/Cameron/Documents/flight/thirdparty/enet/callbacks.c\r\n"
2022-12-15T14:05:58.205 helix_lsp::transport [ERROR] err <- "[C:/Users/Cameron/Documents/flight/]\r\n"
2022-12-15T14:05:58.205 helix_lsp::transport [ERROR] err <- "\"C:\\\\Users\\\\Cameron\\\\AppData\\\\Roaming\\\\ClangPowerTools\\\\LLVM_Lite\\\\Bin\\\\clang++.exe\" --driver-mode=g++ -Wall -fms-compatibility-version=19.10 -Wmicrosoft -Wno-invalid-token-paste -Wno-unknown-pragmas -Wno-unused-value -fsyntax-only -DUNICODE -D_UNICODE -D_MT -D_DEBUG -DDEBUG -D_CONSOLE -D_DEBUG_FUNCTIONAL_MACHINERY \"-isystemC:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.33.31629/include\" \"-isystemC:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.33.31629/atlmfc/include\" \"-isystemC:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/VS/include\" \"-isystemC:/Program Files (x86)/Windows Kits/10/Include/10.0.22000.0/ucrt\" \"-isystemC:/Program Files (x86)/Windows Kits/10/Include/10.0.22000.0/um\" \"-isystemC:/Program Files (x86)/Windows Kits/10/Include/10.0.22000.0/shared\" \"-isystemC:/Program Files (x86)/Windows Kits/10/Include/10.0.22000.0/winrt\" \"-isystemC:/Program Files (x86)/Windows Kits/10/Include/10.0.22000.0/cppwinrt\" -Ithirdparty/enet/include -Ithirdparty/Chipmunk2D/include/chipmunk -Ithirdparty -Ithirdparty/Chipmunk2D/include -Ithirdparty/minilzo -Ithirdparty/opus/include \"-resource-dir=C:\\\\Users\\\\Cameron\\\\Documents\\\\lib\\\\clang\\\\15.0.3\" -- \"C:\\\\Users\\\\Cameron\\\\Documents\\\\flight\\\\tmp.c\"\r\n"
2022-12-15T14:05:58.227 helix_lsp::transport [ERROR] err <- "I[14:05:58.227] --> textDocument/publishDiagnostics\r\n"
2022-12-15T14:06:51.146 helix_lsp::transport [ERROR] err <- "I[14:06:51.146] <-- textDocument/signatureHelp(26)\r\n"
2022-12-15T14:06:51.162 helix_lsp::transport [ERROR] err <- "I[14:06:51.162] --> reply:textDocument/signatureHelp(26) 16 ms\r\n"
2022-12-15T14:06:51.296 helix_lsp::transport [ERROR] err <- "I[14:06:51.296] <-- textDocument/didChange\r\n"
2022-12-15T14:06:51.298 helix_lsp::transport [ERROR] err <- "I[14:06:51.298] <-- textDocument/signatureHelp(27)\r\n"
2022-12-15T14:06:51.314 helix_lsp::transport [ERROR] err <- "I[14:06:51.314] --> reply:textDocument/signatureHelp(27) 15 ms\r\n"
2022-12-15T14:06:51.351 helix_lsp::transport [ERROR] err <- "I[14:06:51.351] ASTWorker building file C:\\Users\\Cameron\\Documents\\flight\\tmp.c version 76 with command inferred from C:/Users/Cameron/Documents/flight/thirdparty/enet/callbacks.c\r\n"
2022-12-15T14:06:51.351 helix_lsp::transport [ERROR] err <- "[C:/Users/Cameron/Documents/flight/]\r\n"
2022-12-15T14:06:51.351 helix_lsp::transport [ERROR] err <- "\"C:\\\\Users\\\\Cameron\\\\AppData\\\\Roaming\\\\ClangPowerTools\\\\LLVM_Lite\\\\Bin\\\\clang++.exe\" --driver-mode=g++ -Wall -fms-compatibility-version=19.10 -Wmicrosoft -Wno-invalid-token-paste -Wno-unknown-pragmas -Wno-unused-value -fsyntax-only -DUNICODE -D_UNICODE -D_MT -D_DEBUG -DDEBUG -D_CONSOLE -D_DEBUG_FUNCTIONAL_MACHINERY \"-isystemC:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.33.31629/include\" \"-isystemC:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.33.31629/atlmfc/include\" \"-isystemC:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/VS/include\" \"-isystemC:/Program Files (x86)/Windows Kits/10/Include/10.0.22000.0/ucrt\" \"-isystemC:/Program Files (x86)/Windows Kits/10/Include/10.0.22000.0/um\" \"-isystemC:/Program Files (x86)/Windows Kits/10/Include/10.0.22000.0/shared\" \"-isystemC:/Program Files (x86)/Windows Kits/10/Include/10.0.22000.0/winrt\" \"-isystemC:/Program Files (x86)/Windows Kits/10/Include/10.0.22000.0/cppwinrt\" -Ithirdparty/enet/include -Ithirdparty/Chipmunk2D/include/chipmunk -Ithirdparty -Ithirdparty/Chipmunk2D/include -Ithirdparty/minilzo -Ithirdparty/opus/include \"-resource-dir=C:\\\\Users\\\\Cameron\\\\Documents\\\\lib\\\\clang\\\\15.0.3\" -- \"C:\\\\Users\\\\Cameron\\\\Documents\\\\flight\\\\tmp.c\"\r\n"
2022-12-15T14:06:51.354 helix_lsp::transport [ERROR] err <- "I[14:06:51.354] <-- textDocument/signatureHelp(28)\r\n"

Platform

Windows

Terminal Emulator

Windows Terminal

Helix Version

22.12-47-g4acdc03b

@creikey creikey added the C-bug Category: This is a bug label Dec 15, 2022
@creikey creikey changed the title Incorrect bracket matching and broken syntax highlighting with this chunk of C text Incorrect bracket matching and broken syntax highlighting with this chunk of C code Dec 15, 2022
@the-mikedavis the-mikedavis added upstream A-language-support Area: Support for programming/text languages labels Dec 15, 2022
@the-mikedavis
Copy link
Member

The highlighting and bracket matching breaks because tree-sitter-c fails to parse it successfully.

You can see the error nodes in this run of tree-sitter parse...
$ tree-sitter parse tmp.c
(translation_unit [0, 0] - [14, 0]
  (compound_statement [0, 0] - [11, 3]
    (function_definition [1, 2] - [10, 5]
      type: (type_identifier [1, 2] - [1, 17])
      (ERROR [2, 2] - [2, 3])
      declarator: (function_declarator [3, 4] - [3, 38]
        declarator: (identifier [3, 4] - [3, 18])
        parameters: (parameter_list [3, 18] - [3, 38]
          (parameter_declaration [3, 19] - [3, 37]
            type: (type_identifier [3, 19] - [3, 37]))))
      body: (compound_statement [4, 4] - [10, 5]
        (expression_statement [5, 6] - [5, 41]
          (call_expression [5, 6] - [5, 40]
            function: (identifier [5, 6] - [5, 19])
            arguments: (argument_list [5, 19] - [5, 40]
              (number_literal [5, 20] - [5, 21])
              (identifier [5, 23] - [5, 39]))))
        (declaration [6, 6] - [6, 63]
          type: (type_identifier [6, 6] - [6, 12])
          declarator: (init_declarator [6, 13] - [6, 62]
            declarator: (identifier [6, 13] - [6, 20])
            value: (call_expression [6, 23] - [6, 62]
              function: (identifier [6, 23] - [6, 29])
              arguments: (argument_list [6, 29] - [6, 62]
                (call_expression [6, 30] - [6, 43]
                  function: (identifier [6, 30] - [6, 40])
                  arguments: (argument_list [6, 40] - [6, 43]
                    (identifier [6, 41] - [6, 42])))
                (call_expression [6, 45] - [6, 61]
                  function: (identifier [6, 45] - [6, 48])
                  arguments: (argument_list [6, 48] - [6, 61]
                    (identifier [6, 49] - [6, 57])
                    (number_literal [6, 59] - [6, 60])))))))
        (expression_statement [7, 6] - [7, 91]
          (call_expression [7, 6] - [7, 90]
            function: (identifier [7, 6] - [7, 15])
            arguments: (argument_list [7, 15] - [7, 90]
              (binary_expression [7, 16] - [7, 67]
                left: (unary_expression [7, 16] - [7, 35]
                  argument: (call_expression [7, 17] - [7, 35]
                    function: (identifier [7, 17] - [7, 32])
                    arguments: (argument_list [7, 32] - [7, 35]
                      (identifier [7, 33] - [7, 34]))))
                right: (call_expression [7, 38] - [7, 67]
                  function: (identifier [7, 38] - [7, 46])
                  arguments: (argument_list [7, 46] - [7, 67]
                    (field_expression [7, 47] - [7, 66]
                      argument: (identifier [7, 47] - [7, 48])
                      field: (field_identifier [7, 50] - [7, 66])))))
              (field_expression [7, 69] - [7, 78]
                argument: (identifier [7, 69] - [7, 76])
                field: (field_identifier [7, 77] - [7, 78]))
              (field_expression [7, 80] - [7, 89]
                argument: (identifier [7, 80] - [7, 87])
                field: (field_identifier [7, 88] - [7, 89])))))
        (expression_statement [8, 6] - [8, 87]
          (call_expression [8, 6] - [8, 86]
            function: (identifier [8, 6] - [8, 27])
            arguments: (argument_list [8, 27] - [8, 86]
              (identifier [8, 28] - [8, 35])
              (binary_expression [8, 37] - [8, 85]
                left: (identifier [8, 37] - [8, 45])
                right: (binary_expression [8, 48] - [8, 85]
                  left: (binary_expression [8, 48] - [8, 79]
                    left: (call_expression [8, 48] - [8, 68]
                      function: (identifier [8, 48] - [8, 51])
                      arguments: (argument_list [8, 51] - [8, 68]
                        (binary_expression [8, 52] - [8, 67]
                          left: (identifier [8, 52] - [8, 61])
                          right: (number_literal [8, 64] - [8, 67]))))
                    right: (identifier [8, 71] - [8, 79]))
                  right: (number_literal [8, 82] - [8, 85]))))))
        (expression_statement [9, 6] - [9, 25]
          (call_expression [9, 6] - [9, 24]
            function: (identifier [9, 6] - [9, 21])
            arguments: (argument_list [9, 21] - [9, 24]
              (number_literal [9, 22] - [9, 23])))))))
  (ERROR [12, 0] - [12, 1]))
tmp.c	0 ms	(ERROR [2, 2] - [2, 3])

or select that text and use :tree-sitter-subtree within Helix.

@creikey
Copy link
Author

creikey commented Dec 15, 2022

Makes sense. That repository seems largely unmaintained, unfortunate! I will have to look into fixing it myself if I want this then. Thanks for the link

@theteachr
Copy link
Contributor

I'm seeing this in Python. The incorrectness can be seen right from the highlighted matched bracket.

wrong_matching_brackets.mov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-language-support Area: Support for programming/text languages C-bug Category: This is a bug upstream
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants