Skip to content

Commit

Permalink
fork (#1)
Browse files Browse the repository at this point in the history
* add support case-insensitive completion

given declarations

	func FunX()
	func funY()

with this enabled, completing `fun|` suggests both functions instead of just `funY`

* Don't suggest builtins when the cursor is in a selector

Previously, completing `fmt.|` would suggest the builtins

This fixes mdempsky#39
  • Loading branch information
DisposaBoy authored Nov 1, 2018
1 parent 466551c commit f2a5109
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
3 changes: 2 additions & 1 deletion suggest/candidate.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type candidateCollector struct {
partial string
filter objectFilter
builtin bool
ignoreCase bool
}

func (b *candidateCollector) getCandidates() []Candidate {
Expand Down Expand Up @@ -182,7 +183,7 @@ func (b *candidateCollector) appendObject(obj types.Object) {
return
}

if b.filter != nil || strings.HasPrefix(obj.Name(), b.partial) {
if !b.ignoreCase && (b.filter != nil || strings.HasPrefix(obj.Name(), b.partial)) {
b.exact = append(b.exact, obj)
} else if strings.HasPrefix(strings.ToLower(obj.Name()), strings.ToLower(b.partial)) {
b.badcase = append(b.badcase, obj)
Expand Down
16 changes: 9 additions & 7 deletions suggest/suggest.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import (
)

type Config struct {
Importer types.Importer
Logf func(fmt string, args ...interface{})
Builtin bool
Importer types.Importer
Logf func(fmt string, args ...interface{})
Builtin bool
IgnoreCase bool
}

// Suggest returns a list of suggestion candidates and the length of
Expand All @@ -35,10 +36,11 @@ func (c *Config) Suggest(filename string, data []byte, cursor int) ([]Candidate,

ctx, expr, partial := deduceCursorContext(data, cursor)
b := candidateCollector{
localpkg: pkg,
partial: partial,
filter: objectFilters[partial],
builtin: c.Builtin,
localpkg: pkg,
partial: partial,
filter: objectFilters[partial],
builtin: ctx != selectContext && c.Builtin,
ignoreCase: c.IgnoreCase,
}

switch ctx {
Expand Down

0 comments on commit f2a5109

Please sign in to comment.