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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
HouzuoGuo/tiedot | data/hashtable.go | Get | func (ht *HashTable) Get(key, limit int) (vals []int) {
if limit == 0 {
vals = make([]int, 0, 10)
} else {
vals = make([]int, 0, limit)
}
for count, entry, bucket := 0, 0, ht.HashKey(key); ; {
entryAddr := bucket*ht.BucketSize + BucketHeader + entry*EntrySize
entryKey, _ := binary.Varint(ht.Buf[entryAddr+1 ... | go | func (ht *HashTable) Get(key, limit int) (vals []int) {
if limit == 0 {
vals = make([]int, 0, 10)
} else {
vals = make([]int, 0, limit)
}
for count, entry, bucket := 0, 0, ht.HashKey(key); ; {
entryAddr := bucket*ht.BucketSize + BucketHeader + entry*EntrySize
entryKey, _ := binary.Varint(ht.Buf[entryAddr+1 ... | [
"func",
"(",
"ht",
"*",
"HashTable",
")",
"Get",
"(",
"key",
",",
"limit",
"int",
")",
"(",
"vals",
"[",
"]",
"int",
")",
"{",
"if",
"limit",
"==",
"0",
"{",
"vals",
"=",
"make",
"(",
"[",
"]",
"int",
",",
"0",
",",
"10",
")",
"\n",
"}",
... | // Look up values by key. | [
"Look",
"up",
"values",
"by",
"key",
"."
] | be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39 | https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/data/hashtable.go#L129-L156 | train |
HouzuoGuo/tiedot | data/hashtable.go | Remove | func (ht *HashTable) Remove(key, val int) {
for entry, bucket := 0, ht.HashKey(key); ; {
entryAddr := bucket*ht.BucketSize + BucketHeader + entry*EntrySize
entryKey, _ := binary.Varint(ht.Buf[entryAddr+1 : entryAddr+11])
entryVal, _ := binary.Varint(ht.Buf[entryAddr+11 : entryAddr+21])
if ht.Buf[entryAddr] == ... | go | func (ht *HashTable) Remove(key, val int) {
for entry, bucket := 0, ht.HashKey(key); ; {
entryAddr := bucket*ht.BucketSize + BucketHeader + entry*EntrySize
entryKey, _ := binary.Varint(ht.Buf[entryAddr+1 : entryAddr+11])
entryVal, _ := binary.Varint(ht.Buf[entryAddr+11 : entryAddr+21])
if ht.Buf[entryAddr] == ... | [
"func",
"(",
"ht",
"*",
"HashTable",
")",
"Remove",
"(",
"key",
",",
"val",
"int",
")",
"{",
"for",
"entry",
",",
"bucket",
":=",
"0",
",",
"ht",
".",
"HashKey",
"(",
"key",
")",
";",
";",
"{",
"entryAddr",
":=",
"bucket",
"*",
"ht",
".",
"Buck... | // Flag an entry as invalid, so that Get will not return it later on. | [
"Flag",
"an",
"entry",
"as",
"invalid",
"so",
"that",
"Get",
"will",
"not",
"return",
"it",
"later",
"on",
"."
] | be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39 | https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/data/hashtable.go#L159-L179 | train |
HouzuoGuo/tiedot | data/hashtable.go | collectEntries | func (ht *HashTable) collectEntries(head int) (keys, vals []int) {
keys = make([]int, 0, ht.PerBucket)
vals = make([]int, 0, ht.PerBucket)
var entry, bucket int = 0, head
for {
entryAddr := bucket*ht.BucketSize + BucketHeader + entry*EntrySize
entryKey, _ := binary.Varint(ht.Buf[entryAddr+1 : entryAddr+11])
e... | go | func (ht *HashTable) collectEntries(head int) (keys, vals []int) {
keys = make([]int, 0, ht.PerBucket)
vals = make([]int, 0, ht.PerBucket)
var entry, bucket int = 0, head
for {
entryAddr := bucket*ht.BucketSize + BucketHeader + entry*EntrySize
entryKey, _ := binary.Varint(ht.Buf[entryAddr+1 : entryAddr+11])
e... | [
"func",
"(",
"ht",
"*",
"HashTable",
")",
"collectEntries",
"(",
"head",
"int",
")",
"(",
"keys",
",",
"vals",
"[",
"]",
"int",
")",
"{",
"keys",
"=",
"make",
"(",
"[",
"]",
"int",
",",
"0",
",",
"ht",
".",
"PerBucket",
")",
"\n",
"vals",
"=",
... | // Collect entries all the way from "head" bucket to the end of its chained buckets. | [
"Collect",
"entries",
"all",
"the",
"way",
"from",
"head",
"bucket",
"to",
"the",
"end",
"of",
"its",
"chained",
"buckets",
"."
] | be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39 | https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/data/hashtable.go#L204-L225 | train |
HouzuoGuo/tiedot | data/hashtable.go | GetPartition | func (ht *HashTable) GetPartition(partNum, partSize int) (keys, vals []int) {
rangeStart, rangeEnd := ht.GetPartitionRange(partNum, partSize)
prealloc := (rangeEnd - rangeStart) * ht.PerBucket
keys = make([]int, 0, prealloc)
vals = make([]int, 0, prealloc)
for head := rangeStart; head < rangeEnd; head++ {
k, v :... | go | func (ht *HashTable) GetPartition(partNum, partSize int) (keys, vals []int) {
rangeStart, rangeEnd := ht.GetPartitionRange(partNum, partSize)
prealloc := (rangeEnd - rangeStart) * ht.PerBucket
keys = make([]int, 0, prealloc)
vals = make([]int, 0, prealloc)
for head := rangeStart; head < rangeEnd; head++ {
k, v :... | [
"func",
"(",
"ht",
"*",
"HashTable",
")",
"GetPartition",
"(",
"partNum",
",",
"partSize",
"int",
")",
"(",
"keys",
",",
"vals",
"[",
"]",
"int",
")",
"{",
"rangeStart",
",",
"rangeEnd",
":=",
"ht",
".",
"GetPartitionRange",
"(",
"partNum",
",",
"partS... | // Return all entries in the chosen partition. | [
"Return",
"all",
"entries",
"in",
"the",
"chosen",
"partition",
"."
] | be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39 | https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/data/hashtable.go#L228-L239 | train |
HouzuoGuo/tiedot | httpapi/document.go | Insert | func Insert(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "must-revalidate")
w.Header().Set("Content-Type", "text/plain")
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS")
var col, doc string
if !Require(w, r, "... | go | func Insert(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "must-revalidate")
w.Header().Set("Content-Type", "text/plain")
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS")
var col, doc string
if !Require(w, r, "... | [
"func",
"Insert",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
... | // Insert a document into collection. | [
"Insert",
"a",
"document",
"into",
"collection",
"."
] | be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39 | https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/httpapi/document.go#L14-L46 | train |
HouzuoGuo/tiedot | httpapi/document.go | GetPage | func GetPage(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "must-revalidate")
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS")
var col, page, total string
if !... | go | func GetPage(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "must-revalidate")
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS")
var col, page, total string
if !... | [
"func",
"GetPage",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",... | // Divide documents into roughly equally sized pages, and return documents in the specified page. | [
"Divide",
"documents",
"into",
"roughly",
"equally",
"sized",
"pages",
"and",
"return",
"documents",
"in",
"the",
"specified",
"page",
"."
] | be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39 | https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/httpapi/document.go#L85-L129 | train |
HouzuoGuo/tiedot | httpapi/document.go | ApproxDocCount | func ApproxDocCount(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "must-revalidate")
w.Header().Set("Content-Type", "text/plain")
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS")
var col string
if !Require(w, r... | go | func ApproxDocCount(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "must-revalidate")
w.Header().Set("Content-Type", "text/plain")
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS")
var col string
if !Require(w, r... | [
"func",
"ApproxDocCount",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"w",
".",
"Header",
"(",
")",
".",
"Set",... | // Return approximate number of documents in the collection. | [
"Return",
"approximate",
"number",
"of",
"documents",
"in",
"the",
"collection",
"."
] | be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39 | https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/httpapi/document.go#L199-L214 | train |
HouzuoGuo/tiedot | httpapi/misc.go | Shutdown | func Shutdown(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "must-revalidate")
w.Header().Set("Content-Type", "text/plain")
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS")
HttpDB.Close()
os.Exit(0)
} | go | func Shutdown(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "must-revalidate")
w.Header().Set("Content-Type", "text/plain")
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS")
HttpDB.Close()
os.Exit(0)
} | [
"func",
"Shutdown",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"("... | // Flush and close all data files and shutdown the entire program. | [
"Flush",
"and",
"close",
"all",
"data",
"files",
"and",
"shutdown",
"the",
"entire",
"program",
"."
] | be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39 | https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/httpapi/misc.go#L14-L21 | train |
HouzuoGuo/tiedot | httpapi/misc.go | Dump | func Dump(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "must-revalidate")
w.Header().Set("Content-Type", "text/plain")
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS")
var dest string
if !Require(w, r, "dest",... | go | func Dump(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "must-revalidate")
w.Header().Set("Content-Type", "text/plain")
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS")
var dest string
if !Require(w, r, "dest",... | [
"func",
"Dump",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
... | // Copy this database into destination directory. | [
"Copy",
"this",
"database",
"into",
"destination",
"directory",
"."
] | be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39 | https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/httpapi/misc.go#L24-L37 | train |
HouzuoGuo/tiedot | httpapi/misc.go | MemStats | func MemStats(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "must-revalidate")
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS")
stats := new(runtime.MemStats)
... | go | func MemStats(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "must-revalidate")
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS")
stats := new(runtime.MemStats)
... | [
"func",
"MemStats",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"("... | // Return server memory statistics. | [
"Return",
"server",
"memory",
"statistics",
"."
] | be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39 | https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/httpapi/misc.go#L40-L54 | train |
HouzuoGuo/tiedot | httpapi/misc.go | Version | func Version(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "must-revalidate")
w.Header().Set("Content-Type", "text/plain")
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS")
w.Write([]byte("6"))
} | go | func Version(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "must-revalidate")
w.Header().Set("Content-Type", "text/plain")
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS")
w.Write([]byte("6"))
} | [
"func",
"Version",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",... | // Return server protocol version number. | [
"Return",
"server",
"protocol",
"version",
"number",
"."
] | be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39 | https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/httpapi/misc.go#L57-L63 | train |
HouzuoGuo/tiedot | gommap/mmap_windows.go | mmap | func mmap(length int, hfile uintptr) ([]byte, error) {
h, errno := syscall.CreateFileMapping(syscall.Handle(hfile), nil, syscall.PAGE_READWRITE, 0, 0, nil)
if h == 0 {
return nil, os.NewSyscallError("CreateFileMapping", errno)
}
addr, errno := syscall.MapViewOfFile(h, syscall.FILE_MAP_WRITE, 0, 0, 0)
if addr ==... | go | func mmap(length int, hfile uintptr) ([]byte, error) {
h, errno := syscall.CreateFileMapping(syscall.Handle(hfile), nil, syscall.PAGE_READWRITE, 0, 0, nil)
if h == 0 {
return nil, os.NewSyscallError("CreateFileMapping", errno)
}
addr, errno := syscall.MapViewOfFile(h, syscall.FILE_MAP_WRITE, 0, 0, 0)
if addr ==... | [
"func",
"mmap",
"(",
"length",
"int",
",",
"hfile",
"uintptr",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"h",
",",
"errno",
":=",
"syscall",
".",
"CreateFileMapping",
"(",
"syscall",
".",
"Handle",
"(",
"hfile",
")",
",",
"nil",
",",
"sys... | // Windows mmap always mapes the entire file regardless of the specified length. | [
"Windows",
"mmap",
"always",
"mapes",
"the",
"entire",
"file",
"regardless",
"of",
"the",
"specified",
"length",
"."
] | be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39 | https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/gommap/mmap_windows.go#L25-L46 | train |
HouzuoGuo/tiedot | data/config.go | CalculateConfigConstants | func (conf *Config) CalculateConfigConstants() {
conf.Padding = strings.Repeat(" ", 128)
conf.LenPadding = len(conf.Padding)
conf.BucketSize = BucketHeader + conf.PerBucket*EntrySize
conf.InitialBuckets = 1 << conf.HashBits
} | go | func (conf *Config) CalculateConfigConstants() {
conf.Padding = strings.Repeat(" ", 128)
conf.LenPadding = len(conf.Padding)
conf.BucketSize = BucketHeader + conf.PerBucket*EntrySize
conf.InitialBuckets = 1 << conf.HashBits
} | [
"func",
"(",
"conf",
"*",
"Config",
")",
"CalculateConfigConstants",
"(",
")",
"{",
"conf",
".",
"Padding",
"=",
"strings",
".",
"Repeat",
"(",
"\"",
"\"",
",",
"128",
")",
"\n",
"conf",
".",
"LenPadding",
"=",
"len",
"(",
"conf",
".",
"Padding",
")"... | // CalculateConfigConstants assignes internal field values to calculation results derived from other fields. | [
"CalculateConfigConstants",
"assignes",
"internal",
"field",
"values",
"to",
"calculation",
"results",
"derived",
"from",
"other",
"fields",
"."
] | be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39 | https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/data/config.go#L36-L42 | train |
HouzuoGuo/tiedot | data/config.go | CreateOrReadConfig | func CreateOrReadConfig(path string) (conf *Config, err error) {
var file *os.File
var j []byte
if err = os.MkdirAll(path, 0700); err != nil {
return
}
filePath := fmt.Sprintf("%s/data-config.json", path)
// set the default dataConfig
conf = defaultConfig()
// try to open the file
if file, err = os.OpenF... | go | func CreateOrReadConfig(path string) (conf *Config, err error) {
var file *os.File
var j []byte
if err = os.MkdirAll(path, 0700); err != nil {
return
}
filePath := fmt.Sprintf("%s/data-config.json", path)
// set the default dataConfig
conf = defaultConfig()
// try to open the file
if file, err = os.OpenF... | [
"func",
"CreateOrReadConfig",
"(",
"path",
"string",
")",
"(",
"conf",
"*",
"Config",
",",
"err",
"error",
")",
"{",
"var",
"file",
"*",
"os",
".",
"File",
"\n",
"var",
"j",
"[",
"]",
"byte",
"\n\n",
"if",
"err",
"=",
"os",
".",
"MkdirAll",
"(",
... | // CreateOrReadConfig creates default performance configuration underneath the input database directory. | [
"CreateOrReadConfig",
"creates",
"default",
"performance",
"configuration",
"underneath",
"the",
"input",
"database",
"directory",
"."
] | be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39 | https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/data/config.go#L45-L98 | train |
HouzuoGuo/tiedot | httpapi/jwt.go | getJWT | func getJWT(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
addCommonJwtRespHeaders(w, r)
// Verify identity
user := r.FormValue(JWT_USER_ATTR)
if user == "" {
http.Error(w, "Please pass JWT 'user' parameter", http.StatusBadRequest)
return
}
jwtCol := HttpDB.Use(J... | go | func getJWT(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
addCommonJwtRespHeaders(w, r)
// Verify identity
user := r.FormValue(JWT_USER_ATTR)
if user == "" {
http.Error(w, "Please pass JWT 'user' parameter", http.StatusBadRequest)
return
}
jwtCol := HttpDB.Use(J... | [
"func",
"getJWT",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"addCommonJwtRespHeaders",
"(",
"w",
",",
"r",
")",... | // Verify user identity and hand out a JWT. | [
"Verify",
"user",
"identity",
"and",
"hand",
"out",
"a",
"JWT",
"."
] | be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39 | https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/httpapi/jwt.go#L117-L170 | train |
HouzuoGuo/tiedot | httpapi/jwt.go | checkJWT | func checkJWT(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
addCommonJwtRespHeaders(w, r)
// Look for JWT in both headers and request value "access_token".
token, err := request.ParseFromRequest(r, TokenExtractor{}, func(token *jwt.Token) (interface{}, error) {
// To... | go | func checkJWT(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
addCommonJwtRespHeaders(w, r)
// Look for JWT in both headers and request value "access_token".
token, err := request.ParseFromRequest(r, TokenExtractor{}, func(token *jwt.Token) (interface{}, error) {
// To... | [
"func",
"checkJWT",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"addCommonJwtRespHeaders",
"(",
"w",
",",
"r",
")... | // Verify user's JWT. | [
"Verify",
"user",
"s",
"JWT",
"."
] | be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39 | https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/httpapi/jwt.go#L189-L205 | train |
HouzuoGuo/tiedot | httpapi/jwt.go | jwtWrap | func jwtWrap(originalHandler http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
addCommonJwtRespHeaders(w, r)
// Look for JWT in both headers and request value "access_token".
token, err := request.ParseFromRequest(r, TokenExtractor{}, func(token *jwt.Token) (interface{}, ... | go | func jwtWrap(originalHandler http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
addCommonJwtRespHeaders(w, r)
// Look for JWT in both headers and request value "access_token".
token, err := request.ParseFromRequest(r, TokenExtractor{}, func(token *jwt.Token) (interface{}, ... | [
"func",
"jwtWrap",
"(",
"originalHandler",
"http",
".",
"HandlerFunc",
")",
"http",
".",
"HandlerFunc",
"{",
"return",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"addCommonJwtRespHeaders",
"(",
"w",
",... | // Enable JWT authorization check on the HTTP handler function. | [
"Enable",
"JWT",
"authorization",
"check",
"on",
"the",
"HTTP",
"handler",
"function",
"."
] | be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39 | https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/httpapi/jwt.go#L208-L240 | train |
HouzuoGuo/tiedot | httpapi/jwt.go | sliceContainsStr | func sliceContainsStr(possibleSlice interface{}, str string) bool {
switch possibleSlice.(type) {
case []string:
for _, elem := range possibleSlice.([]string) {
if elem == str {
return true
}
}
}
return false
} | go | func sliceContainsStr(possibleSlice interface{}, str string) bool {
switch possibleSlice.(type) {
case []string:
for _, elem := range possibleSlice.([]string) {
if elem == str {
return true
}
}
}
return false
} | [
"func",
"sliceContainsStr",
"(",
"possibleSlice",
"interface",
"{",
"}",
",",
"str",
"string",
")",
"bool",
"{",
"switch",
"possibleSlice",
".",
"(",
"type",
")",
"{",
"case",
"[",
"]",
"string",
":",
"for",
"_",
",",
"elem",
":=",
"range",
"possibleSlic... | // Return true if the string appears in string slice. | [
"Return",
"true",
"if",
"the",
"string",
"appears",
"in",
"string",
"slice",
"."
] | be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39 | https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/httpapi/jwt.go#L243-L253 | train |
HouzuoGuo/tiedot | db/db.go | OpenDB | func OpenDB(dbPath string) (*DB, error) {
rand.Seed(time.Now().UnixNano()) // document ID generation relies on this RNG
d, err := data.CreateOrReadConfig(dbPath)
if err != nil {
return nil, err
}
db := &DB{Config: d, path: dbPath, schemaLock: new(sync.RWMutex)}
db.Config.CalculateConfigConstants()
return db, d... | go | func OpenDB(dbPath string) (*DB, error) {
rand.Seed(time.Now().UnixNano()) // document ID generation relies on this RNG
d, err := data.CreateOrReadConfig(dbPath)
if err != nil {
return nil, err
}
db := &DB{Config: d, path: dbPath, schemaLock: new(sync.RWMutex)}
db.Config.CalculateConfigConstants()
return db, d... | [
"func",
"OpenDB",
"(",
"dbPath",
"string",
")",
"(",
"*",
"DB",
",",
"error",
")",
"{",
"rand",
".",
"Seed",
"(",
"time",
".",
"Now",
"(",
")",
".",
"UnixNano",
"(",
")",
")",
"// document ID generation relies on this RNG",
"\n",
"d",
",",
"err",
":=",... | // Open database and load all collections & indexes. | [
"Open",
"database",
"and",
"load",
"all",
"collections",
"&",
"indexes",
"."
] | be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39 | https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/db/db.go#L38-L47 | train |
HouzuoGuo/tiedot | db/db.go | load | func (db *DB) load() error {
// Create DB directory and PART_NUM_FILE if necessary
var numPartsAssumed = false
numPartsFilePath := path.Join(db.path, PART_NUM_FILE)
if err := os.MkdirAll(db.path, 0700); err != nil {
return err
}
if partNumFile, err := os.Stat(numPartsFilePath); err != nil {
// The new databas... | go | func (db *DB) load() error {
// Create DB directory and PART_NUM_FILE if necessary
var numPartsAssumed = false
numPartsFilePath := path.Join(db.path, PART_NUM_FILE)
if err := os.MkdirAll(db.path, 0700); err != nil {
return err
}
if partNumFile, err := os.Stat(numPartsFilePath); err != nil {
// The new databas... | [
"func",
"(",
"db",
"*",
"DB",
")",
"load",
"(",
")",
"error",
"{",
"// Create DB directory and PART_NUM_FILE if necessary",
"var",
"numPartsAssumed",
"=",
"false",
"\n",
"numPartsFilePath",
":=",
"path",
".",
"Join",
"(",
"db",
".",
"path",
",",
"PART_NUM_FILE",... | // Load all collection schema. | [
"Load",
"all",
"collection",
"schema",
"."
] | be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39 | https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/db/db.go#L50-L90 | train |
HouzuoGuo/tiedot | db/db.go | Close | func (db *DB) Close() error {
db.schemaLock.Lock()
defer db.schemaLock.Unlock()
errs := make([]error, 0, 0)
for _, col := range db.cols {
if err := col.close(); err != nil {
errs = append(errs, err)
}
}
if len(errs) == 0 {
return nil
}
return fmt.Errorf("%v", errs)
} | go | func (db *DB) Close() error {
db.schemaLock.Lock()
defer db.schemaLock.Unlock()
errs := make([]error, 0, 0)
for _, col := range db.cols {
if err := col.close(); err != nil {
errs = append(errs, err)
}
}
if len(errs) == 0 {
return nil
}
return fmt.Errorf("%v", errs)
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"Close",
"(",
")",
"error",
"{",
"db",
".",
"schemaLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"db",
".",
"schemaLock",
".",
"Unlock",
"(",
")",
"\n",
"errs",
":=",
"make",
"(",
"[",
"]",
"error",
",",
"0",
... | // Close all database files. Do not use the DB afterwards! | [
"Close",
"all",
"database",
"files",
".",
"Do",
"not",
"use",
"the",
"DB",
"afterwards!"
] | be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39 | https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/db/db.go#L93-L106 | train |
HouzuoGuo/tiedot | db/db.go | create | func (db *DB) create(name string) error {
if _, exists := db.cols[name]; exists {
return fmt.Errorf("Collection %s already exists", name)
} else if err := os.MkdirAll(path.Join(db.path, name), 0700); err != nil {
return err
} else if db.cols[name], err = OpenCol(db, name); err != nil {
return err
}
return ni... | go | func (db *DB) create(name string) error {
if _, exists := db.cols[name]; exists {
return fmt.Errorf("Collection %s already exists", name)
} else if err := os.MkdirAll(path.Join(db.path, name), 0700); err != nil {
return err
} else if db.cols[name], err = OpenCol(db, name); err != nil {
return err
}
return ni... | [
"func",
"(",
"db",
"*",
"DB",
")",
"create",
"(",
"name",
"string",
")",
"error",
"{",
"if",
"_",
",",
"exists",
":=",
"db",
".",
"cols",
"[",
"name",
"]",
";",
"exists",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
... | // create creates collection files. The function does not place a schema lock. | [
"create",
"creates",
"collection",
"files",
".",
"The",
"function",
"does",
"not",
"place",
"a",
"schema",
"lock",
"."
] | be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39 | https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/db/db.go#L109-L118 | train |
HouzuoGuo/tiedot | db/db.go | Create | func (db *DB) Create(name string) error {
db.schemaLock.Lock()
defer db.schemaLock.Unlock()
return db.create(name)
} | go | func (db *DB) Create(name string) error {
db.schemaLock.Lock()
defer db.schemaLock.Unlock()
return db.create(name)
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"Create",
"(",
"name",
"string",
")",
"error",
"{",
"db",
".",
"schemaLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"db",
".",
"schemaLock",
".",
"Unlock",
"(",
")",
"\n",
"return",
"db",
".",
"create",
"(",
"nam... | // Create a new collection. | [
"Create",
"a",
"new",
"collection",
"."
] | be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39 | https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/db/db.go#L121-L125 | train |
HouzuoGuo/tiedot | db/db.go | Use | func (db *DB) Use(name string) *Col {
db.schemaLock.RLock()
defer db.schemaLock.RUnlock()
if col, exists := db.cols[name]; exists {
return col
}
return nil
} | go | func (db *DB) Use(name string) *Col {
db.schemaLock.RLock()
defer db.schemaLock.RUnlock()
if col, exists := db.cols[name]; exists {
return col
}
return nil
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"Use",
"(",
"name",
"string",
")",
"*",
"Col",
"{",
"db",
".",
"schemaLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"db",
".",
"schemaLock",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"col",
",",
"exists",
":=",
"d... | // Use the return value to interact with collection. Return value may be nil if the collection does not exist. | [
"Use",
"the",
"return",
"value",
"to",
"interact",
"with",
"collection",
".",
"Return",
"value",
"may",
"be",
"nil",
"if",
"the",
"collection",
"does",
"not",
"exist",
"."
] | be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39 | https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/db/db.go#L139-L146 | train |
HouzuoGuo/tiedot | db/db.go | Truncate | func (db *DB) Truncate(name string) error {
db.schemaLock.Lock()
defer db.schemaLock.Unlock()
if _, exists := db.cols[name]; !exists {
return fmt.Errorf("Collection %s does not exist", name)
}
col := db.cols[name]
for i := 0; i < db.numParts; i++ {
if err := col.parts[i].Clear(); err != nil {
return err
... | go | func (db *DB) Truncate(name string) error {
db.schemaLock.Lock()
defer db.schemaLock.Unlock()
if _, exists := db.cols[name]; !exists {
return fmt.Errorf("Collection %s does not exist", name)
}
col := db.cols[name]
for i := 0; i < db.numParts; i++ {
if err := col.parts[i].Clear(); err != nil {
return err
... | [
"func",
"(",
"db",
"*",
"DB",
")",
"Truncate",
"(",
"name",
"string",
")",
"error",
"{",
"db",
".",
"schemaLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"db",
".",
"schemaLock",
".",
"Unlock",
"(",
")",
"\n",
"if",
"_",
",",
"exists",
":=",
"db",
... | // Truncate a collection - delete all documents and clear | [
"Truncate",
"a",
"collection",
"-",
"delete",
"all",
"documents",
"and",
"clear"
] | be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39 | https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/db/db.go#L168-L186 | train |
HouzuoGuo/tiedot | db/db.go | Scrub | func (db *DB) Scrub(name string) error {
db.schemaLock.Lock()
defer db.schemaLock.Unlock()
if _, exists := db.cols[name]; !exists {
return fmt.Errorf("Collection %s does not exist", name)
}
// Prepare a temporary collection in file system
tmpColName := fmt.Sprintf("scrub-%s-%d", name, time.Now().UnixNano())
tm... | go | func (db *DB) Scrub(name string) error {
db.schemaLock.Lock()
defer db.schemaLock.Unlock()
if _, exists := db.cols[name]; !exists {
return fmt.Errorf("Collection %s does not exist", name)
}
// Prepare a temporary collection in file system
tmpColName := fmt.Sprintf("scrub-%s-%d", name, time.Now().UnixNano())
tm... | [
"func",
"(",
"db",
"*",
"DB",
")",
"Scrub",
"(",
"name",
"string",
")",
"error",
"{",
"db",
".",
"schemaLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"db",
".",
"schemaLock",
".",
"Unlock",
"(",
")",
"\n",
"if",
"_",
",",
"exists",
":=",
"db",
"... | // Scrub a collection - fix corrupted documents and de-fragment free space. | [
"Scrub",
"a",
"collection",
"-",
"fix",
"corrupted",
"documents",
"and",
"de",
"-",
"fragment",
"free",
"space",
"."
] | be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39 | https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/db/db.go#L189-L238 | train |
HouzuoGuo/tiedot | db/db.go | Drop | func (db *DB) Drop(name string) error {
db.schemaLock.Lock()
defer db.schemaLock.Unlock()
if _, exists := db.cols[name]; !exists {
return fmt.Errorf("Collection %s does not exist", name)
} else if err := db.cols[name].close(); err != nil {
return err
} else if err := os.RemoveAll(path.Join(db.path, name)); err... | go | func (db *DB) Drop(name string) error {
db.schemaLock.Lock()
defer db.schemaLock.Unlock()
if _, exists := db.cols[name]; !exists {
return fmt.Errorf("Collection %s does not exist", name)
} else if err := db.cols[name].close(); err != nil {
return err
} else if err := os.RemoveAll(path.Join(db.path, name)); err... | [
"func",
"(",
"db",
"*",
"DB",
")",
"Drop",
"(",
"name",
"string",
")",
"error",
"{",
"db",
".",
"schemaLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"db",
".",
"schemaLock",
".",
"Unlock",
"(",
")",
"\n",
"if",
"_",
",",
"exists",
":=",
"db",
".... | // Drop a collection and lose all of its documents and indexes. | [
"Drop",
"a",
"collection",
"and",
"lose",
"all",
"of",
"its",
"documents",
"and",
"indexes",
"."
] | be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39 | https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/db/db.go#L241-L253 | train |
HouzuoGuo/tiedot | db/db.go | ForceUse | func (db *DB) ForceUse(name string) *Col {
db.schemaLock.RLock()
defer db.schemaLock.RUnlock()
if db.cols[name] == nil {
if err := db.create(name); err != nil {
tdlog.Panicf("ForceUse: failed to create collection - %v", err)
}
}
return db.cols[name]
} | go | func (db *DB) ForceUse(name string) *Col {
db.schemaLock.RLock()
defer db.schemaLock.RUnlock()
if db.cols[name] == nil {
if err := db.create(name); err != nil {
tdlog.Panicf("ForceUse: failed to create collection - %v", err)
}
}
return db.cols[name]
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"ForceUse",
"(",
"name",
"string",
")",
"*",
"Col",
"{",
"db",
".",
"schemaLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"db",
".",
"schemaLock",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"db",
".",
"cols",
"[",
"... | // ForceUse creates a collection if one does not yet exist. Returns collection handle. Panics on error. | [
"ForceUse",
"creates",
"a",
"collection",
"if",
"one",
"does",
"not",
"yet",
"exist",
".",
"Returns",
"collection",
"handle",
".",
"Panics",
"on",
"error",
"."
] | be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39 | https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/db/db.go#L304-L313 | train |
HouzuoGuo/tiedot | db/db.go | ColExists | func (db *DB) ColExists(name string) bool {
db.schemaLock.RLock()
defer db.schemaLock.RUnlock()
return db.cols[name] != nil
} | go | func (db *DB) ColExists(name string) bool {
db.schemaLock.RLock()
defer db.schemaLock.RUnlock()
return db.cols[name] != nil
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"ColExists",
"(",
"name",
"string",
")",
"bool",
"{",
"db",
".",
"schemaLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"db",
".",
"schemaLock",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"db",
".",
"cols",
"[",
"n... | // ColExists returns true only if the given collection name exists in the database. | [
"ColExists",
"returns",
"true",
"only",
"if",
"the",
"given",
"collection",
"name",
"exists",
"in",
"the",
"database",
"."
] | be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39 | https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/db/db.go#L316-L320 | train |
HouzuoGuo/tiedot | main.go | linuxPerfAdvice | func linuxPerfAdvice() {
readFileIntContent := func(filePath string) (contentInt int, err error) {
content, err := ioutil.ReadFile(filePath)
if err != nil {
return
}
contentInt, err = strconv.Atoi(strings.TrimSpace(string(content)))
return
}
swappiness, err := readFileIntContent("/proc/sys/vm/swappiness... | go | func linuxPerfAdvice() {
readFileIntContent := func(filePath string) (contentInt int, err error) {
content, err := ioutil.ReadFile(filePath)
if err != nil {
return
}
contentInt, err = strconv.Atoi(strings.TrimSpace(string(content)))
return
}
swappiness, err := readFileIntContent("/proc/sys/vm/swappiness... | [
"func",
"linuxPerfAdvice",
"(",
")",
"{",
"readFileIntContent",
":=",
"func",
"(",
"filePath",
"string",
")",
"(",
"contentInt",
"int",
",",
"err",
"error",
")",
"{",
"content",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"filePath",
")",
"\n",
"if... | // Read Linux system VM parameters and print performance configuration advice when necessary. | [
"Read",
"Linux",
"system",
"VM",
"parameters",
"and",
"print",
"performance",
"configuration",
"advice",
"when",
"necessary",
"."
] | be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39 | https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/main.go#L21-L42 | train |
HouzuoGuo/tiedot | benchmark/benchmark.go | average | func average(name string, fun func(), benchSize int) {
numThreads := runtime.GOMAXPROCS(-1)
wp := new(sync.WaitGroup)
iter := float64(benchSize)
start := float64(time.Now().UTC().UnixNano())
// Run function across multiple goroutines
for i := 0; i < benchSize; i += benchSize / numThreads {
wp.Add(1)
go func()... | go | func average(name string, fun func(), benchSize int) {
numThreads := runtime.GOMAXPROCS(-1)
wp := new(sync.WaitGroup)
iter := float64(benchSize)
start := float64(time.Now().UTC().UnixNano())
// Run function across multiple goroutines
for i := 0; i < benchSize; i += benchSize / numThreads {
wp.Add(1)
go func()... | [
"func",
"average",
"(",
"name",
"string",
",",
"fun",
"func",
"(",
")",
",",
"benchSize",
"int",
")",
"{",
"numThreads",
":=",
"runtime",
".",
"GOMAXPROCS",
"(",
"-",
"1",
")",
"\n",
"wp",
":=",
"new",
"(",
"sync",
".",
"WaitGroup",
")",
"\n",
"ite... | // Run the benchmark function a number of times across multiple goroutines, and print out performance data. | [
"Run",
"the",
"benchmark",
"function",
"a",
"number",
"of",
"times",
"across",
"multiple",
"goroutines",
"and",
"print",
"out",
"performance",
"data",
"."
] | be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39 | https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/benchmark/benchmark.go#L18-L36 | train |
HouzuoGuo/tiedot | benchmark/benchmark.go | mkTmpDBAndCol | func mkTmpDBAndCol(dbPath string, colName string) (*db.DB, *db.Col) {
os.RemoveAll(dbPath)
tmpDB, err := db.OpenDB(dbPath)
if err != nil {
panic(err)
}
if err = tmpDB.Create(colName); err != nil {
panic(err)
}
return tmpDB, tmpDB.Use(colName)
} | go | func mkTmpDBAndCol(dbPath string, colName string) (*db.DB, *db.Col) {
os.RemoveAll(dbPath)
tmpDB, err := db.OpenDB(dbPath)
if err != nil {
panic(err)
}
if err = tmpDB.Create(colName); err != nil {
panic(err)
}
return tmpDB, tmpDB.Use(colName)
} | [
"func",
"mkTmpDBAndCol",
"(",
"dbPath",
"string",
",",
"colName",
"string",
")",
"(",
"*",
"db",
".",
"DB",
",",
"*",
"db",
".",
"Col",
")",
"{",
"os",
".",
"RemoveAll",
"(",
"dbPath",
")",
"\n",
"tmpDB",
",",
"err",
":=",
"db",
".",
"OpenDB",
"(... | // Create a temporary database and collection for benchmark use. | [
"Create",
"a",
"temporary",
"database",
"and",
"collection",
"for",
"benchmark",
"use",
"."
] | be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39 | https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/benchmark/benchmark.go#L39-L49 | train |
HouzuoGuo/tiedot | httpapi/collection.go | Create | func Create(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "must-revalidate")
w.Header().Set("Content-Type", "text/plain")
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS")
var col string
if !Require(w, r, "col",... | go | func Create(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "must-revalidate")
w.Header().Set("Content-Type", "text/plain")
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS")
var col string
if !Require(w, r, "col",... | [
"func",
"Create",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
... | // Create a collection. | [
"Create",
"a",
"collection",
"."
] | be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39 | https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/httpapi/collection.go#L12-L26 | train |
HouzuoGuo/tiedot | httpapi/collection.go | Scrub | func Scrub(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "must-revalidate")
w.Header().Set("Content-Type", "text/plain")
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS")
var col string
if !Require(w, r, "col", ... | go | func Scrub(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "must-revalidate")
w.Header().Set("Content-Type", "text/plain")
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS")
var col string
if !Require(w, r, "col", ... | [
"func",
"Scrub",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
... | // De-fragment collection free space and fix corrupted documents. | [
"De",
"-",
"fragment",
"collection",
"free",
"space",
"and",
"fix",
"corrupted",
"documents",
"."
] | be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39 | https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/httpapi/collection.go#L80-L95 | train |
HouzuoGuo/tiedot | httpapi/srv.go | Welcome | func Welcome(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
http.Error(w, "Invalid API endpoint", 404)
return
}
w.Write([]byte("Welcome to tiedot"))
} | go | func Welcome(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
http.Error(w, "Invalid API endpoint", 404)
return
}
w.Write([]byte("Welcome to tiedot"))
} | [
"func",
"Welcome",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"if",
"r",
".",
"URL",
".",
"Path",
"!=",
"\"",
"\"",
"{",
"http",
".",
"Error",
"(",
"w",
",",
"\"",
"\"",
",",
"404",
")",
"\n",
"r... | // Greet user with a welcome message. | [
"Greet",
"user",
"with",
"a",
"welcome",
"message",
"."
] | be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39 | https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/httpapi/srv.go#L136-L142 | train |
google/logger | logger_windows.go | Write | func (w *writer) Write(b []byte) (int, error) {
switch w.pri {
case sInfo:
return len(b), w.el.Info(1, string(b))
case sWarning:
return len(b), w.el.Warning(3, string(b))
case sError:
return len(b), w.el.Error(2, string(b))
}
return 0, fmt.Errorf("unrecognized severity: %v", w.pri)
} | go | func (w *writer) Write(b []byte) (int, error) {
switch w.pri {
case sInfo:
return len(b), w.el.Info(1, string(b))
case sWarning:
return len(b), w.el.Warning(3, string(b))
case sError:
return len(b), w.el.Error(2, string(b))
}
return 0, fmt.Errorf("unrecognized severity: %v", w.pri)
} | [
"func",
"(",
"w",
"*",
"writer",
")",
"Write",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"switch",
"w",
".",
"pri",
"{",
"case",
"sInfo",
":",
"return",
"len",
"(",
"b",
")",
",",
"w",
".",
"el",
".",
"Info",
"(",... | // Write sends a log message to the Event Log. | [
"Write",
"sends",
"a",
"log",
"message",
"to",
"the",
"Event",
"Log",
"."
] | 945e2bd9ed8f9313ef1d14b674500421a51e960b | https://github.com/google/logger/blob/945e2bd9ed8f9313ef1d14b674500421a51e960b/logger_windows.go#L31-L41 | train |
google/logger | logger.go | initialize | func initialize() {
defaultLogger = &Logger{
infoLog: log.New(os.Stderr, initText+tagInfo, flags),
warningLog: log.New(os.Stderr, initText+tagWarning, flags),
errorLog: log.New(os.Stderr, initText+tagError, flags),
fatalLog: log.New(os.Stderr, initText+tagFatal, flags),
}
} | go | func initialize() {
defaultLogger = &Logger{
infoLog: log.New(os.Stderr, initText+tagInfo, flags),
warningLog: log.New(os.Stderr, initText+tagWarning, flags),
errorLog: log.New(os.Stderr, initText+tagError, flags),
fatalLog: log.New(os.Stderr, initText+tagFatal, flags),
}
} | [
"func",
"initialize",
"(",
")",
"{",
"defaultLogger",
"=",
"&",
"Logger",
"{",
"infoLog",
":",
"log",
".",
"New",
"(",
"os",
".",
"Stderr",
",",
"initText",
"+",
"tagInfo",
",",
"flags",
")",
",",
"warningLog",
":",
"log",
".",
"New",
"(",
"os",
".... | // initialize resets defaultLogger. Which allows tests to reset environment. | [
"initialize",
"resets",
"defaultLogger",
".",
"Which",
"allows",
"tests",
"to",
"reset",
"environment",
"."
] | 945e2bd9ed8f9313ef1d14b674500421a51e960b | https://github.com/google/logger/blob/945e2bd9ed8f9313ef1d14b674500421a51e960b/logger.go#L56-L63 | train |
google/logger | logger.go | Close | func (l *Logger) Close() {
logLock.Lock()
defer logLock.Unlock()
for _, c := range l.closers {
if err := c.Close(); err != nil {
fmt.Fprintf(os.Stderr, "Failed to close log %v: %v\n", c, err)
}
}
} | go | func (l *Logger) Close() {
logLock.Lock()
defer logLock.Unlock()
for _, c := range l.closers {
if err := c.Close(); err != nil {
fmt.Fprintf(os.Stderr, "Failed to close log %v: %v\n", c, err)
}
}
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Close",
"(",
")",
"{",
"logLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"logLock",
".",
"Unlock",
"(",
")",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"l",
".",
"closers",
"{",
"if",
"err",
":=",
"c",
".... | // Close closes all the underlying log writers, which will flush any cached logs.
// Any errors from closing the underlying log writers will be printed to stderr.
// Once Close is called, all future calls to the logger will panic. | [
"Close",
"closes",
"all",
"the",
"underlying",
"log",
"writers",
"which",
"will",
"flush",
"any",
"cached",
"logs",
".",
"Any",
"errors",
"from",
"closing",
"the",
"underlying",
"log",
"writers",
"will",
"be",
"printed",
"to",
"stderr",
".",
"Once",
"Close",... | 945e2bd9ed8f9313ef1d14b674500421a51e960b | https://github.com/google/logger/blob/945e2bd9ed8f9313ef1d14b674500421a51e960b/logger.go#L160-L168 | train |
google/logger | logger.go | Info | func (l *Logger) Info(v ...interface{}) {
l.output(sInfo, 0, fmt.Sprint(v...))
} | go | func (l *Logger) Info(v ...interface{}) {
l.output(sInfo, 0, fmt.Sprint(v...))
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Info",
"(",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"l",
".",
"output",
"(",
"sInfo",
",",
"0",
",",
"fmt",
".",
"Sprint",
"(",
"v",
"...",
")",
")",
"\n",
"}"
] | // Info logs with the Info severity.
// Arguments are handled in the manner of fmt.Print. | [
"Info",
"logs",
"with",
"the",
"Info",
"severity",
".",
"Arguments",
"are",
"handled",
"in",
"the",
"manner",
"of",
"fmt",
".",
"Print",
"."
] | 945e2bd9ed8f9313ef1d14b674500421a51e960b | https://github.com/google/logger/blob/945e2bd9ed8f9313ef1d14b674500421a51e960b/logger.go#L172-L174 | train |
google/logger | logger.go | Infoln | func (l *Logger) Infoln(v ...interface{}) {
l.output(sInfo, 0, fmt.Sprintln(v...))
} | go | func (l *Logger) Infoln(v ...interface{}) {
l.output(sInfo, 0, fmt.Sprintln(v...))
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Infoln",
"(",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"l",
".",
"output",
"(",
"sInfo",
",",
"0",
",",
"fmt",
".",
"Sprintln",
"(",
"v",
"...",
")",
")",
"\n",
"}"
] | // Infoln logs with the Info severity.
// Arguments are handled in the manner of fmt.Println. | [
"Infoln",
"logs",
"with",
"the",
"Info",
"severity",
".",
"Arguments",
"are",
"handled",
"in",
"the",
"manner",
"of",
"fmt",
".",
"Println",
"."
] | 945e2bd9ed8f9313ef1d14b674500421a51e960b | https://github.com/google/logger/blob/945e2bd9ed8f9313ef1d14b674500421a51e960b/logger.go#L184-L186 | train |
google/logger | logger.go | Infof | func (l *Logger) Infof(format string, v ...interface{}) {
l.output(sInfo, 0, fmt.Sprintf(format, v...))
} | go | func (l *Logger) Infof(format string, v ...interface{}) {
l.output(sInfo, 0, fmt.Sprintf(format, v...))
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Infof",
"(",
"format",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"l",
".",
"output",
"(",
"sInfo",
",",
"0",
",",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"v",
"...",
")",
")",
"\n",
... | // Infof logs with the Info severity.
// Arguments are handled in the manner of fmt.Printf. | [
"Infof",
"logs",
"with",
"the",
"Info",
"severity",
".",
"Arguments",
"are",
"handled",
"in",
"the",
"manner",
"of",
"fmt",
".",
"Printf",
"."
] | 945e2bd9ed8f9313ef1d14b674500421a51e960b | https://github.com/google/logger/blob/945e2bd9ed8f9313ef1d14b674500421a51e960b/logger.go#L190-L192 | train |
google/logger | logger.go | Warning | func (l *Logger) Warning(v ...interface{}) {
l.output(sWarning, 0, fmt.Sprint(v...))
} | go | func (l *Logger) Warning(v ...interface{}) {
l.output(sWarning, 0, fmt.Sprint(v...))
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Warning",
"(",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"l",
".",
"output",
"(",
"sWarning",
",",
"0",
",",
"fmt",
".",
"Sprint",
"(",
"v",
"...",
")",
")",
"\n",
"}"
] | // Warning logs with the Warning severity.
// Arguments are handled in the manner of fmt.Print. | [
"Warning",
"logs",
"with",
"the",
"Warning",
"severity",
".",
"Arguments",
"are",
"handled",
"in",
"the",
"manner",
"of",
"fmt",
".",
"Print",
"."
] | 945e2bd9ed8f9313ef1d14b674500421a51e960b | https://github.com/google/logger/blob/945e2bd9ed8f9313ef1d14b674500421a51e960b/logger.go#L196-L198 | train |
google/logger | logger.go | Warningln | func (l *Logger) Warningln(v ...interface{}) {
l.output(sWarning, 0, fmt.Sprintln(v...))
} | go | func (l *Logger) Warningln(v ...interface{}) {
l.output(sWarning, 0, fmt.Sprintln(v...))
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Warningln",
"(",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"l",
".",
"output",
"(",
"sWarning",
",",
"0",
",",
"fmt",
".",
"Sprintln",
"(",
"v",
"...",
")",
")",
"\n",
"}"
] | // Warningln logs with the Warning severity.
// Arguments are handled in the manner of fmt.Println. | [
"Warningln",
"logs",
"with",
"the",
"Warning",
"severity",
".",
"Arguments",
"are",
"handled",
"in",
"the",
"manner",
"of",
"fmt",
".",
"Println",
"."
] | 945e2bd9ed8f9313ef1d14b674500421a51e960b | https://github.com/google/logger/blob/945e2bd9ed8f9313ef1d14b674500421a51e960b/logger.go#L208-L210 | train |
google/logger | logger.go | Warningf | func (l *Logger) Warningf(format string, v ...interface{}) {
l.output(sWarning, 0, fmt.Sprintf(format, v...))
} | go | func (l *Logger) Warningf(format string, v ...interface{}) {
l.output(sWarning, 0, fmt.Sprintf(format, v...))
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Warningf",
"(",
"format",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"l",
".",
"output",
"(",
"sWarning",
",",
"0",
",",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"v",
"...",
")",
")",
"\... | // Warningf logs with the Warning severity.
// Arguments are handled in the manner of fmt.Printf. | [
"Warningf",
"logs",
"with",
"the",
"Warning",
"severity",
".",
"Arguments",
"are",
"handled",
"in",
"the",
"manner",
"of",
"fmt",
".",
"Printf",
"."
] | 945e2bd9ed8f9313ef1d14b674500421a51e960b | https://github.com/google/logger/blob/945e2bd9ed8f9313ef1d14b674500421a51e960b/logger.go#L214-L216 | train |
google/logger | logger.go | Error | func (l *Logger) Error(v ...interface{}) {
l.output(sError, 0, fmt.Sprint(v...))
} | go | func (l *Logger) Error(v ...interface{}) {
l.output(sError, 0, fmt.Sprint(v...))
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Error",
"(",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"l",
".",
"output",
"(",
"sError",
",",
"0",
",",
"fmt",
".",
"Sprint",
"(",
"v",
"...",
")",
")",
"\n",
"}"
] | // Error logs with the ERROR severity.
// Arguments are handled in the manner of fmt.Print. | [
"Error",
"logs",
"with",
"the",
"ERROR",
"severity",
".",
"Arguments",
"are",
"handled",
"in",
"the",
"manner",
"of",
"fmt",
".",
"Print",
"."
] | 945e2bd9ed8f9313ef1d14b674500421a51e960b | https://github.com/google/logger/blob/945e2bd9ed8f9313ef1d14b674500421a51e960b/logger.go#L220-L222 | train |
google/logger | logger.go | Errorln | func (l *Logger) Errorln(v ...interface{}) {
l.output(sError, 0, fmt.Sprintln(v...))
} | go | func (l *Logger) Errorln(v ...interface{}) {
l.output(sError, 0, fmt.Sprintln(v...))
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Errorln",
"(",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"l",
".",
"output",
"(",
"sError",
",",
"0",
",",
"fmt",
".",
"Sprintln",
"(",
"v",
"...",
")",
")",
"\n",
"}"
] | // Errorln logs with the ERROR severity.
// Arguments are handled in the manner of fmt.Println. | [
"Errorln",
"logs",
"with",
"the",
"ERROR",
"severity",
".",
"Arguments",
"are",
"handled",
"in",
"the",
"manner",
"of",
"fmt",
".",
"Println",
"."
] | 945e2bd9ed8f9313ef1d14b674500421a51e960b | https://github.com/google/logger/blob/945e2bd9ed8f9313ef1d14b674500421a51e960b/logger.go#L232-L234 | train |
google/logger | logger.go | Errorf | func (l *Logger) Errorf(format string, v ...interface{}) {
l.output(sError, 0, fmt.Sprintf(format, v...))
} | go | func (l *Logger) Errorf(format string, v ...interface{}) {
l.output(sError, 0, fmt.Sprintf(format, v...))
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Errorf",
"(",
"format",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"l",
".",
"output",
"(",
"sError",
",",
"0",
",",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"v",
"...",
")",
")",
"\n",
... | // Errorf logs with the Error severity.
// Arguments are handled in the manner of fmt.Printf. | [
"Errorf",
"logs",
"with",
"the",
"Error",
"severity",
".",
"Arguments",
"are",
"handled",
"in",
"the",
"manner",
"of",
"fmt",
".",
"Printf",
"."
] | 945e2bd9ed8f9313ef1d14b674500421a51e960b | https://github.com/google/logger/blob/945e2bd9ed8f9313ef1d14b674500421a51e960b/logger.go#L238-L240 | train |
google/logger | logger.go | Infof | func Infof(format string, v ...interface{}) {
defaultLogger.output(sInfo, 0, fmt.Sprintf(format, v...))
} | go | func Infof(format string, v ...interface{}) {
defaultLogger.output(sInfo, 0, fmt.Sprintf(format, v...))
} | [
"func",
"Infof",
"(",
"format",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"defaultLogger",
".",
"output",
"(",
"sInfo",
",",
"0",
",",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"v",
"...",
")",
")",
"\n",
"}"
] | // Infof uses the default logger and logs with the Info severity.
// Arguments are handled in the manner of fmt.Printf. | [
"Infof",
"uses",
"the",
"default",
"logger",
"and",
"logs",
"with",
"the",
"Info",
"severity",
".",
"Arguments",
"are",
"handled",
"in",
"the",
"manner",
"of",
"fmt",
".",
"Printf",
"."
] | 945e2bd9ed8f9313ef1d14b674500421a51e960b | https://github.com/google/logger/blob/945e2bd9ed8f9313ef1d14b674500421a51e960b/logger.go#L302-L304 | train |
google/logger | logger.go | Warningf | func Warningf(format string, v ...interface{}) {
defaultLogger.output(sWarning, 0, fmt.Sprintf(format, v...))
} | go | func Warningf(format string, v ...interface{}) {
defaultLogger.output(sWarning, 0, fmt.Sprintf(format, v...))
} | [
"func",
"Warningf",
"(",
"format",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"defaultLogger",
".",
"output",
"(",
"sWarning",
",",
"0",
",",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"v",
"...",
")",
")",
"\n",
"}"
] | // Warningf uses the default logger and logs with the Warning severity.
// Arguments are handled in the manner of fmt.Printf. | [
"Warningf",
"uses",
"the",
"default",
"logger",
"and",
"logs",
"with",
"the",
"Warning",
"severity",
".",
"Arguments",
"are",
"handled",
"in",
"the",
"manner",
"of",
"fmt",
".",
"Printf",
"."
] | 945e2bd9ed8f9313ef1d14b674500421a51e960b | https://github.com/google/logger/blob/945e2bd9ed8f9313ef1d14b674500421a51e960b/logger.go#L326-L328 | train |
google/logger | logger.go | Errorf | func Errorf(format string, v ...interface{}) {
defaultLogger.output(sError, 0, fmt.Sprintf(format, v...))
} | go | func Errorf(format string, v ...interface{}) {
defaultLogger.output(sError, 0, fmt.Sprintf(format, v...))
} | [
"func",
"Errorf",
"(",
"format",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"defaultLogger",
".",
"output",
"(",
"sError",
",",
"0",
",",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"v",
"...",
")",
")",
"\n",
"}"
] | // Errorf uses the default logger and logs with the Error severity.
// Arguments are handled in the manner of fmt.Printf. | [
"Errorf",
"uses",
"the",
"default",
"logger",
"and",
"logs",
"with",
"the",
"Error",
"severity",
".",
"Arguments",
"are",
"handled",
"in",
"the",
"manner",
"of",
"fmt",
".",
"Printf",
"."
] | 945e2bd9ed8f9313ef1d14b674500421a51e960b | https://github.com/google/logger/blob/945e2bd9ed8f9313ef1d14b674500421a51e960b/logger.go#L350-L352 | train |
joho/godotenv | godotenv.go | Parse | func Parse(r io.Reader) (envMap map[string]string, err error) {
envMap = make(map[string]string)
var lines []string
scanner := bufio.NewScanner(r)
for scanner.Scan() {
lines = append(lines, scanner.Text())
}
if err = scanner.Err(); err != nil {
return
}
for _, fullLine := range lines {
if !isIgnoredLin... | go | func Parse(r io.Reader) (envMap map[string]string, err error) {
envMap = make(map[string]string)
var lines []string
scanner := bufio.NewScanner(r)
for scanner.Scan() {
lines = append(lines, scanner.Text())
}
if err = scanner.Err(); err != nil {
return
}
for _, fullLine := range lines {
if !isIgnoredLin... | [
"func",
"Parse",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"envMap",
"map",
"[",
"string",
"]",
"string",
",",
"err",
"error",
")",
"{",
"envMap",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n\n",
"var",
"lines",
"[",
"]",
"strin... | // Parse reads an env file from io.Reader, returning a map of keys and values. | [
"Parse",
"reads",
"an",
"env",
"file",
"from",
"io",
".",
"Reader",
"returning",
"a",
"map",
"of",
"keys",
"and",
"values",
"."
] | 5c0e6c6ab1a0a9ef0a8822cba3a05d62f7dad941 | https://github.com/joho/godotenv/blob/5c0e6c6ab1a0a9ef0a8822cba3a05d62f7dad941/godotenv.go#L99-L124 | train |
joho/godotenv | godotenv.go | Unmarshal | func Unmarshal(str string) (envMap map[string]string, err error) {
return Parse(strings.NewReader(str))
} | go | func Unmarshal(str string) (envMap map[string]string, err error) {
return Parse(strings.NewReader(str))
} | [
"func",
"Unmarshal",
"(",
"str",
"string",
")",
"(",
"envMap",
"map",
"[",
"string",
"]",
"string",
",",
"err",
"error",
")",
"{",
"return",
"Parse",
"(",
"strings",
".",
"NewReader",
"(",
"str",
")",
")",
"\n",
"}"
] | //Unmarshal reads an env file from a string, returning a map of keys and values. | [
"Unmarshal",
"reads",
"an",
"env",
"file",
"from",
"a",
"string",
"returning",
"a",
"map",
"of",
"keys",
"and",
"values",
"."
] | 5c0e6c6ab1a0a9ef0a8822cba3a05d62f7dad941 | https://github.com/joho/godotenv/blob/5c0e6c6ab1a0a9ef0a8822cba3a05d62f7dad941/godotenv.go#L127-L129 | train |
joho/godotenv | godotenv.go | Write | func Write(envMap map[string]string, filename string) error {
content, error := Marshal(envMap)
if error != nil {
return error
}
file, error := os.Create(filename)
if error != nil {
return error
}
_, err := file.WriteString(content)
return err
} | go | func Write(envMap map[string]string, filename string) error {
content, error := Marshal(envMap)
if error != nil {
return error
}
file, error := os.Create(filename)
if error != nil {
return error
}
_, err := file.WriteString(content)
return err
} | [
"func",
"Write",
"(",
"envMap",
"map",
"[",
"string",
"]",
"string",
",",
"filename",
"string",
")",
"error",
"{",
"content",
",",
"error",
":=",
"Marshal",
"(",
"envMap",
")",
"\n",
"if",
"error",
"!=",
"nil",
"{",
"return",
"error",
"\n",
"}",
"\n"... | // Write serializes the given environment and writes it to a file | [
"Write",
"serializes",
"the",
"given",
"environment",
"and",
"writes",
"it",
"to",
"a",
"file"
] | 5c0e6c6ab1a0a9ef0a8822cba3a05d62f7dad941 | https://github.com/joho/godotenv/blob/5c0e6c6ab1a0a9ef0a8822cba3a05d62f7dad941/godotenv.go#L149-L160 | train |
sourcegraph/go-langserver | buildserver/pinned.go | Find | func (p pinnedPkgs) Find(pkg string) string {
if len(p) == 0 {
return ""
}
pkg = pkg + "/"
i := sort.Search(len(p), func(i int) bool { return p[i].Pkg > pkg })
if i > 0 && strings.HasPrefix(pkg, p[i-1].Pkg) {
return p[i-1].Rev
}
return ""
} | go | func (p pinnedPkgs) Find(pkg string) string {
if len(p) == 0 {
return ""
}
pkg = pkg + "/"
i := sort.Search(len(p), func(i int) bool { return p[i].Pkg > pkg })
if i > 0 && strings.HasPrefix(pkg, p[i-1].Pkg) {
return p[i-1].Rev
}
return ""
} | [
"func",
"(",
"p",
"pinnedPkgs",
")",
"Find",
"(",
"pkg",
"string",
")",
"string",
"{",
"if",
"len",
"(",
"p",
")",
"==",
"0",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"pkg",
"=",
"pkg",
"+",
"\"",
"\"",
"\n",
"i",
":=",
"sort",
".",
"Searc... | // Find returns the revision a pkg is pinned at, or the empty string. | [
"Find",
"returns",
"the",
"revision",
"a",
"pkg",
"is",
"pinned",
"at",
"or",
"the",
"empty",
"string",
"."
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/buildserver/pinned.go#L24-L34 | train |
sourcegraph/go-langserver | langserver/cancel.go | WithCancel | func (c *cancel) WithCancel(ctx context.Context, id jsonrpc2.ID) (context.Context, func()) {
ctx, cancel := context.WithCancel(ctx)
c.mu.Lock()
if c.m == nil {
c.m = make(map[jsonrpc2.ID]func())
}
c.m[id] = cancel
c.mu.Unlock()
return ctx, func() {
c.mu.Lock()
delete(c.m, id)
c.mu.Unlock()
cancel()
}
... | go | func (c *cancel) WithCancel(ctx context.Context, id jsonrpc2.ID) (context.Context, func()) {
ctx, cancel := context.WithCancel(ctx)
c.mu.Lock()
if c.m == nil {
c.m = make(map[jsonrpc2.ID]func())
}
c.m[id] = cancel
c.mu.Unlock()
return ctx, func() {
c.mu.Lock()
delete(c.m, id)
c.mu.Unlock()
cancel()
}
... | [
"func",
"(",
"c",
"*",
"cancel",
")",
"WithCancel",
"(",
"ctx",
"context",
".",
"Context",
",",
"id",
"jsonrpc2",
".",
"ID",
")",
"(",
"context",
".",
"Context",
",",
"func",
"(",
")",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithCanc... | // WithCancel is like context.WithCancel, except you can also cancel via
// calling c.Cancel with the same id. | [
"WithCancel",
"is",
"like",
"context",
".",
"WithCancel",
"except",
"you",
"can",
"also",
"cancel",
"via",
"calling",
"c",
".",
"Cancel",
"with",
"the",
"same",
"id",
"."
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/cancel.go#L18-L32 | train |
sourcegraph/go-langserver | langserver/cancel.go | Cancel | func (c *cancel) Cancel(id jsonrpc2.ID) {
var cancel func()
c.mu.Lock()
if c.m != nil {
cancel = c.m[id]
delete(c.m, id)
}
c.mu.Unlock()
if cancel != nil {
cancel()
}
} | go | func (c *cancel) Cancel(id jsonrpc2.ID) {
var cancel func()
c.mu.Lock()
if c.m != nil {
cancel = c.m[id]
delete(c.m, id)
}
c.mu.Unlock()
if cancel != nil {
cancel()
}
} | [
"func",
"(",
"c",
"*",
"cancel",
")",
"Cancel",
"(",
"id",
"jsonrpc2",
".",
"ID",
")",
"{",
"var",
"cancel",
"func",
"(",
")",
"\n",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"if",
"c",
".",
"m",
"!=",
"nil",
"{",
"cancel",
"=",
"c",
"."... | // Cancel will cancel the request with id. If the request has already been
// cancelled or not been tracked before, Cancel is a noop. | [
"Cancel",
"will",
"cancel",
"the",
"request",
"with",
"id",
".",
"If",
"the",
"request",
"has",
"already",
"been",
"cancelled",
"or",
"not",
"been",
"tracked",
"before",
"Cancel",
"is",
"a",
"noop",
"."
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/cancel.go#L36-L47 | train |
sourcegraph/go-langserver | buildserver/build_server.go | Close | func (h *BuildHandler) Close() error {
var result error
for _, closer := range h.closers {
err := closer.Close()
if err != nil {
result = multierror.Append(result, err)
}
}
return result
} | go | func (h *BuildHandler) Close() error {
var result error
for _, closer := range h.closers {
err := closer.Close()
if err != nil {
result = multierror.Append(result, err)
}
}
return result
} | [
"func",
"(",
"h",
"*",
"BuildHandler",
")",
"Close",
"(",
")",
"error",
"{",
"var",
"result",
"error",
"\n",
"for",
"_",
",",
"closer",
":=",
"range",
"h",
".",
"closers",
"{",
"err",
":=",
"closer",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
"!=... | // Close implements io.Closer | [
"Close",
"implements",
"io",
".",
"Closer"
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/buildserver/build_server.go#L581-L590 | train |
sourcegraph/go-langserver | langserver/symbol.go | String | func (q Query) String() string {
s := ""
switch q.Filter {
case FilterExported:
s = queryJoin(s, "is:exported")
case FilterDir:
s = queryJoin(s, fmt.Sprintf("%s:%s", q.Filter, q.Dir))
default:
// no filter.
}
if q.Kind != 0 {
for kwd, kind := range keywords {
if kind == q.Kind {
s = queryJoin(s, k... | go | func (q Query) String() string {
s := ""
switch q.Filter {
case FilterExported:
s = queryJoin(s, "is:exported")
case FilterDir:
s = queryJoin(s, fmt.Sprintf("%s:%s", q.Filter, q.Dir))
default:
// no filter.
}
if q.Kind != 0 {
for kwd, kind := range keywords {
if kind == q.Kind {
s = queryJoin(s, k... | [
"func",
"(",
"q",
"Query",
")",
"String",
"(",
")",
"string",
"{",
"s",
":=",
"\"",
"\"",
"\n",
"switch",
"q",
".",
"Filter",
"{",
"case",
"FilterExported",
":",
"s",
"=",
"queryJoin",
"(",
"s",
",",
"\"",
"\"",
")",
"\n",
"case",
"FilterDir",
":... | // String converts the query back into a logically equivalent, but not strictly
// byte-wise equal, query string. It is useful for converting a modified query
// structure back into a query string. | [
"String",
"converts",
"the",
"query",
"back",
"into",
"a",
"logically",
"equivalent",
"but",
"not",
"strictly",
"byte",
"-",
"wise",
"equal",
"query",
"string",
".",
"It",
"is",
"useful",
"for",
"converting",
"a",
"modified",
"query",
"structure",
"back",
"i... | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/symbol.go#L42-L63 | train |
sourcegraph/go-langserver | langserver/symbol.go | ParseQuery | func ParseQuery(q string) (qu Query) {
// All queries are case insensitive.
q = strings.ToLower(q)
// Split the query into space-delimited fields.
for _, field := range strings.Fields(q) {
// Check if the field is a filter like `is:exported`.
if strings.HasPrefix(field, "dir:") {
qu.Filter = FilterDir
qu... | go | func ParseQuery(q string) (qu Query) {
// All queries are case insensitive.
q = strings.ToLower(q)
// Split the query into space-delimited fields.
for _, field := range strings.Fields(q) {
// Check if the field is a filter like `is:exported`.
if strings.HasPrefix(field, "dir:") {
qu.Filter = FilterDir
qu... | [
"func",
"ParseQuery",
"(",
"q",
"string",
")",
"(",
"qu",
"Query",
")",
"{",
"// All queries are case insensitive.",
"q",
"=",
"strings",
".",
"ToLower",
"(",
"q",
")",
"\n\n",
"// Split the query into space-delimited fields.",
"for",
"_",
",",
"field",
":=",
"r... | // ParseQuery parses a user's raw query string and returns a
// structured representation of the query. | [
"ParseQuery",
"parses",
"a",
"user",
"s",
"raw",
"query",
"string",
"and",
"returns",
"a",
"structured",
"representation",
"of",
"the",
"query",
"."
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/symbol.go#L73-L103 | train |
sourcegraph/go-langserver | langserver/symbol.go | Collect | func (s *resultSorter) Collect(si symbolPair) {
s.resultsMu.Lock()
score := score(s.Query, si)
if score > 0 {
sc := scoredSymbol{score, si}
s.results = append(s.results, sc)
}
s.resultsMu.Unlock()
} | go | func (s *resultSorter) Collect(si symbolPair) {
s.resultsMu.Lock()
score := score(s.Query, si)
if score > 0 {
sc := scoredSymbol{score, si}
s.results = append(s.results, sc)
}
s.resultsMu.Unlock()
} | [
"func",
"(",
"s",
"*",
"resultSorter",
")",
"Collect",
"(",
"si",
"symbolPair",
")",
"{",
"s",
".",
"resultsMu",
".",
"Lock",
"(",
")",
"\n",
"score",
":=",
"score",
"(",
"s",
".",
"Query",
",",
"si",
")",
"\n",
"if",
"score",
">",
"0",
"{",
"s... | // Collect is a thread-safe method that will record the passed-in
// symbol in the list of results if its score > 0. | [
"Collect",
"is",
"a",
"thread",
"-",
"safe",
"method",
"that",
"will",
"record",
"the",
"passed",
"-",
"in",
"symbol",
"in",
"the",
"list",
"of",
"results",
"if",
"its",
"score",
">",
"0",
"."
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/symbol.go#L167-L175 | train |
sourcegraph/go-langserver | langserver/symbol.go | Results | func (s *resultSorter) Results() []lsp.SymbolInformation {
res := make([]lsp.SymbolInformation, len(s.results))
for i, s := range s.results {
res[i] = s.SymbolInformation
}
return res
} | go | func (s *resultSorter) Results() []lsp.SymbolInformation {
res := make([]lsp.SymbolInformation, len(s.results))
for i, s := range s.results {
res[i] = s.SymbolInformation
}
return res
} | [
"func",
"(",
"s",
"*",
"resultSorter",
")",
"Results",
"(",
")",
"[",
"]",
"lsp",
".",
"SymbolInformation",
"{",
"res",
":=",
"make",
"(",
"[",
"]",
"lsp",
".",
"SymbolInformation",
",",
"len",
"(",
"s",
".",
"results",
")",
")",
"\n",
"for",
"i",
... | // Results returns the ranked list of SymbolInformation values. | [
"Results",
"returns",
"the",
"ranked",
"list",
"of",
"SymbolInformation",
"values",
"."
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/symbol.go#L178-L184 | train |
sourcegraph/go-langserver | langserver/symbol.go | score | func score(q Query, s symbolPair) (scor int) {
if q.Kind != 0 {
if q.Kind != s.Kind {
return 0
}
}
if q.Symbol != nil && !s.desc.Contains(q.Symbol) {
return -1
}
name, container := strings.ToLower(s.Name), strings.ToLower(s.ContainerName)
if !util.IsURI(s.Location.URI) {
log.Printf("unexpectedly saw sy... | go | func score(q Query, s symbolPair) (scor int) {
if q.Kind != 0 {
if q.Kind != s.Kind {
return 0
}
}
if q.Symbol != nil && !s.desc.Contains(q.Symbol) {
return -1
}
name, container := strings.ToLower(s.Name), strings.ToLower(s.ContainerName)
if !util.IsURI(s.Location.URI) {
log.Printf("unexpectedly saw sy... | [
"func",
"score",
"(",
"q",
"Query",
",",
"s",
"symbolPair",
")",
"(",
"scor",
"int",
")",
"{",
"if",
"q",
".",
"Kind",
"!=",
"0",
"{",
"if",
"q",
".",
"Kind",
"!=",
"s",
".",
"Kind",
"{",
"return",
"0",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"q"... | // score returns 0 for results that aren't matches. Results that are matches are assigned
// a positive score, which should be used for ranking purposes. | [
"score",
"returns",
"0",
"for",
"results",
"that",
"aren",
"t",
"matches",
".",
"Results",
"that",
"are",
"matches",
"are",
"assigned",
"a",
"positive",
"score",
"which",
"should",
"be",
"used",
"for",
"ranking",
"purposes",
"."
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/symbol.go#L188-L253 | train |
sourcegraph/go-langserver | langserver/symbol.go | toSym | func toSym(name string, bpkg *build.Package, container string, recv string, kind lsp.SymbolKind, fs *token.FileSet, pos token.Pos) symbolPair {
var id string
if container == "" {
id = fmt.Sprintf("%s/-/%s", path.Clean(bpkg.ImportPath), name)
} else {
id = fmt.Sprintf("%s/-/%s/%s", path.Clean(bpkg.ImportPath), co... | go | func toSym(name string, bpkg *build.Package, container string, recv string, kind lsp.SymbolKind, fs *token.FileSet, pos token.Pos) symbolPair {
var id string
if container == "" {
id = fmt.Sprintf("%s/-/%s", path.Clean(bpkg.ImportPath), name)
} else {
id = fmt.Sprintf("%s/-/%s/%s", path.Clean(bpkg.ImportPath), co... | [
"func",
"toSym",
"(",
"name",
"string",
",",
"bpkg",
"*",
"build",
".",
"Package",
",",
"container",
"string",
",",
"recv",
"string",
",",
"kind",
"lsp",
".",
"SymbolKind",
",",
"fs",
"*",
"token",
".",
"FileSet",
",",
"pos",
"token",
".",
"Pos",
")"... | // toSym returns a SymbolInformation value derived from values we get
// from visiting the Go ast. | [
"toSym",
"returns",
"a",
"SymbolInformation",
"value",
"derived",
"from",
"values",
"we",
"get",
"from",
"visiting",
"the",
"Go",
"ast",
"."
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/symbol.go#L257-L282 | train |
sourcegraph/go-langserver | langserver/symbol.go | collectFromPkg | func (h *LangHandler) collectFromPkg(ctx context.Context, bctx *build.Context, pkg string, rootPath string, results *resultSorter) {
symbols := h.symbolCache.Get(pkg, func() interface{} {
findPackage := h.getFindPackageFunc()
buildPkg, err := findPackage(ctx, bctx, pkg, rootPath, rootPath, 0)
if err != nil {
... | go | func (h *LangHandler) collectFromPkg(ctx context.Context, bctx *build.Context, pkg string, rootPath string, results *resultSorter) {
symbols := h.symbolCache.Get(pkg, func() interface{} {
findPackage := h.getFindPackageFunc()
buildPkg, err := findPackage(ctx, bctx, pkg, rootPath, rootPath, 0)
if err != nil {
... | [
"func",
"(",
"h",
"*",
"LangHandler",
")",
"collectFromPkg",
"(",
"ctx",
"context",
".",
"Context",
",",
"bctx",
"*",
"build",
".",
"Context",
",",
"pkg",
"string",
",",
"rootPath",
"string",
",",
"results",
"*",
"resultSorter",
")",
"{",
"symbols",
":="... | // collectFromPkg collects all the symbols from the specified package
// into the results. It uses LangHandler's package symbol cache to
// speed up repeated calls. | [
"collectFromPkg",
"collects",
"all",
"the",
"symbols",
"from",
"the",
"specified",
"package",
"into",
"the",
"results",
".",
"It",
"uses",
"LangHandler",
"s",
"package",
"symbol",
"cache",
"to",
"speed",
"up",
"repeated",
"calls",
"."
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/symbol.go#L403-L436 | train |
sourcegraph/go-langserver | langserver/symbol.go | Visit | func (c *SymbolCollector) Visit(n ast.Node) (w ast.Visitor) {
switch t := n.(type) {
case *ast.TypeSpec:
if t.Name.Name != "_" {
switch term := t.Type.(type) {
case *ast.StructType:
c.addContainer(t.Name.Name, term.Fields, lsp.SKClass, t.Name.NamePos)
case *ast.InterfaceType:
c.addContainer(t.Name.... | go | func (c *SymbolCollector) Visit(n ast.Node) (w ast.Visitor) {
switch t := n.(type) {
case *ast.TypeSpec:
if t.Name.Name != "_" {
switch term := t.Type.(type) {
case *ast.StructType:
c.addContainer(t.Name.Name, term.Fields, lsp.SKClass, t.Name.NamePos)
case *ast.InterfaceType:
c.addContainer(t.Name.... | [
"func",
"(",
"c",
"*",
"SymbolCollector",
")",
"Visit",
"(",
"n",
"ast",
".",
"Node",
")",
"(",
"w",
"ast",
".",
"Visitor",
")",
"{",
"switch",
"t",
":=",
"n",
".",
"(",
"type",
")",
"{",
"case",
"*",
"ast",
".",
"TypeSpec",
":",
"if",
"t",
"... | // Visit visits AST nodes and collects symbol information | [
"Visit",
"visits",
"AST",
"nodes",
"and",
"collects",
"symbol",
"information"
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/symbol.go#L497-L529 | train |
sourcegraph/go-langserver | langserver/config.go | Apply | func (c Config) Apply(o *InitializationOptions) Config {
if o == nil {
return c
}
if o.FuncSnippetEnabled != nil {
c.FuncSnippetEnabled = *o.FuncSnippetEnabled
}
if o.GocodeCompletionEnabled != nil {
c.GocodeCompletionEnabled = *o.GocodeCompletionEnabled
}
if o.FormatTool != nil {
c.FormatTool = *o.Forma... | go | func (c Config) Apply(o *InitializationOptions) Config {
if o == nil {
return c
}
if o.FuncSnippetEnabled != nil {
c.FuncSnippetEnabled = *o.FuncSnippetEnabled
}
if o.GocodeCompletionEnabled != nil {
c.GocodeCompletionEnabled = *o.GocodeCompletionEnabled
}
if o.FormatTool != nil {
c.FormatTool = *o.Forma... | [
"func",
"(",
"c",
"Config",
")",
"Apply",
"(",
"o",
"*",
"InitializationOptions",
")",
"Config",
"{",
"if",
"o",
"==",
"nil",
"{",
"return",
"c",
"\n",
"}",
"\n",
"if",
"o",
".",
"FuncSnippetEnabled",
"!=",
"nil",
"{",
"c",
".",
"FuncSnippetEnabled",
... | // Apply sets the corresponding field in c for each non-nil field in o. | [
"Apply",
"sets",
"the",
"corresponding",
"field",
"in",
"c",
"for",
"each",
"non",
"-",
"nil",
"field",
"in",
"o",
"."
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/config.go#L70-L99 | train |
sourcegraph/go-langserver | langserver/config.go | NewDefaultConfig | func NewDefaultConfig() Config {
// Default max parallelism to half the CPU cores, but at least always one.
maxparallelism := runtime.NumCPU() / 2
if maxparallelism <= 0 {
maxparallelism = 1
}
return Config{
FuncSnippetEnabled: true,
GocodeCompletionEnabled: false,
FormatTool: formatTool... | go | func NewDefaultConfig() Config {
// Default max parallelism to half the CPU cores, but at least always one.
maxparallelism := runtime.NumCPU() / 2
if maxparallelism <= 0 {
maxparallelism = 1
}
return Config{
FuncSnippetEnabled: true,
GocodeCompletionEnabled: false,
FormatTool: formatTool... | [
"func",
"NewDefaultConfig",
"(",
")",
"Config",
"{",
"// Default max parallelism to half the CPU cores, but at least always one.",
"maxparallelism",
":=",
"runtime",
".",
"NumCPU",
"(",
")",
"/",
"2",
"\n",
"if",
"maxparallelism",
"<=",
"0",
"{",
"maxparallelism",
"=",
... | // NewDefaultConfig returns the default config. See the field comments for the
// defaults. | [
"NewDefaultConfig",
"returns",
"the",
"default",
"config",
".",
"See",
"the",
"field",
"comments",
"for",
"the",
"defaults",
"."
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/config.go#L103-L119 | train |
sourcegraph/go-langserver | gosrc/import_path.go | guessImportPath | func guessImportPath(importPath string) (*Directory, error) {
if !strings.Contains(importPath, ".git") {
// Assume GitHub-like where two path elements is the project
// root.
parts := strings.SplitN(importPath, "/", 4)
if len(parts) < 3 {
return nil, fmt.Errorf("invalid GitHub-like import path: %q", importP... | go | func guessImportPath(importPath string) (*Directory, error) {
if !strings.Contains(importPath, ".git") {
// Assume GitHub-like where two path elements is the project
// root.
parts := strings.SplitN(importPath, "/", 4)
if len(parts) < 3 {
return nil, fmt.Errorf("invalid GitHub-like import path: %q", importP... | [
"func",
"guessImportPath",
"(",
"importPath",
"string",
")",
"(",
"*",
"Directory",
",",
"error",
")",
"{",
"if",
"!",
"strings",
".",
"Contains",
"(",
"importPath",
",",
"\"",
"\"",
")",
"{",
"// Assume GitHub-like where two path elements is the project",
"// roo... | // guessImportPath is used by noGoGetDomains since we can't do the usual
// go get resolution. | [
"guessImportPath",
"is",
"used",
"by",
"noGoGetDomains",
"since",
"we",
"can",
"t",
"do",
"the",
"usual",
"go",
"get",
"resolution",
"."
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/gosrc/import_path.go#L152-L183 | train |
sourcegraph/go-langserver | langserver/handler.go | NewHandler | func NewHandler(defaultCfg Config) jsonrpc2.Handler {
return lspHandler{jsonrpc2.HandlerWithError((&LangHandler{
DefaultConfig: defaultCfg,
HandlerShared: &HandlerShared{},
}).handle)}
} | go | func NewHandler(defaultCfg Config) jsonrpc2.Handler {
return lspHandler{jsonrpc2.HandlerWithError((&LangHandler{
DefaultConfig: defaultCfg,
HandlerShared: &HandlerShared{},
}).handle)}
} | [
"func",
"NewHandler",
"(",
"defaultCfg",
"Config",
")",
"jsonrpc2",
".",
"Handler",
"{",
"return",
"lspHandler",
"{",
"jsonrpc2",
".",
"HandlerWithError",
"(",
"(",
"&",
"LangHandler",
"{",
"DefaultConfig",
":",
"defaultCfg",
",",
"HandlerShared",
":",
"&",
"H... | // NewHandler creates a Go language server handler. | [
"NewHandler",
"creates",
"a",
"Go",
"language",
"server",
"handler",
"."
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/handler.go#L26-L31 | train |
sourcegraph/go-langserver | langserver/handler.go | Handle | func (h lspHandler) Handle(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) {
if isFileSystemRequest(req.Method) {
h.Handler.Handle(ctx, conn, req)
return
}
go h.Handler.Handle(ctx, conn, req)
} | go | func (h lspHandler) Handle(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) {
if isFileSystemRequest(req.Method) {
h.Handler.Handle(ctx, conn, req)
return
}
go h.Handler.Handle(ctx, conn, req)
} | [
"func",
"(",
"h",
"lspHandler",
")",
"Handle",
"(",
"ctx",
"context",
".",
"Context",
",",
"conn",
"*",
"jsonrpc2",
".",
"Conn",
",",
"req",
"*",
"jsonrpc2",
".",
"Request",
")",
"{",
"if",
"isFileSystemRequest",
"(",
"req",
".",
"Method",
")",
"{",
... | // Handle implements jsonrpc2.Handler | [
"Handle",
"implements",
"jsonrpc2",
".",
"Handler"
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/handler.go#L49-L55 | train |
sourcegraph/go-langserver | langserver/handler.go | handle | func (h *LangHandler) handle(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) {
return h.Handle(ctx, conn, req)
} | go | func (h *LangHandler) handle(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) {
return h.Handle(ctx, conn, req)
} | [
"func",
"(",
"h",
"*",
"LangHandler",
")",
"handle",
"(",
"ctx",
"context",
".",
"Context",
",",
"conn",
"*",
"jsonrpc2",
".",
"Conn",
",",
"req",
"*",
"jsonrpc2",
".",
"Request",
")",
"(",
"result",
"interface",
"{",
"}",
",",
"err",
"error",
")",
... | // handle implements jsonrpc2.Handler. | [
"handle",
"implements",
"jsonrpc2",
".",
"Handler",
"."
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/handler.go#L153-L155 | train |
sourcegraph/go-langserver | buildserver/stdlib.go | addSysZversionFile | func addSysZversionFile(fs ctxvfs.FileSystem) ctxvfs.FileSystem {
return ctxvfs.SingleFileOverlay(fs,
"/src/runtime/internal/sys/zversion.go",
[]byte(fmt.Sprintf(`
package sys
const DefaultGoroot = %q
const TheVersion = %q
const Goexperiment=""
const StackGuardMultiplier=1`,
goroot, gosrc.RuntimeVersion)))
} | go | func addSysZversionFile(fs ctxvfs.FileSystem) ctxvfs.FileSystem {
return ctxvfs.SingleFileOverlay(fs,
"/src/runtime/internal/sys/zversion.go",
[]byte(fmt.Sprintf(`
package sys
const DefaultGoroot = %q
const TheVersion = %q
const Goexperiment=""
const StackGuardMultiplier=1`,
goroot, gosrc.RuntimeVersion)))
} | [
"func",
"addSysZversionFile",
"(",
"fs",
"ctxvfs",
".",
"FileSystem",
")",
"ctxvfs",
".",
"FileSystem",
"{",
"return",
"ctxvfs",
".",
"SingleFileOverlay",
"(",
"fs",
",",
"\"",
"\"",
",",
"[",
"]",
"byte",
"(",
"fmt",
".",
"Sprintf",
"(",
"`\npackage sys\n... | // addSysZversionFile adds the zversion.go file, which is generated
// during the Go release process and does not exist in the VCS repo
// archive zips. We need to create it here, or else we'll see
// typechecker errors like "StackGuardMultiplier not declared by
// package sys" when any packages import from the Go stdl... | [
"addSysZversionFile",
"adds",
"the",
"zversion",
".",
"go",
"file",
"which",
"is",
"generated",
"during",
"the",
"Go",
"release",
"process",
"and",
"does",
"not",
"exist",
"in",
"the",
"VCS",
"repo",
"archive",
"zips",
".",
"We",
"need",
"to",
"create",
"i... | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/buildserver/stdlib.go#L15-L26 | train |
sourcegraph/go-langserver | langserver/internal/godef/go/types/types.go | DefaultImportPathToName | func DefaultImportPathToName(path, srcDir string) (string, error) {
if path == "C" {
return "C", nil
}
pkg, err := build.Default.Import(path, srcDir, 0)
return pkg.Name, err
} | go | func DefaultImportPathToName(path, srcDir string) (string, error) {
if path == "C" {
return "C", nil
}
pkg, err := build.Default.Import(path, srcDir, 0)
return pkg.Name, err
} | [
"func",
"DefaultImportPathToName",
"(",
"path",
",",
"srcDir",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"path",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
",",
"nil",
"\n",
"}",
"\n",
"pkg",
",",
"err",
":=",
"build",
".",
"Def... | // DefaultImportPathToName returns the package identifier
// for the given import path. | [
"DefaultImportPathToName",
"returns",
"the",
"package",
"identifier",
"for",
"the",
"given",
"import",
"path",
"."
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/internal/godef/go/types/types.go#L123-L129 | train |
sourcegraph/go-langserver | langserver/internal/godef/go/types/types.go | isGoFile | func isGoFile(d os.FileInfo) bool {
return strings.HasSuffix(d.Name(), ".go") &&
!strings.HasSuffix(d.Name(), "_test.go") &&
!strings.HasPrefix(d.Name(), ".") &&
goodOSArch(d.Name())
} | go | func isGoFile(d os.FileInfo) bool {
return strings.HasSuffix(d.Name(), ".go") &&
!strings.HasSuffix(d.Name(), "_test.go") &&
!strings.HasPrefix(d.Name(), ".") &&
goodOSArch(d.Name())
} | [
"func",
"isGoFile",
"(",
"d",
"os",
".",
"FileInfo",
")",
"bool",
"{",
"return",
"strings",
".",
"HasSuffix",
"(",
"d",
".",
"Name",
"(",
")",
",",
"\"",
"\"",
")",
"&&",
"!",
"strings",
".",
"HasSuffix",
"(",
"d",
".",
"Name",
"(",
")",
",",
"... | // isGoFile returns true if we will consider the file as a
// possible candidate for parsing as part of a package.
// Including _test.go here isn't quite right, but what
// else can we do?
// | [
"isGoFile",
"returns",
"true",
"if",
"we",
"will",
"consider",
"the",
"file",
"as",
"a",
"possible",
"candidate",
"for",
"parsing",
"as",
"part",
"of",
"a",
"package",
".",
"Including",
"_test",
".",
"go",
"here",
"isn",
"t",
"quite",
"right",
"but",
"wh... | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/internal/godef/go/types/types.go#L136-L141 | train |
sourcegraph/go-langserver | langserver/internal/godef/go/types/types.go | Member | func (t Type) Member(name string) *ast.Object {
debugp("member %v '%s' {", t, name)
if t.Pkg != "" && !ast.IsExported(name) {
return nil
}
c := make(chan *ast.Object)
go func() {
if !Panic {
defer func() {
if err := recover(); err != nil {
log.Printf("panic: %v", err)
c <- nil
}
}()
}... | go | func (t Type) Member(name string) *ast.Object {
debugp("member %v '%s' {", t, name)
if t.Pkg != "" && !ast.IsExported(name) {
return nil
}
c := make(chan *ast.Object)
go func() {
if !Panic {
defer func() {
if err := recover(); err != nil {
log.Printf("panic: %v", err)
c <- nil
}
}()
}... | [
"func",
"(",
"t",
"Type",
")",
"Member",
"(",
"name",
"string",
")",
"*",
"ast",
".",
"Object",
"{",
"debugp",
"(",
"\"",
"\"",
",",
"t",
",",
"name",
")",
"\n",
"if",
"t",
".",
"Pkg",
"!=",
"\"",
"\"",
"&&",
"!",
"ast",
".",
"IsExported",
"(... | // Member looks for a member with the given name inside
// the type. For packages, the member can be any exported
// top level declaration inside the package. | [
"Member",
"looks",
"for",
"a",
"member",
"with",
"the",
"given",
"name",
"inside",
"the",
"type",
".",
"For",
"packages",
"the",
"member",
"can",
"be",
"any",
"exported",
"top",
"level",
"declaration",
"inside",
"the",
"package",
"."
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/internal/godef/go/types/types.go#L156-L182 | train |
sourcegraph/go-langserver | langserver/internal/godef/go/types/types.go | Iter | func (t Type) Iter() <-chan *ast.Object {
// TODO avoid sending members with the same name twice.
c := make(chan *ast.Object)
go func() {
internal := t.Pkg == ""
doMembers(t, "", func(obj *ast.Object) {
if internal || ast.IsExported(obj.Name) {
c <- obj
}
})
close(c)
}()
return c
} | go | func (t Type) Iter() <-chan *ast.Object {
// TODO avoid sending members with the same name twice.
c := make(chan *ast.Object)
go func() {
internal := t.Pkg == ""
doMembers(t, "", func(obj *ast.Object) {
if internal || ast.IsExported(obj.Name) {
c <- obj
}
})
close(c)
}()
return c
} | [
"func",
"(",
"t",
"Type",
")",
"Iter",
"(",
")",
"<-",
"chan",
"*",
"ast",
".",
"Object",
"{",
"// TODO avoid sending members with the same name twice.",
"c",
":=",
"make",
"(",
"chan",
"*",
"ast",
".",
"Object",
")",
"\n",
"go",
"func",
"(",
")",
"{",
... | // Iter returns a channel, sends on it
// all the members of the type, then closes it.
// Members at a shallower depth will be
// sent first.
// | [
"Iter",
"returns",
"a",
"channel",
"sends",
"on",
"it",
"all",
"the",
"members",
"of",
"the",
"type",
"then",
"closes",
"it",
".",
"Members",
"at",
"a",
"shallower",
"depth",
"will",
"be",
"sent",
"first",
"."
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/internal/godef/go/types/types.go#L189-L202 | train |
sourcegraph/go-langserver | langserver/internal/godef/go/types/types.go | ExprType | func ExprType(e ast.Expr, importer Importer, fs *token.FileSet) (obj *ast.Object, typ Type) {
ctxt := &exprTypeContext{
importer: importer,
fileSet: fs,
}
return ctxt.exprType(e, false, "")
} | go | func ExprType(e ast.Expr, importer Importer, fs *token.FileSet) (obj *ast.Object, typ Type) {
ctxt := &exprTypeContext{
importer: importer,
fileSet: fs,
}
return ctxt.exprType(e, false, "")
} | [
"func",
"ExprType",
"(",
"e",
"ast",
".",
"Expr",
",",
"importer",
"Importer",
",",
"fs",
"*",
"token",
".",
"FileSet",
")",
"(",
"obj",
"*",
"ast",
".",
"Object",
",",
"typ",
"Type",
")",
"{",
"ctxt",
":=",
"&",
"exprTypeContext",
"{",
"importer",
... | // ExprType returns the type for the given expression,
// and the object that represents it, if there is one.
// All variables, methods, top level functions, packages, struct and
// interface members, and types have objects.
// The returned object can be used with DeclPos to find out
// the source location of the defin... | [
"ExprType",
"returns",
"the",
"type",
"for",
"the",
"given",
"expression",
"and",
"the",
"object",
"that",
"represents",
"it",
"if",
"there",
"is",
"one",
".",
"All",
"variables",
"methods",
"top",
"level",
"functions",
"packages",
"struct",
"and",
"interface"... | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/internal/godef/go/types/types.go#L211-L217 | train |
sourcegraph/go-langserver | langserver/internal/godef/go/types/types.go | doMembers | func doMembers(typ Type, name string, fn func(*ast.Object)) {
switch t := typ.Node.(type) {
case nil:
return
case *ast.ImportSpec:
path := litToString(t.Path)
pos := typ.ctxt.fileSet.Position(typ.Node.Pos())
if pkg := typ.ctxt.importer(path, filepath.Dir(pos.Filename)); pkg != nil {
doScope(pkg.Scope, na... | go | func doMembers(typ Type, name string, fn func(*ast.Object)) {
switch t := typ.Node.(type) {
case nil:
return
case *ast.ImportSpec:
path := litToString(t.Path)
pos := typ.ctxt.fileSet.Position(typ.Node.Pos())
if pkg := typ.ctxt.importer(path, filepath.Dir(pos.Filename)); pkg != nil {
doScope(pkg.Scope, na... | [
"func",
"doMembers",
"(",
"typ",
"Type",
",",
"name",
"string",
",",
"fn",
"func",
"(",
"*",
"ast",
".",
"Object",
")",
")",
"{",
"switch",
"t",
":=",
"typ",
".",
"Node",
".",
"(",
"type",
")",
"{",
"case",
"nil",
":",
"return",
"\n\n",
"case",
... | // doMembers iterates through a type's members, calling
// fn for each member. If name is non-empty, it looks
// directly for members with that name when possible.
// It uses the list q as a queue to perform breadth-first
// traversal, as per the Go specification. | [
"doMembers",
"iterates",
"through",
"a",
"type",
"s",
"members",
"calling",
"fn",
"for",
"each",
"member",
".",
"If",
"name",
"is",
"non",
"-",
"empty",
"it",
"looks",
"directly",
"for",
"members",
"with",
"that",
"name",
"when",
"possible",
".",
"It",
"... | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/internal/godef/go/types/types.go#L536-L556 | train |
sourcegraph/go-langserver | langserver/internal/godef/go/types/types.go | doTypeMembers | func doTypeMembers(t Type, name string, fn func(*ast.Object), q *list.List) {
// strip off single indirection
// TODO: eliminate methods disallowed when indirected.
if u, ok := t.Node.(*ast.StarExpr); ok {
_, t = t.ctxt.exprType(u.X, false, t.Pkg)
}
if id, _ := t.Node.(*ast.Ident); id != nil && id.Obj != nil {
... | go | func doTypeMembers(t Type, name string, fn func(*ast.Object), q *list.List) {
// strip off single indirection
// TODO: eliminate methods disallowed when indirected.
if u, ok := t.Node.(*ast.StarExpr); ok {
_, t = t.ctxt.exprType(u.X, false, t.Pkg)
}
if id, _ := t.Node.(*ast.Ident); id != nil && id.Obj != nil {
... | [
"func",
"doTypeMembers",
"(",
"t",
"Type",
",",
"name",
"string",
",",
"fn",
"func",
"(",
"*",
"ast",
".",
"Object",
")",
",",
"q",
"*",
"list",
".",
"List",
")",
"{",
"// strip off single indirection",
"// TODO: eliminate methods disallowed when indirected.",
"... | // doTypeMembers calls fn for each member of the given type,
// at one level only. Unnamed members are pushed onto the queue. | [
"doTypeMembers",
"calls",
"fn",
"for",
"each",
"member",
"of",
"the",
"given",
"type",
"at",
"one",
"level",
"only",
".",
"Unnamed",
"members",
"are",
"pushed",
"onto",
"the",
"queue",
"."
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/internal/godef/go/types/types.go#L560-L579 | train |
sourcegraph/go-langserver | langserver/internal/godef/go/types/types.go | unnamedFieldName | func unnamedFieldName(t ast.Node) *ast.Ident {
switch t := t.(type) {
case *ast.Ident:
return t
case *ast.SelectorExpr:
return t.Sel
case *ast.StarExpr:
return unnamedFieldName(t.X)
}
panic("no name found for unnamed field")
} | go | func unnamedFieldName(t ast.Node) *ast.Ident {
switch t := t.(type) {
case *ast.Ident:
return t
case *ast.SelectorExpr:
return t.Sel
case *ast.StarExpr:
return unnamedFieldName(t.X)
}
panic("no name found for unnamed field")
} | [
"func",
"unnamedFieldName",
"(",
"t",
"ast",
".",
"Node",
")",
"*",
"ast",
".",
"Ident",
"{",
"switch",
"t",
":=",
"t",
".",
"(",
"type",
")",
"{",
"case",
"*",
"ast",
".",
"Ident",
":",
"return",
"t",
"\n\n",
"case",
"*",
"ast",
".",
"SelectorEx... | // unnamedFieldName returns the field name for
// an unnamed field with its type given by ast node t.
// | [
"unnamedFieldName",
"returns",
"the",
"field",
"name",
"for",
"an",
"unnamed",
"field",
"with",
"its",
"type",
"given",
"by",
"ast",
"node",
"t",
"."
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/internal/godef/go/types/types.go#L635-L648 | train |
sourcegraph/go-langserver | langserver/internal/godef/go/types/types.go | doScope | func doScope(s *ast.Scope, name string, fn func(*ast.Object), pkg string) {
if s == nil {
return
}
if name != "" {
if obj := s.Lookup(name); obj != nil {
fn(obj)
}
return
}
for _, obj := range s.Objects {
if obj.Kind == ast.Bad || pkg != "" && !ast.IsExported(obj.Name) {
continue
}
fn(obj)
}
} | go | func doScope(s *ast.Scope, name string, fn func(*ast.Object), pkg string) {
if s == nil {
return
}
if name != "" {
if obj := s.Lookup(name); obj != nil {
fn(obj)
}
return
}
for _, obj := range s.Objects {
if obj.Kind == ast.Bad || pkg != "" && !ast.IsExported(obj.Name) {
continue
}
fn(obj)
}
} | [
"func",
"doScope",
"(",
"s",
"*",
"ast",
".",
"Scope",
",",
"name",
"string",
",",
"fn",
"func",
"(",
"*",
"ast",
".",
"Object",
")",
",",
"pkg",
"string",
")",
"{",
"if",
"s",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"name",
"!=",
... | // doScope iterates through all the functions in the given scope, at
// the top level only. | [
"doScope",
"iterates",
"through",
"all",
"the",
"functions",
"in",
"the",
"given",
"scope",
"at",
"the",
"top",
"level",
"only",
"."
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/internal/godef/go/types/types.go#L652-L668 | train |
sourcegraph/go-langserver | langserver/internal/godef/go/types/types.go | Underlying | func (typ Type) Underlying(all bool) Type {
for {
id, _ := typ.Node.(*ast.Ident)
if id == nil || id.Obj == nil {
break
}
_, typNode := splitDecl(id.Obj, id)
_, t := typ.ctxt.exprType(typNode, false, typ.Pkg)
if t.Kind != ast.Typ {
return badType
}
typ.Node = t.Node
typ.Pkg = t.Pkg
if !all {
... | go | func (typ Type) Underlying(all bool) Type {
for {
id, _ := typ.Node.(*ast.Ident)
if id == nil || id.Obj == nil {
break
}
_, typNode := splitDecl(id.Obj, id)
_, t := typ.ctxt.exprType(typNode, false, typ.Pkg)
if t.Kind != ast.Typ {
return badType
}
typ.Node = t.Node
typ.Pkg = t.Pkg
if !all {
... | [
"func",
"(",
"typ",
"Type",
")",
"Underlying",
"(",
"all",
"bool",
")",
"Type",
"{",
"for",
"{",
"id",
",",
"_",
":=",
"typ",
".",
"Node",
".",
"(",
"*",
"ast",
".",
"Ident",
")",
"\n",
"if",
"id",
"==",
"nil",
"||",
"id",
".",
"Obj",
"==",
... | // If typ represents a named type, Underlying returns
// the type that it was defined as. If all is true,
// it repeats this process until the type is not
// a named type. | [
"If",
"typ",
"represents",
"a",
"named",
"type",
"Underlying",
"returns",
"the",
"type",
"that",
"it",
"was",
"defined",
"as",
".",
"If",
"all",
"is",
"true",
"it",
"repeats",
"this",
"process",
"until",
"the",
"type",
"is",
"not",
"a",
"named",
"type",
... | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/internal/godef/go/types/types.go#L674-L692 | train |
sourcegraph/go-langserver | langserver/internal/godef/go/types/types.go | certify | func (ctxt *exprTypeContext) certify(typ ast.Node, kind ast.ObjKind, pkg string) Type {
_, t := ctxt.exprType(typ, false, pkg)
if t.Kind == ast.Typ {
return ctxt.newType(t.Node, kind, t.Pkg)
}
return badType
} | go | func (ctxt *exprTypeContext) certify(typ ast.Node, kind ast.ObjKind, pkg string) Type {
_, t := ctxt.exprType(typ, false, pkg)
if t.Kind == ast.Typ {
return ctxt.newType(t.Node, kind, t.Pkg)
}
return badType
} | [
"func",
"(",
"ctxt",
"*",
"exprTypeContext",
")",
"certify",
"(",
"typ",
"ast",
".",
"Node",
",",
"kind",
"ast",
".",
"ObjKind",
",",
"pkg",
"string",
")",
"Type",
"{",
"_",
",",
"t",
":=",
"ctxt",
".",
"exprType",
"(",
"typ",
",",
"false",
",",
... | // make sure that the type is really a type expression | [
"make",
"sure",
"that",
"the",
"type",
"is",
"really",
"a",
"type",
"expression"
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/internal/godef/go/types/types.go#L706-L712 | train |
sourcegraph/go-langserver | langserver/internal/godef/go/types/types.go | exprName | func exprName(typ interface{}) *ast.Object {
switch t := noParens(typ).(type) {
case *ast.Ident:
return t.Obj
case *ast.Object:
return t
}
return nil
} | go | func exprName(typ interface{}) *ast.Object {
switch t := noParens(typ).(type) {
case *ast.Ident:
return t.Obj
case *ast.Object:
return t
}
return nil
} | [
"func",
"exprName",
"(",
"typ",
"interface",
"{",
"}",
")",
"*",
"ast",
".",
"Object",
"{",
"switch",
"t",
":=",
"noParens",
"(",
"typ",
")",
".",
"(",
"type",
")",
"{",
"case",
"*",
"ast",
".",
"Ident",
":",
"return",
"t",
".",
"Obj",
"\n",
"c... | // If n represents a single identifier, exprName returns its object. | [
"If",
"n",
"represents",
"a",
"single",
"identifier",
"exprName",
"returns",
"its",
"object",
"."
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/internal/godef/go/types/types.go#L715-L723 | train |
sourcegraph/go-langserver | langserver/internal/godef/go/types/types.go | splitDecl | func splitDecl(obj *ast.Object, id *ast.Ident) (expr, typ ast.Node) {
switch decl := obj.Decl.(type) {
case nil:
return nil, nil
case *ast.ValueSpec:
return splitVarDecl(obj.Name, decl.Names, decl.Values, decl.Type)
case *ast.TypeSpec:
return nil, decl.Type
case *ast.FuncDecl:
if decl.Recv != nil {
re... | go | func splitDecl(obj *ast.Object, id *ast.Ident) (expr, typ ast.Node) {
switch decl := obj.Decl.(type) {
case nil:
return nil, nil
case *ast.ValueSpec:
return splitVarDecl(obj.Name, decl.Names, decl.Values, decl.Type)
case *ast.TypeSpec:
return nil, decl.Type
case *ast.FuncDecl:
if decl.Recv != nil {
re... | [
"func",
"splitDecl",
"(",
"obj",
"*",
"ast",
".",
"Object",
",",
"id",
"*",
"ast",
".",
"Ident",
")",
"(",
"expr",
",",
"typ",
"ast",
".",
"Node",
")",
"{",
"switch",
"decl",
":=",
"obj",
".",
"Decl",
".",
"(",
"type",
")",
"{",
"case",
"nil",
... | // splitDecl splits obj.Decl and returns the expression part and the type part.
// Either may be nil, but not both if the declaration is value.
//
// If id is non-nil, it gives the referring identifier. This is only used
// to determine which node in a type switch is being referred to.
// | [
"splitDecl",
"splits",
"obj",
".",
"Decl",
"and",
"returns",
"the",
"expression",
"part",
"and",
"the",
"type",
"part",
".",
"Either",
"may",
"be",
"nil",
"but",
"not",
"both",
"if",
"the",
"declaration",
"is",
"value",
".",
"If",
"id",
"is",
"non",
"-... | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/internal/godef/go/types/types.go#L746-L795 | train |
sourcegraph/go-langserver | langserver/internal/godef/go/types/types.go | splitConstDecl | func splitConstDecl(name string, decl *ast.GenDecl) (expr, typ ast.Node) {
var lastSpec *ast.ValueSpec // last spec with >0 values.
for _, spec := range decl.Specs {
vspec := spec.(*ast.ValueSpec)
if len(vspec.Values) > 0 {
lastSpec = vspec
}
for i, vname := range vspec.Names {
if vname.Name == name {
... | go | func splitConstDecl(name string, decl *ast.GenDecl) (expr, typ ast.Node) {
var lastSpec *ast.ValueSpec // last spec with >0 values.
for _, spec := range decl.Specs {
vspec := spec.(*ast.ValueSpec)
if len(vspec.Values) > 0 {
lastSpec = vspec
}
for i, vname := range vspec.Names {
if vname.Name == name {
... | [
"func",
"splitConstDecl",
"(",
"name",
"string",
",",
"decl",
"*",
"ast",
".",
"GenDecl",
")",
"(",
"expr",
",",
"typ",
"ast",
".",
"Node",
")",
"{",
"var",
"lastSpec",
"*",
"ast",
".",
"ValueSpec",
"// last spec with >0 values.",
"\n",
"for",
"_",
",",
... | // Constant declarations can omit the type, so the declaration for
// a const may be the entire GenDecl - we find the relevant
// clause and infer the type and expression. | [
"Constant",
"declarations",
"can",
"omit",
"the",
"type",
"so",
"the",
"declaration",
"for",
"a",
"const",
"may",
"be",
"the",
"entire",
"GenDecl",
"-",
"we",
"find",
"the",
"relevant",
"clause",
"and",
"infer",
"the",
"type",
"and",
"expression",
"."
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/internal/godef/go/types/types.go#L830-L847 | train |
sourcegraph/go-langserver | langserver/internal/godef/go/types/types.go | containsNode | func containsNode(node, x ast.Node) (found bool) {
ast.Walk(funcVisitor(func(n ast.Node) bool {
if !found {
found = n == x
}
return !found
}),
node)
return
} | go | func containsNode(node, x ast.Node) (found bool) {
ast.Walk(funcVisitor(func(n ast.Node) bool {
if !found {
found = n == x
}
return !found
}),
node)
return
} | [
"func",
"containsNode",
"(",
"node",
",",
"x",
"ast",
".",
"Node",
")",
"(",
"found",
"bool",
")",
"{",
"ast",
".",
"Walk",
"(",
"funcVisitor",
"(",
"func",
"(",
"n",
"ast",
".",
"Node",
")",
"bool",
"{",
"if",
"!",
"found",
"{",
"found",
"=",
... | // constainsNode returns true if x is found somewhere
// inside node. | [
"constainsNode",
"returns",
"true",
"if",
"x",
"is",
"found",
"somewhere",
"inside",
"node",
"."
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/internal/godef/go/types/types.go#L862-L871 | train |
sourcegraph/go-langserver | langserver/lint.go | lint | func (h *LangHandler) lint(ctx context.Context, bctx *build.Context, conn jsonrpc2.JSONRPC2, args []string, files []string) error {
if h.linter == nil {
return nil
}
diags, err := h.linter.Lint(ctx, bctx, args...)
if err != nil {
return err
}
return h.publishDiagnostics(ctx, conn, diags, h.config.LintTool, ... | go | func (h *LangHandler) lint(ctx context.Context, bctx *build.Context, conn jsonrpc2.JSONRPC2, args []string, files []string) error {
if h.linter == nil {
return nil
}
diags, err := h.linter.Lint(ctx, bctx, args...)
if err != nil {
return err
}
return h.publishDiagnostics(ctx, conn, diags, h.config.LintTool, ... | [
"func",
"(",
"h",
"*",
"LangHandler",
")",
"lint",
"(",
"ctx",
"context",
".",
"Context",
",",
"bctx",
"*",
"build",
".",
"Context",
",",
"conn",
"jsonrpc2",
".",
"JSONRPC2",
",",
"args",
"[",
"]",
"string",
",",
"files",
"[",
"]",
"string",
")",
"... | // lint runs the configured lint command with the given arguments then published the
// results as diagnostics. | [
"lint",
"runs",
"the",
"configured",
"lint",
"command",
"with",
"the",
"given",
"arguments",
"then",
"published",
"the",
"results",
"as",
"diagnostics",
"."
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/lint.go#L34-L45 | train |
sourcegraph/go-langserver | langserver/lint.go | lintPackage | func (h *LangHandler) lintPackage(ctx context.Context, bctx *build.Context, conn jsonrpc2.JSONRPC2, uri lsp.DocumentURI) error {
filename := h.FilePath(uri)
pkg, err := ContainingPackage(h.BuildContext(ctx), filename, h.RootFSPath)
if err != nil {
return err
}
files := make([]string, 0, len(pkg.GoFiles))
for _... | go | func (h *LangHandler) lintPackage(ctx context.Context, bctx *build.Context, conn jsonrpc2.JSONRPC2, uri lsp.DocumentURI) error {
filename := h.FilePath(uri)
pkg, err := ContainingPackage(h.BuildContext(ctx), filename, h.RootFSPath)
if err != nil {
return err
}
files := make([]string, 0, len(pkg.GoFiles))
for _... | [
"func",
"(",
"h",
"*",
"LangHandler",
")",
"lintPackage",
"(",
"ctx",
"context",
".",
"Context",
",",
"bctx",
"*",
"build",
".",
"Context",
",",
"conn",
"jsonrpc2",
".",
"JSONRPC2",
",",
"uri",
"lsp",
".",
"DocumentURI",
")",
"error",
"{",
"filename",
... | // lintPackage runs LangHandler.lint for the package containing the uri. | [
"lintPackage",
"runs",
"LangHandler",
".",
"lint",
"for",
"the",
"package",
"containing",
"the",
"uri",
"."
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/lint.go#L48-L60 | train |
sourcegraph/go-langserver | langserver/lint.go | lintWorkspace | func (h *LangHandler) lintWorkspace(ctx context.Context, bctx *build.Context, conn jsonrpc2.JSONRPC2) error {
var files []string
pkgs := tools.ListPkgsUnderDir(bctx, h.RootFSPath)
find := h.getFindPackageFunc()
for _, pkg := range pkgs {
p, err := find(ctx, bctx, pkg, h.RootFSPath, h.RootFSPath, 0)
if err != ni... | go | func (h *LangHandler) lintWorkspace(ctx context.Context, bctx *build.Context, conn jsonrpc2.JSONRPC2) error {
var files []string
pkgs := tools.ListPkgsUnderDir(bctx, h.RootFSPath)
find := h.getFindPackageFunc()
for _, pkg := range pkgs {
p, err := find(ctx, bctx, pkg, h.RootFSPath, h.RootFSPath, 0)
if err != ni... | [
"func",
"(",
"h",
"*",
"LangHandler",
")",
"lintWorkspace",
"(",
"ctx",
"context",
".",
"Context",
",",
"bctx",
"*",
"build",
".",
"Context",
",",
"conn",
"jsonrpc2",
".",
"JSONRPC2",
")",
"error",
"{",
"var",
"files",
"[",
"]",
"string",
"\n",
"pkgs",... | // lintWorkspace runs LangHandler.lint for the entire workspace | [
"lintWorkspace",
"runs",
"LangHandler",
".",
"lint",
"for",
"the",
"entire",
"workspace"
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/lint.go#L63-L84 | train |
sourcegraph/go-langserver | langserver/diagnostics.go | sync | func (p *diagnosticsCache) sync(update func(diagnostics) diagnostics, compare func(oldDiagnostics, newDiagnostics diagnostics) (publish diagnostics)) (publish diagnostics) {
p.mu.Lock()
defer p.mu.Unlock()
if p.cache == nil {
p.cache = diagnostics{}
}
newCache := update(p.cache)
publish = compare(p.cache, new... | go | func (p *diagnosticsCache) sync(update func(diagnostics) diagnostics, compare func(oldDiagnostics, newDiagnostics diagnostics) (publish diagnostics)) (publish diagnostics) {
p.mu.Lock()
defer p.mu.Unlock()
if p.cache == nil {
p.cache = diagnostics{}
}
newCache := update(p.cache)
publish = compare(p.cache, new... | [
"func",
"(",
"p",
"*",
"diagnosticsCache",
")",
"sync",
"(",
"update",
"func",
"(",
"diagnostics",
")",
"diagnostics",
",",
"compare",
"func",
"(",
"oldDiagnostics",
",",
"newDiagnostics",
"diagnostics",
")",
"(",
"publish",
"diagnostics",
")",
")",
"(",
"pu... | // sync updates the diagnosticsCache and returns diagnostics need to be
// published.
//
// When a file no longer has any diagnostics the file will be removed from
// the cache. The removed file will be included in the returned diagnostics
// in order to clear the client.
//
// sync is thread safe and will only allow o... | [
"sync",
"updates",
"the",
"diagnosticsCache",
"and",
"returns",
"diagnostics",
"need",
"to",
"be",
"published",
".",
"When",
"a",
"file",
"no",
"longer",
"has",
"any",
"diagnostics",
"the",
"file",
"will",
"be",
"removed",
"from",
"the",
"cache",
".",
"The",... | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/diagnostics.go#L42-L54 | train |
sourcegraph/go-langserver | langserver/diagnostics.go | compareCachedDiagnostics | func compareCachedDiagnostics(oldDiagnostics, newDiagnostics diagnostics, files []string) (publish diagnostics) {
publish = diagnostics{}
for _, f := range files {
_, inOld := oldDiagnostics[f]
diags, inNew := newDiagnostics[f]
if inOld && !inNew {
publish[f] = nil
continue
}
if inNew {
publish[f... | go | func compareCachedDiagnostics(oldDiagnostics, newDiagnostics diagnostics, files []string) (publish diagnostics) {
publish = diagnostics{}
for _, f := range files {
_, inOld := oldDiagnostics[f]
diags, inNew := newDiagnostics[f]
if inOld && !inNew {
publish[f] = nil
continue
}
if inNew {
publish[f... | [
"func",
"compareCachedDiagnostics",
"(",
"oldDiagnostics",
",",
"newDiagnostics",
"diagnostics",
",",
"files",
"[",
"]",
"string",
")",
"(",
"publish",
"diagnostics",
")",
"{",
"publish",
"=",
"diagnostics",
"{",
"}",
"\n",
"for",
"_",
",",
"f",
":=",
"range... | // compareCachedDiagnostics compares new and old diagnostics to determine
// what needs to be published. | [
"compareCachedDiagnostics",
"compares",
"new",
"and",
"old",
"diagnostics",
"to",
"determine",
"what",
"needs",
"to",
"be",
"published",
"."
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/diagnostics.go#L121-L138 | train |
sourcegraph/go-langserver | gituri/uri.go | Parse | func Parse(uriStr string) (*URI, error) {
u, err := url.Parse(uriStr)
if err != nil {
return nil, err
}
if !u.IsAbs() {
return nil, &url.Error{Op: "gituri.Parse", URL: uriStr, Err: errors.New("sourcegraph URI must be absolute")}
}
return &URI{*u}, nil
} | go | func Parse(uriStr string) (*URI, error) {
u, err := url.Parse(uriStr)
if err != nil {
return nil, err
}
if !u.IsAbs() {
return nil, &url.Error{Op: "gituri.Parse", URL: uriStr, Err: errors.New("sourcegraph URI must be absolute")}
}
return &URI{*u}, nil
} | [
"func",
"Parse",
"(",
"uriStr",
"string",
")",
"(",
"*",
"URI",
",",
"error",
")",
"{",
"u",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"uriStr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"... | // Parse parses uriStr to a URI. The uriStr should be an absolute URL. | [
"Parse",
"parses",
"uriStr",
"to",
"a",
"URI",
".",
"The",
"uriStr",
"should",
"be",
"an",
"absolute",
"URL",
"."
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/gituri/uri.go#L35-L44 | train |
sourcegraph/go-langserver | gituri/uri.go | CloneURL | func (u *URI) CloneURL() *url.URL {
return &url.URL{
Scheme: u.Scheme,
Host: u.Host,
Path: u.Path,
}
} | go | func (u *URI) CloneURL() *url.URL {
return &url.URL{
Scheme: u.Scheme,
Host: u.Host,
Path: u.Path,
}
} | [
"func",
"(",
"u",
"*",
"URI",
")",
"CloneURL",
"(",
")",
"*",
"url",
".",
"URL",
"{",
"return",
"&",
"url",
".",
"URL",
"{",
"Scheme",
":",
"u",
".",
"Scheme",
",",
"Host",
":",
"u",
".",
"Host",
",",
"Path",
":",
"u",
".",
"Path",
",",
"}"... | // CloneURL returns the repository clone URL component of the URI. | [
"CloneURL",
"returns",
"the",
"repository",
"clone",
"URL",
"component",
"of",
"the",
"URI",
"."
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/gituri/uri.go#L47-L53 | train |
sourcegraph/go-langserver | langserver/format.go | ComputeTextEdits | func ComputeTextEdits(unformatted string, formatted string) []lsp.TextEdit {
// LSP wants a list of TextEdits. We use difflib to compute a
// non-naive TextEdit. Originally we returned an edit which deleted
// everything followed by inserting everything. This leads to a poor
// experience in vscode.
unformattedLin... | go | func ComputeTextEdits(unformatted string, formatted string) []lsp.TextEdit {
// LSP wants a list of TextEdits. We use difflib to compute a
// non-naive TextEdit. Originally we returned an edit which deleted
// everything followed by inserting everything. This leads to a poor
// experience in vscode.
unformattedLin... | [
"func",
"ComputeTextEdits",
"(",
"unformatted",
"string",
",",
"formatted",
"string",
")",
"[",
"]",
"lsp",
".",
"TextEdit",
"{",
"// LSP wants a list of TextEdits. We use difflib to compute a",
"// non-naive TextEdit. Originally we returned an edit which deleted",
"// everything f... | // ComputeTextEdits computes text edits that are required to
// change the `unformatted` to the `formatted` text. | [
"ComputeTextEdits",
"computes",
"text",
"edits",
"that",
"are",
"required",
"to",
"change",
"the",
"unformatted",
"to",
"the",
"formatted",
"text",
"."
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/format.go#L79-L129 | train |
sourcegraph/go-langserver | langserver/signature.go | callExpr | func callExpr(fset *token.FileSet, nodes []ast.Node) *ast.CallExpr {
for _, node := range nodes {
callExpr, ok := node.(*ast.CallExpr)
if ok {
return callExpr
}
}
return nil
} | go | func callExpr(fset *token.FileSet, nodes []ast.Node) *ast.CallExpr {
for _, node := range nodes {
callExpr, ok := node.(*ast.CallExpr)
if ok {
return callExpr
}
}
return nil
} | [
"func",
"callExpr",
"(",
"fset",
"*",
"token",
".",
"FileSet",
",",
"nodes",
"[",
"]",
"ast",
".",
"Node",
")",
"*",
"ast",
".",
"CallExpr",
"{",
"for",
"_",
",",
"node",
":=",
"range",
"nodes",
"{",
"callExpr",
",",
"ok",
":=",
"node",
".",
"(",... | // callExpr climbs AST tree up until call expression | [
"callExpr",
"climbs",
"AST",
"tree",
"up",
"until",
"call",
"expression"
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/signature.go#L77-L85 | train |
sourcegraph/go-langserver | langserver/signature.go | shortType | func shortType(t types.Type) string {
return types.TypeString(t, func(*types.Package) string {
return ""
})
} | go | func shortType(t types.Type) string {
return types.TypeString(t, func(*types.Package) string {
return ""
})
} | [
"func",
"shortType",
"(",
"t",
"types",
".",
"Type",
")",
"string",
"{",
"return",
"types",
".",
"TypeString",
"(",
"t",
",",
"func",
"(",
"*",
"types",
".",
"Package",
")",
"string",
"{",
"return",
"\"",
"\"",
"\n",
"}",
")",
"\n",
"}"
] | // shortTyoe returns shorthand type notation without specifying type's import path | [
"shortTyoe",
"returns",
"shorthand",
"type",
"notation",
"without",
"specifying",
"type",
"s",
"import",
"path"
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/signature.go#L88-L92 | train |
sourcegraph/go-langserver | langserver/signature.go | shortParam | func shortParam(param *types.Var) string {
ret := param.Name()
if ret != "" {
ret += " "
}
return ret + shortType(param.Type())
} | go | func shortParam(param *types.Var) string {
ret := param.Name()
if ret != "" {
ret += " "
}
return ret + shortType(param.Type())
} | [
"func",
"shortParam",
"(",
"param",
"*",
"types",
".",
"Var",
")",
"string",
"{",
"ret",
":=",
"param",
".",
"Name",
"(",
")",
"\n",
"if",
"ret",
"!=",
"\"",
"\"",
"{",
"ret",
"+=",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"ret",
"+",
"shortType",
... | // shortParam returns shorthand parameter notation in form "name type" without specifying type's import path | [
"shortParam",
"returns",
"shorthand",
"parameter",
"notation",
"in",
"form",
"name",
"type",
"without",
"specifying",
"type",
"s",
"import",
"path"
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/signature.go#L95-L101 | train |
sourcegraph/go-langserver | langserver/ast.go | goRangeToLSPLocation | func goRangeToLSPLocation(fset *token.FileSet, pos token.Pos, end token.Pos) lsp.Location {
return lsp.Location{
URI: util.PathToURI(fset.Position(pos).Filename),
Range: rangeForNode(fset, fakeNode{p: pos, e: end}),
}
} | go | func goRangeToLSPLocation(fset *token.FileSet, pos token.Pos, end token.Pos) lsp.Location {
return lsp.Location{
URI: util.PathToURI(fset.Position(pos).Filename),
Range: rangeForNode(fset, fakeNode{p: pos, e: end}),
}
} | [
"func",
"goRangeToLSPLocation",
"(",
"fset",
"*",
"token",
".",
"FileSet",
",",
"pos",
"token",
".",
"Pos",
",",
"end",
"token",
".",
"Pos",
")",
"lsp",
".",
"Location",
"{",
"return",
"lsp",
".",
"Location",
"{",
"URI",
":",
"util",
".",
"PathToURI",
... | // goRangeToLSPLocation converts a token.Pos range into a lsp.Location. end is
// exclusive. | [
"goRangeToLSPLocation",
"converts",
"a",
"token",
".",
"Pos",
"range",
"into",
"a",
"lsp",
".",
"Location",
".",
"end",
"is",
"exclusive",
"."
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/ast.go#L69-L75 | train |
sourcegraph/go-langserver | langserver/lsp.go | Contains | func (a *symbolDescriptor) Contains(b lspext.SymbolDescriptor) bool {
for k, v := range b {
switch k {
case "package":
if s, ok := v.(string); !ok || s != a.Package {
return false
}
case "packageName":
if s, ok := v.(string); !ok || s != a.PackageName {
return false
}
case "recv":
if s, ... | go | func (a *symbolDescriptor) Contains(b lspext.SymbolDescriptor) bool {
for k, v := range b {
switch k {
case "package":
if s, ok := v.(string); !ok || s != a.Package {
return false
}
case "packageName":
if s, ok := v.(string); !ok || s != a.PackageName {
return false
}
case "recv":
if s, ... | [
"func",
"(",
"a",
"*",
"symbolDescriptor",
")",
"Contains",
"(",
"b",
"lspext",
".",
"SymbolDescriptor",
")",
"bool",
"{",
"for",
"k",
",",
"v",
":=",
"range",
"b",
"{",
"switch",
"k",
"{",
"case",
"\"",
"\"",
":",
"if",
"s",
",",
"ok",
":=",
"v"... | // Contains ensures that b is a subset of our symbolDescriptor | [
"Contains",
"ensures",
"that",
"b",
"is",
"a",
"subset",
"of",
"our",
"symbolDescriptor"
] | 33d2968a49e1131825a0accdd64bdf9901cf144c | https://github.com/sourcegraph/go-langserver/blob/33d2968a49e1131825a0accdd64bdf9901cf144c/langserver/lsp.go#L24-L56 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.