Skip to content
This repository has been archived by the owner on Feb 17, 2021. It is now read-only.

Commit

Permalink
Apply gofmt to all go source files.
Browse files Browse the repository at this point in the history
  • Loading branch information
nsf committed Aug 15, 2010
1 parent 9ebe4c2 commit b51bf09
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 97 deletions.
5 changes: 2 additions & 3 deletions apropos.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

type DeclApropos struct {
Decl *Decl
Decl *Decl
Partial string
}

Expand Down Expand Up @@ -137,7 +137,7 @@ func (self *AutoCompleteContext) deduceDecl(file []byte, cursor int) *DeclApropo
// we're '<whatever>.<ident>'
// parse <ident> as Partial and figure out decl
cursor = skipIdent(file, cursor)
partial := string(file[cursor+1:orig])
partial := string(file[cursor+1 : orig])
if file[cursor] == '.' {
return self.deduceExpr(file[0:cursor], partial)
} else {
Expand All @@ -148,4 +148,3 @@ func (self *AutoCompleteContext) deduceDecl(file []byte, cursor int) *DeclApropo

return &DeclApropos{nil, ""}
}

79 changes: 40 additions & 39 deletions autocompletion.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ func filePackageName(filename string) string {
type AutoCompleteContext struct {
m map[string]*Decl // all visible modules

current *PackageFile // currently editted file
others map[string]*PackageFile // other files
current *PackageFile // currently editted file
others map[string]*PackageFile // other files

mcache map[string]*ModuleCache // modules cache
pkg *Scope
uni *Scope
pkg *Scope
uni *Scope
}

func NewAutoCompleteContext() *AutoCompleteContext {
Expand Down Expand Up @@ -141,9 +141,9 @@ func (self *AutoCompleteContext) updateOtherPackageFiles() {
//-------------------------------------------------------------------------

type OutBuffers struct {
tmpbuf *bytes.Buffer
tmpbuf *bytes.Buffer
names, types, classes vector.StringVector
ctx *AutoCompleteContext
ctx *AutoCompleteContext
}

func NewOutBuffers(ctx *AutoCompleteContext) *OutBuffers {
Expand Down Expand Up @@ -444,39 +444,40 @@ func (self *AutoCompleteContext) Apropos(file []byte, filename string, cursor in
//-------------------------------------------------------------------------

type DeclSlice []*Decl

func (s DeclSlice) Less(i, j int) bool {
if declClassToString[s[i].Class][0] == declClassToString[s[j].Class][0] {
return s[i].Name < s[j].Name
}
return declClassToString[s[i].Class] < declClassToString[s[j].Class]
}
func (s DeclSlice) Len() int { return len(s) }
func (s DeclSlice) Len() int { return len(s) }
func (s DeclSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] }

const (
COLOR_red = "\033[0;31m"
COLOR_RED = "\033[1;31m"
COLOR_green = "\033[0;32m"
COLOR_GREEN = "\033[1;32m"
COLOR_yellow = "\033[0;33m"
COLOR_YELLOW = "\033[1;33m"
COLOR_blue = "\033[0;34m"
COLOR_BLUE = "\033[1;34m"
COLOR_red = "\033[0;31m"
COLOR_RED = "\033[1;31m"
COLOR_green = "\033[0;32m"
COLOR_GREEN = "\033[1;32m"
COLOR_yellow = "\033[0;33m"
COLOR_YELLOW = "\033[1;33m"
COLOR_blue = "\033[0;34m"
COLOR_BLUE = "\033[1;34m"
COLOR_magenta = "\033[0;35m"
COLOR_MAGENTA = "\033[1;35m"
COLOR_cyan = "\033[0;36m"
COLOR_CYAN = "\033[1;36m"
COLOR_white = "\033[0;37m"
COLOR_WHITE = "\033[1;37m"
NC = "\033[0m"
COLOR_cyan = "\033[0;36m"
COLOR_CYAN = "\033[1;36m"
COLOR_white = "\033[0;37m"
COLOR_WHITE = "\033[1;37m"
NC = "\033[0m"
)

var declClassToColor = [...]string{
DECL_CONST: COLOR_WHITE,
DECL_VAR: COLOR_magenta,
DECL_TYPE: COLOR_cyan,
DECL_FUNC: COLOR_green,
DECL_MODULE: COLOR_red,
DECL_CONST: COLOR_WHITE,
DECL_VAR: COLOR_magenta,
DECL_TYPE: COLOR_cyan,
DECL_FUNC: COLOR_green,
DECL_MODULE: COLOR_red,
DECL_METHODS_STUB: COLOR_red,
}

Expand Down Expand Up @@ -520,8 +521,8 @@ func (self *AutoCompleteContext) Status() string {
}
fmt.Fprintf(buf, "\nListing declarations from files:\n")

const STATUS_DECLS = "\t%s%s"+ NC +" "+ COLOR_yellow +"%s"+ NC +"\n"
const STATUS_DECLS_CHILDREN = "\t%s%s"+ NC +" "+ COLOR_yellow +"%s"+ NC +" (%d)\n"
const STATUS_DECLS = "\t%s%s" + NC + " " + COLOR_yellow + "%s" + NC + "\n"
const STATUS_DECLS_CHILDREN = "\t%s%s" + NC + " " + COLOR_yellow + "%s" + NC + " (%d)\n"
var ds DeclSlice
var i int

Expand All @@ -536,14 +537,14 @@ func (self *AutoCompleteContext) Status() string {
for _, d := range ds {
if len(d.Children) > 0 {
fmt.Fprintf(buf, STATUS_DECLS_CHILDREN,
declClassToColor[d.Class],
declClassToStringDebug[d.Class],
d.Name, len(d.Children))
declClassToColor[d.Class],
declClassToStringDebug[d.Class],
d.Name, len(d.Children))
} else {
fmt.Fprintf(buf, STATUS_DECLS,
declClassToColor[d.Class],
declClassToStringDebug[d.Class],
d.Name)
declClassToColor[d.Class],
declClassToStringDebug[d.Class],
d.Name)
}
}

Expand All @@ -559,14 +560,14 @@ func (self *AutoCompleteContext) Status() string {
for _, d := range ds {
if len(d.Children) > 0 {
fmt.Fprintf(buf, STATUS_DECLS_CHILDREN,
declClassToColor[d.Class],
declClassToStringDebug[d.Class],
d.Name, len(d.Children))
declClassToColor[d.Class],
declClassToStringDebug[d.Class],
d.Name, len(d.Children))
} else {
fmt.Fprintf(buf, STATUS_DECLS,
declClassToColor[d.Class],
declClassToStringDebug[d.Class],
d.Name)
declClassToColor[d.Class],
declClassToStringDebug[d.Class],
d.Name)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var Config = struct {
func WriteValue(v reflect.Value, name string, c *cfg.ConfigFile) {
switch v.(type) {
case *reflect.BoolValue, *reflect.StringValue,
*reflect.IntValue, *reflect.FloatValue:
*reflect.IntValue, *reflect.FloatValue:
c.AddOption(cfg.DefaultSection, name, fmt.Sprint(v.Interface()))
}
}
Expand Down
23 changes: 11 additions & 12 deletions decl.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ const (
)

var declClassToString = [...]string{
DECL_CONST: "const",
DECL_VAR: "var",
DECL_TYPE: "type",
DECL_FUNC: "func",
DECL_MODULE: "module",
DECL_CONST: "const",
DECL_VAR: "var",
DECL_TYPE: "type",
DECL_FUNC: "func",
DECL_MODULE: "module",
DECL_METHODS_STUB: "IF YOU SEE THIS, REPORT A BUG", // :D
}

var declClassToStringDebug = [...]string {
var declClassToStringDebug = [...]string{
DECL_CONST: " const",
DECL_VAR: " var",
DECL_TYPE: " type",
Expand All @@ -41,8 +41,8 @@ var declClassToStringDebug = [...]string {
}

type Decl struct {
Name string
Type ast.Expr
Name string
Type ast.Expr
Class int

// functions for interface type, fields+methods for struct type
Expand Down Expand Up @@ -416,7 +416,7 @@ func funcReturnType(f *ast.FuncType, index int) ast.Expr {

type TypePath struct {
module string
name string
name string
}

// converts type expressions like:
Expand Down Expand Up @@ -495,7 +495,7 @@ func exprToDecl(e ast.Expr, scope *Scope, ctx *AutoCompleteContext) *Decl {
type TypeInferenceContext struct {
index int
scope *Scope
ac *AutoCompleteContext
ac *AutoCompleteContext
}

// RETURNS:
Expand Down Expand Up @@ -584,7 +584,7 @@ func (ctx *TypeInferenceContext) inferType(v ast.Expr) (ast.Expr, bool, *Scope)
}
switch ct := it.(type) {
case *ast.FuncType:
// in case if <here>() is a function type variable, we're making a
// in case if <here>() is a function type variable, we're making a
// func call, resulting expr is always a value
return funcReturnType(ct, ctx.index), false, scope
case *ast.Ident:
Expand Down Expand Up @@ -806,4 +806,3 @@ func prettyPrintFuncFieldList(out io.Writer, f *ast.FieldList) int {
}
return count
}

31 changes: 15 additions & 16 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ import (
)

type moduleImport struct {
alias string
name string
path string
alias string
name string
path string
module *Decl
}

type PackageFile struct {
name string // file name
name string // file name
packageName string // package name that is in the file
mtime int64
ctx *AutoCompleteContext
mtime int64
ctx *AutoCompleteContext

modules []moduleImport // import section cache (abbrev -> full name)
decls map[string]*Decl // cached
filescope *Scope // cached
modules []moduleImport // import section cache (abbrev -> full name)
decls map[string]*Decl // cached
filescope *Scope // cached

topscope *Scope
scope *Scope // scope, used for parsing
cursor int // for current file buffer
scope *Scope // scope, used for parsing
cursor int // for current file buffer

stage2go chan bool
}
Expand Down Expand Up @@ -81,9 +81,9 @@ func (self *PackageFile) processFile(filename string, stage1 chan *PackageFile)
}

type ProcessDataContext struct {
cur int
cur int
block []byte
file *ast.File
file *ast.File
decls []ast.Decl
}

Expand Down Expand Up @@ -154,7 +154,7 @@ func (self *PackageFile) addModuleImport(alias, path string) {
self.modules = s
}

self.modules = self.modules[0:n+1]
self.modules = self.modules[0 : n+1]
self.modules[n] = moduleImport{alias, name, path, nil}
}

Expand Down Expand Up @@ -592,7 +592,7 @@ func pathAndAlias(imp *ast.ImportSpec) (string, string) {
if imp.Name != nil {
alias = imp.Name.Name()
}
path = path[1:len(path)-1]
path = path[1 : len(path)-1]
return path, alias
}

Expand All @@ -603,4 +603,3 @@ func findGlobalFile(imp string) string {

return fmt.Sprintf("%s/pkg/%s_%s/%s.a", goroot, goos, goarch, imp)
}

11 changes: 4 additions & 7 deletions gocode.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
var (
server = flag.Bool("s", false, "run a server instead of a client")
format = flag.String("f", "nice", "output format (vim | emacs | nice)")
input = flag.String("in", "", "use this file instead of stdin input")
input = flag.String("in", "", "use this file instead of stdin input")
)

//-------------------------------------------------------------------------
Expand All @@ -31,8 +31,7 @@ type Formatter interface {
// NiceFormatter (just for testing, simple textual output)
//-------------------------------------------------------------------------

type NiceFormatter struct {
}
type NiceFormatter struct{}

func (*NiceFormatter) WriteEmpty() {
fmt.Printf("Nothing to complete.\n")
Expand All @@ -53,8 +52,7 @@ func (*NiceFormatter) WriteCandidates(names, types, classes []string, num int) {
// VimFormatter
//-------------------------------------------------------------------------

type VimFormatter struct {
}
type VimFormatter struct{}

func (*VimFormatter) WriteEmpty() {
fmt.Print("[0, []]")
Expand Down Expand Up @@ -85,8 +83,7 @@ func (*VimFormatter) WriteCandidates(names, types, classes []string, num int) {
// EmacsFormatter
//-------------------------------------------------------------------------

type EmacsFormatter struct {
}
type EmacsFormatter struct{}

func (*EmacsFormatter) WriteEmpty() {
}
Expand Down
Loading

0 comments on commit b51bf09

Please sign in to comment.