Code actions not working with Deno LSP - documentChanges support needed?

Hello there! Working on a Deno extension, and having an odd issue with code actions.

Nova is picking up on Deno’s code actions, but nothing happens if you select any of them.

I’m not really sure how to diagnose this. Is there a way I can log all the requests and notifications that Nova receives from a LSP, so that I could begin to determine if the workspace/applyEdit request is coming in the expected format?

Is there some kind of extra logging I can enable within Nova when it can’t process LSP requests?

Added some logging, and was able to get the response from the LSP after selecting the code action:

{
  "jsonrpc":"2.0",
  "result":[
    {
      "title":"Import 'openFile' from module \"./nova_utils.ts\"",
      "kind":"quickfix",
      "diagnostics":[
        {
          "range":{
            "start":{
              "line":14,
              "character":2
            },
            "end":{
              "line":14,
              "character":10
            }
          },
          "severity":1,
          "code":2304,
          "source":"deno-ts",
          "message":"Cannot find name 'openFile'."
        }
      ],
      "edit":{
        "documentChanges":[
          {
            "textDocument":{
              "uri":"file:///Volumes/Macintosh%20HD/Users/gwil/Projects/nova-deno/src/nova_deno.ts",
              "version":1334
            },
            "edits":[
              {
                "range":{
                  "start":{
                    "line":5,
                    "character":0
                  },
                  "end":{
                    "line":5,
                    "character":0
                  }
                },
                "newText":"import { openFile } from \"./nova_utils.ts\";\n"
              }
            ]
          }
        ]
      }
    },
    {
      "title":"Add missing function declaration 'openFile'",
      "kind":"quickfix",
      "diagnostics":[
        {
          "range":{
            "start":{
              "line":14,
              "character":2
            },
            "end":{
              "line":14,
              "character":10
            }
          },
          "severity":1,
          "code":2304,
          "source":"deno-ts",
          "message":"Cannot find name 'openFile'."
        }
      ],
      "edit":{
        "documentChanges":[
          {
            "textDocument":{
              "uri":"file:///Volumes/Macintosh%20HD/Users/gwil/Projects/nova-deno/src/nova_deno.ts",
              "version":1334
            },
            "edits":[
              {
                "range":{
                  "start":{
                    "line":194,
                    "character":0
                  },
                  "end":{
                    "line":194,
                    "character":0
                  }
                },
                "newText":"\nfunction openFile() {\nthrow new Error(\"Function not implemented.\");\n}\n"
              }
            ]
          }
        ]
      }
    }
  ],
  "id":190
}

This seems to include two conflicting fixes: one for adding a suggested import, one for adding an empty function declaration. But maybe that’s okay? Will keep digging but would love someone with insight into how code actions are resolved to take a look.

Could this be because LanguageClient doesn’t support documentChanges?

I had a look yesterday with the Deno extension I started on a while ago, it looks like you came to the same conclusion - Code Actions don't do anything · Issue #5 · robb-j/nova-deno · GitHub. I got similar looking LSP messages in there too.

1 Like

I’m noticing the same problem in my Deno extension, none of the quickfix and refactor code actions do anything:

Don’t know if this needs to be said, but this issue isn’t confined to the Deno language server. Rust Analyzer also only provides documentChanges, and Code Actions are failing to execute. It’s a real shame, as RA has some incredibly handy Code Actions.

This is starting to drive me crazy (and back to Sublime).

@logan If Nova doesn’t support documentChanges in WorkspaceEdits, then it should be setting WorkspaceEditClientCapabilities.documentChanges to false (docs) if my reading of the spec is correct.

From WorkspaceEdit link above:

If a client doesn’t support documentChanges or workspace.workspaceEdit.resourceOperations, then only plain TextEdits using the changes property are supported.

Currently, Nova sets this capability to true in its initialize message to language servers (2nd to last setting pasted below):

{
  "jsonrpc": "2.0",
  "id": 0,
  "method": "initialize",
  "params": {
    "capabilities": {
      "workspace": {
        "configuration": true,
        "applyEdit": true,
        "didChangeConfiguration": {},
        "executeCommand": {},
        "workspaceFolders": true,
        "workspaceEdit": {
          "failureHandling": "undo",
          "documentChanges": true,
          "resourceOperations": ["create", "rename", "delete"]
        }
      },
      ...
    }
  }
}
3 Likes

Nova 9 beta 5:

Wait for it…

:astonished::grinning:

yaaas

2 Likes

:smiling_face_with_tear::smiling_face_with_tear::smiling_face_with_tear: My wrists rejoice

Nova 9 is out and this is fixed!

1 Like