Skip to content

Return key does not trigger Language Server onTypeFormatting request (no end completion) #72

@andyw8

Description

@andyw8

Ruby LSP has a feature to automatically add ends, e.g. after def method_name. It uses the textDocument/onTypeFormatting language server request.

In Zed, this doesn't work. I suspect this is a bug in Zed rather than the extension, but I'm logging it here first until I learn more.

Example (comparing with VS Code)

In Ruby LSP with VS Code, enable verbose logging.

You'll also need to enable "editor.formatOnType": true since it's disabled by default.

Now type the following:

def foo

The logs will show a request:

Sending request 'textDocument/onTypeFormatting - (41)'.
{
    "textDocument": { "uri": "file:///Users/andy/src/github.com/Shopify/ruby-lsp/x.rb" },
    "position": { "line": 3, "character": 1 },
    "ch": "d",
    "options": { "tabSize": 2, "insertSpaces": true }
}

and an empty response

Received response 'textDocument/onTypeFormatting - (41)' in 1ms.

Now press return and you'll see a second request:

Sending request 'textDocument/onTypeFormatting - (48)'.
{
    "textDocument": { "uri": "file:///Users/andy/src/github.com/Shopify/ruby-lsp/x.rb" },
    "position": { "line": 4, "character": 2 },
    "ch": "\n",
    "options": {
        "tabSize": 2,
        "insertSpaces": true
    }
}

and a response, which causes an end to be added:

[
    {
        "range": {
            "start": { "line": 4, "character": 2 },
            "end": { "line": 4, "character": 2 }
        },
        "newText": "\n"
    },
    {
        "range": {
            "start": { "line": 4, "character": 2 },
            "end": { "line": 4, "character": 2 }
        },
        "newText": "end"
    },
    {
        "range": {
            "start": {  "line": 4, "character": 2 },
            "end": { "line": 4, "character": 2 }
        },
        "newText": "$0"
    }
]

In Zed, we see the first request:

// Send:
{"jsonrpc":"2.0","id":39,"method":"textDocument/onTypeFormatting",
"params":{"textDocument":{"uri":"file:///Users/andy/src/github.com/Shopify/ruby-lsp/x.rb"},"position":{"line":0,"character":1},
"ch":"d",
"options":{"tabSize":2,"insertSpaces":true,"trimTrailingWhitespace":true,"insertFinalNewline":true,"trimFinalNewlines":true}}}

// Receive:
{"id":39,"result":[],"jsonrpc":"2.0"}

but after pressing return, there is no second request.

#38 may be related.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions