edit: terminate completion early if current token has no node

This commit is contained in:
Qi Xiao 2016-01-25 23:01:31 +01:00
parent ea2b7e8b92
commit c0d783996e
3 changed files with 15 additions and 0 deletions

View File

@ -1,5 +1,6 @@
package edit
// Styles for UI.
var (
attrForPrompt = ""
attrForRprompt = "7"
@ -11,6 +12,12 @@ var (
attrForSelectedFile = ";7"
)
// Styles for semantic coloring.
var (
styleForBadCommand = "31;3"
styleForBadVariable = "31;3"
)
var attrForType = map[TokenType]string{
ParserError: "31;3",
Bareword: "",

View File

@ -59,6 +59,9 @@ func (c *completion) next(cycle bool) {
func startCompletion(ed *Editor, k Key) *leReturn {
token := tokenAtDot(ed)
node := token.Node
if node == nil {
return nil
}
c := &completion{
start: node.Begin(),

View File

@ -178,6 +178,11 @@ func (ed *Editor) refresh() error {
if ed.mode != modeCompletion {
// XXX Ignore error
ed.tokens, _ = tokenize(ed.line)
for _, t := range ed.tokens {
for _, colorist := range colorists {
t.MoreStyle += colorist(t.Node, ed.evaler)
}
}
}
return ed.writer.refresh(&ed.editorState)
}