fannheyward / coc-deno

Deno extension for coc.nvim
MIT License
151 stars 9 forks source link

Formatter doesn't work #241

Closed englut closed 7 months ago

englut commented 7 months ago

I'm trying to get coc-deno working in my deno project. The linter seems to work fine after I initialize the project, but the formatter doesn't seem to work.

When I run CocAction("format"), nothing seems to happen in my deno project. Is there something I'm doing wrong?

I've initialized the workspace with enable linting, enable unstable APIs and disable coc-prettier.

fannheyward commented 7 months ago

Can't reproduce, the formatting is working as expected.

  1. Set "deno.trace.server": "verbose" in your global coc-settings.json
  2. open your Deno files, and call CocAction("format")
  3. open :CocCommand workspace.showOutput deno
  4. search textDocument/formatting, any logs?
englut commented 7 months ago
4. search `textDocument/formatting`, any logs?

Here's what shows up in my :CocCommand workspace.showOutput deno

[Trace - 09:40:04.540] Sending request 'textDocument/formatting - (1)'.
Params: {
    "textDocument": {
        "uri": "file:///<redacted>/deno/main.ts"
    },
    "options": {
        "tabSize": 2,
        "insertSpaces": true,
        "insertFinalNewline": false
    }
}

[Trace - 09:40:04.540] Received response 'textDocument/formatting - (1)' in 0ms.
No result returned.

@fannheyward The project is set up with deno init so it's pretty boiler plate. It might be something with my neovim setup. But I'm not sure where to look. Any ideas on where I can dig would be greatly appreciated 🙏

My workspace .vim/coc-settings.json shows this:

{
  "deno.enable": true,
  "deno.lint": true,
  "deno.unstable": true,
  "prettier.enable": false,
  "tsserver.enable": false
}
fannheyward commented 7 months ago

The sending request means coc.nvim/coc-deno works as expected after format action. There's no response means current document doesn't need to format.

  1. made some unformatted content in main.ts, save with :noa w, this won't trigger formatting on save
  2. call CocAction("format")
  3. check response from the logs
englut commented 7 months ago

@fannheyward

1. made some unformatted content in main.ts, save with `:noa w`, this won't trigger formatting on save

2. `call CocAction("format")`

3. check response from the logs

I did the same. Still nothing.

There's no response means current document doesn't need to format.

Running deno fmt on the file actually does fix the format issues. But call CocAction("format") does not.

fannheyward commented 7 months ago

Have no idea about this, the trace logs shows client(coc.nvim+coc-deno) sends formatting request to deno server, the server returns empty response, client can do nothing.

I did a quick test:

  1. deno init a project
  2. open the main.ts, made some unformatted, then :call CocAction('format')
[Trace - 09:08:02.325] Sending request 'textDocument/formatting - (9)'.
Params: {
    "textDocument": {
        "uri": "file:///Users/fannheyward/src/hello-deno/main.ts"
    },
    "options": {
        "tabSize": 2,
        "insertSpaces": true,
        "insertFinalNewline": true
    }
}

[Trace - 09:08:02.329] Received response 'textDocument/formatting - (9)' in 4ms.
Result: [
    {
        "range": {
            "start": {
                "line": 6,
                "character": 0
            },
            "end": {
                "line": 6,
                "character": 9
            }
        },
        "newText": ""
    }
]
englut commented 7 months ago

@fannheyward thanks for your help! I really appreciate it. Turns out it was just bad copy and paste of the official documentation for format rules.

https://docs.deno.com/runtime/manual/getting_started/configuration_file#fmt

{
  "fmt": {
...
    "include": ["src/"], <--- the folder here is why
    "exclude": ["src/testdata/", "src/fixtures/**/*.ts"]
  }
}

My bad!! Thanks again!