func()

in src/ulsp/controller/scip/scip.go [622:661]


func (c *controller) hover(ctx context.Context, params *protocol.HoverParams, result *protocol.Hover) error {
	sesh, err := c.sessions.GetFromContext(ctx)
	if err != nil {
		return err
	}
	reg := c.registries[sesh.WorkspaceRoot]
	if reg == nil {
		return nil
	}
	if result == nil {
		return nil
	}

	mappedPosition, err := c.getBasePosition(ctx, params.TextDocument, params.Position)
	if err != nil {
		return err
	} else if mappedPosition == nil {
		return nil
	}

	docs, occ, err := reg.Hover(params.TextDocument.URI, *mappedPosition)
	if err != nil {
		return fmt.Errorf("failed to get hover info: %w", err)
	}

	if len(docs) > 0 {
		rng := mapper.ScipToProtocolRange(occ.Range)
		if result.Range == nil {
			mappedRange := c.getLatestRange(ctx, params.TextDocument, rng)
			result.Range = &mappedRange
		}
		if result.Contents.Value != "" {
			result.Contents.Value += "\n"
		}
		result.Contents.Value += docs
		result.Contents.Kind = protocol.Markdown
	}

	return nil
}