VS Code Python, entry in Run&Debug not present in launch.json

huangapple go评论57阅读模式
英文:

VS Code Python, entry in Run&Debug not present in launch.json

问题

I just started using VS Code to develop in Python, I have the official Python extension installed, and I'm trying to configure the Run & Debug menu.

In one of my workspaces, I created the following launch.json file, with THREE configurations (test.py, preview.py, and Project Tests):

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "test.py",
            "type": "python",
            "request": "launch",
            "program": "./test.py",
            "cwd": "${workspaceFolder}",
            "console": "integratedTerminal",
            "justMyCode": true,
            "variablePresentation": {
                "all": "inline",
                "class": "group",
                "function": "hide",
                "special": "hide"
            }
        },
        {
            "name": "preview.py",
            "type": "python",
            "request": "launch",
            "program": "./preview.py",
            "cwd": "${workspaceFolder}",
            "console": "integratedTerminal",
            "justMyCode": true,
            "variablePresentation": {
                "all": "inline",
                "class": "group",
                "function": "hide",
                "special": "hide"
            }
        },
        {
            "name": "Project Tests",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "cwd": "some_folder",
            "console": "integratedTerminal",
            "justMyCode": true,
            "variablePresentation": {
                "all": "inline",
                "class": "group",
                "function": "hide",
                "special": "hide"
            }
        }
    ]
}

However, in the Run & Debug menu, I see FOUR entries..."test.py", "preview.py", and "Project Tests", the ones I configured in launch.json, and "Python: File", which is applied to the currently open file in the IDE.

I was assuming this "Python: File" might be some default option which is always present, but then I have another workspace where I created launch.json with only one entry (process.py):

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "process.py",
            "type": "python",
            "request": "launch",
            "program": "./process.py",
            "cwd": "${workspaceFolder}",
            "console": "integratedTerminal",
            "justMyCode": true,
            "variablePresentation": {
                "all": "inline",
                "class": "group",
                "function": "hide",
                "special": "hide"
            }
        }   
    ]
}

And here I only have the corresponding entry in the menu as well.

I tried deleting and recreating the launch.json file in the first workspace, but the result is always the same. How does this work precisely?

英文:

I just started using VS Code to develop in Python, I have the official Python extension installed, and I'm trying to configure the Run&Debug menu.

In one of my workspaces, I created the following launch.json file, with THREE configurations (test.py, preview.py and Project Tests):

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "test.py",
            "type": "python",
            "request": "launch",
            "program": "./test.py",
            "cwd": "${workspaceFolder}",
            "console": "integratedTerminal",
            "justMyCode": true,
            "variablePresentation": {
                "all": "inline",
                "class": "group",
                "function": "hide",
                "special": "hide"
            }
        },
        {
            "name": "preview.py",
            "type": "python",
            "request": "launch",
            "program": "./preview.py",
            "cwd": "${workspaceFolder}",
            "console": "integratedTerminal",
            "justMyCode": true,
            "variablePresentation": {
                "all": "inline",
                "class": "group",
                "function": "hide",
                "special": "hide"
            }
        },
        {
            "name": "Project Tests",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "cwd": "some_folder",
            "console": "integratedTerminal",
            "justMyCode": true,
            "variablePresentation": {
                "all": "inline",
                "class": "group",
                "function": "hide",
                "special": "hide"
            }
        }
    ]
}

However, in the Run&Debug menu I see FOUR entries..."test.py", "preview.py" and "Project Tests", the ones I configured in launch.json, and "Python: File", which is applied to the currently open file in the IDE.

VS Code Python, entry in Run&Debug not present in launch.json

I was assuming this "Python: File" might be some default option which is always present, but then I have another workspace where I created launch.json with only one entry (process.py):

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "process.py",
            "type": "python",
            "request": "launch",
            "program": "./process.py",
            "cwd": "${workspaceFolder}",
            "console": "integratedTerminal",
            "justMyCode": true,
            "variablePresentation": {
                "all": "inline",
                "class": "group",
                "function": "hide",
                "special": "hide"
            }
        },
        
    ]
}

and here I only have the corresponding entry in the menu as well:

VS Code Python, entry in Run&Debug not present in launch.json

I tried deleting and recreating the launch.json file in the first workspace, but the result is always the same.
How does this work precisely?

答案1

得分: 1

Simply copying your launch.json does not lead to the same problem.

So I don't think this is only a problem with the launch or debug itself. I have a speculation that you can try it out:

VS Code Python, entry in Run&Debug not present in launch.json

Click Python and choose Python File then click on the gear.

VS Code Python, entry in Run&Debug not present in launch.json

VS Code Python, entry in Run&Debug not present in launch.json

This will add Python: File related settings in launch.json for you, and then try to manually delete them after saving launch.json.

英文:

Simply copying your launch.json does not lead to the same problem.

So I don't think this is only a problem with the launch or debug itself. I have a speculation that you can try it out:

VS Code Python, entry in Run&Debug not present in launch.json

Click Python and choose Python File then click on the gear.

VS Code Python, entry in Run&Debug not present in launch.json

VS Code Python, entry in Run&Debug not present in launch.json

This will add Python: File related settings in launch.json for you, and then try to manually delete them after saving launch.json.

huangapple
  • 本文由 发表于 2023年5月10日 14:22:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76215411.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定