Requirements
Java 8 or 11 provided by OpenJDK or Oracle. Eclipse OpenJ9 is notsupported, please make sure the JAVA_HOME
environment variablepoints to a valid Java 8 or 11 installation.
In this tutorial you'll learn how to compile and run a C/C code in Visual Studio Code. Visual studio code compile c, visual studio code c hello world, g is not recognized visual studio code, compile and run c program in visual studio code, compile and run cpp in visual studio code, how to setup visual studio code for c. Asharhasan20 changed the title couldn't find gin build task g is not recognized in vscode on Sep 3, 2020 sean-mcmanus added question build/tasks labels on Sep 3, 2020 elahehrashedi closed this on Sep 24, 2020 github-actions bot locked and limited conversation to collaborators on Oct 8, 2020. Edit your code and continue debugging (C#, VB, C) In most languages supported by Visual Studio, you can edit your code in the middle of a debugging session and continue debugging. To use this feature, click into your code with your cursor while paused in the debugger, make edits, and press F5, F10, or F11 to continue debugging. I have Windows 10 with the newest version of Visual Studio Code (VSC) with the Run Code Extension and git extension (not sure what git does, but VSC prompted me to install). I am now familiar with the text editor, but do not know how to compile/run my code (apologies if I'm.
macOS, Linux or Windows. Metals is developed on macOS and every PR istested on Ubuntu+Windows.
Scala 2.13, 2.12, 2.11 and Scala 3. Metals supports these Scala versions 2.13.5, 2.12.13, 2.12.12, 2.12.11, 2.12.10, 2.13.3, 2.13.4, 2.11.12, 2.12.8, 2.12.9, 2.13.0, 2.13.1, 2.13.2, 3.0.0-RC3, 3.0.0-RC2, 3.0.0-RC1, 3.0.0-M3, 3.0.0-M2 and 3.0.0-M1.Note that 2.11.x support is deprecated and it will be removed in future releases.It's recommended to upgrade to Scala 2.12 or Scala 2.13
Installation
Install the Metals extension from theMarketplace.
Make sure to disable the extensionsScala Language ServerandScala (sbt)if they are installed. TheDotty Language Serverdoes not need to be disabled because the Metals and Dotty extensions don'tconflict with each other. However, if you want to work on Scala 3 code in aworkspace that was previously opened with Dotty Language Server
you need tofirst remove .dotty-ide-artifact
before opening the workspace with Metals.
Next, open a directory containing your Scala code. The extension activates whenthe main directory contains build.sbt
or build.sc
file, a Scala file isopened, which includes *.sbt
, *.scala
and *.sc
file, or a standard Scaladirectory structure src/main/scala
is detected.
Importing a build
The first time you open Metals in a new workspace it prompts you to import the build.Click 'Import build' to start the installation step.
- 'Not now' disables this prompt for 2 minutes.
- 'Don't show again' disables this prompt forever, use
rm -rf .metals/
to re-enablethe prompt. - Use
tail -f .metals/metals.log
to watch the build import progress. - Behind the scenes, Metals uses Bloop toimport sbt builds, but you don't need Bloop installed on your machine to run this step.
Once the import step completes, compilation starts for your open *.scala
files.
Once the sources have compiled successfully, you can navigate the codebase withgoto definition.
Custom sbt launcher
By default, Metals runs an embedded sbt-launch.jar
launcher that respects .sbtopts
and .jvmopts
.However, the environment variables SBT_OPTS
and JAVA_OPTS
are not respected.
Update the 'Sbt Script' setting to use a custom sbt
script instead of thedefault Metals launcher if you need further customizations like reading environmentvariables.
Speeding up import
The 'Import build' step can take a long time, especially the first time yourun it in a new build. The exact time depends on the complexity of the build andif library dependencies need to be downloaded. For example, this step can takeeverything from 10 seconds in small cached builds up to 10-15 minutes in largeuncached builds.
Consult the Bloop documentationto learn how to speed up build import.
Importing changes
When you change build.sbt
or sources under project/
, you will be prompted tore-import the build.
Manually trigger build import
To manually trigger a build import, execute the 'Import build' command throughthe command palette (Cmd + Shift + P
).
Run doctor
Execute the 'Run Doctor' through the command palette to troubleshoot potentialconfiguration problems in your workspace.
Configure Java version
The VS Code plugin uses by default the JAVA_HOME
environment variable (vialocate-java-home
) to locate thejava
executable. To override the default Java home location, update the 'JavaHome' variable in the settings menu.
If this setting is defined, the VS Code plugin uses the custom path instead ofthe JAVA_HOME
environment variable.
macOS
To globally configure $JAVA_HOME
for all GUI applications, seethis Stackoverflow answer.
If you prefer to manually configure Java home through VS Code, run the followingcommand to copy the Java 8 home path.
Custom artifact repositories (Maven or Ivy resolvers)
Use the 'Custom Repositories' setting for the Metals VS Code extension to tellCoursier to try to download Metalsartifacts from your private artifact repository.
Use .jvmopts
to set sbt options(https://www.scala-sbt.org/1.0/docs/Proxy-Repositories.html) forsbt bloopInstall
which resolves library dependencies. You can also provide acustom sbt script (see 'Custom sbt launcher').
HTTP proxy
Metals uses Coursier to downloadartifacts from Maven Central. To use Metals behind an HTTP proxy, configure thesystem properties -Dhttps.proxyHost=… -Dhttps.proxyPort=…
in one of thefollowing locations:
.jvmopts
file in the workspace directory.JAVA_OPTS
environment variable, make sure to startcode
from your terminalwhen using this option since environment variables don't always propagatecorrectly when opening VS Code as a GUI application outside a terminal.- 'Server Properties' setting for the Metals VS Code extension, which can beconfigured per-workspace or per-user.
Using latest Metals SNAPSHOT
Update the 'Server Version' setting to try out the latest pending Metalsfeatures.
Version | Published |
---|---|
0.10.2 | 21 Apr 2021 14:03 |
0.10.2+11-e47e685a-SNAPSHOT | 23 Apr 2021 13:49 |
Files and Directories to include in your Gitignore
The Metals server places logs and other files in the .metals
directory. TheBloop compile server places logs and compilation artifacts in the .bloop
directory. The Bloop plugin that generates Bloop configuration is added in themetals.sbt
file, which is added at project/metals.sbt
as well as furtherproject
directories depending on how deep *.sbt
files need to be supported.To support each *.sbt
file Metals needs to create an additional file at./project/project/metals.sbt
relative to the sbt file.Working with Ammonite scripts will place compiled scripts into the .ammonite
directory.It's recommended to exclude these directories and filesfrom version control systems like git.
Show document symbols
Run the 'Explorer: Focus on Outline View' command to open the symbol outline forthe current file in the sidebar.
Run the 'Open Symbol in File' command to search for a symbol in the current filewithout opening the sidebar.
As you type, the symbol outline is also visible at the top of the file.
Go to parent code lenses
Metals has the ability to display code lenses that, when invoked,will go to the parent class that contains the definition of the method or symbol.Unfortunately, it might cause some lag in larger code bases,which is why it is not enabled currently by default.
To enable the feature you need to modify the setting metals.superMethodLensesEnabled
to true
.
Even without using the code lenses it's still possible to navigate the method hierarchyusing two commands:
Metals: Go to super method
- immediately goes to the parent of the method the cursor is pointing toMetals: Reveal super method hierachy
- displays the full method hierachy and enables to move to any parent,it is best used with the Metals Quick Pick extension.
You can also bind those commands to a shortcut.
Create new project from template
It is possible using Metals to easily setup a new project using the exiting giter8 templates.This is an equivalent to the sbt new
command, which uses the same mechanism.There is a great number of templates already available and it should be easy to find something for yourself.To start the setup you can use the Metals: New Scala project command, which works as following:
Choose the template and then:
- Use the proposed templates.
- Choose 'Discover more' and then choose from the list downloaded from the Giter8 wiki page.
- Input a custom Github repository following the
organization/repo
schema.
Navigate to the parent directory that you want to create your new project in.
Choose the name or accept the default one.
Choose whether to open a new window for the created project or use the existing one.
The same command will be invoked when clicking the 'New Scala Project' button in the Metals view.
If you feel like a template should be included in the default displayed ones do not hesitate to create aPRor file an issue.
Running and debugging your code
Metals supports running and debugging tests and main methods via theDebug Adapter Protocol.The protocol is used to communicate between the editor and debugger, which meansthat applications can be run the same as for any other language in the nativelysupported Run
view. When using Metals the debugger itself isBloop, which is also responsible forstarting the actual process.
Users can begin the debugging session in two ways:
via code lenses
For each main or test class Metals shows two code lenses run | debug
ortest | test debug
, which show up above the definition as a kind of virtualtext. Clicking run
or test
will start running the main class or test withoutstopping at any breakpoints, while clicking debug
or test debug
will pauseonce any of them are hit. It's not possible to add any arguments or javaproperties when running using this method.
via a launch.json
configuration
Gcc Not Recognized
Visual Studio Code uses .vscode/launch.json
to store user definedconfigurations, which can be run using:
- The
Run -> Start Debugging
menu item orworkbench.action.debug.start
shortcut. - The
Run -> Run Without Debugging
menu item orworkbench.action.debug.run
shortcut.
If a user doesn't have anything yet saved, a configuration wizard will pop up toguide them. In the end users should end up with something like this:
You can also add an optional build target name, which is needed in case thereare more than one class with the same name or when launching a class fromoutside the project. Inside 'configurations':
add the key buildTarget
withyour target name, e.g. root
:
The build target name corresponds to your project name. For example in sbt forlazy val interfaces = project
the name of the build target will beinterfaces
for sources and interfaces-test
for tests. To make sure you havethe correct target names please run the command Metals: Run Doctor
.
Multiple configurations can be stored in that file and can be chosen eithermanually in the Run
view or can be picked by invoking a shortcut defined underworkbench.action.debug.selectandstart
.
On type formatting for multiline string formatting
G++ Vscode
To properly support adding |
in multiline strings we are using theonTypeFormatting
method. The functionality is enabled by default, but you candisable/enable onTypeFormatting
inside Visual Studio Code settings by checkingEditor: Format On Type
:
Formatting on paste for multiline strings
Whenever text is paste into a multiline string with |
it will be properlyformatted by Metals:
This feature is enabled by default. If you need to disable/enable formatting onpaste in Visual Studio Code you can check the Editor: Format On Paste
setting:
Worksheets
Worksheets are a great way to explore an api, try out an idea, or codeup an example and quickly see the evaluated expression or result. Behindthe scenes worksheets are powered by the great work done inmdoc.
Getting started with Worksheets
To get started with a worksheet you can either use the metals.new-scala-file
command and select Worksheet or create a file called *.worksheet.sc
.This format is important since this is what tells Metals that it's meant to betreated as a worksheet and not just a Scala script. Where you create thescript also matters. If you'd like to use classes and values from yourproject, you need to make sure the worksheet is created inside of your src
directory. You can still create a worksheet in other places, but you willonly have access to the standard library and your dependencies.
Evaluations
After saving you'll see the result of the expression as a decoration at the end of the line.You may not see the full result for example if it's too long, so you are alsoable to hover on the decoration to expand the decoration.
Keep in mind that you don't need to wrap your code in an object
. In worksheetseverything can be evaluated at the top level.
Using dependencies in worksheets
You are able to include an external dependency in your worksheet by includingit in one of the following two ways.
::
is the same as %%
in sbt, which will append the current Scala binary versionto the artifact name.
You can also import scalac
options in a special $scalac
import like below:
Coming from IntelliJ
Install theIntelliJ IDEA Keybindingsextension to use default IntelliJ shortcuts with VS Code.
IntelliJ | VS Code |
---|---|
Go to class | Go to symbol in workspace |
Parameter info | Trigger parameter hints |
Basic completion | Trigger suggest |
Type info | Show hover |
Expand | Fold |
Extend Selection | Expand selection |