mirror of
https://github.com/zyedidia/micro.git
synced 2025-06-18 14:55:38 -04:00
Show detail and doc
This commit is contained in:
parent
01f55a6c79
commit
188b579b22
@ -413,6 +413,7 @@ func DoEvent() {
|
||||
action.MainTab().Display()
|
||||
action.InfoBar.Display()
|
||||
screen.Screen.Show()
|
||||
action.InfoBar.Message("")
|
||||
|
||||
// Check for new events
|
||||
select {
|
||||
|
@ -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
|
||||
|
@ -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]
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user