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

Bad indent for anonymous field types with trailing comma #42

Open
yohannd1 opened this issue Feb 23, 2021 · 0 comments
Open

Bad indent for anonymous field types with trailing comma #42

yohannd1 opened this issue Feb 23, 2021 · 0 comments

Comments

@yohannd1
Copy link
Contributor

yohannd1 commented Feb 23, 2021

Before anything, a minimal vimrc:

set nocompatible
" set runtimepath^=/path/to/zig.vim
syntax on
filetype plugin indent on

And my neovim version:

$ nvim --version
NVIM v0.4.4
Build type: Release
LuaJIT 2.0.5
Compilation: /usr/bin/cc -D_FORTIFY_SOURCE=2 -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -O2 -DNDEBUG -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -I/build/neovim/src/build/config -I/build/neovim/src/neovim-0.4.4/src -I/usr/include -I/build/neovim/src/build/src/nvim/auto -I/build/neovim/src/build/include
Compiled by builduser

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info

Here we have a struct declaration, with one of the fields being of type <anonymous enum>.

pub const St = struct {
    anon_field: enum {
    },
};

For some strange reason, this specific example doesn't indent properly.
If indenting the line with the }, in it (using ==), it becomes:

pub const St = struct {
    anon_field: enum {
},
};

That doesn't happen, though, if there is any non-empty line between the opening and closing brackets of the enum declaration:

pub const St = struct {
    anon_field: enum {
        some_field
    }, // indents properly
};

Some other situations:

// if there is no trailing comma, it indents properly
pub const St = struct {
    anon_field: enum {
        some_field
    }
};

// if there is any character other than a comma after the line, it also indents properly
pub const St = struct {
    anon_field: enum {
    }, // this comment prevents the indent problem
};
pub const St = struct {
    anon_field: enum {
    }, 
    // (there's a trailing whitespace on the line above)
};

// empty lines do not solve the problem
pub const St = struct {
    anon_field: enum {

},
};

// identifiers that are on the same line as the opening bracket do not solve the issue either.
pub const St = struct {
    anon_field: enum { foo, bar
},
};
pub const St = struct {
    anon_field: enum { foo, bar,
        a // it solved with this one here, though
    },
};

// it also happens with `struct` and any other type. The problem seems to be on the brackets themselves.
pub const St = struct {
    anon_field: struct {
},
};
pub const St = struct {
    anon_field: union(enum) {
},
};
pub const St = struct {
    anon_field: {
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant