-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.go
More file actions
70 lines (58 loc) · 1.71 KB
/
code.go
File metadata and controls
70 lines (58 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package startprompt
import (
"github.com/yetsing/startprompt/token"
)
/*
分词和补全相关的接口和结构体
*/
type Completion struct {
// Display 展示给用户看的
Display string
// Suffix 加到用户输入后面的
Suffix string
// DisplayMeta 补全的元信息,比如补全是变量或者方法之类的
DisplayMeta string
}
type CodeFactory func(document *Document) Code
type Code interface {
// GetTokens 返回分词后的 Token 列表
GetTokens() []token.Token
// Complete 返回补全文本,可以直接添加在用户输入后,例如按一次 tab 便出现的补全
// 返回空字符串表示没有可直接添加的补全
Complete() string
// GetCompletions 返回当前可选的补全列表,供用户选择,例如连按两次 tab 出现的补全列表
GetCompletions() []*Completion
// ContinueInput 用户按下 Enter 键时调用,
// 返回 true 时,会插入换行符
// 返回 false 时,表示用户本次输入完成, CommandLine.ReadInput(TCommandLine.ReadInput) 则会返回用户输入
ContinueInput() bool
// CompleteAfterInsertText 返回 true 表示每次插入文本我们都获取一次补全
CompleteAfterInsertText() bool
}
// _BaseCode Code 的默认实现
type _BaseCode struct {
document *Document
}
func newBaseCode(document *Document) Code {
return &_BaseCode{document: document}
}
func (c *_BaseCode) GetTokens() []token.Token {
return []token.Token{
{
token.Unspecific,
c.document.Text(),
},
}
}
func (c *_BaseCode) Complete() string {
return ""
}
func (c *_BaseCode) GetCompletions() []*Completion {
return nil
}
func (c *_BaseCode) ContinueInput() bool {
return false
}
func (c *_BaseCode) CompleteAfterInsertText() bool {
return false
}