Skip to content

Latest commit

 

History

History
115 lines (90 loc) · 6.72 KB

README.md

File metadata and controls

115 lines (90 loc) · 6.72 KB

VSCode Extension of Type4Py

vsm-version GH-workflow

This extension provides machine learning-based type autocompletion for Python, which assists developers to gradually add type annotations to their existing codebases.

Core Features

  • Machine learning-based type prediction (powered by Type4Py)
  • It can be used with a local model on your machine (No data sharing)
  • Improved autocompletion for Python type annotations (based on Python Type Hint)
  • Type autocompletion for parameters, return types of functions, and variables.
  • Simple, fairly fast and easy to use.

Usage

Quick Start

Step-by-Step

  1. In VSCode, select a Python source file of your interest.
  2. Go to View -> Command Palette -> Type4Py: Infer type annotations.
  3. Depending on the file size, after a couple of seconds, you can see the in-progress/completed requests at the bottom left of VSCode.

    Type4Py's status bar

  4. After the completion of your request, you can now start adding predicted type annotations to your code, similar to the Quick Start example above.

Tip: At the bottom left of VSCode, click on the status bar of Type4py to see the extension's logs and errors.

Tip: To use the local model for type inference instead of our server, see settings.

Tip: You can also enable automatic type inference when opening Python files. To do so, see settings.

Tip: The same above steps are also applicable to the web version of the extension.

Considerations

  • Do not edit the selected source file after running the Type4Py extension. That is, add the relevant predicted types to the code, save the file and then edit as you wish. We will drop this consideration once the caching solution is implemented.
  • Make sure that the selected source file does not have syntax or parse errors before running the extension. In VSCode, Python linters warn about such errors.
  • Concerning variables' redeclaration, type predictions are available for the last redeclaration of variables.

Installation

NOTE: Update VSCode before installing the extension.

The latest version of the extension can be installed from the Visual Studio Marketplace. The extension is also compatible with the web version of VSCode.

Settings

Name Description Default
workspace.localModelEnabled If enabled, it uses Type4Py's local model on your machine. NOTE THAT you need to pull and run Type4Py's Docker image first. See here for more info. false
workspace.autoInferEnabled If enabled, it automatically infers type annotations when opening a Python source file. Note that automatic inference works only once for a newly opened file. false
workspace.filterPredictionsEnabled If enabled, based on the file's imported names, irrelevent type predictions will be filtered out. Disable this setting if you would like to get all the predicted types regardless of relevancy. true
workspace.shareAcceptedPredictions If enabled, accepted type predictions will be shared with us for research purposes and improving our Type4Py model. Note that the value of VSCode Telemetry overrides this setting. Read our privacy statement here. false

Privacy

Privacy is very prominent for us. You can read our privacy statements here.

Support

Issues and errors can be reported here.

Development

External contributions are welcome such as bug fixes and improvements! Feel free to send a pull request.

Running the extension from source

  1. Build the package & install dependencies using npm install
  2. Compile the extension using npm run compile
  3. Open src/extension.ts in VSCode, open "Select Environment", and run in "VS Code Extension Development"
  4. Open a Python source code file, open the Command Palette, and run the "Type4Py: Infer type annotations" command.
  5. After a success message pops up, fill function annotations as usual (e.g. x: or def ...) ->), and type completion items will show up (if available)

Running tests

  1. Make sure that all instances of VSCode are closed on the machine.
  2. Run npm run test-compile

Web version

To develop and test the web version of the extension, run the following commands at the root of the project:

npm install && npm run compile-web
npx vscode-test-web --browserType=chromium --extensionDevelopmentPath=.

This opens up the VSCode Web at localhost:3000 with the extension.

Roadmap

Here are the desirable features for future releases.

  • Implementing a caching solution to preserve type predictions when source files change.
  • Enabling the type-checking process for the Type4Py's predictions using mypy, preferably at the client-side.
  • Fine-tuning the (pre-trained) Type4Py model on users' projects to learn project-specific types.

Contributors

  • Amir M. Mir (@mir-am)
  • Evaldas Latoškinas (@elatoskinas)
  • Sebastian Proksch (@proksch)
  • Georgios Gousios (@gousiosg)

Acknowledgements

The Type4Py model and its VSCode extension are designed and developed in SERG at the Delft University of Technology.

TUD_logo