Dart SDK
A prebuilt Dart SDK is available for IDE consumption at:
prebuilt/third_party/dart/{linux|mac|windows}-x64/bin/dart
.
Visual Studio Code
- Download and install Visual Studio Code
(Optional) Setup VS Code to launch from the command line
For macOS: To allow running VS Code from the terminal using the
code
command, see Launching from the command line.For Linux and Windows: This should already be done as part of the installation
Install the following extensions:
- Dart Code: Support for programming in Dart. It should automatically find the dart-sdk in the Fuchsia tree.
- FIDL language support: Syntax highlighting support for Fuchsia's FIDL files
- GN: Syntax highlighting for GN build files
- Optional but helpful git extensions:
- Git Blame: See git blame information in the status bar
- Git History: View git log, file history, etc.
To improve your productivity for Dart in VS Code, you can set some useful settings.
To add the settings:
- Open your user settings (Ctrl+,)
- Click the rotating page icon in the top left (or right for macOS) corner
- Add:
- Auto-format your files when you save:
"editor.formatOnSave": true,
- Check for new SDK updates for Fuchsia:
"dart.checkForSdkUpdates": false,
- Configure VS Code to use the bundled Dart SDK
"dart.sdkPath": "/path/to/fuchsia/prebuilt/third_party/dart/linux-x64/bin/dart",
- Don't run pub with fuchsia.
"dart.runPubGetOnPubspecChanges": false,
- Configure an 80 character ruler and a tab size of two spaces
"[dart]": {
"editor.rulers": [80],
"editor.tabSize": 2
},
CLion/IntelliJ
- Add the Dart plugin by going to
Settings > Plugins
then searching for Dart language support. - Set the Dart path in
Settings > Languages & Frameworks > Dart
by- Check Enable Dart support for the project
. - Enter the Dart SDK path "${FUCHSIA_SRC}/third_party/dart/tools/sdks/dart-sdk"
- Check Enable Dart support for the project
Troubleshooting
If you find that the IDE is unable to find imports (red squigglies) that are already correctly in your BUILD.gn dependencies, this is usually a sign that Dart analysis is not working properly in your IDE.
When this happens, try the following:
Open only the project directory you are working on
E.g. only open /topaz/shell/ermine
instead of /topaz
. The analyzer can have
issues with really large source trees.
Remove pub output
- Delete the
.dart_tool/package_config.json
andpubspec.lock
files in your project (if present). - Ensure that
"dart.runPubGetOnPubspecChanges": false,
is present in your VS Code preferences to prevent the files from reappearing whenever apubspec.yaml
file is edited. - Reload VS Code to restart the Dart analyzer.
- Press Ctrl+Shift+P to open the VS Code Command Palette
- Select "Reload Window"
Rebuild
Delete /out
from your Fuchsia directory and rebuild. Dart FIDL bindings are
build-generated and may be absent.
Ensure that your build contains all packages
Any Dart code from packages not included in your build will not be available to
the analyzer, so ensure your build configuration (fx set
) includes all
the packages you need (the --with
flag can be helpful.)
For example, to view the echo_client_async
example Dart code in VS Code, add
--with examples/fidl/dart/echo_client_async_dart
to your fx set
command. Then, rebuild with fx build examples/fidl/dart/echo_client_async_dart
.
Reload the Dart Analyzer
Manually reloading the analyzer is often needed after modifying FIDLs.
VS Code
- Open the Command Palette (Ctrl+Shift+P)
- Enter and select "Reload Window"
This also restarts the Dart analyzer.
IntelliJ
- Open Find Action (Ctrl+Shift+A)
- Enter and select "Restart Dart Analysis Server"
Check that the correct language has been detected for the current file type
- On VS Code use Ctrl+Shift+P then type "Change Language Mode" and ensure it is set to "Auto Detect".
- If this doesn't fix the issue you can try to manually fix via Ctrl+Shift+P and "Configure file association for .dart"
Manually specifying the Dart sdk path
VS Code
See the recommended VS Code options above.
IntelliJ
- Open Settings
- Under Languages & Frameworks > Dart, enter "[YOUR FUCHSIA DIR LOCATION]/prebuilt/third_party/dart/{mac,linux}-x64"