FSH Language Support for VS Code
A language support extension for the FHIR Shorthand (FSH) language.
How to Download
In Visual Studio Code, go to the VS Code Extension Marketplace and download the
vscode-language-fsh extension. Once activated, this extension's features should
be automatically implemented.
FSH files automatically have syntax highlighting applied. This allows for easier reading and writing of FHIR Shorthand.
FSH Snippets make creating new FSH items a breeze! Snippets automatically add relevant keywords and placeholders so you can easily
enter all of the recommended metadata for a FSH definition. Snippets will even auto-create your
Title for you based on the
To use snippets, type one of the trigger phrases, hit the <TAB> or <ENTER> key, type in the first field value, and hit
the <TAB> key to move to the next placeholder. All FSH snippets always stop at the first rule in the definition.
||Profile, Parent, Id (auto), Title (auto), Description
||Extension, Id (auto), Title (auto), Description
||Logical, Parent, Id (auto), Title (auto), Description
||Resource, Parent (choice), Id (auto), Title (auto), Description
||ValueSet, Id (auto), Title (auto), Description
||CodeSystem, Id (auto), Title (auto), Description
||Instance, InstanceOf, Usage (choice), Title (auto), Description
||Invariant, Description, Expression, Severity (choice), XPath
||Mapping, Source, Target, Id, Title (auto), Description
Additionally, a snippet is provided to help when writing slicing rules. When the start of the phrase
^slicing is detected, a block of rules can be inserted for the paths commonly set when defining slicing on an element.
FSH entity definitions have their names provided as autocomplete results in contextually appropriate scenarios.
- After the
Parent keyword, results will include
Resource names depending on the type of entity being defined.
- After the
InstanceOf keyword, results will include
- When writing an
obeys rule, results will include
When writing rules that apply to an element, element paths will be suggested. This feature is still undergoing development, so there are some known limitations to this feature:
- Completion items are only provided for rules on a
- Slice names are not included as part of completion items.
- Completion items are not provided for indented rules.
- If a type is removed from a choice element with an
only rule, completion items will still be offered for the removed types.
- Elements added to a
Resource by a FSH rule will not be available as completion items for other rules.
- Only the main element path will have completion items provided. A caret rule will not have completion items provided for the caret path.
Go to Definition
FSH entity definitions within your workspace can be found from anywhere their name is used. To go to the entity definition, right-click on the entity name and select "Go to Definition" from the context menu. Or, you can press <F12> when your text cursor is on the entity name.
Open FHIR Documentation
Documentation pages can be opened directly from your FSH files. Right-click on the name of any FHIR resource or FSH keyword, and select "Open FHIR Documentation" from the context menu.
The extension provides a custom task for running SUSHI on the current workspace. The task will run SUSHI on the workspace, log messages to VS Code's integrated Terminal tab, report any errors or warnings in VS Code's Problems tab, and highlight errors and warnings inline in the FSH file. Selecting an error or warning from the Problems tab will open the file the error is in.
Note that after any errors or warnings are resolved in the FSH, SUSHI must be run through the task to resolve them in the Problems tab and inline in the FSH file.
To run the SUSHI Build task, use VS Code's Run Task feature. The "Run Task" feature can be accessed in the "Terminal" menu by clicking "Run Task...". When the menu opens in VS Code, select 'fsh' and then select 'sushi'. The task can also be run using the keyboard shortcut for running build tasks, which is ⇧⌘B on Mac and Ctrl+Shift+B on Windows.
Note that you must have SUSHI installed locally in order for the task to run successfully. See SUSHI Installation instructions for help installing.
Compile and Run (for Developers)
npm install in this folder. This installs all necessary npm modules in both the
client and server folder
- open VS Code on this folder.
- Switch to the Debug viewlet.
Extension from the drop down.
The following NPM tasks may be useful in development:
src/**/*.ts files to
out/**/*.js files using the TypeScript compiler (tsc)
||similar to build but automatically builds when changes are detected in src files
||checks all src files to ensure they follow project code styles and rules
||fixes lint errors when automatic fixes are available for them
||checks all src files to ensure they follow project formatting conventions
||fixes prettier errors by rewriting files using project formatting conventions
||runs the test suite
||runs all the checks performed as part of ci (lint, prettier, test)
To run any of these tasks, use
npm run. For example:
$ npm run build:watch
Note about testing
test task will often (but not always) produce an error if it is run while VSCode is open. If you receive this error, close VSCode and run the task from the command line.
Updating the Grammar
src/lang/ directory contains the FSH lexer and parser. When the FSH grammar changes, the files in this directory will need to be updated. These files are generated in the SUSHI project by running ANTLR on the grammar definition files. The files are then copied from the SUSHI project to this project.
The files to copy are: