Chinese documentation is available below. Please scroll down.
中文说明在下方,请向下滚动查看。
Nfield ODIN Extension
A VS Code extension for Nfield ODIN script syntax highlighting and tools.
About
This extension was originally created by PhoenixHuang2020 and is now maintained by Jimmy Liu with the original author's permission.
Email:jimmy.liu@kantar.com
Authorization
The original author PhoenixHuang2020 has granted Jimmy Liu the authorization to continue maintaining and modifying this extension.
Features
1. Syntax Highlighting
Provided by syntaxes/nfieldodin.tmLanguage.json (TextMate grammar).
| Element |
Pattern |
Example |
| Keywords |
* followed by word characters |
*QUESTION, *VAR, *IF, *REPEAT |
| Comments |
** at any position |
** This is a comment |
| Strings |
Double-quoted |
"varName", "Hello world" |
| Question references |
Q + number or Q{IDNAME} |
Q123, Q{satisfaction} |
| Option codes |
Number followed by colon |
1:Yes, 02:No |
| Positions |
Digit + L + digit |
1L5, 10L2 |
| Built-in functions |
Predefined function names |
JSON, PROPERTY, DATETIMEADD, STRLENGTH, TO |
| Question numbers |
Number after QUESTION |
*QUESTION 123 → 123 highlighted |
2. Language Configuration
Provided by nfieldodin-configuration.json.
- Line comment:
** — use Ctrl+/ to toggle
- Bracket matching:
{}, [], ()
- Auto-closing pairs:
{}, [], (), ", ', *REPEAT/*ENDREP, *BLOCK/*ENDBLOCK
- Surrounding pairs:
{}, [], (), ", '
3. Outline View (Document Symbols)
Provided by out/documentSymbolProvider.js.
- Shows all
*QUESTION definitions in the outline panel
- Question name format:
Q123(varName) {idName}
(varName) — from *VAR attribute
[dimvarName] — from DIMVAR attribute
{idName} — from *ID attribute
- Different icons for dummy questions (
*DUMMY) vs normal questions
- Shows
*SUBROUTINE definitions
- Shows
*LIST definitions as List_listName
- Shows option codes (
1:Yes) and *USELIST as child items under each question/list
4. Hover Provider
Provided by out/documentHoverProvider.js.
- Hover over
Q123 → shows question definition, question text, and all option codes
- Hover over
Q{idName} → same, matched by *ID attribute
- Also works on
*GOTO 123, *GOTO {idName}, *BACK 123, *BACK {idName}
- Display uses syntax-highlighted code block (MarkdownString with
nfieldodin language)
5. Go to Definition (F12)
Provided by out/documentDefinitionProvider.js.
- F12 on
Q123 → jumps to *QUESTION 123 definition line
- F12 on
Q{idName} → jumps to the question with matching *ID attribute
- F12 on a variable name → jumps to its
*VARS, *TEXTVARS, or *SAMPLEDATA declaration
6. Find All References (Shift+F12)
Provided by out/documentReferenceProvider.js.
- Right-click a variable → "Find All References" or press
Shift+F12
- Supports three variable types:
- Numeric variables (
*VARS)
- String variables (
*TEXTVARS)
- Sample data variables (
*SAMPLEDATA)
- Array variables handled:
ddd[1], ddd[2] all reference ddd
- Comma-separated definitions supported:
*VARS aaa,ddd[10]
- References inside comments (
**) are automatically excluded
7. Code Snippets
Provided by snippets/nfieldodin.json. Type the prefix and press Tab.
| Prefix |
Name |
Description |
QSA |
QuestionSingle |
Single choice question template |
QMA |
QuestionMulti |
Multiple choice question template |
QOP |
QuestionOpen |
Open-ended question template |
QAL |
QuestionAlpha |
Alpha (text) question template |
QNU |
QuestionNumber |
Numeric question template |
QMT |
QuestionGrid |
Grid/matrix question with dummy title and rows |
Sub |
SubRoutine |
Subroutine template with *SUBROUTINE/*ENDSUB |
rank |
Ranking |
Complete ranking question with validation logic |
REP |
Repeat |
Repeat block with *REPEAT/*ENDREP and index variable |
RanOrder |
RandomOrder |
Random order generator using *VARS and *REPEAT |
SEG |
RandomSegment |
9-segment random rotation with *SEGMENT/*ENDSEGMENT |
8. Keyboard Shortcuts
All shortcuts are active only when editing Nfield ODIN files (.Q, .q, .Odin, .odin).
Text Wrapping (requires selected text)
| Shortcut |
Command |
Action |
Alt+1 |
wrapBluebTag |
Wrap selection with <blueb></blueb> |
Alt+2 |
wrapRedbTag |
Wrap selection with <redb></redb> |
Alt+3 |
wrapBTag |
Wrap selection with <b></b> |
Text Transformation (requires selected text)
| Shortcut |
Command |
Action |
Ctrl+1 |
addLineNumbers |
Add sequential numbers with colon to each line (e.g., 1:text, 2:text) |
Ctrl+2 |
addQuestionMark |
Parse selected question text and generate *QUESTION definition with numbered options |
Quick Insert (at cursor position)
| Shortcut |
Command |
Inserted Text |
Alt+C |
insertControl |
*CONTROL Q |
Alt+I |
insertInclude |
*INCLUDE Q |
Alt+O |
insertOrder |
*ORDER |
Q<number> format: e.g., Q1, Q123
Q{IDNAME} format: e.g., Q{satisfaction} — uses *ID attribute for lookup
Usage
Question Definition
*QUESTION 1 *CODE L5 *VAR "q1" *ID "satisfaction"
您对本次服务满意吗?
1:非常满意
2:满意
3:一般
4:不满意
5:非常不满意
Question References
Q1
Q{satisfaction}
File Structure
nfieldodin-LOCAL/
├── package.json # Extension manifest (commands, keybindings, language config)
├── nfieldodin-configuration.json # Language configuration (comments, brackets, auto-closing)
├── .vsixmanifest # VSIX package manifest for publishing
├── icon.png # Extension icon
├── README.md # This file
├── CHANGELOG.md # Change log
├── LICENSE.txt # MIT License
├── 文件说明.md # Internal development notes (Chinese)
├── syntaxes/
│ └── nfieldodin.tmLanguage.json # TextMate grammar for syntax highlighting
├── snippets/
│ └── nfieldodin.json # Code snippets definitions
└── out/ # Compiled JavaScript (entry point)
├── extension.js # Main entry: registers all providers and commands
├── documentSymbolProvider.js # Outline view provider
├── documentHoverProvider.js # Hover tooltip provider
├── documentDefinitionProvider.js # Go to Definition provider
└── documentReferenceProvider.js # Find All References provider
Changelog
See CHANGELOG.md for detailed changes.
以下是中文说明
Below is the Chinese documentation
Nfield ODIN 插件
一个用于 Nfield ODIN 脚本语法高亮和辅助工具的 VS Code 插件。
关于
本插件最初由 PhoenixHuang2020 创建,现经原作者授权由 Jimmy Liu 继续维护。
授权
原作者 PhoenixHuang2020 已授权 Jimmy Liu 继续维护和修改本插件。
功能说明
1. 语法高亮
由 syntaxes/nfieldodin.tmLanguage.json(TextMate 语法文件)提供。
| 元素 |
匹配模式 |
示例 |
| 关键字 |
* 开头的单词 |
*QUESTION、*VAR、*IF、*REPEAT |
| 注释 |
** 开头 |
** 这是注释 |
| 字符串 |
双引号包裹 |
"varName"、"Hello world" |
| 问题引用 |
Q + 数字 或 Q{ID名} |
Q123、Q{satisfaction} |
| 选项代码 |
数字加冒号 |
1:是、02:否 |
| 位置标记 |
数字 + L + 数字 |
1L5、10L2 |
| 内置函数 |
预定义函数名 |
JSON、PROPERTY、DATETIMEADD、STRLENGTH、TO |
| 问题编号 |
QUESTION 后的数字 |
*QUESTION 123 → 123 高亮 |
2. 语言配置
由 nfieldodin-configuration.json 提供。
- 行注释:
** — 使用 Ctrl+/ 切换注释
- 括号匹配:
{}、[]、()
- 自动闭合对:
{}、[]、()、"、'、*REPEAT/*ENDREP、*BLOCK/*ENDBLOCK
- 包围选择对:
{}、[]、()、"、'
3. 大纲视图(文档符号)
由 out/documentSymbolProvider.js 提供。
- 在大纲面板显示所有
*QUESTION 定义
- 问题名称格式:
Q123(varName) {idName}
(varName) — 来自 *VAR 属性
[dimvarName] — 来自 DIMVAR 属性
{idName} — 来自 *ID 属性
- 虚拟问题(
*DUMMY)和真实问题使用不同图标
- 显示
*SUBROUTINE 子例程定义
- 显示
*LIST 列表定义,名称为 List_列表名
- 在每个问题/列表下显示选项代码(
1:是)和 *USELIST 作为子项
4. 悬停提示
由 out/documentHoverProvider.js 提供。
- 鼠标悬停在
Q123 上 → 显示问题定义、问题文本和所有选项代码
- 鼠标悬停在
Q{idName} 上 → 通过 *ID 属性匹配,显示相同内容
- 同时支持
*GOTO 123、*GOTO {idName}、*BACK 123、*BACK {idName}
- 使用语法高亮的代码块显示(MarkdownString,语言为
nfieldodin)
5. 跳转到定义(F12)
由 out/documentDefinitionProvider.js 提供。
- F12 点击
Q123 → 跳转到 *QUESTION 123 定义行
- F12 点击
Q{idName} → 跳转到匹配 *ID 属性的问题定义
- F12 点击变量名 → 跳转到
*VARS、*TEXTVARS 或 *SAMPLEDATA 声明位置
6. 查找所有引用(Shift+F12)
由 out/documentReferenceProvider.js 提供。
- 右键点击变量 → "查找所有引用" 或按
Shift+F12
- 支持三种变量类型:
- 数值变量(
*VARS)
- 字符串变量(
*TEXTVARS)
- 样本数据变量(
*SAMPLEDATA)
- 数组变量处理:
ddd[1]、ddd[2] 都引用变量 ddd
- 支持逗号分隔的多变量定义:
*VARS aaa,ddd[10]
- 注释(
**)中的引用自动排除
7. 代码片段
由 snippets/nfieldodin.json 提供。输入前缀后按 Tab 展开。
| 前缀 |
名称 |
说明 |
QSA |
单选题 |
单选题模板 |
QMA |
多选题 |
多选题模板 |
QOP |
开放题 |
开放式问题模板 |
QAL |
文本题 |
字母文本题模板 |
QNU |
数字题 |
数字题模板 |
QMT |
矩阵题 |
矩阵/网格题模板,含虚拟标题和行 |
Sub |
子例程 |
子例程模板,含 *SUBROUTINE/*ENDSUB |
rank |
排序题 |
完整排序题模板,含校验逻辑 |
REP |
循环块 |
循环块模板,含 *REPEAT/*ENDREP 和索引变量 |
RanOrder |
随机顺序 |
随机顺序生成器,使用 *VARS 和 *REPEAT |
SEG |
随机分段 |
9 段随机轮换模板,使用 *SEGMENT/*ENDSEGMENT |
8. 快捷键
所有快捷键仅在编辑 Nfield ODIN 文件时生效(.Q、.q、.Odin、.odin)。
文字包裹(需先选中文本)
| 快捷键 |
命令 |
功能 |
Alt+1 |
wrapBluebTag |
用 <blueb></blueb> 包裹选中文字 |
Alt+2 |
wrapRedbTag |
用 <redb></redb> 包裹选中文字 |
Alt+3 |
wrapBTag |
用 <b></b> 包裹选中文字(加粗标记) |
文本转换(需先选中文本)
| 快捷键 |
命令 |
功能 |
Ctrl+1 |
addLineNumbers |
为每行添加序号和冒号(如 1:text、 2:text) |
Ctrl+2 |
addQuestionMark |
解析选中的问题文本,生成带编号选项的 *QUESTION 定义 |
快速插入(在光标位置)
| 快捷键 |
命令 |
插入内容 |
Alt+C |
insertControl |
*CONTROL Q |
Alt+I |
insertInclude |
*INCLUDE Q |
Alt+O |
insertOrder |
*ORDER |
9. 问题引用格式
Q数字 格式:如 Q1、Q123
Q{ID名} 格式:如 Q{satisfaction} — 通过 *ID 属性查找
使用示例
问题定义
*QUESTION 1 *CODE L5 *VAR "q1" *ID "satisfaction"
您对本次服务满意吗?
1:非常满意
2:满意
3:一般
4:不满意
5:非常不满意
问题引用
Q1
Q{satisfaction}
文件结构
nfieldodin-LOCAL/
├── package.json # 插件清单(命令、快捷键、语言配置)
├── nfieldodin-configuration.json # 语言配置(注释、括号、自动闭合)
├── .vsixmanifest # VSIX 打包清单
├── icon.png # 插件图标
├── README.md # 本文件
├── CHANGELOG.md # 变更日志
├── LICENSE.txt # MIT 许可证
├── 文件说明.md # 内部开发说明
├── syntaxes/
│ └── nfieldodin.tmLanguage.json # TextMate 语法高亮定义
├── snippets/
│ └── nfieldodin.json # 代码片段定义
└── out/ # 编译后的 JavaScript
├── extension.js # 主入口:注册所有功能提供者和命令
├── documentSymbolProvider.js # 大纲视图提供者
├── documentHoverProvider.js # 悬停提示提供者
├── documentDefinitionProvider.js # 跳转定义提供者
└── documentReferenceProvider.js # 查找引用提供者
变更日志
详见 CHANGELOG.md。