completeCode does code completion within the session using gopls. in and pos specifies the current input and the cursor position (0 <= pos <= len(in)) respectively. If exprMode is set to true, the completion is done as an expression (e.g. appends "(" to functions). Return value keep specifies how ma
(in string, pos int, exprMode bool)
| 66 | // If exprMode is set to true, the completion is done as an expression (e.g. appends "(" to functions). |
| 67 | // Return value keep specifies how many characters of in should be kept and candidates are what follow in[0:keep]. |
| 68 | func (s *Session) completeCode(in string, pos int, exprMode bool) (keep int, candidates []string, err error) { |
| 69 | if s.completer == nil { |
| 70 | return |
| 71 | } |
| 72 | |
| 73 | s.clearQuickFix() |
| 74 | |
| 75 | source, err := s.source(false) |
| 76 | if err != nil { |
| 77 | return |
| 78 | } |
| 79 | |
| 80 | if err = s.completer.update(source); err != nil { |
| 81 | return |
| 82 | } |
| 83 | |
| 84 | // Kind of dirty hack :/ |
| 85 | p := strings.LastIndex(source, "}") |
| 86 | editingSource := source[:p] + "; " + in + source[p:] |
| 87 | cursor := p + pos + 2 |
| 88 | |
| 89 | debugf("complete code: %q, %d, %v", in, pos, exprMode) |
| 90 | if candidates, keep, err = s.completer.complete( |
| 91 | editingSource, cursor, exprMode); err != nil { |
| 92 | return |
| 93 | } |
| 94 | keep -= p + 2 |
| 95 | debugf("complete results: %q, %d", candidates, keep) |
| 96 | return |
| 97 | } |
| 98 | |
| 99 | func hasPrefixFunc(src string, f func(rune) bool) bool { |
| 100 | for _, r := range src { |
no test coverage detected