IMO we should either switch or copy code from the posframe package: https://github.com/tumashu/posframe . In particular, posframe enforces correctly the size of the windows while lsp-ui-doc implementation does not work fine if there is a very long word. - see #309 .
I have used the package to implement popups in dap-mode and I was very satisfied with the behaviour of the package.
(cc @tumashu )