'How to edit built in code completion or snippets in vscode

Although I searched my problem before, I couldn't find any solution.

I need to find the file in which default/built-in code snippets are, and edit it. Indeed I don't know exactly is it from Python extension or the language server which is currently set to "Pylance" in my setting.

As an example, if want to implement __call__ in my class, in suggestion pop-up there is no indication that it is a snippet: (btw, I haven't defined any custom snippet)

enter image description here

After tab it changes to:

enter image description here

Which is obviously not what I want. I have to either import Any from typing module or manually delete those type hints.

clarification:

  1. OS: Pop!_OS 21.10 x86_64

  2. I've checked ./ms-python.vscode-pylance2022.4.2/dist/typeshedfallback/stubs/whatthepatch/whatthepatch/snippets.pyi file but it doesn't contain those.

  3. Also my /usr/share/code/resources/app/extensions/python directory doesn't have snippets directory as mentioned here

  4. Python extension version : v2022.4.1

  5. Pylance version : v2022.4.2

One possible solution would be to define custom code snippets and set them to be on top in the suggestion list. But I hope I could change the original one.



Solution 1:[1]

The simplest solution is probably to define a custom snippet that overrides the existing snippet for __call__ following the VS Code snippets documentation

In this case, open the command palette and locate/type Preferences: Configure User Snippets, open python.json if it already exists under Existing Snippets, otherwise type in python and select New Snippets file for 'Python'...

In your new snippets file, define a custom snippet for __call__ that's formatted the way you want, e.g.:

{
    "call": {
        "prefix": "__call__",
        "body": ["insert your snippet guts here"],
        "description": "custom __call__ snippet"
    },
}

Solution 2:[2]

As per JRiggles, but re editing, go to snippet generator

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 JRiggles
Solution 2 JL Peyret