tree-sitter-grammars / tree-sitter-odin

Odin grammar for tree-sitter
MIT License
17 stars 4 forks source link

Weird highlighting of fields #5

Closed Mavigno42 closed 11 months ago

Mavigno42 commented 11 months ago

Some fields are getting randomly highlighted. I say randomly because I couldn't make any sense of the pattern.

It seems to me that the cause for the bug is the way how I format my code. By putting the '{' on the same line as the procedure declaration the problem disappears,

Another way I've found that eliminates the problems is putting a semicolon at the end of the first line with a field highlighted with the white color, by doing that the following lines of the procedure would get fixed. Putting the semicolon at the end of line with a red highlighted field doesn`t do anything.

The code is from the Odin's Idiomatic Examples collection and it can be found here. All images presents valid Odin code.

amaanq commented 11 months ago

When reporting parse errors, please post the code as text as well.

If there is no parse error and it's a highlight error - please report it to nvim-treesitter

Mavigno42 commented 11 months ago

I must say that the apparent random highlighting stopped happening after I've updated the Treesitter Plugin, but accordingly to TSPlayground lowering the brace does still introduces some parsing errors. I've also added some more information I case it's needed, sorry for not posting the code at first.

The Code

package main

/*******************************************************************************************
*
*   raylib - classic game: tetroid
*
*   Sample game developed by Marc Palau and Ramon Santamaria
*
*   This game has been created using raylib v1.3 (www.raylib.com)
*   raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
*  Translation from https://github.com/raysan5/raylib-games/blob/master/classics/src/tetris.c to Odin
*
*   Copyright (c) 2015 Ramon Santamaria (@raysan5)
*   Copyright (c) 2021 Ginger Bill
*
********************************************************************************************/

import ray "vendor:raylib"

SQUARE_SIZE             :: 20

GRID_HORIZONTAL_SIZE    :: 12
GRID_VERTICAL_SIZE      :: 20

LATERAL_SPEED           :: 10
TURNING_SPEED           :: 12
FAST_FALL_AWAIT_COUNTER :: 30

FADING_TIME             :: 33

SCREEN_WIDTH            :: 800
SCREEN_HEIGHT           :: 450

Grid_Square :: enum u8
{
    Empty,
    Moving,
    Full,
    Block,
    Fading,
}

game_over := false
pause := false

grid:           [GRID_HORIZONTAL_SIZE][GRID_VERTICAL_SIZE]Grid_Square
piece:          [4][4]Grid_Square
incoming_piece: [4][4]Grid_Square

piece_position: [2]i32

fading_color:   ray.Color

begin_play := true
piece_active := false
detection := false
line_to_delete := false

level := 1
lines := 0

gravity_movement_counter := 0
lateral_movement_counter := 0
turn_movement_counter := 0
fast_fall_movement_counter := 0

fade_line_counter := 0

inverse_gravity_speed := 30

main :: proc()
{
    ray.InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Tetroid")
    defer ray.CloseWindow()

    init_game()

    ray.SetTargetFPS(60)

    for !ray.WindowShouldClose() // Detect window close button or ESC key
    {
        // update_game()
        // draw_game()
    }
}

init_game :: proc() {
    level = 1
    lines = 0

    fading_color = ray.GRAY

    piece_position = {0, 0}

    pause = false

    begin_play      = true
    piece_active    = false
    detection       = false
    line_to_delete  = false

    // Counters
    gravity_movement_counter = 0
    lateral_movement_counter = 0
    turn_movement_counter = 0
    fast_fall_movement_counter = 0
    fade_line_counter = 0
}

Output of :checkhealth nvim-treesitter

==============================================================================
nvim-treesitter: require("nvim-treesitter.health").check()

Installation ~
- WARNING `tree-sitter` executable not found (parser generator, only needed for :TSInstallFromGrammar, not required for :TSInstall)
- WARNING `node` executable not found (only needed for :TSInstallFromGrammar, not required for :TSInstall)
- OK `git` executable found.
- OK `gcc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
  Version: gcc.exe (MinGW-W64 x86_64-posix-seh, built by Brecht Sanders) 11.2.0
- OK Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI.

OS Info:
{
  machine = "x86_64",
  release = "10.0.22621",
  sysname = "Windows_NT",
  version = "Windows 11 Pro"
} ~

Parser/Features         H L F I J
  - c                   ✓ ✓ ✓ ✓ ✓
  - cpp                 ✓ ✓ ✓ ✓ ✓
  - go                  ✓ ✓ ✓ ✓ ✓
  - lua                 ✓ ✓ ✓ ✓ ✓
  - odin                ✓ ✓ ✓ ✓ ✓
  - python              ✓ ✓ ✓ ✓ ✓
  - rust                ✓ ✓ ✓ ✓ ✓
  - vim                 ✓ ✓ ✓ . ✓
  - vimdoc              ✓ . . . ✓
  - zig                 ✓ . ✓ ✓ ✓

  Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
         +) multiple parsers found, only one will be used
         x) errors found in the query, try to run :TSUpdate {lang} ~

Output of nvim --version

NVIM v0.9.2
Build type: RelWithDebInfo
LuaJIT 2.1.1694082368
Compilation: C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe /MD /Zi /O2 /Ob1  -W3 -wd4311 -wd4146 -DUNIT_TESTING -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE -D_WIN32_WINNT=0x0602 -DMSWIN -DINCLUDE_GENERATED_DECLARATIONS -ID:/a/neovim/neovim/.deps/usr/include/luajit-2.1 -ID:/a/neovim/neovim/.deps/usr/include -ID:/a/neovim/neovim/.deps/usr/include -ID:/a/neovim/neovim/build/src/nvim/auto -ID:/a/neovim/neovim/build/include -ID:/a/neovim/neovim/build/cmake.config -ID:/a/neovim/neovim/src -ID:/a/neovim/neovim/.deps/usr/include -ID:/a/neovim/neovim/.deps/usr/include -ID:/a/neovim/neovim/.deps/usr/include -ID:/a/neovim/neovim/.deps/usr/include -ID:/a/neovim/neovim/.deps/usr/include -ID:/a/neovim/neovim/.deps/usr/include -ID:/a/neovim/neovim/.deps/usr/include

    arquivo vimrc de sistema: "$VIM\sysinit.vim"
            padrão para $VIM: "C:/Program Files (x86)/nvim/share/nvim"

Run :checkhealth for more info

Additional content

Some of the TSPlayground output showing the parsing error.

amaanq commented 11 months ago

Alright I haven't touched Odin in a while - in init_game:

init_game :: proc() {
    level = 1
    lines = 0

    fading_color = ray.GRAY

    piece_position = {0, 0}

    pause = false

    begin_play      = true
    piece_active    = false
    detection       = false
    line_to_delete  = false

    // Counters
    gravity_movement_counter = 0
    lateral_movement_counter = 0
    turn_movement_counter = 0
    fast_fall_movement_counter = 0
    fade_line_counter = 0
}

Is this a struct literal with fields or a block of statements? The fix that I saw was to not create a separator node before a { on a newline and treat it as a block

Nvm looked at the linked repo code - it's a block