Skip to content

Commit

Permalink
Merge pull request #41 from joyme123/fix-hover-markdown
Browse files Browse the repository at this point in the history
fix(hover): fix hover markdown syntax
  • Loading branch information
joyme123 authored Oct 22, 2024
2 parents cbe1341 + f6715b8 commit f265f29
Show file tree
Hide file tree
Showing 5 changed files with 476 additions and 489 deletions.
4 changes: 4 additions & 0 deletions format/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func FormatDocumentWithValidation(doc *parser.Document, selfValidation bool) (st

writeBuf := func(node parser.Node, addtionalLine bool) {
if addtionalLine {
if len(buf.Bytes()) > 0 && buf.Bytes()[buf.Len()-1] != '\n' {
// if preNode doesn't have \n at end of line, set \n for it
buf.WriteString("\n")
}
buf.WriteString("\n")
}

Expand Down
1 change: 1 addition & 0 deletions format/document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ exception Xception2 {
}
struct EmptyStruct {}
struct OneField {
1: EmptyStruct field
}
Expand Down
12 changes: 11 additions & 1 deletion lsp/hover.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package lsp

import (
"context"
"strings"

"github.com/joyme123/thrift-ls/lsp/codejump"
"go.lsp.dev/protocol"
Expand All @@ -25,10 +26,19 @@ func (s *Server) hover(ctx context.Context, params *protocol.HoverParams) (*prot
return nil, nil
}

markdown_prefix := "```thrift\n"
if strings.HasPrefix(content, "\n") {
markdown_prefix = "```thrift"
}
markdown_suffix := "\n```"
if strings.HasSuffix(content, "\n") {
markdown_suffix = "```"
}

return &protocol.Hover{
Contents: protocol.MarkupContent{
Kind: protocol.Markdown,
Value: "```thrift\n" + content + "```",
Value: markdown_prefix + content + markdown_suffix,
},
}, nil
}
Loading

0 comments on commit f265f29

Please sign in to comment.