Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

self.settings().get("plugins", {}).get(name, {}).get("enabled", True) throws AttributeError: 'list' object has no attribute 'get' #568

Open
mcepl opened this issue Jun 6, 2024 · 1 comment

Comments

@mcepl
Copy link

mcepl commented Jun 6, 2024

Using vis with vis-lspc plugin, this LSP server from the openSUSE package python311-python-lsp-server-1.11.0 (based on https://files.pythonhosted.org/packages/source/p/python-lsp-server/python-lsp-server-1.11.0.tar.gz) and with this configuration:

lsp = require('plugins/vis-lspc')
lsp.logging = true
lsp.log_file = '/tmp/vis-lspc-log.txt'
lsp.highlight_diagnostics = true

lsp.ls_map['python'] = {
    name = 'python-lsp-server',
    cmd = 'pylsp',
    settings = {
      pylsp = {
        plugins = {
          rope_completion = {"eager"},
          rope_rename = {
              enabled = true
          },
          pylsp_rope = {
              enabled = true
          },
        },
      },
    },
}

This JSON call:

{
  "method": "textDocument\\/didOpen",
  "params": {
    "textDocument": {
      "uri": "file:\\/\\/\\/home\\/matej\\/build\\/devel:languages:python\\/python-fanficfare\\/FanFicFare-4.33.0\\/version_update.py",
      "version": 0,
      "languageId": "python",
      "text": "# -*- coding: utf-8 -*-\n\n# Copyright 2018, Jim Miller\n\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n\n#   http:\\/\\/www.apache.org\\/licenses\\/LICENSE-2.0\n\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport codecs, sys, re\n\nfrom tempfile import mkstemp\nfrom os import rename, close, unlink\n\n#print(sys.argv[1:])\n\n## Files that contain version numbers that will need to be updated.\nversion_files = [\n    # 'version_test.sml',\n    # 'version_test.txt',\n    # 'setup.py',\n    'pyproject.toml',\n    'calibre-plugin\\/__init__.py',\n    # 'webservice\\/app.yaml',\n    'fanficfare\\/cli.py',\n    ]\n\n## save version from this file for index.html link.\n# save_file='version_test.txt'\nsave_file='webservice\\/app.yaml'\nsaved_version = None\n\ndef main(args):\n   ## major minor micro\n    '''\n__version__ = (2, 3, 6)\n    version=\"2.3.6\",\nversion: 2-3-06a\nversion=\"2.3.6\"\n'''\n    version_re = \\\n        r'^(?P<prefix>[ ]*(__)?)version(?P<infix>(__)?[ =:\"\\\\(]+)' \\\n        r'(?P<major>[0-9]+)(?P<dot1>[, \\\\.-]+)' \\\n        r'(?P<minor>[0-9]+)(?P<dot2>[, \\\\.-]+)' \\\n        r'(?P<micro>[0-9]+[a-z]?)(?P<suffix>[\",\\\\)]*\r?\n)$'\n\n    flag = args[0]\n\n    if len(args) > 1 :\n        version = [int(x) for x in args[1:]]\n    else:\n        with codecs.open(version_files[0], 'r', 'utf-8') as source_file:\n            for line in source_file:\n                m = re.match(version_re,line)\n                if m:\n                    prior_version = (m.group('major'),m.group('minor'),m.group('micro'))\n                    print(prior_version)\n                    break\n        version = [int(x) for x in prior_version]\n        if flag == 'test':\n            version[2] += 1\n        if flag == 'release':\n            version[1] += 1\n            version[2] = 0\n\n    print(version)\n    version_subs = r'\\g<prefix>version\\g<infix>%s\\g<dot1>%s\\g<dot2>%s\\g<suffix>' % tuple(version)\n\n    do_loop(version_files, version_re, version_subs)\n\n    index_files = []\n    # index_files = ['webservice\\/index.html']\n    # if saved_version:\n    #     ## only do major\\/minor, always leave micro 0 in index.html.\n    #     index_re = 'https:\\/\\/([0-9-]+[a-z]?)\\\\.fanficfare\\\\.appspot\\\\.com'\n    #     index_subs = 'https:\\/\\/%s-%s-0.fanficfare.appspot.com'%saved_version[0:2]\n    #     do_loop(index_files, index_re, index_subs)\n\n    release = flag.capitalize()\n    print('\ngit add %s'%(\" \".join(version_files+index_files)))\n    print('git commit -m \"Bump %s Version %s\"'%(release,'.'.join([str(x) for x in version])))\n\ndef do_loop(files, pattern, substring):\n    global saved_version\n    for source_file_path in files:\n        print(\"src:\"+source_file_path)\n        fh, target_file_path = mkstemp()\n        with codecs.open(target_file_path, 'w', 'utf-8') as target_file:\n            with codecs.open(source_file_path, 'r', 'utf-8') as source_file:\n                for line in source_file:\n                    repline = re.sub(pattern, substring, line)\n                    if line != repline and source_file_path == save_file:\n                        m = re.match(pattern,line)\n                        saved_version = (m.group('major'),m.group('minor'),m.group('micro'))\n                        print(\"<-%s->%s\"%(line,repline))\n                    target_file.write(repline)\n        close(fh)\n        unlink(source_file_path)\n        rename(target_file_path,source_file_path)\n\nif __name__ == '__main__':\n    args = list(sys.argv[1:])\n\n    if len(args) == 0:\n        args.append('test')\n    if args[0] in ('test', 'release') and len(args) in (1,4):\n        main(args)\n    else:\n        print(\"args: (test|release) [1 2 3]\")\n#    print(saved_version)\n"
    }
  },
  "jsonrpc": "2.0"
}

produces this response:

python-lsp-server response(STDERR): 2024-06-06 08:06:43,238 CEST - ERROR - pylsp_jsonrpc.end
point - Failed to handle notification workspace/didChangeConfiguration: {'settings': {'pylsp
': {'plugins': {'pylsp_rope': {'enabled': True}, 'rope_completion': ['eager'], 'rope_rename'
: {'enabled': True}}}}}

and this lovely traceback:

Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/pylsp_jsonrpc/endpoint.py", line 146, in _handle_n
otification
    handler_result = handler(params)
                     ^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pylsp_jsonrpc/dispatchers.py", line 25, in handler

    return method(**(params or {}))
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pylsp/python_lsp.py", line 799, in m_workspace__di
d_change_configuration
    self.config.update((settings or {}).get("pylsp", {}))
  File "/usr/lib/python3.11/site-packages/pylsp/config/config.py", line 193, in update
    self._update_disabled_plugins()
  File "/usr/lib/python3.11/site-packages/pylsp/config/config.py", line 197, in _update_disa
bled_plugins
    self._disabled_plugins = [
                             ^
  File "/usr/lib/python3.11/site-packages/pylsp/config/config.py", line 200, in <listcomp>
    if not self.settings().get("plugins", {}).get(name, {}).get("enabled", True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'list' object has no attribute 'get'

Installed packages:

~ $ rpm -qa python\*lsp\*
python311-python-lsp-jsonrpc-1.1.2-2.5.noarch
python311-lsprotocol-2023.0.1-1.3.noarch
python311-python-lsp-server-1.11.0-1.1.noarch
python311-pylsp-rope-0.1.16-1.2.noarch
~ $ 
@ccordoba12
Copy link
Member

Hey @mcepl, thanks for reporting. This doesn't seem to be an error in the server but in the configuration you're sending to it. At least that's what this part would seem to imply:

point - Failed to handle notification workspace/didChangeConfiguration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants