Packages icon indicating copy to clipboard operation
Packages copied to clipboard

[Go] Support Go2

Open levonet opened this issue 5 years ago • 7 comments

To this day, .go2 extensions are already used by golang developers and communities who test go2. For example: https://go-review.googlesource.com/c/go/+/187317

~~There doesn't seem to be a syntax highlighting difference between go1 and go2.~~

~~If necessary, here is a little more information about .go2 extension.~~ ~~https://github.com/golang/go/blob/dev.go2go/README.go2go.md~~

Upd: Go 2 Draft Designs

Error Handling check/handlecoming soon

Draft spec. Example:

func printSum(a, b string) error {
    handle err {
        return err
    }
    x := check strconv.Atoi(a)
    y := check strconv.Atoi(b)
    fmt.Println("result:", x + y)
    return nil
}

Generics — already available

Draft Design High level overview:

  • Functions can have an additional type parameter list introduced by the keyword type: func F(type T)(p T) { ... }.
  • These type parameters can be used by the regular parameters and in the function body.
  • Types can also have a type parameter list: type M(type T) []T.
  • Each type parameter can have an optional type constraint: func F(type T Constraint)(p T) { ... }
  • Type constraints are interface types.
  • Interface types used as type constraints can have a list of predeclared types; only types whose underlying type is one of those types can implement the interface.
  • Using a generic function or type requires passing type arguments.
  • Type inference permits omitting the type arguments in common cases.
  • If a type parameter has a type constraint its type argument must implement the interface.
  • Generic functions may only use operations permitted by the type constraint.

  • Sublime Version:
  • OS Version: *

levonet avatar Jun 28 '20 12:06 levonet

If you want syntax highlighting for .go2 files, what you can do is create a file by the name of Go.sublime-settings (this is the syntax specific setting file for Go) in the User directory and paste the following :-

// These settings override both User and Default settings for the Go syntax
{
	"hidden_extensions":
	[
		"go2"
	],
}

You should now have syntax highlighting for .go2 files as well.

The other way would be to send a PR to the syntax file for Go, adding support for file extension for .go2 like :-

file_extensions:
  - go
  - go2

and hope that it get's merged.

(Assuming .go & .go2 both refer to the Go language)

UltraInstinct05 avatar Jun 28 '20 13:06 UltraInstinct05

From what I understand go2 is supposed to offer generics. I don't think the current syntax handles that.

https://go.googlesource.com/proposal/+/refs/heads/master/design/go2draft-type-parameters.md

rwols avatar Jun 28 '20 13:06 rwols

Go.sublime-settings with

{
	"hidden_extensions":
	[
		"go2"
	],
}

works for me.

levonet avatar Jun 28 '20 14:06 levonet

The point made by rwols is a valid one. If .go2 contains any experimental language features, the syntax highlighting might not work properly.

UltraInstinct05 avatar Jun 28 '20 15:06 UltraInstinct05

I discourage anyone from using hidden_extensions unless they know what they are doing, because integration in ST for that is limited. Instead, use just extensions with the same value. The same result can also be achieved by opening a .go2 file and selecting View -> Syntax -> Open all with current extension as… -> Go.

FichteFoll avatar Jul 03 '20 23:07 FichteFoll

If you can elaborate a bit more on why hidden_extensions is discouraged, it'd be more helpful. What is meant by this ?

integration in ST for that is limited

Does that mean not every syntax specific setting file can have hidden_extensions as a setting ?

UltraInstinct05 avatar Jul 04 '20 13:07 UltraInstinct05

@Ultra-Instinct-05 See https://github.com/sublimehq/sublime_text/issues/1326

michaelblyons avatar Jul 05 '20 02:07 michaelblyons