# Code intelligence in Skink: LSP completion, go to definition

> Set up language servers for Skink (rust-analyzer, TypeScript, pyright, gopls, zls, Dart): completion, hover, go to definition, references, rename and format.

Source: https://skink.cc/code/code-intelligence/

Skink gets completion, errors, go to definition and the rest from language servers. Install the server for your language and put it on your `PATH`. Skink starts it the first time you open a file of that language, with no config.

Then Ctrl+Space completes, Alt+G goes to the definition and Alt+R lists references.

## Which language servers

| Language | Server Skink looks for | One way to install it |
|---|---|---|
| Rust | `rust-analyzer` | `rustup component add rust-analyzer` |
| TypeScript, JavaScript | `typescript-language-server` | `npm i -g typescript-language-server typescript` |
| Python | `basedpyright-langserver`, else `pyright-langserver` | `pip install basedpyright` or `npm i -g pyright` |
| Go | `gopls` | `go install golang.org/x/tools/gopls@latest` |
| Zig | `zls` | Your package manager, or a release from the zls project |
| Dart | `dart language-server` | Comes with the Dart (or Flutter) SDK |

Other languages get syntax colours and every editing feature, but no language server yet. The server list is built in; you cannot add your own servers in settings.

## Check and restart a server

`:lsp` shows the server for the current file, its memory use and progress. If the server is missing, it says which program it looked for.

- `:lsp restart` restarts it.
- `:lsp log` shows its full log.

A server that crashes is restarted once automatically. One with no open files for 10 minutes is stopped and starts again when you need it, which keeps memory low.

## Keys and commands

| Key | Command | Does |
|---|---|---|
| Ctrl+Space | `:complete` | Completion list |
| Alt+K | `:hover` | Type and docs of the symbol at the cursor |
| Alt+G | `:definition` (`:def`) | Go to definition (several: a list) |
| Alt+Shift+G | `:typedef` | Go to the type's definition |
| Alt+J | `:peek` | Peek the definition in a popup |
| | `:implementation` (`:impl`) | Go to implementations |
| Alt+R | `:references` (`:refs`) | Every use, in a results tab (Enter jumps) |
| Alt+Enter | `:fix` or `:actions` | Code actions: quick fixes and refactorings |
| Alt+Shift+R | `:renamesymbol NEW` (`:rn`) | Rename the symbol everywhere |
| Alt+Shift+F | `:format` (`:fmt`) | Format the selection or the file |
| Ctrl+R | `:symbols` | Symbols in this file |
| Alt+W | `:allsymbols` | Symbols in the whole project |
| Shift+F8 (F9 before 0.8) | `:problems` | Errors and warnings of the open files |
| F6 / Shift+F6 | `:nextproblem` / `:prevproblem` | Next / previous error or warning in this file |
| Alt+U / Alt+Shift+U | `:back` / `:forward` | Back to where you were before a jump, and forward again |

While a debug session runs, F6 pauses the program instead.

## Completion

The list opens by itself after two letters or after `.`, `::` or `->`.

| Key | Does |
|---|---|
| ↑ / ↓ | Choose an item |
| Enter or Tab | Insert it |
| Esc | Close the list |

Docs for the selected item show beside the list. Snippets select their first placeholder; Tab moves to the next one.

### Turn off the automatic popup

Set `"autocomplete": false`. Ctrl+Space still works.

### Signature help

Signature help opens after `(` and `,`, showing the parameters of the call you are typing.

## Errors and warnings

Diagnostics show in the gutter and as red and yellow marks on the scrollbar (the editor's last column).

F6 steps through them. Shift+F8 or `:problems` lists all of them in a tab.

A lightbulb in the sign column means the cursor line has code actions: press Alt+Enter, or type `:fix`.

To send the errors to an AI agent, press Alt+Shift+E. See [AI agents](https://skink.cc/tools/ai-agents/).

## Format on save

```json
{ "formatonsave": true }
```

With this, Ctrl+S asks the language server to format the file first.

Alt+Shift+F (or `:format`) formats on demand.

## Inlay hints

Inline type and parameter hints from the server are off by default. Turn them on with:

```json
{ "inlayhints": true }
```

## Rename and other multi-file edits

Rename (Alt+Shift+R) and code actions that touch several files open the refactor preview, where you check which changes to apply. See [Refactoring](https://skink.cc/code/refactoring/).

## Breadcrumbs and quick open

The status line shows where the cursor is, like `impl Foo > fn bar`.

Quick open (Alt+P, or `:recent`) switches mode by its first character:

- `@` for symbols in the file
- `#` for symbols in the project
- `>` for commands

## When nothing happens

- Run `:lsp`. If it says the server is not installed, install it and make sure your shell's `PATH` has it, then `:lsp restart`.
- Files of 2 MB or more open as LARGE, without a language server.
- Over SSH, the server has to be installed on the server.
- Inside [EveryAI](https://skink.cc/tools/everyai/), language servers come from EveryAI instead.

**Changed in 0.8:**
The debugger took over some F-keys. F5 starts or continues debugging and no longer zooms (use Alt+Z or `:zoom`). F9 toggles a breakpoint, so the Problems list moved to Shift+F8. F10, F11, Shift+F11 and F6 step and pause only while debugging; otherwise they keep their old jobs. See [Keyboard shortcuts](https://skink.cc/reference/shortcuts/).
