VSCode Python 智能感知无法正常工作

VSCode Python Intellisense Not Working Properly

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

这是我的系统:

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

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

当我按下 enter 键时,我的代码完全变笨了。这只是一个例子,一直让我很沮丧!

下面是我的 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" 有帮助,但我仍然遇到错误:

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

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

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