Show detail and doc

This commit is contained in:
Zachary Yedidia 2020-08-16 17:20:17 -04:00
parent 01f55a6c79
commit 188b579b22
4 changed files with 70 additions and 15 deletions

View File

@ -413,6 +413,7 @@ func DoEvent() {
action.MainTab().Display()
action.InfoBar.Display()
screen.Screen.Show()
action.InfoBar.Message("")
// Check for new events
select {

View File

@ -668,7 +668,7 @@ func (h *BufPane) Autocomplete() bool {
// if there is an existing completion, always cycle it
if b.HasSuggestions {
b.CycleAutocomplete(true)
h.cycleAutocomplete(true)
return true
}
@ -682,8 +682,12 @@ func (h *BufPane) Autocomplete() bool {
// don't autocomplete if cursor is on alpha numeric character (middle of a word)
return false
}
ret := true
if !b.Autocomplete(buffer.LSPComplete) {
return b.Autocomplete(buffer.BufferComplete)
ret = b.Autocomplete(buffer.BufferComplete)
}
if ret {
h.displayCompletionDoc()
}
return true
}
@ -695,12 +699,24 @@ func (h *BufPane) CycleAutocompleteBack() bool {
}
if h.Buf.HasSuggestions {
h.Buf.CycleAutocomplete(false)
h.cycleAutocomplete(false)
return true
}
return false
}
func (h *BufPane) cycleAutocomplete(forward bool) {
h.Buf.CycleAutocomplete(forward)
h.displayCompletionDoc()
}
func (h *BufPane) displayCompletionDoc() {
c := h.Buf.CurCompletion
if c >= 0 && c < len(h.Buf.Completions) {
InfoBar.Message(h.Buf.Completions[c].Doc)
}
}
// InsertTab inserts a tab or spaces
func (h *BufPane) InsertTab() bool {
b := h.Buf

View File

@ -9,6 +9,7 @@ import (
"github.com/zyedidia/micro/v2/internal/lsp"
"github.com/zyedidia/micro/v2/internal/util"
"go.lsp.dev/protocol"
)
// A Completer is a function that takes a buffer and returns info
@ -24,7 +25,7 @@ type Completion struct {
Edits []Delta
Label string
CommitChars []rune
Kind int
Kind string
Filter string
Detail string
Doc string
@ -235,6 +236,8 @@ func LSPComplete(b *Buffer) []Completion {
completions[i] = Completion{
Label: item.Label,
Detail: item.Detail,
Kind: toKindStr(item.Kind),
Doc: getDoc(item.Documentation),
}
if item.TextEdit != nil && len(item.TextEdit.NewText) > 0 {
@ -288,3 +291,21 @@ func ConvertCompletions(completions, suggestions []string, c *Cursor) []Completi
}
return comp
}
func toKindStr(k protocol.CompletionItemKind) string {
s := k.String()
return strings.ToLower(string(s[0]))
}
// returns documentation from a string | MarkupContent item
func getDoc(documentation interface{}) string {
var doc string
switch s := documentation.(type) {
case string:
doc = s
case protocol.MarkupContent:
doc = s.Value
}
return strings.Split(doc, "\n")[0]
}

View File

@ -755,32 +755,49 @@ func (w *BufWindow) displayCompleteBox() {
return
}
width := 0
labelw := 0
detailw := 0
kindw := 0
for _, comp := range w.Buf.Completions {
charcount := util.CharacterCountInString(comp.Label)
if charcount > width {
width = charcount
if charcount > labelw {
labelw = charcount
}
charcount = util.CharacterCountInString(comp.Detail)
if charcount > detailw {
detailw = charcount
}
charcount = util.CharacterCountInString(comp.Kind)
if charcount > kindw {
kindw = charcount
}
}
width++
labelw++
kindw++
for i, comp := range w.Buf.Completions {
label := comp.Label
display := func(s string, width, x, y int, cur bool) {
for j := 0; j < width; j++ {
r := ' '
var combc []rune
var size int
if len(label) > 0 {
r, combc, size = util.DecodeCharacterInString(label)
label = label[size:]
if len(s) > 0 {
r, combc, size = util.DecodeCharacterInString(s)
s = s[size:]
}
st := config.DefStyle.Reverse(true)
if i == w.Buf.CurCompletion {
if cur {
st = st.Reverse(false)
}
screen.SetContent(w.completeBox.X+j, w.completeBox.Y+i+1, r, combc, st)
screen.SetContent(w.completeBox.X+x+j, w.completeBox.Y+y, r, combc, st)
}
}
for i, comp := range w.Buf.Completions {
cur := i == w.Buf.CurCompletion
display(comp.Label+" ", labelw, 0, i+1, cur)
display(comp.Kind+" ", kindw, labelw, i+1, cur)
display(comp.Detail, detailw, labelw+kindw, i+1, cur)
}
}
// Display displays the buffer and the statusline