2

VSCode 中的 Python 自动完成功能弄乱了我的代码

智能感知问题

这是我的系统:

在此处输入图像描述

如果我使用Pylance,Intellisense 无法正常工作

皮兰斯

如果我使用Jedi,Intellisense 无法正常工作

绝地

当我按下回车键时,我的代码完全失效了。这只是一个例子,让我很沮丧!

下面是我的settings.json文件:

{
    "AREPL.pythonPath": "${workspaceFolder}\\.venv\\Scripts\\python.exe",
    "dicom.alwaysShowMenu": true,
    "editor.codeActionsOnSave": {
        "source.organizeImports": true
    },
    "editor.formatOnSave": true,
    "editor.insertSpaces": false,
    "editor.rulers": [
        90
    ],
    "editor.suggestSelection": "first",
    "explorer.compactFolders": false,
    "explorer.confirmDragAndDrop": false,
    "files.exclude": {
        "**/.git": false
    },
    "files.trimFinalNewlines": true,
    "files.trimTrailingWhitespace": true,
    "git-graph.defaultColumnVisibility": {
        "Author": false,
        "Commit": true,
        "Date": false
    },
    "git-graph.referenceLabels.alignment": "Branches (aligned to the graph) & Tags (on the right)",
    "glassit.alpha": 255,
    "json.format.enable": true,
    "mypy.dmypyExecutable": "${workspaceFolder}\\.venv\\Scripts\\dmypy.exe",
    "mypy.runUsingActiveInterpreter": true,
    "notebook.cellToolbarLocation": {
        "default": "right",
        "jupyter-notebook": "left"
    },
    "python.defaultInterpreterPath": "${workspaceFolder}\\.venv\\Scripts\\python.exe",
    "python.formatting.blackArgs": [
        "--line-length",
        "90"
    ],
    "python.formatting.provider": "black",
    "python.languageServer": "Jedi",
    "python.linting.enabled": true,
    // "python.linting.flake8Args": [
    //     "--line-length",
    //     "90"
    // ],
    "python.linting.mypyEnabled": true,
    "python.linting.mypyPath": "${workspaceFolder}\\.venv\\Scripts\\mypy.exe",
    // "python.linting.pylintArgs": [
    //     "--generate-members"
    // ],
    // "python.linting.pylintEnabled": true,
    "python.pythonPath": "${workspaceFolder}\\.venv\\Scripts\\python.exe",
    "python.terminal.activateEnvironment": true,
    "python.testing.pytestArgs": [
        "${workspaceFolder}\\tests"
    ],
    "python.testing.pytestEnabled": true,
    "python.testing.unittestEnabled": true,
    "python.venvPath": ".venv",
    "restructuredtext.builtDocumentationPath": "${workspaceFolder}\\docs\\build\\html",
    "restructuredtext.confPath": "{workspaceFolder}\\docs\\source",
    "restructuredtext.languageserver.disabled": true,
    "restructuredtext.sphinxBuildPath": "${workspaceFolder}\\.venv\\Scripts\\sphinx-build.exe",
    "screencastMode.keyboardOverlayTimeout": 1500,
    "screencastMode.mouseIndicatorSize": 20,
    "screencastMode.onlyKeyboardShortcuts": true,
    "screencastMode.verticalOffset": 0,
    "security.workspace.trust.untrustedFiles": "open",
    "shellcheck.customargs": [
        "-x"
    ],
    "terminal.integrated.defaultProfile.windows": "PowerShell",
    "terminal.integrated.fontFamily": "CaskaydiaCove Nerd Font Mono",
    "terminal.integrated.tabs.enabled": true,
    "trailing-spaces.syntaxIgnore": [
        "markdown"
    ],
    "update.enableWindowsBackgroundUpdates": false,
    "vsicons.dontShowNewVersionMessage": true,
    "workbench.colorTheme": "Predawn",
    "workbench.editor.enablePreview": true,
    "workbench.editorAssociations": {
        "*.dcm": "default",
        "*.ipynb": "jupyter-notebook",
        "*.tiff": "tiff.preview",
        "git-rebase-todo": "default"
    },
    "workbench.iconTheme": "material-icon-theme",
    "workbench.settings.editor": "json",
    "workbench.settings.openDefaultSettings": true,
    "workbench.settings.useSplitJSON": true,
    "workbench.startupEditor": "newUntitledFile"
}

为什么会发生这种情况,我该如何修复我的 Intellisense?

更新:

删除"editor.suggestSelection": "first"有帮助,但我仍然收到错误:

新问题

4

1 回答 1

0

将以下内容添加到我的settings.json使 Intellisense 按预期工作:

"editor.acceptSuggestionOnEnter": "off",
"editor.tabCompletion": "on"

解决

为什么默认值分别是"on""off",我永远不会知道。tab如果您想使用该建议(例如 in ),每个人都希望按下bash terminal,并且没有人希望自动完成在按 Enter 时盲目完成。

于 2021-09-01T19:29:08.183 回答