Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/prerelease_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
with:
python-version: '3.12'
- run: pip install PyYAML
- run: npm ci
- name: Publish to Visual Studio Marketplace
id: publishToVSCMarketplace
uses: HaaLeo/publish-vscode-extension@v1.6.2
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
with:
python-version: '3.12'
- run: pip install PyYAML
- run: npm ci
- name: Publish to Visual Studio Marketplace
id: publishToVSCMarketplace
uses: HaaLeo/publish-vscode-extension@v1.6.2
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
out
*.vsix
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"preLaunchTask": "parseyaml"
"preLaunchTask": "build-extension"
}
]
}
28 changes: 24 additions & 4 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "parseyaml",
"type": "shell",
"command": "py build-grammar.py syntaxes\\mts.tmLanguage.yaml syntaxes\\mts.tmLanguage.json"
"command": "python build-grammar.py syntaxes/mts.tmLanguage.yaml syntaxes/mts.tmLanguage.json",
"problemMatcher": [],
"options": {
"cwd": "${workspaceFolder}"
}
},
{
"label": "compile",
"type": "npm",
"script": "compile",
"problemMatcher": "$tsc",
"options": {
"cwd": "${workspaceFolder}"
}
},
{
"label": "build-extension",
"dependsOn": [
"parseyaml",
"compile"
],
"dependsOrder": "sequence",
"problemMatcher": []
}
]
}
}
16 changes: 11 additions & 5 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# Ignore
# Ignore everything by default; whitelist packaged files.
**

# Keep
!package.json
!language-configuration.json
!CHANGELOG.md
!LICENSE
!images/
!syntaxes/
!language-configuration.json
!images/**
!syntaxes/**
!out/**/*.js
!node_modules/vscode-html-languageservice/**
!node_modules/vscode-languageserver-textdocument/**
!node_modules/vscode-languageserver-types/**
!node_modules/vscode-uri/**
!node_modules/@vscode/l10n/**
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Variable usage before assignment waring.
- For-loop argument validation.

## [0.1.4]

### Added

- `.mtmacro` file extension registered for MapTool Script (same grammar and language configuration as `.mts`).
- **Format Document** for `.mts` / `.mtmacro`: indents macro source by brace nesting.
- Optional formatting of HTML fragments inside string literals, using the workspace HTML formatter rules for those segments.
- Settings under **MapTool Script**:
- `maptoolScript.format.enable` — toggle Format Document (default: on).
- `maptoolScript.format.htmlInSingleQuotedStrings` — format HTML inside single-quoted strings (default: on).
- `maptoolScript.format.htmlInDoubleQuotedStrings` — format HTML inside double-quoted strings (default: off; turning on may insert `"` and break the macro string).

## [0.1.3]

### Fixed
Expand Down
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,41 @@ Visual Studio Code extension for MapTool macro script language support.

## Features

Basic syntax highlighting for MapTool script.
Syntax highlighting and formatting for MapTool macro script (`.mts` and `.mtmacro`).

* Roll Options.
* *Most* nested macros.
* Special variables.
* Separate scopes for built-in vs user-defined fuctions.
* Separate scopes for built-in vs user-defined functions.
* By default built-in functions are bold, but that can be customized by theme.
* RPEdit formatting support.
* **Format Document** indents macro source by brace nesting.
* Optional formatting of HTML fragments inside string literals (see settings below).

![Multi-part example](images/multi-part-macro.png)

## Extension Settings

None yet. :/
Open **Settings** and search for **MapTool Script**, or edit `settings.json`:

| Setting | Default | Description |
| --- | --- | --- |
| `maptoolScript.format.enable` | `true` | Enable **Format Document** for `.mts` / `.mtmacro`. |
| `maptoolScript.format.htmlInSingleQuotedStrings` | `true` | Format HTML inside single-quoted strings. |
| `maptoolScript.format.htmlInDoubleQuotedStrings` | `false` | Format HTML inside double-quoted strings. Off by default because beautified HTML may insert double quotes and break the macro string. |

## Known Issues

This is very basic. So depending on your coding style it may not catch everything.

## Release Notes

### 0.1.4

* `.mtmacro` files use the same MapTool Script language as `.mts`.
* **Format Document** for `.mts` / `.mtmacro` (brace-based indentation).
* Optional formatting of embedded HTML in strings, with settings to control single- vs double-quoted strings.

### 0.1.3

* Fixed colon used for identifying library in macro roll-option breaks highlighting.
Expand Down
87 changes: 85 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 44 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@
"displayName": "MapTool-Script Support",
"description": "Syntax highlighting support for the old MapTool scripting language",
"icon": "images/logo.png",
"version": "0.1.3",
"version": "0.1.4",
"publisher": "bryan-c-jones",
"repository": {
"url" : "https://github.com/Daedeross/maptool-script.vscode"
"url": "https://github.com/Daedeross/maptool-script.vscode"
},
"main": "./out/extension.js",
"engines": {
"vscode": "^1.75.0"
},
"categories": [
"Programming Languages"
],
"activationEvents": [
"onLanguage:mts"
],
"contributes": {
"languages": [
{
Expand All @@ -23,7 +27,8 @@
"mts"
],
"extensions": [
".mts"
".mts",
".mtmacro"
],
"configuration": "./language-configuration.json"
}
Expand All @@ -32,7 +37,10 @@
{
"language": "mts",
"scopeName": "source.mts",
"path": "./syntaxes/mts.tmLanguage.json"
"path": "./syntaxes/mts.tmLanguage.json",
"embeddedLanguages": {
"meta.embedded.block.html": "html"
}
}
],
"configurationDefaults": {
Expand All @@ -49,9 +57,40 @@
}
]
}
},
"configuration": {
"title": "MapTool Script",
"properties": {
"maptoolScript.format.enable": {
"type": "boolean",
"default": true,
"description": "Enable Format Document for MapTool Script (.mts / .mtmacro)."
},
"maptoolScript.format.htmlInSingleQuotedStrings": {
"type": "boolean",
"default": true,
"description": "Format HTML fragments inside single-quoted string literals."
},
"maptoolScript.format.htmlInDoubleQuotedStrings": {
"type": "boolean",
"default": false,
"description": "Format HTML inside double-quoted strings. Disabled by default because beautified HTML often inserts double quotes and breaks the macro string."
}
}
}
},
"scripts": {
"vscode:prepublish": "python build-grammar.py syntaxes/mts.tmLanguage.yaml syntaxes/mts.tmLanguage.json"
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"vscode:prepublish": "python build-grammar.py syntaxes/mts.tmLanguage.yaml syntaxes/mts.tmLanguage.json && npm run compile"
},
"dependencies": {
"vscode-html-languageservice": "^5.6.2",
"vscode-languageserver-textdocument": "^1.0.12"
},
"devDependencies": {
"@types/node": "^25.5.2",
"@types/vscode": "^1.75.0",
"typescript": "^6.0.2"
}
}
41 changes: 41 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import * as vscode from 'vscode';
import { formatWholeDocument } from './formatDocument';

const MTS_SELECTOR: vscode.DocumentSelector = { language: 'mts' };

function readSegmentOptions(doc: vscode.TextDocument) {
const cfg = vscode.workspace.getConfiguration('maptoolScript', doc.uri);
return {
htmlInSingleQuotedStrings: cfg.get<boolean>('format.htmlInSingleQuotedStrings', true),
htmlInDoubleQuotedStrings: cfg.get<boolean>('format.htmlInDoubleQuotedStrings', false),
};
}

export function activate(context: vscode.ExtensionContext): void {
const provider: vscode.DocumentFormattingEditProvider = {
provideDocumentFormattingEdits(document, options) {
const cfg = vscode.workspace.getConfiguration('maptoolScript', document.uri);
if (!cfg.get<boolean>('format.enable', true)) {
return [];
}

const segmentOptions = readSegmentOptions(document);
const tabSize = options.tabSize ?? 4;
const insertSpaces = options.insertSpaces ?? true;
const next = formatWholeDocument(document, segmentOptions, tabSize, insertSpaces);
const fullRange = document.validateRange(
new vscode.Range(0, 0, Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER),
);
if (next === document.getText()) {
return [];
}
return [vscode.TextEdit.replace(fullRange, next)];
},
};

context.subscriptions.push(
vscode.languages.registerDocumentFormattingEditProvider(MTS_SELECTOR, provider),
);
}

export function deactivate(): void {}
Loading