emacs-lsp / lsp-ui

UI integrations for lsp-mode
https://emacs-lsp.github.io/lsp-ui
GNU General Public License v3.0
1.03k stars 141 forks source link

lsp-ui mode's 'sideline' feature still has width issues on MacOS (Emacs 28.1, MacPorts Version) #716

Closed SamuelBanya closed 2 years ago

SamuelBanya commented 2 years ago

After doing most of the suggestions within these issues, I can confirm that this width issue still exists on MacOS: https://github.com/emacs-lsp/lsp-ui/issues/285 https://github.com/emacs-lsp/lsp-ui/issues/284

The bug occurs right after zooming in with 'text-scale-increase'.

I think this more or less has to deal with the default font size that is present when the LSP mode buffer is first enabled.

I think the fix would be to adjust accordingly to 'text-scale-increase', or adjust to the font size present. That way there would be no overlap anyway.

I was getting the same overlapping issues as featured in the two issues pages mentioned above.

My affected environment:

The only thing I could do for the time being is to nuke 'sideline' from my LSP config:

(use-package lsp-ui
  :ensure t
  :after lsp-mode
  :commands lsp-ui-mode
  :hook (lsp-mode . lsp-ui-mode)
  :custom
  (lsp-ui-doc-enable t)
  ;; Nuking sideline as it doesn't work with MacOS nicely with fonts (Part 1):
  (lsp-ui-sideline-enable nil)
  ;; Nuking sideline as it doesn't work with MacOS nicely with fonts (Part 2):
  (lsp-ui-sideline-show-hover nil)
  (lsp-ui-flycheck-enable t)
  (lsp-ui-flycheck-live-reporting t)
  (lsp-ui-sideline-toggle-symbols-info t)
  (lsp-ui-sideline-show-hover t)
  (lsp-ui-peek-enable t))
gustavotcabral commented 2 years ago

I had the same problem in Linux (Emacs 28.1 with Cairo) for a long time. So I decided to dive into the lsp-ui source code and solved it (link) for my use case. I don't know if it is the right solution, but it's working like a charm.

I've created a snippet to test/show the behavior without extra dependencies:

;; This overlay overflows
(let* ((p (line-end-position))
       (ov (make-overlay p p))
       (msg (propertize "This overlay overflows to the next line. Bad, bad overlay..." 'face 'error))
       (string (concat (propertize " " 'display `(space :align-to (- right-fringe ,(1+ (length msg))))) msg)))
  (overlay-put ov 'after-string string))

;; This overlay doesn't overflow
(let* ((p (line-end-position))
       (ov (make-overlay p p))
       (msg (propertize "This overlay DOESN'T overflow to the next line. Woo-hoo!!!!!" 'face 'error))
       (string (concat (propertize " " 'display `(space :align-to (- right-fringe (,(1+ (length msg)) . width)))) msg)))
  (overlay-put ov 'after-string string))

overlays

SamuelBanya commented 2 years ago

Hey @gustavotcabral

Question regarding workflow for this particular patch:

Should I put this in a custom function within the ':config' section of my 'use-package' config for 'lsp-mode' in my config? : https://github.com/SamuelBanya/SamsEmacs/blob/main/configuration.org

Or do I have to use Straight.el to benefit from this fix?

Thanks,

Sam

On Fri, Jun 17, 2022, at 2:00 PM, gustavotcabral wrote:

I had the same problem in Linux (Emacs 28.1 with Cairo) for a long time. So I decided to dive into the lsp-ui source code and solved it (link https://github.com/emacs-lsp/lsp-ui/issues/184#issuecomment-1158057166) for my use case. I don't know if it is the right solution, but it's working like a charm.

I've created a snippet to test/show the behavior without extra dependencies:

;; This overlay overflows (let* ((p (line-end-position)) (ov (make-overlay p p)) (msg (propertize "This overlay overflows to the next line. Bad, bad overlay..." 'face 'error)) (string (concat (propertize " " 'display `(space :align-to (- right-fringe ,(1+ (length msg))))) msg))) (overlay-put ov 'after-string string))

;; This overlay doesn't overflow (let* ((p (line-end-position)) (ov (make-overlay p p)) (msg (propertize "This overlay DOESN'T overflow to the next line. Woo-hoo!!!!!" 'face 'error)) (string (concat (propertize " " 'display `(space :align-to (- right-fringe (,(1+ (length msg)) . width)))) msg))) (overlay-put ov 'after-string string)) overlays https://user-images.githubusercontent.com/15175513/174352744-3036661a-b3af-421b-b0eb-f45592da6fa4.png

— Reply to this email directly, view it on GitHub https://github.com/emacs-lsp/lsp-ui/issues/716#issuecomment-1159114632, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVU3GXOSMCADJ7NBIIKHGR3VPS4NXANCNFSM5X5NVJKQ. You are receiving this because you authored the thread.Message ID: @.***>

gustavotcabral commented 2 years ago

Hey @gustavotcabral Question regarding workflow for this particular patch: Should I put this in a custom function within the ':config' section of my 'use-package' config for 'lsp-mode' in my config? : https://github.com/SamuelBanya/SamsEmacs/blob/main/configuration.org Or do I have to use Straight.el to benefit from this fix? Thanks, Sam On Fri, Jun 17, 2022, at 2:00 PM, gustavotcabral wrote: I had the same problem in Linux (Emacs 28.1 with Cairo) for a long time. So I decided to dive into the lsp-ui source code and solved it (link <#184 (comment)>) for my use case. I don't know if it is the right solution, but it's working like a charm. I've created a snippet to test/show the behavior without extra dependencies: ;; This overlay overflows (let ((p (line-end-position)) (ov (make-overlay p p)) (msg (propertize "This overlay overflows to the next line. Bad, bad overlay..." 'face 'error)) (string (concat (propertize " " 'display `(space :align-to (- right-fringe ,(1+ (length msg))))) msg))) (overlay-put ov 'after-string string)) ;; This overlay doesn't overflow (let ((p (line-end-position)) (ov (make-overlay p p)) (msg (propertize "This overlay DOESN'T overflow to the next line. Woo-hoo!!!!!" 'face 'error)) (string (concat (propertize " " 'display `(space :align-to (- right-fringe (,(1+ (length msg)) . width)))) msg))) (overlay-put ov 'after-string string)) overlays https://user-images.githubusercontent.com/15175513/174352744-3036661a-b3af-421b-b0eb-f45592da6fa4.png — Reply to this email directly, view it on GitHub <#716 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVU3GXOSMCADJ7NBIIKHGR3VPS4NXANCNFSM5X5NVJKQ. You are receiving this because you authored the thread.Message ID: @.***>

Hi, @SamuelBanya.

To test the fix, yank the new function in a lisp-interaction-mode or emacs-lisp-mode buffer (I use *scratch*), put the point after the last ) and call eval-last-sexp (or C-x C-e). The first LSP sideline created after this eval will use the new behavior.

I use a mybugs.el file:

(eval-after-load 'lsp-ui-sideline
  (defun ... custom-code-here ...))

I've never used use-package. Maybe it's a better alternative.

SamuelBanya commented 2 years ago

Is there a way I can make a hook function to call your separate custom function as soon as a LSP Mode buffer is enabled instead?

On Sat, Jun 18, 2022, at 3:35 PM, gustavotcabral wrote:

Hey @gustavotcabral https://github.com/gustavotcabral Question regarding workflow for this particular patch: Should I put this in a custom function within the ':config' section of my 'use-package' config for 'lsp-mode' in my config? : https://github.com/SamuelBanya/SamsEmacs/blob/main/configuration.org Or do I have to use Straight.el to benefit from this fix? Thanks, Sam … https://www.fastmail.com/mail/Inbox/compose?u=80f940c1# On Fri, Jun 17, 2022, at 2:00 PM, gustavotcabral wrote: I had the same problem in Linux (Emacs 28.1 with Cairo) for a long time. So I decided to dive into the lsp-ui source code and solved it (link <#184 (comment) https://github.com/emacs-lsp/lsp-ui/issues/184#issuecomment-1158057166>) for my use case. I don't know if it is the right solution, but it's working like a charm. I've created a snippet to test/show the behavior without extra dependencies: ;; This overlay overflows (let ((p (line-end-position)) (ov (make-overlay p p)) (msg (propertize "This overlay overflows to the next line. Bad, bad overlay..." 'face 'error)) (string (concat (propertize " " 'display `(space :align-to (- right-fringe ,(1+ (length msg))))) msg))) (overlay-put ov 'after-string string)) ;; This overlay doesn't overflow (let ((p (line-end-position)) (ov (make-overlay p p)) (msg (propertize "This overlay DOESN'T overflow to the next line. Woo-hoo!!!!!" 'face 'error)) (string (concat (propertize " " 'display `(space :align-to (- right-fringe (,(1+ (length msg)) . width)))) msg))) (overlay-put ov 'after-string string)) overlays https://user-images.githubusercontent.com/15175513/174352744-3036661a-b3af-421b-b0eb-f45592da6fa4.png — Reply to this email directly, view it on GitHub <#716 (comment) https://github.com/emacs-lsp/lsp-ui/issues/716#issuecomment-1159114632>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVU3GXOSMCADJ7NBIIKHGR3VPS4NXANCNFSM5X5NVJKQ. You are receiving this because you authored the thread.Message ID: @.***>

Hi, @SamuelBanya https://github.com/SamuelBanya.

To test the fix, yank the new function in a lisp-interaction-mode or emacs-lisp-mode buffer (I use *scratch*), put the point after the last ) and call eval-last-sexp (or C-x C-e). The first LSP sideline created after this eval will use the new behavior.

I use a mybugs.el file:

(eval-after-load 'lsp-ui-sideline (defun ... custom-code-here ...)) I've never used use-package. Maybe it's a better alternative.

— Reply to this email directly, view it on GitHub https://github.com/emacs-lsp/lsp-ui/issues/716#issuecomment-1159545971, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVU3GXPLGNSSELLASK535SDVPYQITANCNFSM5X5NVJKQ. You are receiving this because you were mentioned.Message ID: @.***>

gustavotcabral commented 2 years ago

Is there a way I can make a hook function to call your separate custom function as soon as a LSP Mode buffer is enabled instead? On Sat, Jun 18, 2022, at 3:35 PM, gustavotcabral wrote: > > Hey @gustavotcabral https://github.com/gustavotcabral Question regarding workflow for this particular patch: Should I put this in a custom function within the ':config' section of my 'use-package' config for 'lsp-mode' in my config? : https://github.com/SamuelBanya/SamsEmacs/blob/main/configuration.org Or do I have to use Straight.el to benefit from this fix? Thanks, Sam > … https://www.fastmail.com/mail/Inbox/compose?u=80f940c1# > On Fri, Jun 17, 2022, at 2:00 PM, gustavotcabral wrote: I had the same problem in Linux (Emacs 28.1 with Cairo) for a long time. So I decided to dive into the lsp-ui source code and solved it (link <#184 (comment) <#184 (comment)>>) for my use case. I don't know if it is the right solution, but it's working like a charm. I've created a snippet to test/show the behavior without extra dependencies: ;; This overlay overflows (let ((p (line-end-position)) (ov (make-overlay p p)) (msg (propertize "This overlay overflows to the next line. Bad, bad overlay..." 'face 'error)) (string (concat (propertize " " 'display `(space :align-to (- right-fringe ,(1+ (length msg))))) msg))) (overlay-put ov 'after-string string)) ;; This overlay doesn't overflow (let ((p (line-end-position)) (ov (make-overlay p p)) (msg (propertize "This overlay DOESN'T overflow to the next line. Woo-hoo!!!!!" 'face 'error)) (string (concat (propertize " " 'display (space :align-to (- right-fringe (,(1+ (length msg)) . width)))) msg))) (overlay-put ov 'after-string string)) overlays https://user-images.githubusercontent.com/15175513/174352744-3036661a-b3af-421b-b0eb-f45592da6fa4.png — Reply to this email directly, view it on GitHub <#716 (comment) <[#716 (comment)](https://github.com/emacs-lsp/lsp-ui/issues/716#issuecomment-1159114632)>>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVU3GXOSMCADJ7NBIIKHGR3VPS4NXANCNFSM5X5NVJKQ. You are receiving this because you authored the thread.Message ID: **@**.***> > Hi, @SamuelBanya <https://github.com/SamuelBanya>. To test the fix, yank the new function in alisp-interaction-modeoremacs-lisp-modebuffer (I usescratch), put the point after the last)and calleval-last-sexp(orC-x C-e). The first LSP sideline created after this eval will use the new behavior. I use amybugs.elfile: (eval-after-load 'lsp-ui-sideline (defun ... custom-code-here ...)) I've never useduse-package`. Maybe it's a better alternative. — Reply to this email directly, view it on GitHub <#716 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVU3GXPLGNSSELLASK535SDVPYQITANCNFSM5X5NVJKQ. You are receiving this because you were mentioned.Message ID: @.***>

You don't need hooks. Here is the code I use:

(eval-after-load 'lsp-ui-sideline
  '(progn
     (defun lsp-ui-sideline--align (&rest lengths)
       "Align sideline string by LENGTHS from the right of the window."
       (cons (+ (apply '+ lengths)
                (if (display-graphic-p) 1 2))
             'width))))
SamuelBanya commented 2 years ago

Hey @gustavotcabral That totally worked!

Thanks for this, put it into my config, and this works on my MacOS version like a charm.

Good to see it got merged into the main branch as well. Sweet!