# VS Code

<div align="left"><img src="https://2893586400-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MP5jWcLZLbbbzO-_ua1%2F-MdsIwkqtzkin4UhMUcO%2F-MdsJJfMVIeKrIcmoUiX%2Fcet-vscode-demo-115.gif?alt=media&#x26;token=0a549402-78de-4e5c-9436-0a6e464aa246" alt=""></div>

## Features

* Code completion for built-in Cyber Engine Tweaks, Dear ImGui and Cyberpunk 2077 types and functions (except sqlite)
* Type resolving for `Game.GetScriptableSystemsContainer():Get("Type")`, `NewObject("Type")`, and `GetSingleton("Type")`&#x20;
* Contextual suggestions for default values and predefined sets

## Installation

### CET typedef

1. Download and extract the [Cyber Engine Tweaks Lua Lib](https://github.com/psiberx/cp2077-cet-typedefs/releases/download/v211124/cet-lua-b-1.18.0-211124.zip).
   * The lib files linked above is not the newest version.
   * You can join the [Cyberpunk 2077 Modding Community discord server](https://discord.gg/redmodding) and then visit [this message](https://discord.com/channels/717692382849663036/795037494106128434/1160542144528912524) to download the newest version  (CET 1.27 / Patch 2.01 Typedefs).
   * You can alos check the pinned messages in the [#cet-lua-scripting channel](https://discord.com/channels/717692382849663036/795037494106128434) for any future update.
2. Install the [Lua by sumneko](https://marketplace.visualstudio.com/items?itemName=sumneko.lua) extension.
3. Locate settings.json in VS code
   * Ctrl + Shift + P
   * `C: > Users > (yourname) > AppData > Roaming > Code > User > {} settings.json`

<figure><img src="https://2893586400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MP5jWcLZLbbbzO-_ua1-887967055%2Fuploads%2Fpi2EdKo6krZ1mNkKOGJK%2FScreenshot%202024-03-08%20162816.png?alt=media&#x26;token=6d06fc86-7e5a-4cc3-a0d2-089f6a211686" alt=""><figcaption><p>select JSON, not UI</p></figcaption></figure>

4. Add next settings to the `.vscode\settings.json` or in the Settings GUI: &#x20;
   * NOTE: ensure commas occur after every line

```json5
     "Lua.runtime.version": "LuaJIT",
     "Lua.workspace.preloadFileSize": 15360,
     "Lua.workspace.library": [
         "c:\\path\\to\\cet-lua-lib",
     ], 
```

5. On first use it takes a couple of minutes to parse and cache all definitions. Unfortunately there is no visual indication of this process.  When it's done the code assistance will be more responsive.

### Dear ImGui typedef

To install the typedefs for **Dear ImGui**, you can manually download the files from GitHub repository [Nats-ji/CET\_ImGui\_lua\_type\_defines](https://github.com/Nats-ji/CET_ImGui_lua_type_defines) and then follow the same installation process in [#cet-typedef](#cet-typedef "mention") to install them in VSCode.

## Annotations

#### Callback parameters

You can specify the type of the parameters with `@param` annotation. It's very handy for `Observe` and `Override`:

```lua
---@param request PerformFastTravelRequest
Observe("FastTravelSystem", "OnPerformFastTravelRequest", function(request)
    -- Now request object has type and suitable for code completion
end)
```

<div align="left"><img src="https://2893586400-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MP5jWcLZLbbbzO-_ua1%2F-MdsIwkqtzkin4UhMUcO%2F-MdsJTbtYaGgYVI-4NpG%2Fcet-vscode-param.png?alt=media&#x26;token=71706c04-e183-4cf1-96d3-32f3cbade863" alt=""></div>

#### Unresolved type

If type of some variable cannot be resolved or ambiguous you can force the type with `@type` annotation:

```lua
---@type ScriptedPuppet
local puppet
```

#### Generic functions

The type of the result of some functions depends on the parameters passed to the function. If a valid type name is passed as a parameter, then the resulting type must be resolved without custom annotations.

<div align="left"><img src="https://2893586400-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MP5jWcLZLbbbzO-_ua1%2F-MdsIwkqtzkin4UhMUcO%2F-MdsJWVc8TNhTQzR9QKh%2Fcet-vscode-generic.png?alt=media&#x26;token=27bd6784-06d3-40e1-b38d-af7b08910549" alt=""></div>
