Mistake on this page? Email us

Code editing

Mbed Studio provides C and C++ language support using the clangd language server and the Language Server Protocol (LSP). Mbed Studio includes a variety of navigation features and IntelliSense code editing features to help you code faster and more efficiently. IntelliSense is available for stand-alone files or for multiple files that are part of the same program.

Note: You need to set a target and an active program to get all IntelliSense features.

Quick file navigation

To follow a link included in your code or find a file where a code element has been defined, hold Cmd (macOS) or Ctrl (Windows and Linux) and click the link or the code element. The file opens in a new tab and is directly accessible from the Explorer view.

Navigating to a file.

Bracket and quote highlighting

By default, the editor highlights the matching brackets or quotes when your cursor is over them. When you type the left bracket or quote, the editor automatically inserts the matching right bracket or quote.

Source hover

Additional information about the code elements you are hovering over in your code is displayed in popups.

Displaying additional information.

Go to Definition and Peek Definition

You can jump to the definition of a code element with the Go to Definition and Peek Definition options.

Hover over the code element, right-click and select one of these options:

  • Go to Definition: This option opens the file where the element is defined in a separate tab.
  • Peek > Peek Definition: This option also takes you to the definition of an element but the definition is presented inline.

Definition presented inline with the Peek Definition option.

Go to References and Peek References

You can find the references to a code element throughout all the files of an active program with the Go to References and Peek References options. These two options show the code element references inline (or, if there is only one reference, the Go to References option takes you directly to the element). You can navigate between references and make edits in the inline editor. Double-click a reference to open the file or files where the code element appears.

Hover over the code element, right-click and select one of the options.

You can edit directly in the inline editor.

Go to Symbol

To perform a focused search of your code and quickly find symbols: right-click anywhere in the editor and select Go to Symbol.... The search bar displays the available symbols in the file you are currently working on. Select a symbol to directly go to it.

Go to Symbol... option.

Outline view

The Outline view gives you a tree view of the classes, variables and functions in the current file.

From the View menu, select Outline or click the Outline button at the top-right corner of the screen. Click the elements in the Outline view to navigate through the file.

In the Outline view, orange icons represent classes, white icons represent variables and purple icons represent functions.

Editing and refactoring your code

Auto-completion and signature help

When you start typing a keyword, type, function, variable name, or other program element that Mbed Studio recognizes, the editor offers to complete what you are typing. A drop-down list with possible options opens where you can select what you need. The list also shows an icon that represents the code entity of each option (for example namespace, function, class or variable), and signature help for parameters of functions. Clicking the "i" icon gives you more details on each option.

You can trigger auto-complete and help for existing code by pressing Ctrl+Space.

Auto-completion and "i" icon.

Renaming

If you want to rename an element in your code such as a class, a function, or a variable, use the Rename symbol option. This option renames all the occurrences of a symbol in the file you are currently working on.

To find and replace a string everywhere in the file you are currently working on, use the Change All Occurrences option.

Renaming a symbol.

Code formatting

The Format Document and Format Selection options allow you to indent your code correctly. If you select Format Document, the indentation is corrected in the whole file you are currently working on. If you select Format Selection, then only the line or lines of code you selected are indented properly.

Changing the indentation with Format Selection.

You can change the indentation by clicking the Spaces / Tab Size option on the right-hand side of the status bar.

Clicking Spaces or Tab Size opens a drop-down list at the top of the editor. Select Indent Using Spaces / Indent Using Tabs in the drop-down list, then select the number of spaces / tabs to use for the indentation.

Selecting the number of spaces / tabs.

Fix-its, Peek Problem and Quick Fix

Fix-its offer suggestions to correct problems in your code, for example a missing bracket or semicolon. Click an element underlined with a squiggly line to display corrections. A light bulb icon appears next to the problematic line. Click the light bulb and check the correction suggested. If you are happy with the suggestion, click the popup message.

Fix-it example.

Similarly, you can use the Peek Problem and Quick Fix... options to correct your code. Hover over a red squiggly line in your code to display these options. Peek Problem shows the errors inline. Quick Fix... works the same way as fix-its, click the popup message to apply a correction.

Peek problem example.

Problems view

When Mbed Studio detects problems in your code, it lists them in the Problems view. To open the view, go the View menu and select Problems, or click the Problems option in the status bar.

Opening the Problems view from the status bar.

Refactoring

Mbed Studio supports refactoring operations such as extract function and extract variable.

Extract function

Source code fragments can be extracted into a new function.

Select the source code you would like to extract and then right-click the code and select Refactor.... An Extract to function popup message appears. Click the popup message to refactor the code.

Alternatively, you can click the light bulb next to the code you want to refactor.

Extract to function refactoring example.

Extract variable

You can create a new local variable for the currently selected expression.

Select the source code you would like to extract and then right-click the code and select Refactor.... An Extract subexpression to variable popup message appears. Click the popup message to refactor the code.

Alternatively, you can click the light bulb next to the code you want to refactor.

Extract to variable refactoring example.

Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.