0

I am currently implementing the new Events for file operations in my language server, which have been introduced in LSP protocol version 3.16. My server shall be able to react on didRename, didDelete etc., but so far I am unable to get these notifications from VSCode.

First of all, in my server's capabilities, I list the file operations, to tell the client that I am interested in these events:

"capabilities": {
            ...
            "workspace": {
                "fileOperations": {
                    "didDelete": {
                        "filters": [
                            {
                                "pattern": {
                                    "glob": "**​/*.{rs,rd}"
                                }
                            }
                        ]
                    },
                    "didRename": {
                        "filters": [
                            {
                                "pattern": {
                                    "glob": "**​/*.{rs,rd}"
                                }
                            }
                        ]
                    }
                }
            }
        }

Additionally, after initialization has been completed, the server sends a registerCapability request to the client, which gets confirmed by VSCode. I register these capabilities separately, because within the init message, VSCode says that dynamicRegistration for file operations shall be used.

{
    "id": "register_caps",
    "jsonrpc": "2.0",
    "method": "client/registerCapability",
    "params": {
        "registrations": [
            {
                "id": "dhjas88-asdhjkahsd89as-dhas89",
                "method": "workspace/didRenameFiles",
                "registerOptions": {
                    "filters": [
                        {
                            "pattern": {
                                "glob": "**​/*.{rs,rd}"
                            }
                        }
                    ]
                }
            },
            {
                "id": "dhjas88-asdhjkahsd89as-dhas90",
                "method": "workspace/didDeleteFiles",
                "registerOptions": {
                    "filters": [
                        {
                            "pattern": {
                                "glob": "**​/*.{rs,rd}"
                            }
                        }
                    ]
                }
            }
        ]
    }
}

Confirmation:

{"jsonrpc":"2.0","id":"register_caps","result":null}

According to the specification of LSP, I would now expect that VSCode sends the e.g. didRename notification, as soon as a file that matches with the glob is renamed within VSCode. Unfortunately, I never receive it. The notification is not sent by VSCode.

Any ideas or clues, what is still missing here? Which part of the protocol did I miss, which prevents VSCode to send the file operation notifications?

sscit
  • 1
  • 1

1 Answers1

0

Were you able to find your issue?

I was in the same situation, and I found a few gotches wrt server notifications

  • VS Code allowes to define synchronize options in the extension. When those are set, some of the notifications cannot be registered via LSP... Removing those helped.
  • Make sure not to miss the **/ at the beginning of glob patterns or they will not match
  • There is no need to dynamically register didRename etc. if already registered statically, but if you do, make sure to send your register after you received the initialized event and not before.
  • I used multiple patterns - one for each extension - instead of braces.

Still I am not sure what exactly you are/were doing wrong...

mihi
  • 6,507
  • 1
  • 38
  • 48