repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
sourcegraph/go-langserver
langserver/references.go
reverseImportGraph
func (h *LangHandler) reverseImportGraph(ctx context.Context, conn jsonrpc2.JSONRPC2) <-chan importgraph.Graph { // Ensure our buffer is big enough to prevent deadlock c := make(chan importgraph.Graph, 2) go func() { // This should always be related to the go import path for // this repo. For sourcegraph.com th...
go
func (h *LangHandler) reverseImportGraph(ctx context.Context, conn jsonrpc2.JSONRPC2) <-chan importgraph.Graph { // Ensure our buffer is big enough to prevent deadlock c := make(chan importgraph.Graph, 2) go func() { // This should always be related to the go import path for // this repo. For sourcegraph.com th...
[ "func", "(", "h", "*", "LangHandler", ")", "reverseImportGraph", "(", "ctx", "context", ".", "Context", ",", "conn", "jsonrpc2", ".", "JSONRPC2", ")", "<-", "chan", "importgraph", ".", "Graph", "{", "// Ensure our buffer is big enough to prevent deadlock", "c", ":...
// reverseImportGraph returns the reversed import graph for the workspace // under the RootPath. Computing the reverse import graph is IO intensive, as // such we may send down more than one import graph. The later a graph is // sent, the more accurate it is. The channel will be closed, and the last // graph sent is ac...
[ "reverseImportGraph", "returns", "the", "reversed", "import", "graph", "for", "the", "workspace", "under", "the", "RootPath", ".", "Computing", "the", "reverse", "import", "graph", "is", "IO", "intensive", "as", "such", "we", "may", "send", "down", "more", "th...
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/references.go#L215-L271
train
sourcegraph/go-langserver
langserver/references.go
refStreamAndCollect
func refStreamAndCollect(ctx context.Context, conn jsonrpc2.JSONRPC2, req *jsonrpc2.Request, fset *token.FileSet, refs <-chan *ast.Ident, limit int, stop func()) []lsp.Location { if limit == 0 { // If we don't have a limit, just set it to a value we should never exceed limit = math.MaxInt32 } id := lsp.ID{ Nu...
go
func refStreamAndCollect(ctx context.Context, conn jsonrpc2.JSONRPC2, req *jsonrpc2.Request, fset *token.FileSet, refs <-chan *ast.Ident, limit int, stop func()) []lsp.Location { if limit == 0 { // If we don't have a limit, just set it to a value we should never exceed limit = math.MaxInt32 } id := lsp.ID{ Nu...
[ "func", "refStreamAndCollect", "(", "ctx", "context", ".", "Context", ",", "conn", "jsonrpc2", ".", "JSONRPC2", ",", "req", "*", "jsonrpc2", ".", "Request", ",", "fset", "*", "token", ".", "FileSet", ",", "refs", "<-", "chan", "*", "ast", ".", "Ident", ...
// refStreamAndCollect returns all refs read in from chan until it is // closed. While it is reading, it will also occasionally stream out updates of // the refs received so far.
[ "refStreamAndCollect", "returns", "all", "refs", "read", "in", "from", "chan", "until", "it", "is", "closed", ".", "While", "it", "is", "reading", "it", "will", "also", "occasionally", "stream", "out", "updates", "of", "the", "refs", "received", "so", "far",...
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/references.go#L276-L337
train
sourcegraph/go-langserver
langserver/references.go
classify
func classify(obj types.Object) (global, pkglevel bool) { if obj.Exported() { if obj.Parent() == nil { // selectable object (field or method) return true, false } if obj.Parent() == obj.Pkg().Scope() { // lexical object (package-level var/const/func/type) return true, true } } // object with unex...
go
func classify(obj types.Object) (global, pkglevel bool) { if obj.Exported() { if obj.Parent() == nil { // selectable object (field or method) return true, false } if obj.Parent() == obj.Pkg().Scope() { // lexical object (package-level var/const/func/type) return true, true } } // object with unex...
[ "func", "classify", "(", "obj", "types", ".", "Object", ")", "(", "global", ",", "pkglevel", "bool", ")", "{", "if", "obj", ".", "Exported", "(", ")", "{", "if", "obj", ".", "Parent", "(", ")", "==", "nil", "{", "// selectable object (field or method)", ...
// classify classifies objects by how far // we have to look to find references to them.
[ "classify", "classifies", "objects", "by", "how", "far", "we", "have", "to", "look", "to", "find", "references", "to", "them", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/references.go#L730-L743
train
sourcegraph/go-langserver
langserver/references.go
findObject
func findObject(fset *token.FileSet, info *types.Info, objposn token.Position) types.Object { good := func(obj types.Object) bool { if obj == nil { return false } posn := fset.Position(obj.Pos()) return posn.Filename == objposn.Filename && posn.Offset == objposn.Offset } for _, obj := range info.Defs { ...
go
func findObject(fset *token.FileSet, info *types.Info, objposn token.Position) types.Object { good := func(obj types.Object) bool { if obj == nil { return false } posn := fset.Position(obj.Pos()) return posn.Filename == objposn.Filename && posn.Offset == objposn.Offset } for _, obj := range info.Defs { ...
[ "func", "findObject", "(", "fset", "*", "token", ".", "FileSet", ",", "info", "*", "types", ".", "Info", ",", "objposn", "token", ".", "Position", ")", "types", ".", "Object", "{", "good", ":=", "func", "(", "obj", "types", ".", "Object", ")", "bool"...
// findObject returns the object defined at the specified position.
[ "findObject", "returns", "the", "object", "defined", "at", "the", "specified", "position", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/references.go#L761-L780
train
sourcegraph/go-langserver
langserver/references.go
sameObj
func sameObj(x, y types.Object) bool { if x == y { return true } if x, ok := x.(*types.PkgName); ok { if y, ok := y.(*types.PkgName); ok { return x.Imported() == y.Imported() } } return false }
go
func sameObj(x, y types.Object) bool { if x == y { return true } if x, ok := x.(*types.PkgName); ok { if y, ok := y.(*types.PkgName); ok { return x.Imported() == y.Imported() } } return false }
[ "func", "sameObj", "(", "x", ",", "y", "types", ".", "Object", ")", "bool", "{", "if", "x", "==", "y", "{", "return", "true", "\n", "}", "\n", "if", "x", ",", "ok", ":=", "x", ".", "(", "*", "types", ".", "PkgName", ")", ";", "ok", "{", "if...
// same reports whether x and y are identical, or both are PkgNames // that import the same Package.
[ "same", "reports", "whether", "x", "and", "y", "are", "identical", "or", "both", "are", "PkgNames", "that", "import", "the", "same", "Package", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/references.go#L794-L804
train
sourcegraph/go-langserver
langserver/references.go
readFile
func readFile(ctxt *build.Context, filename string, buf *bytes.Buffer) ([]byte, error) { rc, err := buildutil.OpenFile(ctxt, filename) if err != nil { return nil, err } defer rc.Close() if buf == nil { buf = new(bytes.Buffer) } if _, err := io.Copy(buf, rc); err != nil { return nil, err } return buf.Byte...
go
func readFile(ctxt *build.Context, filename string, buf *bytes.Buffer) ([]byte, error) { rc, err := buildutil.OpenFile(ctxt, filename) if err != nil { return nil, err } defer rc.Close() if buf == nil { buf = new(bytes.Buffer) } if _, err := io.Copy(buf, rc); err != nil { return nil, err } return buf.Byte...
[ "func", "readFile", "(", "ctxt", "*", "build", ".", "Context", ",", "filename", "string", ",", "buf", "*", "bytes", ".", "Buffer", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "rc", ",", "err", ":=", "buildutil", ".", "OpenFile", "(", "ctxt"...
// readFile is like ioutil.ReadFile, but // it goes through the virtualized build.Context. // If non-nil, buf must have been reset.
[ "readFile", "is", "like", "ioutil", ".", "ReadFile", "but", "it", "goes", "through", "the", "virtualized", "build", ".", "Context", ".", "If", "non", "-", "nil", "buf", "must", "have", "been", "reset", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/references.go#L809-L822
train
sourcegraph/go-langserver
langserver/handler_common.go
ShutDown
func (h *HandlerCommon) ShutDown() { h.mu.Lock() if h.shutdown { log.Printf("Warning: server received a shutdown request after it was already shut down.") } h.shutdown = true h.mu.Unlock() }
go
func (h *HandlerCommon) ShutDown() { h.mu.Lock() if h.shutdown { log.Printf("Warning: server received a shutdown request after it was already shut down.") } h.shutdown = true h.mu.Unlock() }
[ "func", "(", "h", "*", "HandlerCommon", ")", "ShutDown", "(", ")", "{", "h", ".", "mu", ".", "Lock", "(", ")", "\n", "if", "h", ".", "shutdown", "{", "log", ".", "Printf", "(", "\"", "\"", ")", "\n", "}", "\n", "h", ".", "shutdown", "=", "tru...
// ShutDown marks this server as being shut down and causes all future calls to checkReady to return an error.
[ "ShutDown", "marks", "this", "server", "as", "being", "shut", "down", "and", "causes", "all", "future", "calls", "to", "checkReady", "to", "return", "an", "error", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/handler_common.go#L40-L47
train
sourcegraph/go-langserver
langserver/handler_common.go
CheckReady
func (h *HandlerCommon) CheckReady() error { h.mu.Lock() defer h.mu.Unlock() if h.shutdown { return errors.New("server is shutting down") } return nil }
go
func (h *HandlerCommon) CheckReady() error { h.mu.Lock() defer h.mu.Unlock() if h.shutdown { return errors.New("server is shutting down") } return nil }
[ "func", "(", "h", "*", "HandlerCommon", ")", "CheckReady", "(", ")", "error", "{", "h", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "h", ".", "mu", ".", "Unlock", "(", ")", "\n", "if", "h", ".", "shutdown", "{", "return", "errors", ".", "N...
// CheckReady returns an error if the handler has been shut // down.
[ "CheckReady", "returns", "an", "error", "if", "the", "handler", "has", "been", "shut", "down", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/handler_common.go#L51-L58
train
sourcegraph/go-langserver
langserver/fs.go
FS
func (h *overlay) FS() ctxvfs.FileSystem { return ctxvfs.Sync(&h.mu, ctxvfs.Map(h.m)) }
go
func (h *overlay) FS() ctxvfs.FileSystem { return ctxvfs.Sync(&h.mu, ctxvfs.Map(h.m)) }
[ "func", "(", "h", "*", "overlay", ")", "FS", "(", ")", "ctxvfs", ".", "FileSystem", "{", "return", "ctxvfs", ".", "Sync", "(", "&", "h", ".", "mu", ",", "ctxvfs", ".", "Map", "(", "h", ".", "m", ")", ")", "\n", "}" ]
// FS returns a vfs for the overlay.
[ "FS", "returns", "a", "vfs", "for", "the", "overlay", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/fs.go#L117-L119
train
sourcegraph/go-langserver
langserver/fs.go
applyContentChanges
func applyContentChanges(uri lsp.DocumentURI, contents []byte, changes []lsp.TextDocumentContentChangeEvent) ([]byte, error) { for _, change := range changes { if change.Range == nil && change.RangeLength == 0 { contents = []byte(change.Text) // new full content continue } start, ok, why := offsetForPositi...
go
func applyContentChanges(uri lsp.DocumentURI, contents []byte, changes []lsp.TextDocumentContentChangeEvent) ([]byte, error) { for _, change := range changes { if change.Range == nil && change.RangeLength == 0 { contents = []byte(change.Text) // new full content continue } start, ok, why := offsetForPositi...
[ "func", "applyContentChanges", "(", "uri", "lsp", ".", "DocumentURI", ",", "contents", "[", "]", "byte", ",", "changes", "[", "]", "lsp", ".", "TextDocumentContentChangeEvent", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "for", "_", ",", "change"...
// applyContentChanges updates `contents` based on `changes`
[ "applyContentChanges", "updates", "contents", "based", "on", "changes" ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/fs.go#L141-L173
train
sourcegraph/go-langserver
langserver/fs.go
NewAtomicFS
func NewAtomicFS() *AtomicFS { fs := &AtomicFS{} fs.v.Store(make(ctxvfs.NameSpace)) return fs }
go
func NewAtomicFS() *AtomicFS { fs := &AtomicFS{} fs.v.Store(make(ctxvfs.NameSpace)) return fs }
[ "func", "NewAtomicFS", "(", ")", "*", "AtomicFS", "{", "fs", ":=", "&", "AtomicFS", "{", "}", "\n", "fs", ".", "v", ".", "Store", "(", "make", "(", "ctxvfs", ".", "NameSpace", ")", ")", "\n", "return", "fs", "\n", "}" ]
// NewAtomicFS returns an AtomicFS with an empty wrapped ctxvfs.NameSpace
[ "NewAtomicFS", "returns", "an", "AtomicFS", "with", "an", "empty", "wrapped", "ctxvfs", ".", "NameSpace" ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/fs.go#L242-L246
train
sourcegraph/go-langserver
langserver/fs.go
Bind
func (a *AtomicFS) Bind(old string, newfs ctxvfs.FileSystem, new string, mode ctxvfs.BindMode) { // We do copy-on-write a.mu.Lock() defer a.mu.Unlock() fs1 := a.v.Load().(ctxvfs.NameSpace) fs2 := make(ctxvfs.NameSpace) for k, v := range fs1 { fs2[k] = v } fs2.Bind(old, newfs, new, mode) a.v.Store(fs2) }
go
func (a *AtomicFS) Bind(old string, newfs ctxvfs.FileSystem, new string, mode ctxvfs.BindMode) { // We do copy-on-write a.mu.Lock() defer a.mu.Unlock() fs1 := a.v.Load().(ctxvfs.NameSpace) fs2 := make(ctxvfs.NameSpace) for k, v := range fs1 { fs2[k] = v } fs2.Bind(old, newfs, new, mode) a.v.Store(fs2) }
[ "func", "(", "a", "*", "AtomicFS", ")", "Bind", "(", "old", "string", ",", "newfs", "ctxvfs", ".", "FileSystem", ",", "new", "string", ",", "mode", "ctxvfs", ".", "BindMode", ")", "{", "// We do copy-on-write", "a", ".", "mu", ".", "Lock", "(", ")", ...
// Bind wraps ctxvfs.NameSpace.Bind
[ "Bind", "wraps", "ctxvfs", ".", "NameSpace", ".", "Bind" ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/fs.go#L249-L261
train
sourcegraph/go-langserver
langserver/fs.go
Open
func (a *AtomicFS) Open(ctx context.Context, path string) (ctxvfs.ReadSeekCloser, error) { fs := a.v.Load().(ctxvfs.NameSpace) return fs.Open(ctx, path) }
go
func (a *AtomicFS) Open(ctx context.Context, path string) (ctxvfs.ReadSeekCloser, error) { fs := a.v.Load().(ctxvfs.NameSpace) return fs.Open(ctx, path) }
[ "func", "(", "a", "*", "AtomicFS", ")", "Open", "(", "ctx", "context", ".", "Context", ",", "path", "string", ")", "(", "ctxvfs", ".", "ReadSeekCloser", ",", "error", ")", "{", "fs", ":=", "a", ".", "v", ".", "Load", "(", ")", ".", "(", "ctxvfs",...
// Open wraps ctxvfs.NameSpace.Open
[ "Open", "wraps", "ctxvfs", ".", "NameSpace", ".", "Open" ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/fs.go#L268-L271
train
sourcegraph/go-langserver
langserver/fs.go
Stat
func (a *AtomicFS) Stat(ctx context.Context, path string) (os.FileInfo, error) { fs := a.v.Load().(ctxvfs.NameSpace) return fs.Stat(ctx, path) }
go
func (a *AtomicFS) Stat(ctx context.Context, path string) (os.FileInfo, error) { fs := a.v.Load().(ctxvfs.NameSpace) return fs.Stat(ctx, path) }
[ "func", "(", "a", "*", "AtomicFS", ")", "Stat", "(", "ctx", "context", ".", "Context", ",", "path", "string", ")", "(", "os", ".", "FileInfo", ",", "error", ")", "{", "fs", ":=", "a", ".", "v", ".", "Load", "(", ")", ".", "(", "ctxvfs", ".", ...
// Stat wraps ctxvfs.NameSpace.Stat
[ "Stat", "wraps", "ctxvfs", ".", "NameSpace", ".", "Stat" ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/fs.go#L274-L277
train
sourcegraph/go-langserver
langserver/cache.go
newLRU
func newLRU(env string, defaultSize int) *lru.Cache { size := defaultSize if i, err := strconv.Atoi(os.Getenv(env)); err == nil && i > 0 { size = i } c, err := lru.New(size) if err != nil { // This should never happen since our size is always > 0 panic(err) } return c }
go
func newLRU(env string, defaultSize int) *lru.Cache { size := defaultSize if i, err := strconv.Atoi(os.Getenv(env)); err == nil && i > 0 { size = i } c, err := lru.New(size) if err != nil { // This should never happen since our size is always > 0 panic(err) } return c }
[ "func", "newLRU", "(", "env", "string", ",", "defaultSize", "int", ")", "*", "lru", ".", "Cache", "{", "size", ":=", "defaultSize", "\n", "if", "i", ",", "err", ":=", "strconv", ".", "Atoi", "(", "os", ".", "Getenv", "(", "env", ")", ")", ";", "e...
// newLRU returns an LRU based cache.
[ "newLRU", "returns", "an", "LRU", "based", "cache", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/cache.go#L142-L153
train
sourcegraph/go-langserver
buildserver/util.go
add
func (e *errorList) add(err error) { e.mu.Lock() e.errors = append(e.errors, err) e.mu.Unlock() }
go
func (e *errorList) add(err error) { e.mu.Lock() e.errors = append(e.errors, err) e.mu.Unlock() }
[ "func", "(", "e", "*", "errorList", ")", "add", "(", "err", "error", ")", "{", "e", ".", "mu", ".", "Lock", "(", ")", "\n", "e", ".", "errors", "=", "append", "(", "e", ".", "errors", ",", "err", ")", "\n", "e", ".", "mu", ".", "Unlock", "(...
// add adds err to the list of errors. It is safe to call it from // concurrent goroutines.
[ "add", "adds", "err", "to", "the", "list", "of", "errors", ".", "It", "is", "safe", "to", "call", "it", "from", "concurrent", "goroutines", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/buildserver/util.go#L15-L19
train
sourcegraph/go-langserver
buildserver/util.go
error
func (e *errorList) error() error { switch len(e.errors) { case 0: return nil case 1: return e.errors[0] default: return fmt.Errorf("%s [and %d more errors]", e.errors[0], len(e.errors)-1) } }
go
func (e *errorList) error() error { switch len(e.errors) { case 0: return nil case 1: return e.errors[0] default: return fmt.Errorf("%s [and %d more errors]", e.errors[0], len(e.errors)-1) } }
[ "func", "(", "e", "*", "errorList", ")", "error", "(", ")", "error", "{", "switch", "len", "(", "e", ".", "errors", ")", "{", "case", "0", ":", "return", "nil", "\n", "case", "1", ":", "return", "e", ".", "errors", "[", "0", "]", "\n", "default...
// errors returns the list of errors as a single error. It is NOT safe // to call from concurrent goroutines.
[ "errors", "returns", "the", "list", "of", "errors", "as", "a", "single", "error", ".", "It", "is", "NOT", "safe", "to", "call", "from", "concurrent", "goroutines", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/buildserver/util.go#L23-L32
train
sourcegraph/go-langserver
langserver/handler_shared.go
getFindPackageFunc
func (h *HandlerShared) getFindPackageFunc() FindPackageFunc { if h.FindPackage != nil { return h.FindPackage } return defaultFindPackageFunc }
go
func (h *HandlerShared) getFindPackageFunc() FindPackageFunc { if h.FindPackage != nil { return h.FindPackage } return defaultFindPackageFunc }
[ "func", "(", "h", "*", "HandlerShared", ")", "getFindPackageFunc", "(", ")", "FindPackageFunc", "{", "if", "h", ".", "FindPackage", "!=", "nil", "{", "return", "h", ".", "FindPackage", "\n", "}", "\n", "return", "defaultFindPackageFunc", "\n", "}" ]
// getFindPackageFunc is a helper which returns h.FindPackage if non-nil, otherwise defaultFindPackageFunc
[ "getFindPackageFunc", "is", "a", "helper", "which", "returns", "h", ".", "FindPackage", "if", "non", "-", "nil", "otherwise", "defaultFindPackageFunc" ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/handler_shared.go#L93-L98
train
sourcegraph/go-langserver
vfsutil/cache.go
Evict
func (f *cachedFile) Evict() { // Best-effort. Ignore error _ = os.Remove(f.path) cachedFileEvict.Inc() }
go
func (f *cachedFile) Evict() { // Best-effort. Ignore error _ = os.Remove(f.path) cachedFileEvict.Inc() }
[ "func", "(", "f", "*", "cachedFile", ")", "Evict", "(", ")", "{", "// Best-effort. Ignore error", "_", "=", "os", ".", "Remove", "(", "f", ".", "path", ")", "\n", "cachedFileEvict", ".", "Inc", "(", ")", "\n", "}" ]
// Evict will remove the file from the cache. It does not close File. It also // does not protect against other open readers or concurrent fetches.
[ "Evict", "will", "remove", "the", "file", "from", "the", "cache", ".", "It", "does", "not", "close", "File", ".", "It", "also", "does", "not", "protect", "against", "other", "open", "readers", "or", "concurrent", "fetches", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/vfsutil/cache.go#L38-L42
train
sourcegraph/go-langserver
vfsutil/cache.go
cachedFetch
func cachedFetch(ctx context.Context, key string, s *diskcache.Store, fetcher func(context.Context) (io.ReadCloser, error)) (ff *cachedFile, err error) { f, err := s.Open(ctx, key, fetcher) if err != nil { return nil, err } return &cachedFile{ File: f.File, path: f.Path, }, nil }
go
func cachedFetch(ctx context.Context, key string, s *diskcache.Store, fetcher func(context.Context) (io.ReadCloser, error)) (ff *cachedFile, err error) { f, err := s.Open(ctx, key, fetcher) if err != nil { return nil, err } return &cachedFile{ File: f.File, path: f.Path, }, nil }
[ "func", "cachedFetch", "(", "ctx", "context", ".", "Context", ",", "key", "string", ",", "s", "*", "diskcache", ".", "Store", ",", "fetcher", "func", "(", "context", ".", "Context", ")", "(", "io", ".", "ReadCloser", ",", "error", ")", ")", "(", "ff"...
// cachedFetch will open a file from the local cache with key. If missing, // fetcher will fill the cache first. cachedFetch also performs // single-flighting.
[ "cachedFetch", "will", "open", "a", "file", "from", "the", "local", "cache", "with", "key", ".", "If", "missing", "fetcher", "will", "fill", "the", "cache", "first", ".", "cachedFetch", "also", "performs", "single", "-", "flighting", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/vfsutil/cache.go#L47-L56
train
sourcegraph/go-langserver
buildserver/environment.go
determineEnvironment
func determineEnvironment(ctx context.Context, fs ctxvfs.FileSystem, params lspext.InitializeParams) (*langserver.InitializeParams, error) { rootImportPath, err := determineRootImportPath(ctx, params.OriginalRootURI, fs) if err != nil { return nil, fmt.Errorf("unable to determine workspace's root Go import path: %s...
go
func determineEnvironment(ctx context.Context, fs ctxvfs.FileSystem, params lspext.InitializeParams) (*langserver.InitializeParams, error) { rootImportPath, err := determineRootImportPath(ctx, params.OriginalRootURI, fs) if err != nil { return nil, fmt.Errorf("unable to determine workspace's root Go import path: %s...
[ "func", "determineEnvironment", "(", "ctx", "context", ".", "Context", ",", "fs", "ctxvfs", ".", "FileSystem", ",", "params", "lspext", ".", "InitializeParams", ")", "(", "*", "langserver", ".", "InitializeParams", ",", "error", ")", "{", "rootImportPath", ","...
// determineEnvironment will setup the language server InitializeParams based // what it can detect from the filesystem and what it received from the client's // InitializeParams. // // It is expected that fs will be mounted at InitializeParams.RootURI.
[ "determineEnvironment", "will", "setup", "the", "language", "server", "InitializeParams", "based", "what", "it", "can", "detect", "from", "the", "filesystem", "and", "what", "it", "received", "from", "the", "client", "s", "InitializeParams", ".", "It", "is", "ex...
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/buildserver/environment.go#L44-L108
train
sourcegraph/go-langserver
buildserver/environment.go
detectCustomGOPATH
func detectCustomGOPATH(ctx context.Context, fs ctxvfs.FileSystem) (gopaths []string) { // If we detect any .sorucegraph/config.json GOPATHs then they take // absolute precedence and override all others. if paths := detectSourcegraphGOPATH(ctx, fs); len(paths) > 0 { return paths } // Check .vscode/config.json a...
go
func detectCustomGOPATH(ctx context.Context, fs ctxvfs.FileSystem) (gopaths []string) { // If we detect any .sorucegraph/config.json GOPATHs then they take // absolute precedence and override all others. if paths := detectSourcegraphGOPATH(ctx, fs); len(paths) > 0 { return paths } // Check .vscode/config.json a...
[ "func", "detectCustomGOPATH", "(", "ctx", "context", ".", "Context", ",", "fs", "ctxvfs", ".", "FileSystem", ")", "(", "gopaths", "[", "]", "string", ")", "{", "// If we detect any .sorucegraph/config.json GOPATHs then they take", "// absolute precedence and override all ot...
// detectCustomGOPATH tries to detect monorepos which require their own custom // GOPATH. // // This is best-effort. If any errors occur or we do not detect a custom // gopath, an empty result is returned.
[ "detectCustomGOPATH", "tries", "to", "detect", "monorepos", "which", "require", "their", "own", "custom", "GOPATH", ".", "This", "is", "best", "-", "effort", ".", "If", "any", "errors", "occur", "or", "we", "do", "not", "detect", "a", "custom", "gopath", "...
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/buildserver/environment.go#L115-L130
train
sourcegraph/go-langserver
buildserver/environment.go
unmarshalJSONC
func unmarshalJSONC(text string, v interface{}) error { data, errs := jsonx.Parse(text, jsonx.ParseOptions{Comments: true, TrailingCommas: true}) if len(errs) > 0 { return fmt.Errorf("failed to parse JSON: %v", errs) } return json.Unmarshal(data, v) }
go
func unmarshalJSONC(text string, v interface{}) error { data, errs := jsonx.Parse(text, jsonx.ParseOptions{Comments: true, TrailingCommas: true}) if len(errs) > 0 { return fmt.Errorf("failed to parse JSON: %v", errs) } return json.Unmarshal(data, v) }
[ "func", "unmarshalJSONC", "(", "text", "string", ",", "v", "interface", "{", "}", ")", "error", "{", "data", ",", "errs", ":=", "jsonx", ".", "Parse", "(", "text", ",", "jsonx", ".", "ParseOptions", "{", "Comments", ":", "true", ",", "TrailingCommas", ...
// unmarshalJSONC unmarshals the JSON using a fault-tolerant parser that allows comments // and trailing commas. If any unrecoverable faults are found, an error is returned.
[ "unmarshalJSONC", "unmarshals", "the", "JSON", "using", "a", "fault", "-", "tolerant", "parser", "that", "allows", "comments", "and", "trailing", "commas", ".", "If", "any", "unrecoverable", "faults", "are", "found", "an", "error", "is", "returned", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/buildserver/environment.go#L165-L171
train
sourcegraph/go-langserver
langserver/types.go
deref
func deref(typ types.Type) types.Type { if p, ok := typ.Underlying().(*types.Pointer); ok { return p.Elem() } return typ }
go
func deref(typ types.Type) types.Type { if p, ok := typ.Underlying().(*types.Pointer); ok { return p.Elem() } return typ }
[ "func", "deref", "(", "typ", "types", ".", "Type", ")", "types", ".", "Type", "{", "if", "p", ",", "ok", ":=", "typ", ".", "Underlying", "(", ")", ".", "(", "*", "types", ".", "Pointer", ")", ";", "ok", "{", "return", "p", ".", "Elem", "(", "...
// deref returns a pointer's element type; otherwise it returns typ.
[ "deref", "returns", "a", "pointer", "s", "element", "type", ";", "otherwise", "it", "returns", "typ", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/types.go#L6-L11
train
sourcegraph/go-langserver
buildserver/deps.go
get
func (k *keyMutex) get(key string) *sync.Mutex { k.mu.Lock() mu, ok := k.mus[key] if !ok { mu = &sync.Mutex{} k.mus[key] = mu } k.mu.Unlock() return mu }
go
func (k *keyMutex) get(key string) *sync.Mutex { k.mu.Lock() mu, ok := k.mus[key] if !ok { mu = &sync.Mutex{} k.mus[key] = mu } k.mu.Unlock() return mu }
[ "func", "(", "k", "*", "keyMutex", ")", "get", "(", "key", "string", ")", "*", "sync", ".", "Mutex", "{", "k", ".", "mu", ".", "Lock", "(", ")", "\n", "mu", ",", "ok", ":=", "k", ".", "mus", "[", "key", "]", "\n", "if", "!", "ok", "{", "m...
// get returns a mutex unique to the given key.
[ "get", "returns", "a", "mutex", "unique", "to", "the", "given", "key", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/buildserver/deps.go#L34-L43
train
sourcegraph/go-langserver
buildserver/deps.go
fetchTransitiveDepsOfFile
func (h *BuildHandler) fetchTransitiveDepsOfFile(ctx context.Context, fileURI lsp.DocumentURI, dc *depCache) (err error) { parentSpan := opentracing.SpanFromContext(ctx) span := parentSpan.Tracer().StartSpan("go-langserver-go: fetch transitive dependencies", opentracing.Tags{"fileURI": fileURI}, opentracing.Child...
go
func (h *BuildHandler) fetchTransitiveDepsOfFile(ctx context.Context, fileURI lsp.DocumentURI, dc *depCache) (err error) { parentSpan := opentracing.SpanFromContext(ctx) span := parentSpan.Tracer().StartSpan("go-langserver-go: fetch transitive dependencies", opentracing.Tags{"fileURI": fileURI}, opentracing.Child...
[ "func", "(", "h", "*", "BuildHandler", ")", "fetchTransitiveDepsOfFile", "(", "ctx", "context", ".", "Context", ",", "fileURI", "lsp", ".", "DocumentURI", ",", "dc", "*", "depCache", ")", "(", "err", "error", ")", "{", "parentSpan", ":=", "opentracing", "....
// fetchTransitiveDepsOfFile fetches the transitive dependencies of // the named Go file. A Go file's dependencies are the imports of its // own package, plus all of its imports' imports, and so on. // // It adds fetched dependencies to its own file system overlay, and // the returned depFiles should be passed onto the...
[ "fetchTransitiveDepsOfFile", "fetches", "the", "transitive", "dependencies", "of", "the", "named", "Go", "file", ".", "A", "Go", "file", "s", "dependencies", "are", "the", "imports", "of", "its", "own", "package", "plus", "all", "of", "its", "imports", "import...
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/buildserver/deps.go#L86-L112
train
sourcegraph/go-langserver
buildserver/deps.go
findPackage
func (h *BuildHandler) findPackage(ctx context.Context, bctx *build.Context, path, srcDir string, mode build.ImportMode) (*build.Package, error) { return h.doFindPackage(ctx, bctx, path, srcDir, mode, newDepCache()) }
go
func (h *BuildHandler) findPackage(ctx context.Context, bctx *build.Context, path, srcDir string, mode build.ImportMode) (*build.Package, error) { return h.doFindPackage(ctx, bctx, path, srcDir, mode, newDepCache()) }
[ "func", "(", "h", "*", "BuildHandler", ")", "findPackage", "(", "ctx", "context", ".", "Context", ",", "bctx", "*", "build", ".", "Context", ",", "path", ",", "srcDir", "string", ",", "mode", "build", ".", "ImportMode", ")", "(", "*", "build", ".", "...
// findPackage is a langserver.FindPackageFunc which integrates with the build // server. It will fetch dependencies just in time.
[ "findPackage", "is", "a", "langserver", ".", "FindPackageFunc", "which", "integrates", "with", "the", "build", "server", ".", "It", "will", "fetch", "dependencies", "just", "in", "time", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/buildserver/deps.go#L194-L196
train
sourcegraph/go-langserver
buildserver/deps.go
isUnderRootImportPath
func isUnderRootImportPath(rootImportPath, path string) bool { return rootImportPath != "" && util.PathHasPrefix(path, rootImportPath) }
go
func isUnderRootImportPath(rootImportPath, path string) bool { return rootImportPath != "" && util.PathHasPrefix(path, rootImportPath) }
[ "func", "isUnderRootImportPath", "(", "rootImportPath", ",", "path", "string", ")", "bool", "{", "return", "rootImportPath", "!=", "\"", "\"", "&&", "util", ".", "PathHasPrefix", "(", "path", ",", "rootImportPath", ")", "\n", "}" ]
// isUnderCanonicalImportPath tells if the given path is under the given root import path.
[ "isUnderCanonicalImportPath", "tells", "if", "the", "given", "path", "is", "under", "the", "given", "root", "import", "path", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/buildserver/deps.go#L199-L201
train
sourcegraph/go-langserver
buildserver/deps.go
FetchCommonDeps
func FetchCommonDeps() { // github.com/golang/go d, _ := gosrc.ResolveImportPath(http.DefaultClient, "time") u, _ := url.Parse(d.CloneURL) _, _ = NewDepRepoVFS(context.Background(), u, d.Rev, nil) }
go
func FetchCommonDeps() { // github.com/golang/go d, _ := gosrc.ResolveImportPath(http.DefaultClient, "time") u, _ := url.Parse(d.CloneURL) _, _ = NewDepRepoVFS(context.Background(), u, d.Rev, nil) }
[ "func", "FetchCommonDeps", "(", ")", "{", "// github.com/golang/go", "d", ",", "_", ":=", "gosrc", ".", "ResolveImportPath", "(", "http", ".", "DefaultClient", ",", "\"", "\"", ")", "\n", "u", ",", "_", ":=", "url", ".", "Parse", "(", "d", ".", "CloneU...
// FetchCommonDeps will fetch our common used dependencies. This is to avoid // impacting the first ever typecheck we do in a repo since it will have to // fetch the dependency from the internet.
[ "FetchCommonDeps", "will", "fetch", "our", "common", "used", "dependencies", ".", "This", "is", "to", "avoid", "impacting", "the", "first", "ever", "typecheck", "we", "do", "in", "a", "repo", "since", "it", "will", "have", "to", "fetch", "the", "dependency",...
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/buildserver/deps.go#L479-L484
train
sourcegraph/go-langserver
langserver/hover.go
maybeAddComments
func maybeAddComments(comments string, contents []lsp.MarkedString) []lsp.MarkedString { if comments == "" { return contents } var b bytes.Buffer doc.ToMarkdown(&b, comments, nil) return append(contents, lsp.RawMarkedString(b.String())) }
go
func maybeAddComments(comments string, contents []lsp.MarkedString) []lsp.MarkedString { if comments == "" { return contents } var b bytes.Buffer doc.ToMarkdown(&b, comments, nil) return append(contents, lsp.RawMarkedString(b.String())) }
[ "func", "maybeAddComments", "(", "comments", "string", ",", "contents", "[", "]", "lsp", ".", "MarkedString", ")", "[", "]", "lsp", ".", "MarkedString", "{", "if", "comments", "==", "\"", "\"", "{", "return", "contents", "\n", "}", "\n", "var", "b", "b...
// maybeAddComments appends the specified comments converted to Markdown godoc // form to the specified contents slice, if the comments string is not empty.
[ "maybeAddComments", "appends", "the", "specified", "comments", "converted", "to", "Markdown", "godoc", "form", "to", "the", "specified", "contents", "slice", "if", "the", "comments", "string", "is", "not", "empty", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/hover.go#L179-L186
train
sourcegraph/go-langserver
langserver/hover.go
joinCommentGroups
func joinCommentGroups(a, b *ast.CommentGroup) string { aText := a.Text() bText := b.Text() if aText == "" { return bText } else if bText == "" { return aText } else { return aText + "\n" + bText } }
go
func joinCommentGroups(a, b *ast.CommentGroup) string { aText := a.Text() bText := b.Text() if aText == "" { return bText } else if bText == "" { return aText } else { return aText + "\n" + bText } }
[ "func", "joinCommentGroups", "(", "a", ",", "b", "*", "ast", ".", "CommentGroup", ")", "string", "{", "aText", ":=", "a", ".", "Text", "(", ")", "\n", "bText", ":=", "b", ".", "Text", "(", ")", "\n", "if", "aText", "==", "\"", "\"", "{", "return"...
// joinCommentGroups joins the resultant non-empty comment text from two // CommentGroups with a newline.
[ "joinCommentGroups", "joins", "the", "resultant", "non", "-", "empty", "comment", "text", "from", "two", "CommentGroups", "with", "a", "newline", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/hover.go#L190-L200
train
sourcegraph/go-langserver
langserver/hover.go
packageDoc
func packageDoc(files []*ast.File, pkgName string) string { for _, f := range files { if f.Name.Name == pkgName { txt := f.Doc.Text() if strings.TrimSpace(txt) != "" { return txt } } } return "" }
go
func packageDoc(files []*ast.File, pkgName string) string { for _, f := range files { if f.Name.Name == pkgName { txt := f.Doc.Text() if strings.TrimSpace(txt) != "" { return txt } } } return "" }
[ "func", "packageDoc", "(", "files", "[", "]", "*", "ast", ".", "File", ",", "pkgName", "string", ")", "string", "{", "for", "_", ",", "f", ":=", "range", "files", "{", "if", "f", ".", "Name", ".", "Name", "==", "pkgName", "{", "txt", ":=", "f", ...
// packageDoc finds the documentation for the named package from its files or // additional files.
[ "packageDoc", "finds", "the", "documentation", "for", "the", "named", "package", "from", "its", "files", "or", "additional", "files", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/hover.go#L204-L214
train
sourcegraph/go-langserver
langserver/hover.go
builtinDoc
func builtinDoc(ident string) []lsp.MarkedString { // Grab files from builtin package pkgs, err := packages.Load( &packages.Config{ Mode: packages.LoadFiles, }, "builtin", ) if err != nil { return nil } // Parse the files into ASTs pkg := pkgs[0] fs := token.NewFileSet() asts := &ast.Package{ Nam...
go
func builtinDoc(ident string) []lsp.MarkedString { // Grab files from builtin package pkgs, err := packages.Load( &packages.Config{ Mode: packages.LoadFiles, }, "builtin", ) if err != nil { return nil } // Parse the files into ASTs pkg := pkgs[0] fs := token.NewFileSet() asts := &ast.Package{ Nam...
[ "func", "builtinDoc", "(", "ident", "string", ")", "[", "]", "lsp", ".", "MarkedString", "{", "// Grab files from builtin package", "pkgs", ",", "err", ":=", "packages", ".", "Load", "(", "&", "packages", ".", "Config", "{", "Mode", ":", "packages", ".", "...
// builtinDoc finds the documentation for a builtin node.
[ "builtinDoc", "finds", "the", "documentation", "for", "a", "builtin", "node", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/hover.go#L217-L249
train
sourcegraph/go-langserver
langserver/hover.go
packageForFile
func packageForFile(pkgs map[string]*ast.Package, filename string) (string, *ast.Package, error) { for path, pkg := range pkgs { for pkgFile := range pkg.Files { if pkgFile == filename { return path, pkg, nil } } } return "", nil, fmt.Errorf("failed to find %q in packages %q", filename, pkgs) }
go
func packageForFile(pkgs map[string]*ast.Package, filename string) (string, *ast.Package, error) { for path, pkg := range pkgs { for pkgFile := range pkg.Files { if pkgFile == filename { return path, pkg, nil } } } return "", nil, fmt.Errorf("failed to find %q in packages %q", filename, pkgs) }
[ "func", "packageForFile", "(", "pkgs", "map", "[", "string", "]", "*", "ast", ".", "Package", ",", "filename", "string", ")", "(", "string", ",", "*", "ast", ".", "Package", ",", "error", ")", "{", "for", "path", ",", "pkg", ":=", "range", "pkgs", ...
// packageForFile returns the import path and pkg from pkgs that contains the // named file.
[ "packageForFile", "returns", "the", "import", "path", "and", "pkg", "from", "pkgs", "that", "contains", "the", "named", "file", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/hover.go#L495-L504
train
sourcegraph/go-langserver
langserver/hover.go
inRange
func inRange(x, a, b token.Position) bool { if !util.PathEqual(x.Filename, a.Filename) || !util.PathEqual(x.Filename, b.Filename) { return false } return x.Offset >= a.Offset && x.Offset <= b.Offset }
go
func inRange(x, a, b token.Position) bool { if !util.PathEqual(x.Filename, a.Filename) || !util.PathEqual(x.Filename, b.Filename) { return false } return x.Offset >= a.Offset && x.Offset <= b.Offset }
[ "func", "inRange", "(", "x", ",", "a", ",", "b", "token", ".", "Position", ")", "bool", "{", "if", "!", "util", ".", "PathEqual", "(", "x", ".", "Filename", ",", "a", ".", "Filename", ")", "||", "!", "util", ".", "PathEqual", "(", "x", ".", "Fi...
// inRange tells if x is in the range of a-b inclusive.
[ "inRange", "tells", "if", "x", "is", "in", "the", "range", "of", "a", "-", "b", "inclusive", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/hover.go#L507-L512
train
sourcegraph/go-langserver
langserver/hover.go
fmtNode
func fmtNode(fset *token.FileSet, n ast.Node) string { var buf bytes.Buffer err := format.Node(&buf, fset, n) if err != nil { panic("unreachable") } return buf.String() }
go
func fmtNode(fset *token.FileSet, n ast.Node) string { var buf bytes.Buffer err := format.Node(&buf, fset, n) if err != nil { panic("unreachable") } return buf.String() }
[ "func", "fmtNode", "(", "fset", "*", "token", ".", "FileSet", ",", "n", "ast", ".", "Node", ")", "string", "{", "var", "buf", "bytes", ".", "Buffer", "\n", "err", ":=", "format", ".", "Node", "(", "&", "buf", ",", "fset", ",", "n", ")", "\n", "...
// fmtNode formats the given node as a string.
[ "fmtNode", "formats", "the", "given", "node", "as", "a", "string", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/hover.go#L671-L678
train
sourcegraph/go-langserver
langserver/internal/refs/refs.go
dereferenceType
func dereferenceType(otyp types.Type) types.Type { for { switch typ := otyp.(type) { case *types.Map: return otyp case dereferencable: otyp = typ.Elem() default: return otyp } } }
go
func dereferenceType(otyp types.Type) types.Type { for { switch typ := otyp.(type) { case *types.Map: return otyp case dereferencable: otyp = typ.Elem() default: return otyp } } }
[ "func", "dereferenceType", "(", "otyp", "types", ".", "Type", ")", "types", ".", "Type", "{", "for", "{", "switch", "typ", ":=", "otyp", ".", "(", "type", ")", "{", "case", "*", "types", ".", "Map", ":", "return", "otyp", "\n", "case", "dereferencabl...
// dereferenceType finds the "root" type of a thing, meaning // the type pointed-to by a pointer, the element type of // a slice or array, or the object type of a chan. The special // case for Map is because a Map would also have a key, and // you might be interested in either of those.
[ "dereferenceType", "finds", "the", "root", "type", "of", "a", "thing", "meaning", "the", "type", "pointed", "-", "to", "by", "a", "pointer", "the", "element", "type", "of", "a", "slice", "or", "array", "or", "the", "object", "type", "of", "a", "chan", ...
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/internal/refs/refs.go#L316-L327
train
sourcegraph/go-langserver
langserver/workspace_refs.go
workspaceRefsFromPkg
func (h *LangHandler) workspaceRefsFromPkg(ctx context.Context, bctx *build.Context, conn jsonrpc2.JSONRPC2, params lspext.WorkspaceReferencesParams, fs *token.FileSet, pkg *loader.PackageInfo, files []*ast.File, rootPath string, results *refResult) (err error) { if err := ctx.Err(); err != nil { return err } span...
go
func (h *LangHandler) workspaceRefsFromPkg(ctx context.Context, bctx *build.Context, conn jsonrpc2.JSONRPC2, params lspext.WorkspaceReferencesParams, fs *token.FileSet, pkg *loader.PackageInfo, files []*ast.File, rootPath string, results *refResult) (err error) { if err := ctx.Err(); err != nil { return err } span...
[ "func", "(", "h", "*", "LangHandler", ")", "workspaceRefsFromPkg", "(", "ctx", "context", ".", "Context", ",", "bctx", "*", "build", ".", "Context", ",", "conn", "jsonrpc2", ".", "JSONRPC2", ",", "params", "lspext", ".", "WorkspaceReferencesParams", ",", "fs...
// workspaceRefsFromPkg collects all the references made to dependencies from // the specified package and returns the results.
[ "workspaceRefsFromPkg", "collects", "all", "the", "references", "made", "to", "dependencies", "from", "the", "specified", "package", "and", "returns", "the", "results", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/workspace_refs.go#L282-L334
train
sourcegraph/go-langserver
langserver/internal/godef/godef.go
parseLocalPackage
func parseLocalPackage(fset *token.FileSet, filename string, src *ast.File, pkgScope *ast.Scope, pathToName parser.ImportPathToName) (*ast.Package, error) { pkg := &ast.Package{src.Name.Name, pkgScope, nil, map[string]*ast.File{filename: src}} d, f := filepath.Split(filename) if d == "" { d = "./" } fd, err := o...
go
func parseLocalPackage(fset *token.FileSet, filename string, src *ast.File, pkgScope *ast.Scope, pathToName parser.ImportPathToName) (*ast.Package, error) { pkg := &ast.Package{src.Name.Name, pkgScope, nil, map[string]*ast.File{filename: src}} d, f := filepath.Split(filename) if d == "" { d = "./" } fd, err := o...
[ "func", "parseLocalPackage", "(", "fset", "*", "token", ".", "FileSet", ",", "filename", "string", ",", "src", "*", "ast", ".", "File", ",", "pkgScope", "*", "ast", ".", "Scope", ",", "pathToName", "parser", ".", "ImportPathToName", ")", "(", "*", "ast",...
// parseLocalPackage reads and parses all go files from the // current directory that implement the same package name // the principal source file, except the original source file // itself, which will already have been parsed. //
[ "parseLocalPackage", "reads", "and", "parses", "all", "go", "files", "from", "the", "current", "directory", "that", "implement", "the", "same", "package", "name", "the", "principal", "source", "file", "except", "the", "original", "source", "file", "itself", "whi...
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/internal/godef/godef.go#L197-L230
train
sourcegraph/go-langserver
langserver/internal/godef/godef.go
pkgName
func pkgName(fset *token.FileSet, filename string) string { prog, _ := parser.ParseFile(fset, filename, nil, parser.PackageClauseOnly, nil, types.DefaultImportPathToName) if prog != nil { return prog.Name.Name } return "" }
go
func pkgName(fset *token.FileSet, filename string) string { prog, _ := parser.ParseFile(fset, filename, nil, parser.PackageClauseOnly, nil, types.DefaultImportPathToName) if prog != nil { return prog.Name.Name } return "" }
[ "func", "pkgName", "(", "fset", "*", "token", ".", "FileSet", ",", "filename", "string", ")", "string", "{", "prog", ",", "_", ":=", "parser", ".", "ParseFile", "(", "fset", ",", "filename", ",", "nil", ",", "parser", ".", "PackageClauseOnly", ",", "ni...
// pkgName returns the package name implemented by the // go source filename. //
[ "pkgName", "returns", "the", "package", "name", "implemented", "by", "the", "go", "source", "filename", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/internal/godef/godef.go#L235-L241
train
sourcegraph/go-langserver
langserver/internal/godef/go/parser/interface.go
ParseExpr
func ParseExpr(fset *token.FileSet, filename string, src interface{}, scope *ast.Scope, pathToName ImportPathToName) (ast.Expr, error) { data, err := readSource(filename, src) if err != nil { return nil, err } var p parser p.init(fset, filename, data, 0, scope, pathToName) x := p.parseExpr() if p.tok == token...
go
func ParseExpr(fset *token.FileSet, filename string, src interface{}, scope *ast.Scope, pathToName ImportPathToName) (ast.Expr, error) { data, err := readSource(filename, src) if err != nil { return nil, err } var p parser p.init(fset, filename, data, 0, scope, pathToName) x := p.parseExpr() if p.tok == token...
[ "func", "ParseExpr", "(", "fset", "*", "token", ".", "FileSet", ",", "filename", "string", ",", "src", "interface", "{", "}", ",", "scope", "*", "ast", ".", "Scope", ",", "pathToName", "ImportPathToName", ")", "(", "ast", ".", "Expr", ",", "error", ")"...
// ParseExpr parses a Go expression and returns the corresponding // AST node. The fset, filename, and src arguments have the same interpretation // as for ParseFile. If there is an error, the result expression // may be nil or contain a partial AST. // // if scope is non-nil, it will be used as the scope for the expre...
[ "ParseExpr", "parses", "a", "Go", "expression", "and", "returns", "the", "corresponding", "AST", "node", ".", "The", "fset", "filename", "and", "src", "arguments", "have", "the", "same", "interpretation", "as", "for", "ParseFile", ".", "If", "there", "is", "...
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/internal/godef/go/parser/interface.go#L72-L85
train
sourcegraph/go-langserver
langserver/internal/godef/go/parser/interface.go
ParseDir
func ParseDir(fset *token.FileSet, path string, filter func(os.FileInfo) bool, mode uint, pathToName ImportPathToName) (map[string]*ast.Package, error) { fd, err := os.Open(path) if err != nil { return nil, err } defer fd.Close() list, err := fd.Readdir(-1) if err != nil { return nil, err } filenames := m...
go
func ParseDir(fset *token.FileSet, path string, filter func(os.FileInfo) bool, mode uint, pathToName ImportPathToName) (map[string]*ast.Package, error) { fd, err := os.Open(path) if err != nil { return nil, err } defer fd.Close() list, err := fd.Readdir(-1) if err != nil { return nil, err } filenames := m...
[ "func", "ParseDir", "(", "fset", "*", "token", ".", "FileSet", ",", "path", "string", ",", "filter", "func", "(", "os", ".", "FileInfo", ")", "bool", ",", "mode", "uint", ",", "pathToName", "ImportPathToName", ")", "(", "map", "[", "string", "]", "*", ...
// ParseDir calls ParseFile for the files in the directory specified by path and // returns a map of package name -> package AST with all the packages found. If // filter != nil, only the files with os.FileInfo entries passing through the filter // are considered. The mode bits are passed to ParseFile unchanged. Positi...
[ "ParseDir", "calls", "ParseFile", "for", "the", "files", "in", "the", "directory", "specified", "by", "path", "and", "returns", "a", "map", "of", "package", "name", "-", ">", "package", "AST", "with", "all", "the", "packages", "found", ".", "If", "filter",...
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/internal/godef/go/parser/interface.go#L176-L200
train
sourcegraph/go-langserver
vfsutil/github_archive.go
NewGitHubRepoVFS
func NewGitHubRepoVFS(ctx context.Context, repo, rev string) (*ArchiveFS, error) { if !githubRepoRx.MatchString(repo) { return nil, fmt.Errorf(`invalid GitHub repo %q: must be "github.com/user/repo"`, repo) } url := fmt.Sprintf("https://codeload.%s/zip/%s", repo, rev) return NewZipVFS(ctx, url, ghFetch.Inc, ghFe...
go
func NewGitHubRepoVFS(ctx context.Context, repo, rev string) (*ArchiveFS, error) { if !githubRepoRx.MatchString(repo) { return nil, fmt.Errorf(`invalid GitHub repo %q: must be "github.com/user/repo"`, repo) } url := fmt.Sprintf("https://codeload.%s/zip/%s", repo, rev) return NewZipVFS(ctx, url, ghFetch.Inc, ghFe...
[ "func", "NewGitHubRepoVFS", "(", "ctx", "context", ".", "Context", ",", "repo", ",", "rev", "string", ")", "(", "*", "ArchiveFS", ",", "error", ")", "{", "if", "!", "githubRepoRx", ".", "MatchString", "(", "repo", ")", "{", "return", "nil", ",", "fmt",...
// NewGitHubRepoVFS creates a new VFS backed by a GitHub downloadable // repository archive.
[ "NewGitHubRepoVFS", "creates", "a", "new", "VFS", "backed", "by", "a", "GitHub", "downloadable", "repository", "archive", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/vfsutil/github_archive.go#L13-L20
train
sourcegraph/go-langserver
langserver/build_context.go
BuildContext
func (h *LangHandler) BuildContext(ctx context.Context) *build.Context { var bctx *build.Context if override := h.init.BuildContext; override != nil { bctx = &build.Context{ GOOS: override.GOOS, GOARCH: override.GOARCH, GOPATH: override.GOPATH, GOROOT: override.GOROOT, CgoEnable...
go
func (h *LangHandler) BuildContext(ctx context.Context) *build.Context { var bctx *build.Context if override := h.init.BuildContext; override != nil { bctx = &build.Context{ GOOS: override.GOOS, GOARCH: override.GOARCH, GOPATH: override.GOPATH, GOROOT: override.GOROOT, CgoEnable...
[ "func", "(", "h", "*", "LangHandler", ")", "BuildContext", "(", "ctx", "context", ".", "Context", ")", "*", "build", ".", "Context", "{", "var", "bctx", "*", "build", ".", "Context", "\n", "if", "override", ":=", "h", ".", "init", ".", "BuildContext", ...
// BuildContext creates a build.Context which uses the overlay FS and the InitializeParams.BuildContext overrides.
[ "BuildContext", "creates", "a", "build", ".", "Context", "which", "uses", "the", "overlay", "FS", "and", "the", "InitializeParams", ".", "BuildContext", "overrides", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/build_context.go#L18-L47
train
sourcegraph/go-langserver
buildserver/deps_refs.go
references
func (d *depCache) references(emitRef func(path string, r goDependencyReference), depthLimit int) { // Example import graph with edge cases: // // '/' (root) // | // a // |\ // b c // \| // .>. d <<<<<<. // | \ / \ | | // .<< e f >>^ | // | ...
go
func (d *depCache) references(emitRef func(path string, r goDependencyReference), depthLimit int) { // Example import graph with edge cases: // // '/' (root) // | // a // |\ // b c // \| // .>. d <<<<<<. // | \ / \ | | // .<< e f >>^ | // | ...
[ "func", "(", "d", "*", "depCache", ")", "references", "(", "emitRef", "func", "(", "path", "string", ",", "r", "goDependencyReference", ")", ",", "depthLimit", "int", ")", "{", "// Example import graph with edge cases:", "//", "// '/' (root)", "// |", ...
// references calls emitRef on each transitive package that has been seen by // the dependency cache. The parameters say that the Go package directory `path` // has imported the Go package described by r.
[ "references", "calls", "emitRef", "on", "each", "transitive", "package", "that", "has", "been", "seen", "by", "the", "dependency", "cache", ".", "The", "parameters", "say", "that", "the", "Go", "package", "directory", "path", "has", "imported", "the", "Go", ...
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/buildserver/deps_refs.go#L60-L168
train
sourcegraph/go-langserver
langserver/internal/godef/go/parser/parser.go
resolve
func (p *parser) resolve(ident *ast.Ident) { if ident.Name == "_" { return } // try to resolve the identifier for s := p.topScope; s != nil; s = s.Outer { if obj := s.Lookup(ident.Name); obj != nil { ident.Obj = obj return } } if p.pkgScope == nil { return } ident.Obj = ast.NewObj(ast.Bad, ident.N...
go
func (p *parser) resolve(ident *ast.Ident) { if ident.Name == "_" { return } // try to resolve the identifier for s := p.topScope; s != nil; s = s.Outer { if obj := s.Lookup(ident.Name); obj != nil { ident.Obj = obj return } } if p.pkgScope == nil { return } ident.Obj = ast.NewObj(ast.Bad, ident.N...
[ "func", "(", "p", "*", "parser", ")", "resolve", "(", "ident", "*", "ast", ".", "Ident", ")", "{", "if", "ident", ".", "Name", "==", "\"", "\"", "{", "return", "\n", "}", "\n", "// try to resolve the identifier", "for", "s", ":=", "p", ".", "topScope...
// newIdent returns a new identifier with attached Object. // If no Object currently exists for the identifier, it is // created in package scope.
[ "newIdent", "returns", "a", "new", "identifier", "with", "attached", "Object", ".", "If", "no", "Object", "currently", "exists", "for", "the", "identifier", "it", "is", "created", "in", "package", "scope", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/internal/godef/go/parser/parser.go#L280-L296
train
sourcegraph/go-langserver
langserver/internal/godef/go/parser/parser.go
next0
func (p *parser) next0() { // Because of one-token look-ahead, print the previous token // when tracing as it provides a more readable output. The // very first token (!p.pos.IsValid()) is not initialized // (it is token.ILLEGAL), so don't print it . if p.trace && p.pos.IsValid() { s := p.tok.String() switch {...
go
func (p *parser) next0() { // Because of one-token look-ahead, print the previous token // when tracing as it provides a more readable output. The // very first token (!p.pos.IsValid()) is not initialized // (it is token.ILLEGAL), so don't print it . if p.trace && p.pos.IsValid() { s := p.tok.String() switch {...
[ "func", "(", "p", "*", "parser", ")", "next0", "(", ")", "{", "// Because of one-token look-ahead, print the previous token", "// when tracing as it provides a more readable output. The", "// very first token (!p.pos.IsValid()) is not initialized", "// (it is token.ILLEGAL), so don't print...
// Advance to the next token.
[ "Advance", "to", "the", "next", "token", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/internal/godef/go/parser/parser.go#L328-L346
train
sourcegraph/go-langserver
langserver/internal/godef/go/parser/parser.go
consumeComment
func (p *parser) consumeComment() (comment *ast.Comment, endline int) { // /*-style comments may end on a different line than where they start. // Scan the comment for '\n' chars and adjust endline accordingly. endline = p.file.Line(p.pos) if p.lit[1] == '*' { for _, b := range p.lit { if b == '\n' { endli...
go
func (p *parser) consumeComment() (comment *ast.Comment, endline int) { // /*-style comments may end on a different line than where they start. // Scan the comment for '\n' chars and adjust endline accordingly. endline = p.file.Line(p.pos) if p.lit[1] == '*' { for _, b := range p.lit { if b == '\n' { endli...
[ "func", "(", "p", "*", "parser", ")", "consumeComment", "(", ")", "(", "comment", "*", "ast", ".", "Comment", ",", "endline", "int", ")", "{", "// /*-style comments may end on a different line than where they start.", "// Scan the comment for '\\n' chars and adjust endline ...
// Consume a comment and return it and the line on which it ends.
[ "Consume", "a", "comment", "and", "return", "it", "and", "the", "line", "on", "which", "it", "ends", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/internal/godef/go/parser/parser.go#L349-L365
train
sourcegraph/go-langserver
langserver/internal/godef/go/parser/parser.go
consumeCommentGroup
func (p *parser) consumeCommentGroup() (comments *ast.CommentGroup, endline int) { var list []*ast.Comment endline = p.file.Line(p.pos) for p.tok == token.COMMENT && endline+1 >= p.file.Line(p.pos) { var comment *ast.Comment comment, endline = p.consumeComment() list = append(list, comment) } // add comment...
go
func (p *parser) consumeCommentGroup() (comments *ast.CommentGroup, endline int) { var list []*ast.Comment endline = p.file.Line(p.pos) for p.tok == token.COMMENT && endline+1 >= p.file.Line(p.pos) { var comment *ast.Comment comment, endline = p.consumeComment() list = append(list, comment) } // add comment...
[ "func", "(", "p", "*", "parser", ")", "consumeCommentGroup", "(", ")", "(", "comments", "*", "ast", ".", "CommentGroup", ",", "endline", "int", ")", "{", "var", "list", "[", "]", "*", "ast", ".", "Comment", "\n", "endline", "=", "p", ".", "file", "...
// Consume a group of adjacent comments, add it to the parser's // comments list, and return it together with the line at which // the last comment in the group ends. An empty line or non-comment // token terminates a comment group. //
[ "Consume", "a", "group", "of", "adjacent", "comments", "add", "it", "to", "the", "parser", "s", "comments", "list", "and", "return", "it", "together", "with", "the", "line", "at", "which", "the", "last", "comment", "in", "the", "group", "ends", ".", "An"...
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/internal/godef/go/parser/parser.go#L372-L386
train
sourcegraph/go-langserver
langserver/internal/godef/go/parser/parser.go
next
func (p *parser) next() { p.leadComment = nil p.lineComment = nil line := p.file.Line(p.pos) // current line p.next0() if p.tok == token.COMMENT { var comment *ast.CommentGroup var endline int if p.file.Line(p.pos) == line { // The comment is on same line as previous token; it // cannot be a lead com...
go
func (p *parser) next() { p.leadComment = nil p.lineComment = nil line := p.file.Line(p.pos) // current line p.next0() if p.tok == token.COMMENT { var comment *ast.CommentGroup var endline int if p.file.Line(p.pos) == line { // The comment is on same line as previous token; it // cannot be a lead com...
[ "func", "(", "p", "*", "parser", ")", "next", "(", ")", "{", "p", ".", "leadComment", "=", "nil", "\n", "p", ".", "lineComment", "=", "nil", "\n", "line", ":=", "p", ".", "file", ".", "Line", "(", "p", ".", "pos", ")", "// current line", "\n", ...
// Advance to the next non-comment token. In the process, collect // any comment groups encountered, and remember the last lead and // and line comments. // // A lead comment is a comment group that starts and ends in a // line without any other tokens and that is followed by a non-comment // token on the line immediat...
[ "Advance", "to", "the", "next", "non", "-", "comment", "token", ".", "In", "the", "process", "collect", "any", "comment", "groups", "encountered", "and", "remember", "the", "last", "lead", "and", "and", "line", "comments", ".", "A", "lead", "comment", "is"...
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/internal/godef/go/parser/parser.go#L403-L436
train
sourcegraph/go-langserver
langserver/internal/godef/go/parser/parser.go
makeAnonField
func makeAnonField(t, declType ast.Expr) ast.Expr { switch t := t.(type) { case *ast.Ident: id := new(ast.Ident) *id = *t id.Obj = ast.NewObj(ast.Var, id.Name) id.Obj.Decl = &ast.Field{nil, []*ast.Ident{id}, declType, nil, nil} return id case *ast.SelectorExpr: return &ast.SelectorExpr{t.X, makeAnonFiel...
go
func makeAnonField(t, declType ast.Expr) ast.Expr { switch t := t.(type) { case *ast.Ident: id := new(ast.Ident) *id = *t id.Obj = ast.NewObj(ast.Var, id.Name) id.Obj.Decl = &ast.Field{nil, []*ast.Ident{id}, declType, nil, nil} return id case *ast.SelectorExpr: return &ast.SelectorExpr{t.X, makeAnonFiel...
[ "func", "makeAnonField", "(", "t", ",", "declType", "ast", ".", "Expr", ")", "ast", ".", "Expr", "{", "switch", "t", ":=", "t", ".", "(", "type", ")", "{", "case", "*", "ast", ".", "Ident", ":", "id", ":=", "new", "(", "ast", ".", "Ident", ")",...
// The object for the identifier in an anonymous // field must point to the original type because // the object has its own identity as a field member. //
[ "The", "object", "for", "the", "identifier", "in", "an", "anonymous", "field", "must", "point", "to", "the", "original", "type", "because", "the", "object", "has", "its", "own", "identity", "as", "a", "field", "member", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/internal/godef/go/parser/parser.go#L664-L680
train
sourcegraph/go-langserver
langserver/internal/godef/go/parser/parser.go
isLiteralType
func isLiteralType(x ast.Expr) bool { switch t := x.(type) { case *ast.BadExpr: case *ast.Ident: case *ast.SelectorExpr: _, isIdent := t.X.(*ast.Ident) return isIdent case *ast.ArrayType: case *ast.StructType: case *ast.MapType: default: return false // all other nodes are not legal composite literal type...
go
func isLiteralType(x ast.Expr) bool { switch t := x.(type) { case *ast.BadExpr: case *ast.Ident: case *ast.SelectorExpr: _, isIdent := t.X.(*ast.Ident) return isIdent case *ast.ArrayType: case *ast.StructType: case *ast.MapType: default: return false // all other nodes are not legal composite literal type...
[ "func", "isLiteralType", "(", "x", "ast", ".", "Expr", ")", "bool", "{", "switch", "t", ":=", "x", ".", "(", "type", ")", "{", "case", "*", "ast", ".", "BadExpr", ":", "case", "*", "ast", ".", "Ident", ":", "case", "*", "ast", ".", "SelectorExpr"...
// isLiteralType returns true iff x is a legal composite literal type.
[ "isLiteralType", "returns", "true", "iff", "x", "is", "a", "legal", "composite", "literal", "type", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/internal/godef/go/parser/parser.go#L1272-L1286
train
sourcegraph/go-langserver
langserver/internal/godef/go/parser/parser.go
newScope
func (p *parser) newScope(outer *ast.Scope) *ast.Scope { if p.topScope == nil { return nil } return ast.NewScope(outer) }
go
func (p *parser) newScope(outer *ast.Scope) *ast.Scope { if p.topScope == nil { return nil } return ast.NewScope(outer) }
[ "func", "(", "p", "*", "parser", ")", "newScope", "(", "outer", "*", "ast", ".", "Scope", ")", "*", "ast", ".", "Scope", "{", "if", "p", ".", "topScope", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "return", "ast", ".", "NewScope", "(", ...
// newScope creates a new scope only if we're using scopes.
[ "newScope", "creates", "a", "new", "scope", "only", "if", "we", "re", "using", "scopes", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/internal/godef/go/parser/parser.go#L2200-L2205
train
sourcegraph/go-langserver
langserver/internal/gocode/suggest/suggest.go
Suggest
func (c *Config) Suggest(filename string, data []byte, cursor int) ([]Candidate, int, error) { if cursor < 0 { return nil, 0, nil } a, err := c.analyzePackage(filename, data, cursor) if err != nil { return nil, 0, err } fset := a.fset pos := a.pos pkg := a.pkg if pkg == nil { return nil, 0, nil } scop...
go
func (c *Config) Suggest(filename string, data []byte, cursor int) ([]Candidate, int, error) { if cursor < 0 { return nil, 0, nil } a, err := c.analyzePackage(filename, data, cursor) if err != nil { return nil, 0, err } fset := a.fset pos := a.pos pkg := a.pkg if pkg == nil { return nil, 0, nil } scop...
[ "func", "(", "c", "*", "Config", ")", "Suggest", "(", "filename", "string", ",", "data", "[", "]", "byte", ",", "cursor", "int", ")", "(", "[", "]", "Candidate", ",", "int", ",", "error", ")", "{", "if", "cursor", "<", "0", "{", "return", "nil", ...
// Suggest returns a list of suggestion candidates and the length of // the text that should be replaced, if any.
[ "Suggest", "returns", "a", "list", "of", "suggestion", "candidates", "and", "the", "length", "of", "the", "text", "that", "should", "be", "replaced", "if", "any", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/internal/gocode/suggest/suggest.go#L32-L91
train
sourcegraph/go-langserver
diskcache/cache.go
Open
func (s *Store) Open(ctx context.Context, key string, fetcher Fetcher) (file *File, err error) { span, ctx := opentracing.StartSpanFromContext(ctx, "Cached Fetch") if s.Component != "" { ext.Component.Set(span, s.Component) } defer func() { if err != nil { ext.Error.Set(span, true) span.SetTag("err", err....
go
func (s *Store) Open(ctx context.Context, key string, fetcher Fetcher) (file *File, err error) { span, ctx := opentracing.StartSpanFromContext(ctx, "Cached Fetch") if s.Component != "" { ext.Component.Set(span, s.Component) } defer func() { if err != nil { ext.Error.Set(span, true) span.SetTag("err", err....
[ "func", "(", "s", "*", "Store", ")", "Open", "(", "ctx", "context", ".", "Context", ",", "key", "string", ",", "fetcher", "Fetcher", ")", "(", "file", "*", "File", ",", "err", "error", ")", "{", "span", ",", "ctx", ":=", "opentracing", ".", "StartS...
// Open will open a file from the local cache with key. If missing, fetcher // will fill the cache first. Open also performs single-flighting for fetcher.
[ "Open", "will", "open", "a", "file", "from", "the", "local", "cache", "with", "key", ".", "If", "missing", "fetcher", "will", "fill", "the", "cache", "first", ".", "Open", "also", "performs", "single", "-", "flighting", "for", "fetcher", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/diskcache/cache.go#L58-L121
train
sourcegraph/go-langserver
diskcache/cache.go
EvictMaxSize
func (s *Store) EvictMaxSize(maxCacheSizeBytes int64) (stats EvictStats, err error) { isZip := func(fi os.FileInfo) bool { return strings.HasSuffix(fi.Name(), ".zip") } list, err := ioutil.ReadDir(s.Dir) if err != nil { if os.IsNotExist(err) { return EvictStats{ CacheSize: 0, Evicted: 0, }, nil...
go
func (s *Store) EvictMaxSize(maxCacheSizeBytes int64) (stats EvictStats, err error) { isZip := func(fi os.FileInfo) bool { return strings.HasSuffix(fi.Name(), ".zip") } list, err := ioutil.ReadDir(s.Dir) if err != nil { if os.IsNotExist(err) { return EvictStats{ CacheSize: 0, Evicted: 0, }, nil...
[ "func", "(", "s", "*", "Store", ")", "EvictMaxSize", "(", "maxCacheSizeBytes", "int64", ")", "(", "stats", "EvictStats", ",", "err", "error", ")", "{", "isZip", ":=", "func", "(", "fi", "os", ".", "FileInfo", ")", "bool", "{", "return", "strings", ".",...
// Evict will remove files from Store.Dir until it is smaller than // maxCacheSizeBytes. It evicts files with the oldest modification time first.
[ "Evict", "will", "remove", "files", "from", "Store", ".", "Dir", "until", "it", "is", "smaller", "than", "maxCacheSizeBytes", ".", "It", "evicts", "files", "with", "the", "oldest", "modification", "time", "first", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/diskcache/cache.go#L199-L255
train
sourcegraph/go-langserver
langserver/util/util.go
PathHasPrefix
func PathHasPrefix(s, prefix string) bool { s = normalizePath(s) prefix = normalizePath(prefix) if s == prefix { return true } if !strings.HasSuffix(prefix, "/") { prefix += "/" } return s == prefix || strings.HasPrefix(s, prefix) }
go
func PathHasPrefix(s, prefix string) bool { s = normalizePath(s) prefix = normalizePath(prefix) if s == prefix { return true } if !strings.HasSuffix(prefix, "/") { prefix += "/" } return s == prefix || strings.HasPrefix(s, prefix) }
[ "func", "PathHasPrefix", "(", "s", ",", "prefix", "string", ")", "bool", "{", "s", "=", "normalizePath", "(", "s", ")", "\n", "prefix", "=", "normalizePath", "(", "prefix", ")", "\n", "if", "s", "==", "prefix", "{", "return", "true", "\n", "}", "\n",...
// PathHasPrefix returns true if s is starts with the given prefix
[ "PathHasPrefix", "returns", "true", "if", "s", "is", "starts", "with", "the", "given", "prefix" ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/util/util.go#L31-L41
train
sourcegraph/go-langserver
langserver/util/util.go
PathTrimPrefix
func PathTrimPrefix(s, prefix string) string { s = normalizePath(s) prefix = normalizePath(prefix) if s == prefix { return "" } if !strings.HasSuffix(prefix, "/") { prefix += "/" } return strings.TrimPrefix(s, prefix) }
go
func PathTrimPrefix(s, prefix string) string { s = normalizePath(s) prefix = normalizePath(prefix) if s == prefix { return "" } if !strings.HasSuffix(prefix, "/") { prefix += "/" } return strings.TrimPrefix(s, prefix) }
[ "func", "PathTrimPrefix", "(", "s", ",", "prefix", "string", ")", "string", "{", "s", "=", "normalizePath", "(", "s", ")", "\n", "prefix", "=", "normalizePath", "(", "prefix", ")", "\n", "if", "s", "==", "prefix", "{", "return", "\"", "\"", "\n", "}"...
// PathTrimPrefix removes the prefix from s
[ "PathTrimPrefix", "removes", "the", "prefix", "from", "s" ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/util/util.go#L44-L54
train
sourcegraph/go-langserver
langserver/util/util.go
IsVendorDir
func IsVendorDir(dir string) bool { return strings.HasPrefix(dir, "vendor/") || strings.Contains(dir, "/vendor/") }
go
func IsVendorDir(dir string) bool { return strings.HasPrefix(dir, "vendor/") || strings.Contains(dir, "/vendor/") }
[ "func", "IsVendorDir", "(", "dir", "string", ")", "bool", "{", "return", "strings", ".", "HasPrefix", "(", "dir", ",", "\"", "\"", ")", "||", "strings", ".", "Contains", "(", "dir", ",", "\"", "\"", ")", "\n", "}" ]
// IsVendorDir tells if the specified directory is a vendor directory.
[ "IsVendorDir", "tells", "if", "the", "specified", "directory", "is", "a", "vendor", "directory", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/util/util.go#L62-L64
train
sourcegraph/go-langserver
langserver/util/util.go
PathToURI
func PathToURI(path string) lsp.DocumentURI { path = filepath.ToSlash(path) parts := strings.SplitN(path, "/", 2) // If the first segment is a Windows drive letter, prefix with a slash and skip encoding head := parts[0] if head != "" { head = "/" + head } rest := "" if len(parts) > 1 { rest = "/" + parts[...
go
func PathToURI(path string) lsp.DocumentURI { path = filepath.ToSlash(path) parts := strings.SplitN(path, "/", 2) // If the first segment is a Windows drive letter, prefix with a slash and skip encoding head := parts[0] if head != "" { head = "/" + head } rest := "" if len(parts) > 1 { rest = "/" + parts[...
[ "func", "PathToURI", "(", "path", "string", ")", "lsp", ".", "DocumentURI", "{", "path", "=", "filepath", ".", "ToSlash", "(", "path", ")", "\n", "parts", ":=", "strings", ".", "SplitN", "(", "path", ",", "\"", "\"", ",", "2", ")", "\n\n", "// If the...
// PathToURI converts given absolute path to file URI
[ "PathToURI", "converts", "given", "absolute", "path", "to", "file", "URI" ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/util/util.go#L76-L92
train
sourcegraph/go-langserver
langserver/util/util.go
UriToPath
func UriToPath(uri lsp.DocumentURI) string { u, err := url.Parse(string(uri)) if err != nil { return trimFilePrefix(string(uri)) } return u.Path }
go
func UriToPath(uri lsp.DocumentURI) string { u, err := url.Parse(string(uri)) if err != nil { return trimFilePrefix(string(uri)) } return u.Path }
[ "func", "UriToPath", "(", "uri", "lsp", ".", "DocumentURI", ")", "string", "{", "u", ",", "err", ":=", "url", ".", "Parse", "(", "string", "(", "uri", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "trimFilePrefix", "(", "string", "(", "u...
// UriToPath converts given file URI to path
[ "UriToPath", "converts", "given", "file", "URI", "to", "path" ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/util/util.go#L95-L101
train
sourcegraph/go-langserver
langserver/util/util.go
UriToRealPath
func UriToRealPath(uri lsp.DocumentURI) string { path := UriToPath(uri) if regDriveLetter.MatchString(path) { // remove the leading slash if it starts with a drive letter // and convert to back slashes path = filepath.FromSlash(path[1:]) } return path }
go
func UriToRealPath(uri lsp.DocumentURI) string { path := UriToPath(uri) if regDriveLetter.MatchString(path) { // remove the leading slash if it starts with a drive letter // and convert to back slashes path = filepath.FromSlash(path[1:]) } return path }
[ "func", "UriToRealPath", "(", "uri", "lsp", ".", "DocumentURI", ")", "string", "{", "path", ":=", "UriToPath", "(", "uri", ")", "\n\n", "if", "regDriveLetter", ".", "MatchString", "(", "path", ")", "{", "// remove the leading slash if it starts with a drive letter",...
// UriToRealPath converts the given file URI to the platform specific path
[ "UriToRealPath", "converts", "the", "given", "file", "URI", "to", "the", "platform", "specific", "path" ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/util/util.go#L106-L116
train
sourcegraph/go-langserver
langserver/util/util.go
IsAbs
func IsAbs(path string) bool { // Windows implementation accepts path-like and filepath-like arguments return strings.HasPrefix(path, "/") || filepath.IsAbs(path) }
go
func IsAbs(path string) bool { // Windows implementation accepts path-like and filepath-like arguments return strings.HasPrefix(path, "/") || filepath.IsAbs(path) }
[ "func", "IsAbs", "(", "path", "string", ")", "bool", "{", "// Windows implementation accepts path-like and filepath-like arguments", "return", "strings", ".", "HasPrefix", "(", "path", ",", "\"", "\"", ")", "||", "filepath", ".", "IsAbs", "(", "path", ")", "\n", ...
// IsAbs returns true if the given path is absolute
[ "IsAbs", "returns", "true", "if", "the", "given", "path", "is", "absolute" ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/util/util.go#L119-L122
train
sourcegraph/go-langserver
langserver/tracing.go
InitTracer
func (h *HandlerCommon) InitTracer(conn *jsonrpc2.Conn) { h.mu.Lock() defer h.mu.Unlock() if h.tracer != nil { return } if _, isNoopTracer := opentracing.GlobalTracer().(opentracing.NoopTracer); !isNoopTracer { // We have configured a tracer, use that instead of telemetry/event h.tracer = opentracing.Global...
go
func (h *HandlerCommon) InitTracer(conn *jsonrpc2.Conn) { h.mu.Lock() defer h.mu.Unlock() if h.tracer != nil { return } if _, isNoopTracer := opentracing.GlobalTracer().(opentracing.NoopTracer); !isNoopTracer { // We have configured a tracer, use that instead of telemetry/event h.tracer = opentracing.Global...
[ "func", "(", "h", "*", "HandlerCommon", ")", "InitTracer", "(", "conn", "*", "jsonrpc2", ".", "Conn", ")", "{", "h", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "h", ".", "mu", ".", "Unlock", "(", ")", "\n", "if", "h", ".", "tracer", "!=",...
// InitTracer initializes the tracer for the connection if it has not // already been initialized. // // It assumes that h is only ever called for this conn.
[ "InitTracer", "initializes", "the", "tracer", "for", "the", "connection", "if", "it", "has", "not", "already", "been", "initialized", ".", "It", "assumes", "that", "h", "is", "only", "ever", "called", "for", "this", "conn", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/tracing.go#L19-L42
train
sourcegraph/go-langserver
langserver/tracing.go
startSpanFollowsFromContext
func startSpanFollowsFromContext(ctx context.Context, operationName string, opts ...opentracing.StartSpanOption) opentracing.Span { if parentSpan := opentracing.SpanFromContext(ctx); parentSpan != nil { opts = append(opts, opentracing.FollowsFrom(parentSpan.Context())) return parentSpan.Tracer().StartSpan(operatio...
go
func startSpanFollowsFromContext(ctx context.Context, operationName string, opts ...opentracing.StartSpanOption) opentracing.Span { if parentSpan := opentracing.SpanFromContext(ctx); parentSpan != nil { opts = append(opts, opentracing.FollowsFrom(parentSpan.Context())) return parentSpan.Tracer().StartSpan(operatio...
[ "func", "startSpanFollowsFromContext", "(", "ctx", "context", ".", "Context", ",", "operationName", "string", ",", "opts", "...", "opentracing", ".", "StartSpanOption", ")", "opentracing", ".", "Span", "{", "if", "parentSpan", ":=", "opentracing", ".", "SpanFromCo...
// FollowsFrom means the parent span does not depend on the child span, but // caused it to start.
[ "FollowsFrom", "means", "the", "parent", "span", "does", "not", "depend", "on", "the", "child", "span", "but", "caused", "it", "to", "start", "." ]
33d2968a49e1131825a0accdd64bdf9901cf144c
https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/tracing.go#L109-L115
train
radovskyb/watcher
watcher.go
String
func (e Op) String() string { if op, found := ops[e]; found { return op } return "???" }
go
func (e Op) String() string { if op, found := ops[e]; found { return op } return "???" }
[ "func", "(", "e", "Op", ")", "String", "(", ")", "string", "{", "if", "op", ",", "found", ":=", "ops", "[", "e", "]", ";", "found", "{", "return", "op", "\n", "}", "\n", "return", "\"", "\"", "\n", "}" ]
// String prints the string version of the Op consts
[ "String", "prints", "the", "string", "version", "of", "the", "Op", "consts" ]
f33c874a09dcfac90f008abeee9171d88431e212
https://github.com/radovskyb/watcher/blob/f33c874a09dcfac90f008abeee9171d88431e212/watcher.go#L58-L63
train
radovskyb/watcher
watcher.go
String
func (e Event) String() string { if e.FileInfo == nil { return "???" } pathType := "FILE" if e.IsDir() { pathType = "DIRECTORY" } return fmt.Sprintf("%s %q %s [%s]", pathType, e.Name(), e.Op, e.Path) }
go
func (e Event) String() string { if e.FileInfo == nil { return "???" } pathType := "FILE" if e.IsDir() { pathType = "DIRECTORY" } return fmt.Sprintf("%s %q %s [%s]", pathType, e.Name(), e.Op, e.Path) }
[ "func", "(", "e", "Event", ")", "String", "(", ")", "string", "{", "if", "e", ".", "FileInfo", "==", "nil", "{", "return", "\"", "\"", "\n", "}", "\n\n", "pathType", ":=", "\"", "\"", "\n", "if", "e", ".", "IsDir", "(", ")", "{", "pathType", "=...
// String returns a string depending on what type of event occurred and the // file name associated with the event.
[ "String", "returns", "a", "string", "depending", "on", "what", "type", "of", "event", "occurred", "and", "the", "file", "name", "associated", "with", "the", "event", "." ]
f33c874a09dcfac90f008abeee9171d88431e212
https://github.com/radovskyb/watcher/blob/f33c874a09dcfac90f008abeee9171d88431e212/watcher.go#L76-L86
train
radovskyb/watcher
watcher.go
RegexFilterHook
func RegexFilterHook(r *regexp.Regexp, useFullPath bool) FilterFileHookFunc { return func(info os.FileInfo, fullPath string) error { str := info.Name() if useFullPath { str = fullPath } // Match if r.MatchString(str) { return nil } // No match. return ErrSkip } }
go
func RegexFilterHook(r *regexp.Regexp, useFullPath bool) FilterFileHookFunc { return func(info os.FileInfo, fullPath string) error { str := info.Name() if useFullPath { str = fullPath } // Match if r.MatchString(str) { return nil } // No match. return ErrSkip } }
[ "func", "RegexFilterHook", "(", "r", "*", "regexp", ".", "Regexp", ",", "useFullPath", "bool", ")", "FilterFileHookFunc", "{", "return", "func", "(", "info", "os", ".", "FileInfo", ",", "fullPath", "string", ")", "error", "{", "str", ":=", "info", ".", "...
// RegexFilterHook is a function that accepts or rejects a file // for listing based on whether it's filename or full path matches // a regular expression.
[ "RegexFilterHook", "is", "a", "function", "that", "accepts", "or", "rejects", "a", "file", "for", "listing", "based", "on", "whether", "it", "s", "filename", "or", "full", "path", "matches", "a", "regular", "expression", "." ]
f33c874a09dcfac90f008abeee9171d88431e212
https://github.com/radovskyb/watcher/blob/f33c874a09dcfac90f008abeee9171d88431e212/watcher.go#L95-L111
train
radovskyb/watcher
watcher.go
New
func New() *Watcher { // Set up the WaitGroup for w.Wait(). var wg sync.WaitGroup wg.Add(1) return &Watcher{ Event: make(chan Event), Error: make(chan error), Closed: make(chan struct{}), close: make(chan struct{}), mu: new(sync.Mutex), wg: &wg, files: make(map[string]os.FileInfo),...
go
func New() *Watcher { // Set up the WaitGroup for w.Wait(). var wg sync.WaitGroup wg.Add(1) return &Watcher{ Event: make(chan Event), Error: make(chan error), Closed: make(chan struct{}), close: make(chan struct{}), mu: new(sync.Mutex), wg: &wg, files: make(map[string]os.FileInfo),...
[ "func", "New", "(", ")", "*", "Watcher", "{", "// Set up the WaitGroup for w.Wait().", "var", "wg", "sync", ".", "WaitGroup", "\n", "wg", ".", "Add", "(", "1", ")", "\n\n", "return", "&", "Watcher", "{", "Event", ":", "make", "(", "chan", "Event", ")", ...
// New creates a new Watcher.
[ "New", "creates", "a", "new", "Watcher", "." ]
f33c874a09dcfac90f008abeee9171d88431e212
https://github.com/radovskyb/watcher/blob/f33c874a09dcfac90f008abeee9171d88431e212/watcher.go#L134-L150
train
radovskyb/watcher
watcher.go
SetMaxEvents
func (w *Watcher) SetMaxEvents(delta int) { w.mu.Lock() w.maxEvents = delta w.mu.Unlock() }
go
func (w *Watcher) SetMaxEvents(delta int) { w.mu.Lock() w.maxEvents = delta w.mu.Unlock() }
[ "func", "(", "w", "*", "Watcher", ")", "SetMaxEvents", "(", "delta", "int", ")", "{", "w", ".", "mu", ".", "Lock", "(", ")", "\n", "w", ".", "maxEvents", "=", "delta", "\n", "w", ".", "mu", ".", "Unlock", "(", ")", "\n", "}" ]
// SetMaxEvents controls the maximum amount of events that are sent on // the Event channel per watching cycle. If max events is less than 1, there is // no limit, which is the default.
[ "SetMaxEvents", "controls", "the", "maximum", "amount", "of", "events", "that", "are", "sent", "on", "the", "Event", "channel", "per", "watching", "cycle", ".", "If", "max", "events", "is", "less", "than", "1", "there", "is", "no", "limit", "which", "is", ...
f33c874a09dcfac90f008abeee9171d88431e212
https://github.com/radovskyb/watcher/blob/f33c874a09dcfac90f008abeee9171d88431e212/watcher.go#L155-L159
train
radovskyb/watcher
watcher.go
IgnoreHiddenFiles
func (w *Watcher) IgnoreHiddenFiles(ignore bool) { w.mu.Lock() w.ignoreHidden = ignore w.mu.Unlock() }
go
func (w *Watcher) IgnoreHiddenFiles(ignore bool) { w.mu.Lock() w.ignoreHidden = ignore w.mu.Unlock() }
[ "func", "(", "w", "*", "Watcher", ")", "IgnoreHiddenFiles", "(", "ignore", "bool", ")", "{", "w", ".", "mu", ".", "Lock", "(", ")", "\n", "w", ".", "ignoreHidden", "=", "ignore", "\n", "w", ".", "mu", ".", "Unlock", "(", ")", "\n", "}" ]
// IgnoreHiddenFiles sets the watcher to ignore any file or directory // that starts with a dot.
[ "IgnoreHiddenFiles", "sets", "the", "watcher", "to", "ignore", "any", "file", "or", "directory", "that", "starts", "with", "a", "dot", "." ]
f33c874a09dcfac90f008abeee9171d88431e212
https://github.com/radovskyb/watcher/blob/f33c874a09dcfac90f008abeee9171d88431e212/watcher.go#L170-L174
train
radovskyb/watcher
watcher.go
FilterOps
func (w *Watcher) FilterOps(ops ...Op) { w.mu.Lock() w.ops = make(map[Op]struct{}) for _, op := range ops { w.ops[op] = struct{}{} } w.mu.Unlock() }
go
func (w *Watcher) FilterOps(ops ...Op) { w.mu.Lock() w.ops = make(map[Op]struct{}) for _, op := range ops { w.ops[op] = struct{}{} } w.mu.Unlock() }
[ "func", "(", "w", "*", "Watcher", ")", "FilterOps", "(", "ops", "...", "Op", ")", "{", "w", ".", "mu", ".", "Lock", "(", ")", "\n", "w", ".", "ops", "=", "make", "(", "map", "[", "Op", "]", "struct", "{", "}", ")", "\n", "for", "_", ",", ...
// FilterOps filters which event op types should be returned // when an event occurs.
[ "FilterOps", "filters", "which", "event", "op", "types", "should", "be", "returned", "when", "an", "event", "occurs", "." ]
f33c874a09dcfac90f008abeee9171d88431e212
https://github.com/radovskyb/watcher/blob/f33c874a09dcfac90f008abeee9171d88431e212/watcher.go#L178-L185
train
radovskyb/watcher
watcher.go
Add
func (w *Watcher) Add(name string) (err error) { w.mu.Lock() defer w.mu.Unlock() name, err = filepath.Abs(name) if err != nil { return err } // If name is on the ignored list or if hidden files are // ignored and name is a hidden file or directory, simply return. _, ignored := w.ignored[name] isHidden, er...
go
func (w *Watcher) Add(name string) (err error) { w.mu.Lock() defer w.mu.Unlock() name, err = filepath.Abs(name) if err != nil { return err } // If name is on the ignored list or if hidden files are // ignored and name is a hidden file or directory, simply return. _, ignored := w.ignored[name] isHidden, er...
[ "func", "(", "w", "*", "Watcher", ")", "Add", "(", "name", "string", ")", "(", "err", "error", ")", "{", "w", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "w", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "name", ",", "err", "=", "filepath...
// Add adds either a single file or directory to the file list.
[ "Add", "adds", "either", "a", "single", "file", "or", "directory", "to", "the", "file", "list", "." ]
f33c874a09dcfac90f008abeee9171d88431e212
https://github.com/radovskyb/watcher/blob/f33c874a09dcfac90f008abeee9171d88431e212/watcher.go#L188-L223
train
radovskyb/watcher
watcher.go
AddRecursive
func (w *Watcher) AddRecursive(name string) (err error) { w.mu.Lock() defer w.mu.Unlock() name, err = filepath.Abs(name) if err != nil { return err } fileList, err := w.listRecursive(name) if err != nil { return err } for k, v := range fileList { w.files[k] = v } // Add the name to the names list. ...
go
func (w *Watcher) AddRecursive(name string) (err error) { w.mu.Lock() defer w.mu.Unlock() name, err = filepath.Abs(name) if err != nil { return err } fileList, err := w.listRecursive(name) if err != nil { return err } for k, v := range fileList { w.files[k] = v } // Add the name to the names list. ...
[ "func", "(", "w", "*", "Watcher", ")", "AddRecursive", "(", "name", "string", ")", "(", "err", "error", ")", "{", "w", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "w", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "name", ",", "err", "=", ...
// AddRecursive adds either a single file or directory recursively to the file list.
[ "AddRecursive", "adds", "either", "a", "single", "file", "or", "directory", "recursively", "to", "the", "file", "list", "." ]
f33c874a09dcfac90f008abeee9171d88431e212
https://github.com/radovskyb/watcher/blob/f33c874a09dcfac90f008abeee9171d88431e212/watcher.go#L279-L300
train
radovskyb/watcher
watcher.go
Remove
func (w *Watcher) Remove(name string) (err error) { w.mu.Lock() defer w.mu.Unlock() name, err = filepath.Abs(name) if err != nil { return err } // Remove the name from w's names list. delete(w.names, name) // If name is a single file, remove it and return. info, found := w.files[name] if !found { retur...
go
func (w *Watcher) Remove(name string) (err error) { w.mu.Lock() defer w.mu.Unlock() name, err = filepath.Abs(name) if err != nil { return err } // Remove the name from w's names list. delete(w.names, name) // If name is a single file, remove it and return. info, found := w.files[name] if !found { retur...
[ "func", "(", "w", "*", "Watcher", ")", "Remove", "(", "name", "string", ")", "(", "err", "error", ")", "{", "w", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "w", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "name", ",", "err", "=", "filep...
// Remove removes either a single file or directory from the file's list.
[ "Remove", "removes", "either", "a", "single", "file", "or", "directory", "from", "the", "file", "s", "list", "." ]
f33c874a09dcfac90f008abeee9171d88431e212
https://github.com/radovskyb/watcher/blob/f33c874a09dcfac90f008abeee9171d88431e212/watcher.go#L342-L374
train
radovskyb/watcher
watcher.go
RemoveRecursive
func (w *Watcher) RemoveRecursive(name string) (err error) { w.mu.Lock() defer w.mu.Unlock() name, err = filepath.Abs(name) if err != nil { return err } // Remove the name from w's names list. delete(w.names, name) // If name is a single file, remove it and return. info, found := w.files[name] if !found ...
go
func (w *Watcher) RemoveRecursive(name string) (err error) { w.mu.Lock() defer w.mu.Unlock() name, err = filepath.Abs(name) if err != nil { return err } // Remove the name from w's names list. delete(w.names, name) // If name is a single file, remove it and return. info, found := w.files[name] if !found ...
[ "func", "(", "w", "*", "Watcher", ")", "RemoveRecursive", "(", "name", "string", ")", "(", "err", "error", ")", "{", "w", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "w", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "name", ",", "err", "=",...
// RemoveRecursive removes either a single file or a directory recursively from // the file's list.
[ "RemoveRecursive", "removes", "either", "a", "single", "file", "or", "a", "directory", "recursively", "from", "the", "file", "s", "list", "." ]
f33c874a09dcfac90f008abeee9171d88431e212
https://github.com/radovskyb/watcher/blob/f33c874a09dcfac90f008abeee9171d88431e212/watcher.go#L378-L408
train
radovskyb/watcher
watcher.go
Ignore
func (w *Watcher) Ignore(paths ...string) (err error) { for _, path := range paths { path, err = filepath.Abs(path) if err != nil { return err } // Remove any of the paths that were already added. if err := w.RemoveRecursive(path); err != nil { return err } w.mu.Lock() w.ignored[path] = struct{}{...
go
func (w *Watcher) Ignore(paths ...string) (err error) { for _, path := range paths { path, err = filepath.Abs(path) if err != nil { return err } // Remove any of the paths that were already added. if err := w.RemoveRecursive(path); err != nil { return err } w.mu.Lock() w.ignored[path] = struct{}{...
[ "func", "(", "w", "*", "Watcher", ")", "Ignore", "(", "paths", "...", "string", ")", "(", "err", "error", ")", "{", "for", "_", ",", "path", ":=", "range", "paths", "{", "path", ",", "err", "=", "filepath", ".", "Abs", "(", "path", ")", "\n", "...
// Ignore adds paths that should be ignored. // // For files that are already added, Ignore removes them.
[ "Ignore", "adds", "paths", "that", "should", "be", "ignored", ".", "For", "files", "that", "are", "already", "added", "Ignore", "removes", "them", "." ]
f33c874a09dcfac90f008abeee9171d88431e212
https://github.com/radovskyb/watcher/blob/f33c874a09dcfac90f008abeee9171d88431e212/watcher.go#L413-L428
train
radovskyb/watcher
watcher.go
WatchedFiles
func (w *Watcher) WatchedFiles() map[string]os.FileInfo { w.mu.Lock() defer w.mu.Unlock() files := make(map[string]os.FileInfo) for k, v := range w.files { files[k] = v } return files }
go
func (w *Watcher) WatchedFiles() map[string]os.FileInfo { w.mu.Lock() defer w.mu.Unlock() files := make(map[string]os.FileInfo) for k, v := range w.files { files[k] = v } return files }
[ "func", "(", "w", "*", "Watcher", ")", "WatchedFiles", "(", ")", "map", "[", "string", "]", "os", ".", "FileInfo", "{", "w", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "w", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "files", ":=", "make"...
// WatchedFiles returns a map of files added to a Watcher.
[ "WatchedFiles", "returns", "a", "map", "of", "files", "added", "to", "a", "Watcher", "." ]
f33c874a09dcfac90f008abeee9171d88431e212
https://github.com/radovskyb/watcher/blob/f33c874a09dcfac90f008abeee9171d88431e212/watcher.go#L431-L441
train
radovskyb/watcher
watcher.go
TriggerEvent
func (w *Watcher) TriggerEvent(eventType Op, file os.FileInfo) { w.Wait() if file == nil { file = &fileInfo{name: "triggered event", modTime: time.Now()} } w.Event <- Event{Op: eventType, Path: "-", FileInfo: file} }
go
func (w *Watcher) TriggerEvent(eventType Op, file os.FileInfo) { w.Wait() if file == nil { file = &fileInfo{name: "triggered event", modTime: time.Now()} } w.Event <- Event{Op: eventType, Path: "-", FileInfo: file} }
[ "func", "(", "w", "*", "Watcher", ")", "TriggerEvent", "(", "eventType", "Op", ",", "file", "os", ".", "FileInfo", ")", "{", "w", ".", "Wait", "(", ")", "\n", "if", "file", "==", "nil", "{", "file", "=", "&", "fileInfo", "{", "name", ":", "\"", ...
// TriggerEvent is a method that can be used to trigger an event, separate to // the file watching process.
[ "TriggerEvent", "is", "a", "method", "that", "can", "be", "used", "to", "trigger", "an", "event", "separate", "to", "the", "file", "watching", "process", "." ]
f33c874a09dcfac90f008abeee9171d88431e212
https://github.com/radovskyb/watcher/blob/f33c874a09dcfac90f008abeee9171d88431e212/watcher.go#L476-L482
train
radovskyb/watcher
watcher.go
Start
func (w *Watcher) Start(d time.Duration) error { // Return an error if d is less than 1 nanosecond. if d < time.Nanosecond { return ErrDurationTooShort } // Make sure the Watcher is not already running. w.mu.Lock() if w.running { w.mu.Unlock() return ErrWatcherRunning } w.running = true w.mu.Unlock() ...
go
func (w *Watcher) Start(d time.Duration) error { // Return an error if d is less than 1 nanosecond. if d < time.Nanosecond { return ErrDurationTooShort } // Make sure the Watcher is not already running. w.mu.Lock() if w.running { w.mu.Unlock() return ErrWatcherRunning } w.running = true w.mu.Unlock() ...
[ "func", "(", "w", "*", "Watcher", ")", "Start", "(", "d", "time", ".", "Duration", ")", "error", "{", "// Return an error if d is less than 1 nanosecond.", "if", "d", "<", "time", ".", "Nanosecond", "{", "return", "ErrDurationTooShort", "\n", "}", "\n\n", "// ...
// Start begins the polling cycle which repeats every specified // duration until Close is called.
[ "Start", "begins", "the", "polling", "cycle", "which", "repeats", "every", "specified", "duration", "until", "Close", "is", "called", "." ]
f33c874a09dcfac90f008abeee9171d88431e212
https://github.com/radovskyb/watcher/blob/f33c874a09dcfac90f008abeee9171d88431e212/watcher.go#L534-L609
train
radovskyb/watcher
watcher.go
Close
func (w *Watcher) Close() { w.mu.Lock() if !w.running { w.mu.Unlock() return } w.running = false w.files = make(map[string]os.FileInfo) w.names = make(map[string]bool) w.mu.Unlock() // Send a close signal to the Start method. w.close <- struct{}{} }
go
func (w *Watcher) Close() { w.mu.Lock() if !w.running { w.mu.Unlock() return } w.running = false w.files = make(map[string]os.FileInfo) w.names = make(map[string]bool) w.mu.Unlock() // Send a close signal to the Start method. w.close <- struct{}{} }
[ "func", "(", "w", "*", "Watcher", ")", "Close", "(", ")", "{", "w", ".", "mu", ".", "Lock", "(", ")", "\n", "if", "!", "w", ".", "running", "{", "w", ".", "mu", ".", "Unlock", "(", ")", "\n", "return", "\n", "}", "\n", "w", ".", "running", ...
// Close stops a Watcher and unlocks its mutex, then sends a close signal.
[ "Close", "stops", "a", "Watcher", "and", "unlocks", "its", "mutex", "then", "sends", "a", "close", "signal", "." ]
f33c874a09dcfac90f008abeee9171d88431e212
https://github.com/radovskyb/watcher/blob/f33c874a09dcfac90f008abeee9171d88431e212/watcher.go#L701-L713
train
canthefason/go-watcher
common.go
NewParams
func NewParams() *Params { return &Params{ Package: make([]string, 0), Watcher: make(map[string]string), } }
go
func NewParams() *Params { return &Params{ Package: make([]string, 0), Watcher: make(map[string]string), } }
[ "func", "NewParams", "(", ")", "*", "Params", "{", "return", "&", "Params", "{", "Package", ":", "make", "(", "[", "]", "string", ",", "0", ")", ",", "Watcher", ":", "make", "(", "map", "[", "string", "]", "string", ")", ",", "}", "\n", "}" ]
// NewParams creates a new Params instance
[ "NewParams", "creates", "a", "new", "Params", "instance" ]
59980168ee35c24b8dc3c3bb3dec2ed749fa5c44
https://github.com/canthefason/go-watcher/blob/59980168ee35c24b8dc3c3bb3dec2ed749fa5c44/common.go#L28-L33
train
canthefason/go-watcher
common.go
generateBinaryName
func (p *Params) generateBinaryName() string { rand.Seed(time.Now().UnixNano()) randName := rand.Int31n(999999) packageName := strings.Replace(p.packagePath(), "/", "-", -1) return fmt.Sprintf("%s-%s-%d", generateBinaryPrefix(), packageName, randName) }
go
func (p *Params) generateBinaryName() string { rand.Seed(time.Now().UnixNano()) randName := rand.Int31n(999999) packageName := strings.Replace(p.packagePath(), "/", "-", -1) return fmt.Sprintf("%s-%s-%d", generateBinaryPrefix(), packageName, randName) }
[ "func", "(", "p", "*", "Params", ")", "generateBinaryName", "(", ")", "string", "{", "rand", ".", "Seed", "(", "time", ".", "Now", "(", ")", ".", "UnixNano", "(", ")", ")", "\n", "randName", ":=", "rand", ".", "Int31n", "(", "999999", ")", "\n", ...
// generateBinaryName generates a new binary name for each rebuild, for preventing any sorts of conflicts
[ "generateBinaryName", "generates", "a", "new", "binary", "name", "for", "each", "rebuild", "for", "preventing", "any", "sorts", "of", "conflicts" ]
59980168ee35c24b8dc3c3bb3dec2ed749fa5c44
https://github.com/canthefason/go-watcher/blob/59980168ee35c24b8dc3c3bb3dec2ed749fa5c44/common.go#L56-L62
train
canthefason/go-watcher
common.go
runCommand
func runCommand(name string, args ...string) (*exec.Cmd, error) { cmd := exec.Command(name, args...) stderr, err := cmd.StderrPipe() if err != nil { return cmd, err } stdout, err := cmd.StdoutPipe() if err != nil { return cmd, err } if err := cmd.Start(); err != nil { return cmd, err } go io.Copy(os....
go
func runCommand(name string, args ...string) (*exec.Cmd, error) { cmd := exec.Command(name, args...) stderr, err := cmd.StderrPipe() if err != nil { return cmd, err } stdout, err := cmd.StdoutPipe() if err != nil { return cmd, err } if err := cmd.Start(); err != nil { return cmd, err } go io.Copy(os....
[ "func", "runCommand", "(", "name", "string", ",", "args", "...", "string", ")", "(", "*", "exec", ".", "Cmd", ",", "error", ")", "{", "cmd", ":=", "exec", ".", "Command", "(", "name", ",", "args", "...", ")", "\n", "stderr", ",", "err", ":=", "cm...
// runCommand runs the command with given name and arguments. It copies the // logs to standard output
[ "runCommand", "runs", "the", "command", "with", "given", "name", "and", "arguments", ".", "It", "copies", "the", "logs", "to", "standard", "output" ]
59980168ee35c24b8dc3c3bb3dec2ed749fa5c44
https://github.com/canthefason/go-watcher/blob/59980168ee35c24b8dc3c3bb3dec2ed749fa5c44/common.go#L75-L95
train
canthefason/go-watcher
common.go
ParseArgs
func ParseArgs(args []string) *Params { params := NewParams() // remove the command argument args = args[1:len(args)] for i := 0; i < len(args); i++ { arg := args[i] arg = stripDash(arg) if existIn(arg, watcherFlags) { // used for fetching the value of the given parameter if len(args) <= i+1 { l...
go
func ParseArgs(args []string) *Params { params := NewParams() // remove the command argument args = args[1:len(args)] for i := 0; i < len(args); i++ { arg := args[i] arg = stripDash(arg) if existIn(arg, watcherFlags) { // used for fetching the value of the given parameter if len(args) <= i+1 { l...
[ "func", "ParseArgs", "(", "args", "[", "]", "string", ")", "*", "Params", "{", "params", ":=", "NewParams", "(", ")", "\n\n", "// remove the command argument", "args", "=", "args", "[", "1", ":", "len", "(", "args", ")", "]", "\n\n", "for", "i", ":=", ...
// ParseArgs extracts the application parameters from args and returns // Params instance with separated watcher and application parameters
[ "ParseArgs", "extracts", "the", "application", "parameters", "from", "args", "and", "returns", "Params", "instance", "with", "separated", "watcher", "and", "application", "parameters" ]
59980168ee35c24b8dc3c3bb3dec2ed749fa5c44
https://github.com/canthefason/go-watcher/blob/59980168ee35c24b8dc3c3bb3dec2ed749fa5c44/common.go#L99-L131
train
canthefason/go-watcher
common.go
stripDash
func stripDash(arg string) string { if len(arg) > 1 { if arg[1] == '-' { return arg[2:] } else if arg[0] == '-' { return arg[1:] } } return arg }
go
func stripDash(arg string) string { if len(arg) > 1 { if arg[1] == '-' { return arg[2:] } else if arg[0] == '-' { return arg[1:] } } return arg }
[ "func", "stripDash", "(", "arg", "string", ")", "string", "{", "if", "len", "(", "arg", ")", ">", "1", "{", "if", "arg", "[", "1", "]", "==", "'-'", "{", "return", "arg", "[", "2", ":", "]", "\n", "}", "else", "if", "arg", "[", "0", "]", "=...
// stripDash removes the both single and double dash chars and returns // the actual parameter name
[ "stripDash", "removes", "the", "both", "single", "and", "double", "dash", "chars", "and", "returns", "the", "actual", "parameter", "name" ]
59980168ee35c24b8dc3c3bb3dec2ed749fa5c44
https://github.com/canthefason/go-watcher/blob/59980168ee35c24b8dc3c3bb3dec2ed749fa5c44/common.go#L135-L145
train
canthefason/go-watcher
build.go
NewBuilder
func NewBuilder(w *Watcher, r *Runner) *Builder { return &Builder{watcher: w, runner: r} }
go
func NewBuilder(w *Watcher, r *Runner) *Builder { return &Builder{watcher: w, runner: r} }
[ "func", "NewBuilder", "(", "w", "*", "Watcher", ",", "r", "*", "Runner", ")", "*", "Builder", "{", "return", "&", "Builder", "{", "watcher", ":", "w", ",", "runner", ":", "r", "}", "\n", "}" ]
// NewBuilder constructs the Builder instance
[ "NewBuilder", "constructs", "the", "Builder", "instance" ]
59980168ee35c24b8dc3c3bb3dec2ed749fa5c44
https://github.com/canthefason/go-watcher/blob/59980168ee35c24b8dc3c3bb3dec2ed749fa5c44/build.go#L20-L22
train
canthefason/go-watcher
build.go
Build
func (b *Builder) Build(p *Params) { go b.registerSignalHandler() go func() { // used for triggering the first build b.watcher.update <- struct{}{} }() for range b.watcher.Wait() { fileName := p.generateBinaryName() pkg := p.packagePath() log.Println("build started") color.Cyan("Building %s...\n", pk...
go
func (b *Builder) Build(p *Params) { go b.registerSignalHandler() go func() { // used for triggering the first build b.watcher.update <- struct{}{} }() for range b.watcher.Wait() { fileName := p.generateBinaryName() pkg := p.packagePath() log.Println("build started") color.Cyan("Building %s...\n", pk...
[ "func", "(", "b", "*", "Builder", ")", "Build", "(", "p", "*", "Params", ")", "{", "go", "b", ".", "registerSignalHandler", "(", ")", "\n", "go", "func", "(", ")", "{", "// used for triggering the first build", "b", ".", "watcher", ".", "update", "<-", ...
// Build listens watch events from Watcher and sends messages to Runner // when new changes are built.
[ "Build", "listens", "watch", "events", "from", "Watcher", "and", "sends", "messages", "to", "Runner", "when", "new", "changes", "are", "built", "." ]
59980168ee35c24b8dc3c3bb3dec2ed749fa5c44
https://github.com/canthefason/go-watcher/blob/59980168ee35c24b8dc3c3bb3dec2ed749fa5c44/build.go#L26-L62
train
canthefason/go-watcher
watch.go
MustRegisterWatcher
func MustRegisterWatcher(params *Params) *Watcher { watchVendorStr := params.Get("watch-vendor") var watchVendor bool var err error if watchVendorStr != "" { watchVendor, err = strconv.ParseBool(watchVendorStr) if err != nil { log.Println("Wrong watch-vendor value: %s (default=false)", watchVendorStr) } }...
go
func MustRegisterWatcher(params *Params) *Watcher { watchVendorStr := params.Get("watch-vendor") var watchVendor bool var err error if watchVendorStr != "" { watchVendor, err = strconv.ParseBool(watchVendorStr) if err != nil { log.Println("Wrong watch-vendor value: %s (default=false)", watchVendorStr) } }...
[ "func", "MustRegisterWatcher", "(", "params", "*", "Params", ")", "*", "Watcher", "{", "watchVendorStr", ":=", "params", ".", "Get", "(", "\"", "\"", ")", "\n", "var", "watchVendor", "bool", "\n", "var", "err", "error", "\n", "if", "watchVendorStr", "!=", ...
// MustRegisterWatcher creates a new Watcher and starts listening to // given folders
[ "MustRegisterWatcher", "creates", "a", "new", "Watcher", "and", "starts", "listening", "to", "given", "folders" ]
59980168ee35c24b8dc3c3bb3dec2ed749fa5c44
https://github.com/canthefason/go-watcher/blob/59980168ee35c24b8dc3c3bb3dec2ed749fa5c44/watch.go#L37-L63
train
canthefason/go-watcher
watch.go
Watch
func (w *Watcher) Watch() { eventSent := false for { select { case event := <-w.watcher.Events: // discard chmod events if event.Op&fsnotify.Chmod != fsnotify.Chmod { // test files do not need a rebuild if isTestFile(event.Name) { continue } if !isWatchedFileType(event.Name) { con...
go
func (w *Watcher) Watch() { eventSent := false for { select { case event := <-w.watcher.Events: // discard chmod events if event.Op&fsnotify.Chmod != fsnotify.Chmod { // test files do not need a rebuild if isTestFile(event.Name) { continue } if !isWatchedFileType(event.Name) { con...
[ "func", "(", "w", "*", "Watcher", ")", "Watch", "(", ")", "{", "eventSent", ":=", "false", "\n\n", "for", "{", "select", "{", "case", "event", ":=", "<-", "w", ".", "watcher", ".", "Events", ":", "// discard chmod events", "if", "event", ".", "Op", "...
// Watch listens file updates, and sends signal to // update channel when .go and .tmpl files are updated
[ "Watch", "listens", "file", "updates", "and", "sends", "signal", "to", "update", "channel", "when", ".", "go", "and", ".", "tmpl", "files", "are", "updated" ]
59980168ee35c24b8dc3c3bb3dec2ed749fa5c44
https://github.com/canthefason/go-watcher/blob/59980168ee35c24b8dc3c3bb3dec2ed749fa5c44/watch.go#L67-L101
train
canthefason/go-watcher
watch.go
watchFolders
func (w *Watcher) watchFolders() { wd, err := w.prepareRootDir() if err != nil { log.Fatalf("Could not get root working directory: %s", err) } filepath.Walk(wd, func(path string, info os.FileInfo, err error) error { // skip files if info == nil { log.Fatalf("wrong watcher package: %s", path) } if !i...
go
func (w *Watcher) watchFolders() { wd, err := w.prepareRootDir() if err != nil { log.Fatalf("Could not get root working directory: %s", err) } filepath.Walk(wd, func(path string, info os.FileInfo, err error) error { // skip files if info == nil { log.Fatalf("wrong watcher package: %s", path) } if !i...
[ "func", "(", "w", "*", "Watcher", ")", "watchFolders", "(", ")", "{", "wd", ",", "err", ":=", "w", ".", "prepareRootDir", "(", ")", "\n\n", "if", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n"...
// watchFolders recursively adds folders that will be watched against the changes, // starting from the working directory
[ "watchFolders", "recursively", "adds", "folders", "that", "will", "be", "watched", "against", "the", "changes", "starting", "from", "the", "working", "directory" ]
59980168ee35c24b8dc3c3bb3dec2ed749fa5c44
https://github.com/canthefason/go-watcher/blob/59980168ee35c24b8dc3c3bb3dec2ed749fa5c44/watch.go#L126-L160
train
canthefason/go-watcher
watch.go
addFolder
func (w *Watcher) addFolder(name string) { if err := w.watcher.Add(name); err != nil { log.Fatalf("Could not watch folder: %s", err) } }
go
func (w *Watcher) addFolder(name string) { if err := w.watcher.Add(name); err != nil { log.Fatalf("Could not watch folder: %s", err) } }
[ "func", "(", "w", "*", "Watcher", ")", "addFolder", "(", "name", "string", ")", "{", "if", "err", ":=", "w", ".", "watcher", ".", "Add", "(", "name", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatalf", "(", "\"", "\"", ",", "err", ")", "...
// addFolder adds given folder name to the watched folders, and starts // watching it for further changes
[ "addFolder", "adds", "given", "folder", "name", "to", "the", "watched", "folders", "and", "starts", "watching", "it", "for", "further", "changes" ]
59980168ee35c24b8dc3c3bb3dec2ed749fa5c44
https://github.com/canthefason/go-watcher/blob/59980168ee35c24b8dc3c3bb3dec2ed749fa5c44/watch.go#L164-L168
train
canthefason/go-watcher
watch.go
prepareRootDir
func (w *Watcher) prepareRootDir() (string, error) { if w.rootdir == "" { return os.Getwd() } path := os.Getenv("GOPATH") if path == "" { return "", ErrPathNotSet } root := fmt.Sprintf("%s/src/%s", path, w.rootdir) return root, nil }
go
func (w *Watcher) prepareRootDir() (string, error) { if w.rootdir == "" { return os.Getwd() } path := os.Getenv("GOPATH") if path == "" { return "", ErrPathNotSet } root := fmt.Sprintf("%s/src/%s", path, w.rootdir) return root, nil }
[ "func", "(", "w", "*", "Watcher", ")", "prepareRootDir", "(", ")", "(", "string", ",", "error", ")", "{", "if", "w", ".", "rootdir", "==", "\"", "\"", "{", "return", "os", ".", "Getwd", "(", ")", "\n", "}", "\n\n", "path", ":=", "os", ".", "Get...
// prepareRootDir prepares working directory depending on root directory
[ "prepareRootDir", "prepares", "working", "directory", "depending", "on", "root", "directory" ]
59980168ee35c24b8dc3c3bb3dec2ed749fa5c44
https://github.com/canthefason/go-watcher/blob/59980168ee35c24b8dc3c3bb3dec2ed749fa5c44/watch.go#L171-L184
train
canthefason/go-watcher
run.go
Run
func (r *Runner) Run(p *Params) { for fileName := range r.start { color.Green("Running %s...\n", p.Get("run")) cmd, err := runCommand(fileName, p.Package...) if err != nil { log.Printf("Could not run the go binary: %s \n", err) r.kill(cmd) continue } r.cmd = cmd removeFile(fileName) go func...
go
func (r *Runner) Run(p *Params) { for fileName := range r.start { color.Green("Running %s...\n", p.Get("run")) cmd, err := runCommand(fileName, p.Package...) if err != nil { log.Printf("Could not run the go binary: %s \n", err) r.kill(cmd) continue } r.cmd = cmd removeFile(fileName) go func...
[ "func", "(", "r", "*", "Runner", ")", "Run", "(", "p", "*", "Params", ")", "{", "for", "fileName", ":=", "range", "r", ".", "start", "{", "color", ".", "Green", "(", "\"", "\\n", "\"", ",", "p", ".", "Get", "(", "\"", "\"", ")", ")", "\n\n", ...
// Run initializes runner with given parameters.
[ "Run", "initializes", "runner", "with", "given", "parameters", "." ]
59980168ee35c24b8dc3c3bb3dec2ed749fa5c44
https://github.com/canthefason/go-watcher/blob/59980168ee35c24b8dc3c3bb3dec2ed749fa5c44/run.go#L31-L54
train
canthefason/go-watcher
run.go
restart
func (r *Runner) restart(fileName string) { r.kill(r.cmd) r.start <- fileName }
go
func (r *Runner) restart(fileName string) { r.kill(r.cmd) r.start <- fileName }
[ "func", "(", "r", "*", "Runner", ")", "restart", "(", "fileName", "string", ")", "{", "r", ".", "kill", "(", "r", ".", "cmd", ")", "\n\n", "r", ".", "start", "<-", "fileName", "\n", "}" ]
// Restart kills the process, removes the old binary and // restarts the new process
[ "Restart", "kills", "the", "process", "removes", "the", "old", "binary", "and", "restarts", "the", "new", "process" ]
59980168ee35c24b8dc3c3bb3dec2ed749fa5c44
https://github.com/canthefason/go-watcher/blob/59980168ee35c24b8dc3c3bb3dec2ed749fa5c44/run.go#L58-L62
train
sony/sonyflake
sonyflake.go
NextID
func (sf *Sonyflake) NextID() (uint64, error) { const maskSequence = uint16(1<<BitLenSequence - 1) sf.mutex.Lock() defer sf.mutex.Unlock() current := currentElapsedTime(sf.startTime) if sf.elapsedTime < current { sf.elapsedTime = current sf.sequence = 0 } else { // sf.elapsedTime >= current sf.sequence = ...
go
func (sf *Sonyflake) NextID() (uint64, error) { const maskSequence = uint16(1<<BitLenSequence - 1) sf.mutex.Lock() defer sf.mutex.Unlock() current := currentElapsedTime(sf.startTime) if sf.elapsedTime < current { sf.elapsedTime = current sf.sequence = 0 } else { // sf.elapsedTime >= current sf.sequence = ...
[ "func", "(", "sf", "*", "Sonyflake", ")", "NextID", "(", ")", "(", "uint64", ",", "error", ")", "{", "const", "maskSequence", "=", "uint16", "(", "1", "<<", "BitLenSequence", "-", "1", ")", "\n\n", "sf", ".", "mutex", ".", "Lock", "(", ")", "\n", ...
// NextID generates a next unique ID. // After the Sonyflake time overflows, NextID returns an error.
[ "NextID", "generates", "a", "next", "unique", "ID", ".", "After", "the", "Sonyflake", "time", "overflows", "NextID", "returns", "an", "error", "." ]
6d5bd61810093eae37d7d605d0cbdd845969b5b2
https://github.com/sony/sonyflake/blob/6d5bd61810093eae37d7d605d0cbdd845969b5b2/sonyflake.go#L86-L106
train
sony/sonyflake
sonyflake.go
Decompose
func Decompose(id uint64) map[string]uint64 { const maskSequence = uint64((1<<BitLenSequence - 1) << BitLenMachineID) const maskMachineID = uint64(1<<BitLenMachineID - 1) msb := id >> 63 time := id >> (BitLenSequence + BitLenMachineID) sequence := id & maskSequence >> BitLenMachineID machineID := id & maskMachin...
go
func Decompose(id uint64) map[string]uint64 { const maskSequence = uint64((1<<BitLenSequence - 1) << BitLenMachineID) const maskMachineID = uint64(1<<BitLenMachineID - 1) msb := id >> 63 time := id >> (BitLenSequence + BitLenMachineID) sequence := id & maskSequence >> BitLenMachineID machineID := id & maskMachin...
[ "func", "Decompose", "(", "id", "uint64", ")", "map", "[", "string", "]", "uint64", "{", "const", "maskSequence", "=", "uint64", "(", "(", "1", "<<", "BitLenSequence", "-", "1", ")", "<<", "BitLenMachineID", ")", "\n", "const", "maskMachineID", "=", "uin...
// Decompose returns a set of Sonyflake ID parts.
[ "Decompose", "returns", "a", "set", "of", "Sonyflake", "ID", "parts", "." ]
6d5bd61810093eae37d7d605d0cbdd845969b5b2
https://github.com/sony/sonyflake/blob/6d5bd61810093eae37d7d605d0cbdd845969b5b2/sonyflake.go#L168-L183
train
sony/sonyflake
awsutil/awsutil.go
AmazonEC2MachineID
func AmazonEC2MachineID() (uint16, error) { ip, err := amazonEC2PrivateIPv4() if err != nil { return 0, err } return uint16(ip[2])<<8 + uint16(ip[3]), nil }
go
func AmazonEC2MachineID() (uint16, error) { ip, err := amazonEC2PrivateIPv4() if err != nil { return 0, err } return uint16(ip[2])<<8 + uint16(ip[3]), nil }
[ "func", "AmazonEC2MachineID", "(", ")", "(", "uint16", ",", "error", ")", "{", "ip", ",", "err", ":=", "amazonEC2PrivateIPv4", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n\n", "return", "uint16", "(", "ip",...
// AmazonEC2MachineID retrieves the private IP address of the Amazon EC2 instance // and returns its lower 16 bits. // It works correctly on Docker as well.
[ "AmazonEC2MachineID", "retrieves", "the", "private", "IP", "address", "of", "the", "Amazon", "EC2", "instance", "and", "returns", "its", "lower", "16", "bits", ".", "It", "works", "correctly", "on", "Docker", "as", "well", "." ]
6d5bd61810093eae37d7d605d0cbdd845969b5b2
https://github.com/sony/sonyflake/blob/6d5bd61810093eae37d7d605d0cbdd845969b5b2/awsutil/awsutil.go#L37-L44
train
sony/sonyflake
awsutil/awsutil.go
TimeDifference
func TimeDifference(server string) (time.Duration, error) { output, err := exec.Command("/usr/sbin/ntpdate", "-q", server).CombinedOutput() if err != nil { return time.Duration(0), err } re, _ := regexp.Compile("offset (.*) sec") submatched := re.FindSubmatch(output) if len(submatched) != 2 { return time.Dur...
go
func TimeDifference(server string) (time.Duration, error) { output, err := exec.Command("/usr/sbin/ntpdate", "-q", server).CombinedOutput() if err != nil { return time.Duration(0), err } re, _ := regexp.Compile("offset (.*) sec") submatched := re.FindSubmatch(output) if len(submatched) != 2 { return time.Dur...
[ "func", "TimeDifference", "(", "server", "string", ")", "(", "time", ".", "Duration", ",", "error", ")", "{", "output", ",", "err", ":=", "exec", ".", "Command", "(", "\"", "\"", ",", "\"", "\"", ",", "server", ")", ".", "CombinedOutput", "(", ")", ...
// TimeDifference returns the time difference between the localhost and the given NTP server.
[ "TimeDifference", "returns", "the", "time", "difference", "between", "the", "localhost", "and", "the", "given", "NTP", "server", "." ]
6d5bd61810093eae37d7d605d0cbdd845969b5b2
https://github.com/sony/sonyflake/blob/6d5bd61810093eae37d7d605d0cbdd845969b5b2/awsutil/awsutil.go#L47-L64
train
terraform-providers/terraform-provider-openstack
openstack/dns_zone_v2.go
ToZoneCreateMap
func (opts ZoneCreateOpts) ToZoneCreateMap() (map[string]interface{}, error) { b, err := BuildRequest(opts, "") if err != nil { return nil, err } if m, ok := b[""].(map[string]interface{}); ok { if opts.TTL > 0 { m["ttl"] = opts.TTL } return m, nil } return nil, fmt.Errorf("Expected map but got %T",...
go
func (opts ZoneCreateOpts) ToZoneCreateMap() (map[string]interface{}, error) { b, err := BuildRequest(opts, "") if err != nil { return nil, err } if m, ok := b[""].(map[string]interface{}); ok { if opts.TTL > 0 { m["ttl"] = opts.TTL } return m, nil } return nil, fmt.Errorf("Expected map but got %T",...
[ "func", "(", "opts", "ZoneCreateOpts", ")", "ToZoneCreateMap", "(", ")", "(", "map", "[", "string", "]", "interface", "{", "}", ",", "error", ")", "{", "b", ",", "err", ":=", "BuildRequest", "(", "opts", ",", "\"", "\"", ")", "\n", "if", "err", "!=...
// ToZoneCreateMap casts a CreateOpts struct to a map. // It overrides zones.ToZoneCreateMap to add the ValueSpecs field.
[ "ToZoneCreateMap", "casts", "a", "CreateOpts", "struct", "to", "a", "map", ".", "It", "overrides", "zones", ".", "ToZoneCreateMap", "to", "add", "the", "ValueSpecs", "field", "." ]
a4c13eee81a7ca8682741b049cb067610bdf45b2
https://github.com/terraform-providers/terraform-provider-openstack/blob/a4c13eee81a7ca8682741b049cb067610bdf45b2/openstack/dns_zone_v2.go#L21-L36
train