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

[1.0] Coloring for various visibility levels #1241

Closed
dlsniper opened this issue Feb 3, 2015 · 9 comments
Closed

[1.0] Coloring for various visibility levels #1241

dlsniper opened this issue Feb 3, 2015 · 9 comments
Assignees
Labels
Milestone

Comments

@dlsniper
Copy link
Member

dlsniper commented Feb 3, 2015

Hi,

Based on the discussion from #1211, I've created this ticket so we can keep track of the various coloring progress:

  • package.Var1 -> Var1 is a package Exported variable
  • package.var2 -> var2 is a package Private variable
  • struct.Var3 -> Var3 is a struct Exported variable
  • struct.var4 -> var4 is a struct Private variable
  • func(){ var var5, var Var6 } -> var5 and Var6 are Local variables
  • package.Const1 -> Const1 is a package Exported constant
  • package.const2 -> const2 is a package Private constant
  • func(){ const const3, const const4 } -> const4 and Const5 are Local constants
  • package.Func1() -> Func1() is a package Exported function
  • package.func2() -> func2() is a package Private function
  • interface.Func3() -> Func3() is a struct Exported function
  • interface.func4() -> func4() is a struct Private function.
  • variable redefined by usage in if statement (which makes it local to the if statement)

As a code sample, we could use this:

package demo

type (
    PublicInterface interface {
        PublicFunc() int
        privateFunc() int
    }

    private interface {
        PublicFunc() int
        privateFunc() int
    }

    PublicStruct struct {
        PublicField  int
        privateField int
    }

    privateStruct struct {
        PublicField  int
        privateField int
    }
)

const (
    PublicConst  = 1
    privateConst = 2
)

var (
    PublicVar  = 1
    privateVar = 2
)

func PublicFunc() int {
    const LocalConst = 1
    localVar := PublicVar
    return localVar
}

func privateFunc() int {
    const localConst = 2
    LocalVar := privateVar
    return LocalVar
}

func (ps PublicStruct) PublicFunc() int {
    return ps.privateField
}

func (ps PublicStruct) privateFunc() {
    return ps.PublicField
}

func (ps privateStruct) PublicFunc() int {
    return ps.privateField
}

func (ps privateStruct) privateFunc() {
    return ps.PublicField
}

func variableFunc() {
    var demo1 int
    demo1 = 3

    if demo1 := privateFunc(); demo1 != 3 {
        _ = demo1
        return
    }

    _ = demo1
}
@dlsniper dlsniper added this to the 1.0.0 milestone Feb 3, 2015
@dlsniper
Copy link
Member Author

dlsniper commented Feb 3, 2015

@dmitry-vovk did I miss anything in the example?

@dlsniper
Copy link
Member Author

dlsniper commented Feb 3, 2015

updated example w/ all listed use-cases.

@dmytro-vovk
Copy link

How about adding function argument(s) coloring?

@dlsniper
Copy link
Member Author

dlsniper commented Feb 3, 2015

Maybe those should be considered as local variables? Since they are defined in the local scope of the function. Different colors for pointers vs non-pointers would be better I think, no?

@dlsniper
Copy link
Member Author

dlsniper commented Feb 3, 2015

I've added variable redefined in if statements example, which can be a good case of headaches.

@ignatov
Copy link
Contributor

ignatov commented Feb 3, 2015

BTW, it's a good ticket for a PR, so any help is welcome and feel free to ask me about some internal stuff.

@dlsniper
Copy link
Member Author

dlsniper commented Feb 3, 2015

I've looked over e47bebd#diff-c0610615a0aedbe9e98e368d6ace7869R60 and abfba5f and indeed it seems pretty straight forward to do it, I'll see if I can manage the time to get this done (if not one else does it before me)

@dmytro-vovk
Copy link

@dlsniper Having function arguments colored differently is as helpful as having global and local. I rely on that in JavaScript and PHP code. It really helps.

See screenshot for PHP sample:
screenshot - 030215 - 18 32 37 crop
Here you can see see three different variables having the word "package" in it, $packageId, $package, and $packages. Coloring arguments differently makes life easier.

@ignatov
Copy link
Contributor

ignatov commented Feb 8, 2015

Relates to #1257

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants