Browse Source

Linting tabComplete for future Travis checks

pull/26/head
Gregory Rudolph 5 years ago
parent
commit
20a687208a
Signed by: rudi
GPG Key ID: EF64F3CBD1A1EBDD
  1. 99
      tabComplete.go

99
tabComplete.go

@ -20,46 +20,46 @@ func handleTab(viewName string) error {
inputString, err := getInputString(viewName) inputString, err := getInputString(viewName)
if err != nil { if err != nil {
return err return err
}
// if you successfully get an input string, grab the last word from the string
ss := regexp.MustCompile(`[ #]`).Split(inputString, -1)
s := ss[len(ss)-1]
// create a variable in which to store the result
var resultSlice []string
// if the word starts with a : its an emoji lookup
if strings.HasPrefix(s, ":") {
resultSlice = getEmojiTabCompletionSlice(s)
} else if strings.HasPrefix(s, "/") {
generateCommandTabCompletionSlice()
s = strings.Replace(s, "/", "", 1)
resultSlice = getCommandTabCompletionSlice(s)
} else { } else {
// if you successfully get an input string, grab the last word from the string if strings.HasPrefix(s, "@") {
ss := regexp.MustCompile(`[ #]`).Split(inputString, -1) // now in case the word (s) is a mention @something, lets remove it to normalize
s := ss[len(ss)-1] s = strings.Replace(s, "@", "", 1)
// create a variable in which to store the result
var resultSlice []string
// if the word starts with a : its an emoji lookup
if strings.HasPrefix(s, ":") {
resultSlice = getEmojiTabCompletionSlice(s)
} else if strings.HasPrefix(s, "/") {
generateCommandTabCompletionSlice()
s = strings.Replace(s, "/", "", 1)
resultSlice = getCommandTabCompletionSlice(s)
} else {
if strings.HasPrefix(s, "@") {
// now in case the word (s) is a mention @something, lets remove it to normalize
s = strings.Replace(s, "@", "", 1)
}
// now call get the list of all possible cantidates that have that as a prefix
resultSlice = getChannelTabCompletionSlice(s)
} }
rLen := len(resultSlice) // now call get the list of all possible cantidates that have that as a prefix
lcp := longestCommonPrefix(resultSlice) resultSlice = getChannelTabCompletionSlice(s)
if lcp != "" { }
originalViewTitle := getViewTitle("Input") rLen := len(resultSlice)
newViewTitle := "" lcp := longestCommonPrefix(resultSlice)
if rLen >= 1 && originalViewTitle != "" { if lcp != "" {
if rLen == 1 { originalViewTitle := getViewTitle("Input")
newViewTitle = originalViewTitle newViewTitle := ""
} else if rLen <= 5 { if rLen >= 1 && originalViewTitle != "" {
newViewTitle = fmt.Sprintf("%s|| %s", originalViewTitle, strings.Join(resultSlice, " ")) if rLen == 1 {
} else if rLen > 5 { newViewTitle = originalViewTitle
newViewTitle = fmt.Sprintf("%s|| %s +%d more", originalViewTitle, strings.Join(resultSlice[:6], " "), rLen-5) } else if rLen <= 5 {
} newViewTitle = fmt.Sprintf("%s|| %s", originalViewTitle, strings.Join(resultSlice, " "))
setViewTitle(viewName, newViewTitle) } else if rLen > 5 {
remainder := stringRemainder(s, lcp) newViewTitle = fmt.Sprintf("%s|| %s +%d more", originalViewTitle, strings.Join(resultSlice[:6], " "), rLen-5)
writeToView(viewName, remainder)
} }
setViewTitle(viewName, newViewTitle)
remainder := stringRemainder(s, lcp)
writeToView(viewName, remainder)
} }
} }
return nil return nil
} }
@ -123,22 +123,23 @@ func getCurrentChannelMembership() []string {
var rs []string var rs []string
if channel.Name != "" { if channel.Name != "" {
t := k.NewTeam(channel.Name) t := k.NewTeam(channel.Name)
if testVar, err := t.MemberList(); err != nil { testVar, err := t.MemberList()
if err != nil {
return rs // then this isn't a team, its a PM or there was an error in the API call return rs // then this isn't a team, its a PM or there was an error in the API call
} else {
for _, m := range testVar.Result.Members.Owners {
rs = append(rs, fmt.Sprintf("%+v", m.Username))
}
for _, m := range testVar.Result.Members.Admins {
rs = append(rs, fmt.Sprintf("%+v", m.Username))
}
for _, m := range testVar.Result.Members.Writers {
rs = append(rs, fmt.Sprintf("%+v", m.Username))
}
for _, m := range testVar.Result.Members.Readers {
rs = append(rs, fmt.Sprintf("%+v", m.Username))
}
} }
for _, m := range testVar.Result.Members.Owners {
rs = append(rs, fmt.Sprintf("%+v", m.Username))
}
for _, m := range testVar.Result.Members.Admins {
rs = append(rs, fmt.Sprintf("%+v", m.Username))
}
for _, m := range testVar.Result.Members.Writers {
rs = append(rs, fmt.Sprintf("%+v", m.Username))
}
for _, m := range testVar.Result.Members.Readers {
rs = append(rs, fmt.Sprintf("%+v", m.Username))
}
} }
return rs return rs
} }

Loading…
Cancel
Save