Visual Studio Code extension with support for the Fanuc Macro Executor programming language including syntax highlighting, validating and project building.
- Compiling and linking
- Compiler problem matcher
- Syntax/Semantic highlighting
- Syntax validation
- Symbol provider
- Completion provider
- CodeLens
- Lint features
- Sequence number refactoring
- English
en
- Deutsch
de
- 中文
zh-cn
- Macro files
.src
- Include files
.def
- Link files
.lnk
$Include
paths must be absolute or relative to the workspace folder- Uppercase for constants:
@MY_CONSTANT 100
- Space between statements:
O SUB_PROGRAM; N9000 G01 X1; DO 1; END 1; GOTO 1
etc. - A comment of a declaration
@var
/* my comment is displayed on hover and completion
The reference service supports the search for the following types:
- Symbols
- Labels
- Sequence numbers
- GOTO Label/sequence numbers
- M-Codes and G-Codes
- Macro variables (#..)
- Addresses
The search for symbol and label references is global (workspace) if the definitions are included by a definition file .def
, otherwise the search is limited to the current file scope. Sequence numbers only can be found within a file scope (there is currently no function scope available).
Implementations of one of the following types are found by the implementations search service:
- Subprograms
- Label statements
- GOTO Label/Sequence number
The global / local search behavior is equal to the reference search.
- Consecutive numbering on completion (snippet N-Number)
- Command for renumbering sequences (incl. GOTOs)
- Command for adding missing sequences (for NC statements)
Semantic highlighting is used to highlight the represented type of a symbol. Following types are supported:
- M-Code and G-Code
- Address
- Macro variable
- Constant
- Label
For some color themes, the semantic highlighting must be enabled in the settings:
"editor.semanticTokenColorCustomizations": {
"enabled": true,
}
disabled | enabled |
---|---|
The color theme used in screenshot → Noctis
- Symbol highlighting
- Symbol description for hover and completion
Out of the box the extension supports semantic highlighting for Labels (>symbol), Variables (@symbol) and M/G-Codes. Sometimes it could be useful to change the default highlighting for a particular symbol or for a type like a macro variable.
Such a customization can be achieved by adding custom keyword items to the configuration property macro.keywords
in the user/workspace settings:
Keyword item | |
---|---|
symbol | Symbol text |
scope | Scopes |
nodeType | Label, Code (M/G), Variable (all @ symbols) |
description | Markdown string | string[] |
The field nodeType
defines the related type in the macro program. If the field is empty, a keyword item affects all symbol occurrences regardless of the symbols type. E.g. if you want to add a hover text to a particular P-Code variable, an item could be structed as follows:
{
"symbol": "10000",
"nodeType" :"Variable",
"description": "some variable text"
}
Style for compile-time Variable nodeType | |
---|---|
number | Numeric (@var 10000) |
macrovar | Macro variable (@var #10000) |
constant | Constant numeric (@UPPER 10000) |
language | Language constant (e.g. true/false) |
label | Label |
code | M-Code/G-Code |
parameter | NC-Parameter |
address | Address |
These scopes are used internally and are responsible for the symbol style which depends on the chosen color theme like Noctis. To override the style just add rules to the editor.semanticTokenColorCustomizations
configuration property.
In case the default scopes should be unchanged, the additional custom scopes custom_1
- custom_5
could be used:
The following example changes the symbol M08
, which has a default scope code
, to custom_1
and the scope custom_1
is associated with the color red:
"macro.keywords" : [
{
"symbol": "M08",
"scope": "custom_1",
"description": ["*Coolant*", "ON"]
}
],
"editor.semanticTokenColorCustomizations": {
"enabled": true,
"rules": {
"custom_1": "#ff0000"
}
},
The extension supports multi-root workspaces. Each workspace is handled as a separate macro project. This could be useful if a fanuc project consists of several controls e.g machine and handling:
The Lint is configurable by changing the following rules in the settings (user or workspace).
Three levels are supported: error
, warning
and ignore
.
"macro.lint": {
"rules" : {
"duplicateInclude": "error",
"duplicateDeclaration": "error",
"duplicateFunction": "warning",
"duplicateAddress": "ignore",
"duplicateSequence": "warning",
"duplicateLabel": "warning",
"duplicateLabelSequence": "warning",
"unknownSymbol": "error",
"whileLogicOperator": "error",
"doEndNumberTooBig": "error",
"doEndNumberNotEqual": "error",
"nestingTooDeep": "error",
"duplicateDoEndNumber": "warning",
"mixedConditionals": "error",
"tooManyConditionals": "error",
"seqNotFound": "error",
"incompleteParameter": "error",
"includeNotFound": "error",
"assignmentConstant": "warning"
}
Command | Key |
---|---|
Build | Ctrl+Shift+B |
Link / build all | Ctrl+Shift+L |
Clean | Ctrl+Shift+C |
This extension contributes the following settings:
macro.keywords
: Custom Keywordsmacro.lint
: Lint settings and rule configurationmacro.sequence.base
: Sequences start number for refactoringmacro.sequence.increment
: Sequences increment for refactoringmacro.codelens.enable
: Enables or disables the CodeLens function. Deprecated: Please useeditor.codeLens
instead.macro.validate.enable
: Enables or disables the validationmacro.validate.workspace
: Enables or disables the workspace validation
Build settings:
macro.build.compiler
: Selection of the macro compilermacro.build.controlType
: Selection of the control typemacro.build.compilerParams
: Additional compiler parameters: -NR, -L1, -L2, -L3, -PRmacro.build.linkerParams
: Additional linker parameters: -NR, -NL, -Fm, -Frmacro.build.makeFile
: The path to the makefilemacro.project.exportPath
: The path to the directory for the memory card file (.mem)macro.project.sourcePath
: The path to the directory for the source files (.src)macro.project.buildPath
: The path to the directory for the build filesmacro.project.linkPath
: The path to the directory for the link files (.lnk) and the library (.mex)
The building process can be performed by using an external script or the internal system. If an external script is used,
just set the path in macro.build.makeFile
. If a clean
script in the same directory exists, it is used for the cleaning process.
The following parameters are passed to the external script:
- Export directory
- Option [make, clean].
- Compiler
- Control type parameter
If macro.build.makeFile
is empty the internal system is used.
- Currently only working with powershell (select default shell -> powershell)
- The compiler must be available over the system path
- All
.src
files under the foldermacro.project.sourcePath
and its subfolders will be compiled- There are two ways to define a libray path in a link file:
- absolute: CNC=C:\lib.mex
- relative: CNC=..\lnk\lib.mex (relative to
macro.project.buildPath
)
project
│
└───src
│ │ file1.src
│ │ file2.src
│ │
│ └───sub
│ file3.src
│ file4.src
└───def
│ file1.def
│ file2.def
│
└───lnk
│ file1.lnk
│ file2.lnk
│ F30iA_01.MEX
│
└───bin
.rom
.ref
.prg
The path settings could also be empty if no further directory tree is needed
macro.project.exportPath
macro.project.sourcePath
macro.project.buildPath
CNC=..\lnk\F30iA_01.MEX
/* file1.src
$INCLUDE def\file1.def
/* file3.src
$INCLUDE def\file2.def
A convenient way to compile 16 bit macro programs if the host system doesn't support it, is to use Dosbox. Below an example task definition which executes dosbox and passes the build script as command line argument.
{
"label": "Fanuc Macro 16bit build",
"type": "shell",
"command": "C:/Program Files (x86)/DOSBox-0.74-3/DOSBox.exe",
"args": [
"Make.bat",
"-noconsole"
],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": false
},
"problemMatcher": []
}
Special thanks to Pan and Yu for translating the chinese texts
特别感谢潘先生和于先生翻译了中文文本