Sarrus1 / sourcepawn-studio

VSCode extension for SourcePawn scripting
https://sarrus1.github.io/sourcepawn-studio/
MIT License
145 stars 23 forks source link

methodmap and enum struct syntax are not formatted correctly #397

Open KashimuraBaka opened 4 months ago

KashimuraBaka commented 4 months ago

Basic informations

Code to reproduce the behaviour

I tried to add a function using methodmap and enum struct.

enum struct TestStruct
{
    int a;
    int aa;
    int aaa;

    /**
     * init
     * @noreturn
     */
    void Init()
    {
        this.a = 1;
        this.aa = 2;
        this.aaa = 3;
    }

    /**
     * calc
     * @return
     */
    int Calc()
    {
        return this.a + this.aa + this.aaa;
    }
}   

methodmap TestMethodmap {

    public TestMethodmap(int a) {
        return view_as<TestMethodmap>(a);
    }

    /**
     * test
     * @return
     */
    public int test() {
        return view_as<int>(this);
    }
}

Incorrect typography after formatting with formatter, it doesn't work very well.

enum struct TestStruct
{
    int  a;
    int  aa;
    int  aaa;

    /**
     * init
     * @noreturn
     */
    void Init(){
        this.a   = 1;
        this.aa  = 2;
        this.aaa = 3; }

/**
 * calc
 * @return
 */
int Calc()
{
    return this.a + this.aa + this.aaa;
}
}

methodmap TestMethodmap
{

public  TestMethodmap(int a)
    {
        return view_as<TestMethodmap>(a);
    }

    /**
     * test
     * @return
     */
public  int test()
    {
        return view_as<int>(this);
    }
}

Is there any way to keep methopmap and enum struct from being formatted by formatter? Thanks for the reply!

Sarrus1 commented 4 months ago

Hi! Thanks for reporting this, the formatter uses clang-formar under the hood, and sadly it works really bad with enum structs :/

I'm looking for a way to make it better, but it will probably involve editing clang-format itself.