Skip to content

Commit

Permalink
Merge pull request #578 from moosq/get-hover-content-from-definition
Browse files Browse the repository at this point in the history
Get hover content from definition
  • Loading branch information
moosq committed Aug 25, 2022
2 parents 2f11bb4 + ca7a7a2 commit ca7adea
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions internal/lsp/hover.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,34 @@ package lsp

import (
"context"
"fmt"
"github.com/nokia/ntt/internal/log"
"strings"

"github.com/nokia/ntt/internal/lsp/protocol"
"github.com/nokia/ntt/ttcn3"
"github.com/nokia/ntt/ttcn3/ast"
)

func (s *Server) hover(ctx context.Context, params *protocol.HoverParams) (*protocol.Hover, error) {
var (
file = string(params.TextDocument.URI.SpanURI())
line = int(params.Position.Line) + 1
col = int(params.Position.Character) + 1
file = string(params.TextDocument.URI.SpanURI())
line = int(params.Position.Line) + 1
col = int(params.Position.Character) + 1
comment string
)

tree := ttcn3.ParseFile(file)
x := tree.ExprAt(tree.Pos(line, col))
if x == nil {
log.Debug(fmt.Sprintf("No expression at %s:%d:%d\n", file, line, col))
return nil, nil
}
for _, def := range tree.LookupWithDB(x, &s.db) {
if firstTok := ast.FirstToken(def.Node); firstTok == nil {
continue
} else {
// make line breaks conform to markdown spec
comment = strings.ReplaceAll(firstTok.Comments(), "\n", " \n")
}
}

comment := ast.FirstToken(x).Comments()

hoverContents := protocol.MarkupContent{Kind: "markdown", Value: comment}
hover := &protocol.Hover{Contents: hoverContents}
Expand Down

0 comments on commit ca7adea

Please sign in to comment.