Lsp-mode: mccabe configuration is not respected

Created on 16 Mar 2019  路  5Comments  路  Source: emacs-lsp/lsp-mode

Describe the bug
Changing settings in lsp-clients-python-settings does not affect the operation of mccabe.

To Reproduce
Open any Python file which has a function whose cyclomatic complexity is greater than 15. Here is an example:


Click to expand code

def complex_function():
    if True:
        if True:
            if True:
                if True:
                    pass
                else:
                    pass
            else:
                if True:
                    pass
                else:
                    pass
        else:
            if True:
                if True:
                    pass
                else:
                    pass
            else:
                if True:
                    pass
                else:
                    pass
    else:
        if True:
            if True:
                if True:
                    pass
                else:
                    pass
            else:
                if True:
                    pass
                else:
                    pass
        else:
            if True:
                if True:
                    pass
                else:
                    pass
            else:
                if True:
                    pass
                else:
                    pass

Set up lsp-mode with pyls and enable lsp-ui with Flycheck.

Expected behavior
No error should be reported as :plugins.mccabe.enabled is set to nil in lsp-clients-python-settings.

Actual behavior
I see an error mccabe: Cyclomatic complexity too high: 16 (threshold 15) in the sideline from lsp-ui-sideline. Furthermore, if I change :plugins.mccabe.threshold in lsp-clients-python-settings from its default of 15 to, say, 50 and then run M-x lsp-restart-workspace, I see no difference at all鈥攖he threshold is still reported as 15. Clearly, the configuration in lsp-clients-python-settings is not being respected by the LSP server.

Which Language Server did you use
lsp-python

OS
macOS 10.14.3

Logging

>>> pyls:36303(async)
Content-Length: 793

{
  "jsonrpc": "2.0",
  "method": "textDocument/codeAction",
  "params": {
    "textDocument": {
      "uri": "file:///Users/raxod502/files/code/web/hyperschedule-scraper/libportal.py"
    },
    "range": {
      "start": {
        "line": 174,
        "character": 0
      },
      "end": {
        "line": 174,
        "character": 7
      }
    },
    "context": {
      "diagnostics": [
        {
          "severity": 2,
          "message": "Cyclomatic complexity too high: 35 (threshold 15)",
          "range": {
            "end": {
              "character": 8,
              "line": 174
            },
            "start": {
              "character": 0,
              "line": 174
            }
          },
          "source": "mccabe"
        }
      ]
    }
  },
  "id": 11774
}

Most helpful comment

I am going to implement - https://github.com/emacs-lsp/lsp-mode/issues/715#issuecomment-473503166 . Apparently, in order to make our life easier, we should have a similar to vscodes mechanism for defining extension properties.

All 5 comments

Apparently, the proper way to do that is

(setq lsp-clients-python-settings '(:plugins (:mccabe (:threshold 17 :enabled t))))

And the default configuration is wrong... Are you interested in helping to fix that?

(cc @cslux)

Here it is a link to the lsp-java https://github.com/emacs-lsp/lsp-java/blob/master/lsp-java.el#L231 . We probably need to define a macro which simplifies that job, something like:

(lsp-defcustom pyls.plugins.jedi_completion.enabled server-id default-value "description" [type])

@yyoncho I can give it a shot!

I did not notice it the last time, because I customized mccab, etc.. through setup.cfg and tox.ini.

@cslux sure, go ahead.

I am going to implement - https://github.com/emacs-lsp/lsp-mode/issues/715#issuecomment-473503166 . Apparently, in order to make our life easier, we should have a similar to vscodes mechanism for defining extension properties.

Was this page helpful?
0 / 5 - 0 ratings