emacs-lsp / lsp-mode

Emacs client/library for the Language Server Protocol
https://emacs-lsp.github.io/lsp-mode
GNU General Public License v3.0
4.75k stars 869 forks source link

`lsp-org` breaks with `org 9.7-pre` #4300

Open aavanian opened 7 months ago

aavanian commented 7 months ago

Thank you for the bug report

Bug description

lsp-org breaks with org 9.7-pre (not released yet).

The issue is that in 9.7 org stops exposing some properties from org elements (see this comment in ORG-NEWS).

At least one of the issues is https://github.com/emacs-lsp/lsp-mode/blob/2da66b3dabce4925f4c03a1243fe702d8c2f7a93/lsp-mode.el#L9490

I can make it work by replacing the offending line with (apologies for the quick'n'dirty non-idiomatic code):

              (elem (org-element-context))
              (begin (org-element-property :begin elem))
              (end (org-element-property :end elem))
              (post-blank (org-element-property :post-blank elem))
              (language (org-element-property :language elem))

As far as I tested, this seems enough. The next line still works though changing it to use org-element-property might future-proof it as well.

Steps to reproduce

test.org

#+begin_src python :tangle "test.py"
print("hello")
#+end_src

With point in the source block, invoke lsp-org leads to progn: Wrong type argument: integer-or-marker-p, nil.

Expected behavior

Initialization of lsp

Which Language Server did you use?

lsp-pyright

OS

MacOS

Error callstack

No response

Anything else?

No response

yyoncho commented 7 months ago

Can you confirm that this patch works with older org versions? If yes, are you willing to provide a PR?

aavanian commented 7 months ago

I can confirm it works with org 9.6.7.

As for the PR, I researched a bit and there's three possible ways to rewrite it:

somewhere in lsp-mode.el

(defun dash-expand:&oelem (key source)
  "Generate extracting KEY from SOURCE for &oelem (org-element) destructuring."
  `(org-element-property ,key ,source))

in place of the offending line

((&oelem :begin :end :post-blank :language) (org-element-context))

as for the next line, nothing to do as that property doesn't reside in an org-element anyway.

The third seems cleanest but you may want a different name (as far as I understand dash, it needs to remain in the form dash-expand:&...). I'll make a PR once I know your pref and testing it again.

quzyte commented 1 month ago

Any updates on this? I recently updated to org 9.6.24, and semantic highlighting in imenu is broken. I don't know if it is the same issue, but as far as I was able to figure, this seems the closest related issue.

aavanian commented 1 month ago

I don't think yours is the same issue as this one as I'm pretty sure org-element api changes are 9.7+ only. As far as the above is concerned, I'm waiting for a member to tell me which fix style they prefer to send a PR