A narrated lesson with original music and captions. Slides teach each step; every editor clip is real footage from the refactoring walkthrough, recorded in VS Code. Fast-forwarded stretches are marked on screen.

Lesson: code actions in SharpLsp, from Cmd+. to F# quick fixes, generated match cases, rename across files, C# generate method and add using

Read the guide: Refactoring & Code Actions

Transcript

Welcome to a quick lesson on code actions in SharpLsp! In the next few minutes, you'll fix code, generate code, and rename across files, in F# and C#, on any OS.

First, the one shortcut you need. On a Mac, press Command dot.

On Windows and Linux, it's Control dot.

Or just click the lightbulb.

Either way, the menu only lists actions that apply to your cursor, your selection, or the diagnostic under it.

So where do actions come from? Three places.

A diagnostic: a warning or an error asks for its own fix.

The cursor: a type or member you can reshape.

And a selection: refactorings that work on the code you highlight.

On a blank line, you get an empty menu. SharpLsp never guesses.

Let's start with F#. This describe function matches on a stage, but it's missing a union case.

The compiler flags it with warning FS0025: an incomplete pattern match.

Press Command dot, pick Generate missing union case, and SharpLsp writes the arm for you.

Prefer a catch-all? Add wildcard case is right there too.

Here's the result. The new arm matches exactly the case that was missing,

because the F# compiler knows every case of the union. You just write the body.

That's one fix from a whole F# toolkit, each tied to a compiler diagnostic.

Unresolved name? Add the open. Unused binding? Prefix it with an underscore. A discarded value? Pipe it to ignore.

And beyond matches, SharpLsp generates missing record fields and interface member stubs.

Renaming is separate from code actions. Put the cursor on a symbol and press F2.

Type the new name and hit enter.

Every reference follows, even in other files. Here, the call in Program.fs updates too.

In C#, rename runs on Roslyn's loaded solution. In F#, on the loaded F# project.

Now C#. Here's a favourite workflow: write the call you wish existed. Receipt, of invoice.

It doesn't exist yet, so the compiler reports an error.

Command dot. Generate method.

Roslyn writes the stub, and takes the parameter type from your call.

Next, use a type without importing its namespace. StringBuilder, say.

Quick Fix puts using System.Text right at the top.

You could also qualify it in place, or even generate a new class.

These come straight from Roslyn's own code fix providers, bundled with SharpLsp.

So what's happening underneath? Your editor asks for code actions at the cursor.

Roslyn, or the F# compiler, sends back a list of titles. That keeps the menu fast.

Only when you pick one does SharpLsp resolve it and compute the edits.

The result is one workspace edit, which can touch several files.

And if an action has gone stale, you get no edit, never a guess.

Two things that aren't code actions.

SharpLsp doesn't format your code. Use CSharpier for C#, and Fantomas for F#.

And Sort Members is its own command. Right-click a C# type in the Solution Explorer to reorder its members.

Let's recap. Command dot, or Control dot, opens every action that applies.

F# fixes follow the compiler's diagnostics, and they can write whole match cases.

F2 renames across files.

And in C#, you can call first, and generate second.

The full lesson is in the SharpLsp docs. Now go fix some code!