neoclide / coc-solargraph

Solargraph extension for coc.nvim
202 stars 10 forks source link

CocAction('format') not respecting by rubocop.yml file — where can I update the setting? #54

Closed thornomad closed 3 years ago

thornomad commented 3 years ago

Hello! Thanks so much for this extension! This may be a question more than a problem: I am trying to understand where CocAction('format') is sourcing the formatting rules (because it seems to source them differently than when it is displaying errors).

In my project .rubocop.yml file I have:

Style/StringLiterals:
  Enabled: true
  EnforcedStyle: double_quotes

Inside of neovim, it is correctly sourcing this file and showing errors for single quotes. For example:

image

This all looks perfect! And in the past, calling :call CocAction('format') would fix all those errors and convert single to double quotes.

However, quite recently (not sure what triggered it) this no longer works. It will not change the single quotes to double quotes. What's more, is if I do have double quotes and :call CocAction('format') it is actually converting my double quotes to single quotes! There are other rules I have defined in .rubocop.yml that are also not being respected.

It seems like the call to format is not sourcing the same rules that are being displayed ... but I cannot figure out where it is looking for them.

Thanks so much.

coc solargraph settings

{
  "solargraph.diagnostics": true,
  "solargraph.formatting": true,
  "solargraph.logLevel": "debug",
  "solargraph.useBundler": false,
  "solargraph.checkGemVersion": true,
}
chemzqm commented 3 years ago

Should be problem of your language server, checkout https://github.com/neoclide/coc.nvim/wiki/Debug-language-server#using-output-channel

thornomad commented 3 years ago

Hello @chemzqm — thank you for getting back to me so quickly. Here is (I think) relevant input.

You said:

Should be a problem of your language server

Do you mean that the problem is with the solargraph gem and not the this vim plugin? If so, I can open the issue there instead.

**PS: I noticed if I move my .rubocop.yml file to my root $HOME folder the problem is resolved. It seems that on formatting it is not sourcing my .rubocop.yml file but when it is doing diagnostics it is.

valid file no errors

[Trace - 12:48:50 PM] Sending notification 'textDocument/didOpen'.
Params: {
    "textDocument": {
        "uri": "file:///Users/damon/Linguabee/octoo-api-v3/test.rb",
        "languageId": "ruby",
        "version": 1,
        "text": "# frozen_string_literal: true\n\nrequire \"rails_helper\"\n"
    }
}

[Trace - 12:48:52 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
    "uri": "file:///Users/damon/Linguabee/octoo-api-v3/test.rb",
    "diagnostics": []
}

run coc action

[Trace - 12:49:46 PM] Sending request 'textDocument/formatting - (1)'.
Params: {
    "textDocument": {
        "uri": "file:///Users/damon/Linguabee/octoo-api-v3/test.rb"
    },
    "options": {
        "tabSize": 2,
        "insertSpaces": true
    }
}

[Trace - 12:49:46 PM] Received response 'textDocument/formatting - (1)' in 87ms.
Result: [
    {
        "range": {
            "start": {
                "line": 0,
                "character": 0
            },
            "end": {
                "line": 3,
                "character": 0
            }
        },
        "newText": "# frozen_string_literal: true\n\nrequire 'rails_helper'\n"
    }
]

get notification that it is invalid

[Trace - 12:49:46 PM] Sending notification 'textDocument/didChange'.
Params: {
    "textDocument": {
        "version": 2,
        "uri": "file:///Users/damon/Linguabee/octoo-api-v3/test.rb"
    },
    "contentChanges": [
        {
            "range": {
                "start": {
                    "line": 2,
                    "character": 8
                },
                "end": {
                    "line": 2,
                    "character": 22
                }
            },
            "rangeLength": 14,
            "text": "'rails_helper'"
        }
    ]
}

[Trace - 12:49:46 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
    "uri": "file:///Users/damon/Linguabee/octoo-api-v3/test.rb",
    "diagnostics": [
        {
            "range": {
                "start": {
                    "line": 2,
                    "character": 8
                },
                "end": {
                    "line": 2,
                    "character": 22
                }
            },
            "severity": 3,
            "source": "Style/StringLiterals",
            "message": " Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping."
        }
    ]
}
khiet commented 3 years ago

Hi, I'm having the exact behaviour @thornomad is detailing. For formatting, it only respects .rubocop.ymlwhen it is put in $HOME.

chemzqm commented 3 years ago

.rubocop.yml is loaded by solargraph, not this extenison.

ubmit commented 3 years ago

I'm having the same behaviour. Did you find a workaround besides placing the .rubocop.yml in $HOME? This isn't a good solution, because I have different projects with their own .rubocop.yml file.

thornomad commented 3 years ago

See: https://github.com/castwide/solargraph/issues/406