Skip to content

nil crashes on textDocument/didSave notification #1202

Closed

Description

@js6pak

nil crashes with following message every time a file is saved:

ERROR nil: Unexpected error: Unhandled notification: textDocument/didSave

According to oxalica/nil#158, lsp4ij shouldn't be sending that notification as it was not advertised by nil.

Activity

  1. rcjsuen commented on Aug 4, 2025

    @rcjsuen
    Contributor

    Also see #1076.

  2. angelozerr commented on Aug 9, 2025

    @angelozerr
    Contributor
  3. rcjsuen commented on Aug 9, 2025

    @rcjsuen
    Contributor

    I still get these log messages on 0.15.0-20250809-013311.

    2025/08/09 06:55:41 jsonrpc2 handler: notification "textDocument/didSave" handling error: jsonrpc2: code -32601 message: method not supported: textDocument/didSave
    2025/08/09 06:55:41 jsonrpc2 handler: notification "textDocument/didSave" handling error: jsonrpc2: code -32601 message: method not supported: textDocument/didSave
    
  4. rcjsuen commented on Aug 9, 2025

    @rcjsuen
    Contributor

    This code is calling newSyncOptions.setSave(true) which seems to ignore/override what the server is doing.

    private @NotNull TextDocumentSyncOptions createSyncOptions() {
    Either<TextDocumentSyncKind, TextDocumentSyncOptions> syncOptions = initializeFuture == null ? null
    : this.serverCapabilities.getTextDocumentSync();
    if (syncOptions != null) {
    if (syncOptions.isLeft()) {
    TextDocumentSyncKind change = syncOptions.getLeft();
    TextDocumentSyncOptions newSyncOptions = new TextDocumentSyncOptions();
    newSyncOptions.setOpenClose(true);
    newSyncOptions.setChange(change);
    newSyncOptions.setSave(true);
    return newSyncOptions;
    } else if (syncOptions.isRight()) {
    TextDocumentSyncOptions newSyncOptions = syncOptions.getRight();
    if (newSyncOptions.getSave() == null) {
    newSyncOptions.setSave(true);
    }
    return newSyncOptions;
    }
    }
    return DEFAULT_SYNC_OPTIONS;
    }

  5. angelozerr commented on Aug 9, 2025

    @angelozerr
    Contributor

    This code is calling newSyncOptions.setSave(true) which seems to ignore/override what the server is doing.

    private @NotNull TextDocumentSyncOptions createSyncOptions() {
    Either<TextDocumentSyncKind, TextDocumentSyncOptions> syncOptions = initializeFuture == null ? null
    : this.serverCapabilities.getTextDocumentSync();
    if (syncOptions != null) {
    if (syncOptions.isLeft()) {
    TextDocumentSyncKind change = syncOptions.getLeft();
    TextDocumentSyncOptions newSyncOptions = new TextDocumentSyncOptions();
    newSyncOptions.setOpenClose(true);
    newSyncOptions.setChange(change);
    newSyncOptions.setSave(true);
    return newSyncOptions;
    } else if (syncOptions.isRight()) {
    TextDocumentSyncOptions newSyncOptions = syncOptions.getRight();
    if (newSyncOptions.getSave() == null) {
    newSyncOptions.setSave(true);
    }
    return newSyncOptions;
    }
    }
    return DEFAULT_SYNC_OPTIONS;
    }

    Good catch! I think I have implemented that without testing since I had not a language server usecase.

  6. angelozerr commented on Aug 9, 2025

    @angelozerr
    Contributor

    @js6pak could you please share your lsp traces by activating trace as verbose in lsp console

  7. angelozerr commented on Aug 9, 2025

    @angelozerr
    Contributor

    @js6pak could you please share your lsp traces by activating trace as verbose in lsp console

    I will fix your issue asap. Just one question: how do you use nil with lsp4ij ? With user defined ls or with an IJ plugin?

    If it is the first, do you want to contribute to LSP4IJ with nil as user defined ls?

  8. js6pak commented on Aug 9, 2025

    @js6pak
    Author

    could you try to install redhat-developer/lsp4ij#testing-nightly-builds and tell me if it fixes your issue.

    I should have specified, but that's the first thing I tried, yeah.

    could you please share your lsp traces by activating trace as verbose in lsp console

    lsp-trace.txt

    how do you use nil with lsp4ij ? With user defined ls or with an IJ plugin?

    I have it user defined.

    If it is the first, do you want to contribute to LSP4IJ with nil as user defined ls?

    All that's needed is assigning nil to *.nix, default config works fine. So I'm not sure that there's much value in that? And I imagine most Nix users wouldn't want an auto installer.

  9. added
    bug
    on Aug 9, 2025
  10. self-assigned this
    on Aug 9, 2025
  11. added this to the 0.15.0 milestone on Aug 9, 2025
  12. moved this to In Progress in Java Toolingon Aug 9, 2025
  13. angelozerr commented on Aug 9, 2025

    @angelozerr
    Contributor

    @js6pak your LSP trace seems specify that nil can support save ?

    [Trace - 20:23:20] Received response 'initialize - (1)' in 0ms.
    Result: {
      "capabilities": {
        "textDocumentSync": {
          "openClose": true,
          "change": 2,
          "save": true
        },
    

    I don't understand.

  14. rcjsuen commented on Aug 10, 2025

    @rcjsuen
    Contributor

    your LSP trace seems specify that nil can support save ?

    The code doesn't seem to match.

  15. angelozerr commented on Aug 10, 2025

    @angelozerr
    Contributor

    your LSP trace seems specify that nil can support save ?

    The code doesn't seem to match.

    You are right, perhaps the force from LSP4IJ to true when save is null is the cause of this issue.

    Let me try to fix it @js6pak

  16. added a commit that references this issue on Aug 10, 2025
    7fabb98
  17. moved this from In Progress to Done in Java Toolingon Aug 10, 2025
  18. angelozerr commented on Aug 10, 2025

    @angelozerr
    Contributor
  19. rcjsuen commented on Aug 10, 2025

    @rcjsuen
    Contributor

    I don't see the error messages in my logs with 0.15.0-20250810-070516. 👍

  20. angelozerr commented on Aug 10, 2025

    @angelozerr
    Contributor

    could you try to install redhat-developer/lsp4ij#testing-nightly-builds and tell me if it fixes your issue.

    I should have specified, but that's the first thing I tried, yeah.

    could you please share your lsp traces by activating trace as verbose in lsp console

    lsp-trace.txt

    how do you use nil with lsp4ij ? With user defined ls or with an IJ plugin?

    I have it user defined.

    If it is the first, do you want to contribute to LSP4IJ with nil as user defined ls?

    All that's needed is assigning nil to *.nix, default config works fine. So I'm not sure that there's much value in that? And I imagine most Nix users wouldn't want an auto installer.

    Take a sample with astro https://github.com/redhat-developer/lsp4ij/blob/main/docs/user-defined-ls/astro-ls.md#step-1-install-the-language-server

    As you can see you need just to create the file and you will have editor notifictation which promote intall of the language server.

    I think it could be very nice to have that for nix. If you contribute with templates like https://github.com/redhat-developer/lsp4ij/tree/main/src/main/resources/templates/lsp/astro-ls you will benefit with this feature.

    If you want to do that, please read https://github.com/redhat-developer/lsp4ij/blob/main/docs/UserDefinedLanguageServerTemplate.md#how-to-contribute-a-user-defined-language-server-template

  21. js6pak commented on Aug 10, 2025

    @js6pak
    Author

    once will be finished redhat-developer/lsp4ij/actions/runs/16858552411 please try again nighty and tell me if it fixes your issue

    It works fine now! Thanks!

    I think it could be very nice to have that for nix

    There is no official nix lsp. There are currently 2 options, nil and nixd. With the main difference being that nixd uses official nix libraries directly to provide proper auto completion, but at least in my experience, nil is still better in terms of code editing. Would the editor notification support promoting two LSPs?

    Also do note that there is an official(I think?) nix intellij plugin (https://github.com/NixOS/nix-idea), but compared to either nil or nixd, it's pretty useless... It also provides LSP support via the IJ Ultimate LSP api (as you know, considering you commented under NixOS/nix-idea#68), but honestly, this project works so much better <3

  22. angelozerr commented on Aug 11, 2025

    @angelozerr
    Contributor

    once will be finished redhat-developer/lsp4ij/actions/runs/16858552411 please try again nighty and tell me if it fixes your issue

    It works fine now! Thanks!

    You are welcome!

    I think it could be very nice to have that for nix

    There is no official nix lsp. There are currently 2 options, nil and nixd. With the main difference being that nixd uses official nix libraries directly to provide proper auto completion, but at least in my experience, nil is still better in terms of code editing. Would the editor notification support promoting two LSPs?

    Also do note that there is an official(I think?) nix intellij plugin (https://github.com/NixOS/nix-idea), but compared to either nil or nixd, it's pretty useless... It also provides LSP support via the IJ Ultimate LSP api (as you know, considering you commented under NixOS/nix-idea#68), but honestly, this project works so much better <3

    Thanks for your explanation. I think we can start with an user defined ls with nil. If you could be intersted to contribute with nil, I suggest that you use as sample
    https://github.com/redhat-developer/lsp4ij/tree/main/src/main/resources/templates/lsp/gopls and use https://github.com/redhat-developer/lsp4ij/blob/main/src/main/resources/templates/lsp/gopls/installer.json to describe the install of nil (ex: check if nix is installed)

    Do you think you could be interested to do that?

  23. added a commit that references this issue on Aug 11, 2025
    e7b5126
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

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions