Skip to content

textDocument/didOpen not called when language server doesn't support codelens, highlight, etc #1224

Closed

Description

@bzoracler

Note: pygls is a language server framework written in Python.

Reproduction (in PyCharm, other IDEs should be similar):

  1. Use the following directory structure in a new PyCharm project:

    project/  # <--- navigate to this as root directory in the PyCharm terminal
        s.py
        test1.py  # Empty file
        test2.py  # Empty file
    
  2. Set up new Python environment and pip install pygls==1.3.1 (latest stable release)

  3. Use this as contents of s.py:

    from lsprotocol import types
    from pygls.server import LanguageServer
    
    server = LanguageServer("example-server", "v0.1")
    
    @server.feature(types.TEXT_DOCUMENT_DID_OPEN)
    def did_open(ls: LanguageServer, params: types.DidOpenTextDocumentParams):
        ls.show_message_log(f"OPENED {params.text_document.uri}")
    
    @server.feature(types.TEXT_DOCUMENT_DID_CLOSE)
    def did_close(ls: LanguageServer, params: types.DidCloseTextDocumentParams):
        ls.show_message_log(f"CLOSED {params.text_document.uri}")
    
    if __name__ == "__main__":
        server.start_io()
  4. Use the following server definition:

    1. Image

      (Make sure $PyInterpreterDirectory$/python is the same python as the one with pygls installed. If not using PyCharm, you may have to provide the absolute path to the python interpreter binary instead of $PyInterpreterDirectory$/python, and the absolute path to s.py instead of $PROJECT_DIR$/s.py.)

    2. Image
  5. Close all open code editor windows without exiting PyCharm, then open test1.py in PyCharm, then exit PyCharm with test1.py still open.

  6. Re-open PyCharm, which should automatically launch the language server and open test1.py at the same time.

  7. Open test2.py

  8. Close test1.py

  9. Close test2.py

Results

Expected behaviour is showing in LSP4IJ v0.12.0 Language Server. Logs below:

Ignoring notification for unknown method "workspace/didChangeConfiguration"
OPENED /absolute/path/to/project/test1.py
OPENED /absolute/path/to/project/test2.py
CLOSED /absolute/path/to/project/test1.py
CLOSED /absolute/path/to/project/test2.py

Unexpected behaviour is showing in LSP4IJ v0.14.2 Language Server. Logs below:

Ignoring notification for unknown method "workspace/didChangeConfiguration"
OPENED /absolute/path/to/project/test1.py
<no event for test2.py>
CLOSED /absolute/path/to/project/test1.py
<no event for test2.py>

Activity

  1. angelozerr commented on Aug 20, 2025

    @angelozerr
    Contributor

    Could yiu share your full lsp traces please

  2. bzoracler commented on Aug 20, 2025

    @bzoracler
    ContributorAuthor
  3. bzoracler commented on Aug 20, 2025

    @bzoracler
    ContributorAuthor

    Oops, I omitted the end of the trace from LSP4IJ 0.12.0 sample, it should have this at the end:

    [Trace - 17:02:33] Sending request 'shutdown - (2)'.
    Params: null
    
    
    [Trace - 17:02:33] Received response 'shutdown - (2)' in 2ms.
    No response returned.
    
    
    [Trace - 17:02:33] Sending notification 'exit'
    Params: null
    
  4. angelozerr commented on Aug 20, 2025

    @angelozerr
    Contributor

    Thanks for the lsp traces.

    I dont understand what your ls provides as lsp features. Therevare no highlight, codelens, inlayhint support which should force the didOpen

  5. bzoracler commented on Aug 20, 2025

    @bzoracler
    ContributorAuthor

    The traces are reproduced from the sequence of steps given in the top post. In particular,

    • The first didOpen (on test1.py) comes from step 5 and 6, triggered by the automatic re-opening of test1.py upon launching PyCharm.
    • The second didOpen (on test2.py) comes from step 7, triggered by the user manually opening test2.py. (This only triggers on LSP4IJ v0.12.0; it doesn't trigger on LSP4IJ v0.14.2, which is the cause of this bug report).
  6. angelozerr commented on Aug 20, 2025

    @angelozerr
    Contributor

    @bzoracler the main difference between 0.12 and 0.13 is that didOpen should call only when file tab is visible. Technically when IJ consumes highlight, codevision, etc when editor is displayed.

    Before 0.13.0 didOpen occurs when IJ fileOpen is sent. This sent is done for all opened files even if it is not visible.

    This behavior is the same than vscode and improve performance when IJ starts. If you have a lot of files opened which are associated to several servers, only the server associated to visible tab file will be started.

    In other words you need to click on the editor tab to have a didOpen. Is it working for you?

  7. bzoracler commented on Aug 20, 2025

    @bzoracler
    ContributorAuthor

    No, for me the didOpen in v0.13 and newer only triggers for file tabs that are automatically opened when launching PyCharm (these automatically-opened windows are the ones not closed when exiting the previous PyCharm session).

    Newer opened file tabs do not trigger didOpen at all (see step 7 in the top post; didOpen doesn't appear in the trace for test2.py for LSP4IJ 0.14.2).

    The real language server I'm using does not use highlight, code lens, codevision, or inlay hint. It currently only uses textDocument/publishDiagnostics, which I need upon opening a code editor window.

  8. bzoracler commented on Aug 20, 2025

    @bzoracler
    ContributorAuthor

    This is LSP4IJ 0.14.2, the editor tab for test2.py is open (I manually opened it) but does not have trace for didOpen. test1.py has a trace because it was automatically opened when I launched PyCharm (I didn't close test1.py when I exited PyCharm last session).

    Image

    In LSP4IJ 0.12.0, both test1.py and test2.py would show didOpen traces.

  9. angelozerr commented on Aug 20, 2025

    @angelozerr
    Contributor

    Ok I think the cause of your problem is that your language server has no highlight, codelens, inlayhint which forces the didOpen.

    Let me investigate how to fix that.

  10. changed the title [-]`textDocument/didOpen` stopped working properly with pygls after v0.12.0[/-] [+]`textDocument/didOpen` not called when language server doesn't supports codelens, highlight, etc[/+] on Aug 20, 2025
  11. added a commit that references this issue on Aug 20, 2025
    66ed137
  12. added
    bug
    on Aug 20, 2025
  13. added this to the 0.15.0 milestone on Aug 20, 2025
  14. self-assigned this
    on Aug 20, 2025
  15. changed the title [-]`textDocument/didOpen` not called when language server doesn't supports codelens, highlight, etc[/-] [+]`textDocument/didOpen` not called when language server doesn't support codelens, highlight, etc[/+] on Aug 20, 2025
  16. added 4 commits that reference this issue on Aug 20, 2025
    b58e59a
    58c227f
    ae32333
    7e9f532
  17. bzoracler commented on Aug 20, 2025

    @bzoracler
    ContributorAuthor

    Thank you, I will test the build and get back to looking at #1223 if it works.

  18. angelozerr commented on Aug 20, 2025

    @angelozerr
    Contributor

    Thank you, I will test the build and get back to looking at #1223 if it works.

    Hope it will work and if it is working, please wait that rebase was done in #1223 (see #1223 (comment))

  19. bzoracler commented on Aug 20, 2025

    @bzoracler
    ContributorAuthor

    @angelozerr Thank you for the fast fix, this worked great!

  20. angelozerr commented on Aug 20, 2025

    @angelozerr
    Contributor

    @angelozerr Thank you for the fast fix, this worked great!

    That's great! If you like LSP4IJ, don't hesitate to add a review at JetBrains Marketplace to help us to promote LSP4IJ.

  21. bzoracler commented on Aug 20, 2025

    @bzoracler
    ContributorAuthor

    Don't worry, I've left a 5-star review back in February :)

    Thanks again for the great product!

  22. angelozerr commented on Aug 20, 2025

    @angelozerr
    Contributor

    Don't worry, I've left a 5-star review back in February :)

    Thanks again for the great product!

    Ooops sorry I have forgotten that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions