C# support
Runesmith supports C# through a built-in plugin, runesmith.csharp. It highlights .cs and .csx files, gives completion, hover, go to
definition, signature help, problems, quick fixes, rename, formatting and inlay hints from Runesmith's own C# analyzer, and builds solutions and
projects with dotnet build. This page covers what the analyzer does, how it finds your projects, how fast it is and what it does not do
yet.
Set up
There is nothing to install for completion and the other language features: the analyzer is built on the C# compiler (Roslyn 5.9), ships with the plugin and runs inside Runesmith. Nothing is downloaded.
- Install the .NET SDK, or download one in File › SDKs.... The analyzer needs it to load your projects, and
Build needs
dotneton thePATHor a default SDK that Runesmith installed. - Open a folder with a solution or project in Runesmith and open a
.csfile.
Features
| Feature | How to use it |
|---|---|
| Completion | Shows while you type, after a ., or with CtrlSpace. The selected suggestion shows its documentation. |
| Signature help | Shows when you type ( or , in a call. |
| Hover | Rest the pointer on a symbol to see its signature and documentation. |
| Go to definition | F12, or Ctrl+click a symbol declared in your source. |
| Problems | The compiler's own errors and warnings, underlined in the editor and listed in the Problems panel as csharp with their code, such as CS0103. |
| Quick fixes and refactorings | The light bulb shows on a line with a problem the compiler can fix, such as a missing using. AltEnter lists the fixes and the compiler's refactorings for the line or selection. |
| Rename | F2 on a symbol declared in your source renames it in every file of the solution. |
| Formatting | Format Document (ShiftAltF) and Format Selection format with the compiler's formatter, indenting with the editor's tab size and spaces or tabs. |
| Inlay hints | The names of the parameters that literal arguments go to, such as count: before 1, and the types of variables declared with var. Turn them off with Inlay hints (editor.inlayHints). |
C# versions
The analyzer supports every C# version up to C# 14. It respects each project's LangVersion, so a feature newer than the project's
version is reported as an error, as the compiler reports it when building.
Projects
The analyzer loads your projects in the background when you open a folder, so the editor never waits for it. It looks at the top of the open folder for a solution, and loads the first it finds:
- a
.slnxfile; - else a
.slnfile; - else every
.csprojfile in the folder and its subfolders, up to three levels deep, skipping folders such asbin,obj,.gitandnode_modules.
Loading uses MSBuild, so it needs the .NET SDK installed, as building does. The Language analyzers channel of the Output panel shows which solution or projects loaded, how long it took, and why a project failed to load. Project files are read when the folder opens; the analyzer does not watch them for changes.
A solution file below the top of the folder is not used, and projects more than three levels down are not found. Open the folder that holds the solution, or one closer to the projects.
Files outside projects
A C# file that belongs to no loaded project, or that you open before the projects finish loading, gets a project of its own. That project
uses the newest C# version, the .NET reference assemblies, and the global usings of a console app (System, System.Collections.Generic,
System.IO, System.Linq, System.Net.Http, System.Threading and System.Threading.Tasks), so a lone file gets completion and
problems right away. Problems that only say the files are not a complete program, such as a missing Main method, are left out.
Performance
Completion asks the compiler once per word and filters that list as the word grows, so typing more of a word does not ask again. The
analyzer also works ahead of you: after you type a separator, such as a space, ( or =, it computes the list for the next word before its
first letter, and while you type a name it computes the members that a . after it would show.
Problems are checked in the background. Typing pauses the check, and it runs again when typing pauses.
| Measurement | p95 |
|---|---|
| Completion at the start of a word, measured directly on the Runesmith solution | under 5 ms |
Completion after a ., measured directly on the Runesmith solution | 13 ms |
| Suggestions shown in the editor while typing, in the typing benchmark | about 36 ms |
Language services describes how these are measured, and how to run the typing benchmark.
Limitations
- Suggestions that expand into more than their label, such as completing an
overridewith its whole method, insert only the label. - Go to definition finds symbols declared in source; symbols from a library or the .NET reference assemblies have no location to go to.
- Problems are the compiler's own. Code style rules and analyzers that a project references are not run.
- Fixes and refactorings that add, move or delete files, such as generating a class in a new file, are listed but not applied yet: picking one says so and changes nothing.
- Fixes and refactorings whose providers need services of a full development environment, such as installing packages, are left out.
Build
Build › Build runs dotnet build on the open folder. It builds the first .slnx file at the top of the folder, or else the first
.sln, .csproj or .fsproj file. The build's output goes to the Output panel, and every error and warning appears in the
Problems panel with its file, line and code, such as CS0103, as soon as the compiler reports it. Build › Cancel Build stops the
build.
Errors without a file, such as a missing project, are listed on the solution or project being built.
Run configurations
The plugin adds three kinds of run configuration. When you open a folder, it finds the projects in it (up to six folders deep, skipping
bin, obj and hidden folders) and makes a configuration for each one, so most folders run without setup. Running
covers the run widget, the Run panel and Run › Edit Configurations....
| Kind | Found for | What it runs |
|---|---|---|
| .NET project | Each project whose OutputType is Exe or WinExe, or that uses the web or worker SDK | dotnet run --project <project> --no-build -c <configuration> -f <framework>, with the launch profile and the arguments after -- |
| .NET tests | Each project that sets IsTestProject or references xUnit, NUnit, MSTest or Microsoft.NET.Test.Sdk | dotnet test <project> --no-build -c <configuration>, with --filter when you set one |
| .NET command | Never; you add it | Any dotnet command line, such as format or ef database update, in the open folder |
A .NET project configuration has these settings:
| Setting | Meaning |
|---|---|
| Project | The project to run, from the projects found in the folder. |
| Target framework | One of the project's TargetFramework or TargetFrameworks; Project default is the first. |
| Launch profile | A profile from Properties/launchSettings.json whose commandName is Project, with its environment and URLs, or None. |
| Configuration | Debug or Release. |
| Program arguments | One argument per row, passed to the program as they are. |
| Environment variables | Names and values set for the program, over Runesmith's own environment. |
| Working directory | Where the program starts; the project's folder when empty. |
| .NET SDK | The SDK whose dotnet runs it; empty uses the default SDK. An SDK with its own dotnet runs with DOTNET_ROOT set to its folder. |
The Build step before a .NET project or tests configuration builds only that project, with dotnet build and the same configuration
and framework, and its errors and warnings appear in the Problems panel as a folder build's do. A .NET command builds the folder.
Debugging a .NET project will start the built assembly, bin/<configuration>/<framework>/<assembly>.dll, with dotnet; the .NET
debugger is not part of Runesmith yet.
SDKs
The plugin finds the .NET SDKs on your computer and downloads new ones from Microsoft's release metadata. File › SDKs... lists them,
with their channel's updates, and installs SDKs side by side in Runesmith's own .NET folder, checking each download's SHA-512 checksum.
When the default .NET SDK is one Runesmith installed, Build runs the dotnet of that folder. SDKs describes the page.
Templates
File › New Project lists the project templates of every .NET SDK Runesmith finds and of every template package you installed with
dotnet new install, so a package you install shows up the next time the dialog opens. They come from a separate built-in plugin,
C# templates (runesmith.csharp-templates); turn it off in Settings › Plugins to hide them and keep the rest of C# support.
The plugin reads the packages without unpacking them:
- the SDK's own packages, in
templates/<version>of each .NET root: the roots Runesmith's SDK list knows,DOTNET_ROOT, and the folder of thedotneton thePATH; - your installed packages, in
.templateengine/packagesof your home folder, or ofDOTNET_CLI_HOMEwhen it is set.
Each template's template.json gives its name, description, language and parameters. A template that comes in C#, F# and Visual Basic
shows once, with a Language choice. Its parameters become options: a choice becomes a drop-down, a bool a check box, a number a
number field and text a text field, and the Framework parameter becomes Target framework. Parameters that dotnet new --help hides,
such as port numbers, and Skip restore are left out. Item and solution templates are not listed; Blank Solution makes an empty
.slnx solution.
Create runs dotnet new with the template's short name, its language and the options you changed, using the .NET SDK you picked,
and lets it restore the project. The project goes in a folder of its own, next to a .slnx solution that lists it. With Put solution
and project in the same directory, the project is created directly in the new folder, without a solution.
Related
- Plugins: how the C# plugin and yours are loaded.
- Language features: completion, hover and problems in the editor.
- Language services: how the analyzer runs, for contributors.