# Koka Syntax Highlighting and Language Server

Syntax highlighting and language server support for the
Koka programming language in Visual Studio Code.
Visit <https://koka-lang.github.io> for more information.



## Run and edit the standard examples

Open the command panel in VSCode `(Ctrl/Cmd + Shift + P)`, and run the
**`Koka: Open samples`** command (when you start typing the command will surface to the top).

You can execute any `main`, `test..`, and `example..` functions
directly in the debug console by clicking on the
`run debug | optimized` code lenses displayed above these functions.

<img width="220px" style="border:1px solid grey" src="support/vscode/koka.language-koka/images/codelens.png">


## (Re)Install the latest Koka compiler

Open the command panel in VSCode `(Ctrl/Cmd + Shift + P)` and run the
`Koka: Download and install the latest compiler` command.
In the extension settings, you can also set the Koka compiler
path and specific compiler flags manually.


## Inlay hints

The extension shows inlay hints for inferred types of parameters and local declarations. You can toggle the visibility of inlay hints by pressing and holding `ctrl+alt` (or `ctrl+option` on MacOS) to show these inlay hints.


# Customization

## Supported Language Server Aspects

- Diagnostics (parse and type errors)
- Code completion
- Hover information
- Find definitions
- Inlay hints (shows inferred types)
- Document outline
- Code folding ranges
- Code Lenses (`run debug` and `run optimized`)
- Jump to definition

## Syntax token classes

* `koka.conid`: constructors.
* `koka.op`: operators.
* `koka.id`: identifiers.
* `koka.id.decl`(`.function`|`.val`|`.var`): declarations.
* `koka.id.library`(`.resume`|`.finally`|...): control related library identifiers.
* `koka.moduleid`: module identifiers.
* `koka.keyword`: keywords.
* `koka.keyword.control`: control flow keywords.
* `koka.special`: reserved separators (`{};,` etc).
* `koka.special.dot`: the dot separator.
* `koka.number`: numbers.
* `koka.string`(`.invalid`|`.escape`|`.raw`): string literals.
* `koka.char`(`.invalid`|`.escape`): character literals.
* `koka.type`(`.kind`|`.special`|`.typevar`|`.typecon`): types.
* `koka.comment`(`.line`|`.block`): comments.
* `koka.comment.doc`(`.emph`|`.pre`|`.pre.type`|`.pre.block`): documentation inside a comment.

## Custom launch

You can create custom launch configurations in your `launch.json` file.
The following settings are available:
```json
{
  "type": "koka",
  "request": "launch",
  "program": "",      // The path to the file you want to run
  "name": "",         // The name as you want it to appear in the run configurations dropdown
  "functionName": "", // optional function name to run
  "programArgs": [],  // optional arguments you want to give to the compiled program
  "compilerArgs": "", // optional arguments you want to give to the compiler (e.g. --verbose or -O2)
}
```

Compilation progress is shown in the language server _terminal_ window,
while the _debug console_ shows the output of the program.

## Custom syntax colors

You can customize the Koka syntax highlighting by editing
the `settings.json` file of VS Code (press `Ctrl/Cmd+Shift+P` and
select "Open Settings (JSON)" to open it).
Then add a [editor.tokenColorCustomizations](https://code.visualstudio.com/docs/getstarted/themes#_editor-syntax-highlighting)
entry, for example:
```json
"editor.tokenColorCustomizations": {
  "textMateRules": [
    { "scope": "koka.type",
      "settings": { "foreground": "#00B8B8" }
    },
    { "scope": "koka.conid, koka.number",
      "settings": { "foreground": "#a6c2a3" }
    },
    { "scope": "koka.comment.doc.pre",
      "settings": { "foreground": "#91ac91" }
    },
    { "scope": "koka.id.decl.function",
      "settings": { "foreground": "#cac199" }
    },
  ]
}
```
