@duet3d/monacotokens 3.6.1 → 3.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/expressions/expressions.json +277 -0
- package/dist/expressions/index.d.ts +24 -0
- package/dist/expressions/index.js +2 -0
- package/dist/gcodes/gcodes.json +5821 -0
- package/dist/gcodes/index.d.ts +60 -0
- package/dist/gcodes/index.js +17 -0
- package/dist/gcodes/local-variables.d.ts +26 -0
- package/dist/gcodes/local-variables.js +62 -0
- package/dist/gcodes/search.d.ts +17 -0
- package/dist/gcodes/search.js +589 -0
- package/dist/monaco-gcode.js +17 -6
- package/dist/monaco-menu.d.ts +3 -0
- package/dist/monaco-menu.js +32 -0
- package/dist/monaco-stm32.d.ts +3 -0
- package/dist/monaco-stm32.js +81 -0
- package/dist/objectmodel/deprecations.d.ts +12 -0
- package/dist/objectmodel/deprecations.js +42 -0
- package/dist/objectmodel/enums.d.ts +4 -0
- package/dist/objectmodel/enums.js +17 -0
- package/dist/objectmodel/machine-context.d.ts +33 -0
- package/dist/objectmodel/machine-context.js +30 -0
- package/dist/objectmodel/paths.d.ts +3 -0
- package/dist/objectmodel/paths.js +5 -0
- package/dist/providers.d.ts +55 -0
- package/dist/providers.js +1581 -0
- package/dist/register.d.ts +13 -0
- package/dist/register.js +73 -0
- package/package.json +1 -1
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export const stm32Language = {
|
|
2
|
+
keywordsPrimary: ["8266wifi", "accelerometer", "atx", "board", "heat", "lcd", "led", "leds", "pins", "power", "sbc", "sdCard", "serial", "SPI0", "SPI1", "SPI2", "SPI3", "SPI4", "SPI5", "SPI6", "SPI7", "SPI8", "stepper"],
|
|
3
|
+
keywordsSecondary: ["clockReg", "csPin", "espDataReadyPin", "espResetPin", "TfrReadyPin", "serialRxTxPins", "spiChannel", "initialPowerOn", "powerPin", "powerPinInverted", "spiTempSensorChannel", "spiTempSensorCSPins", "tempSensePins", "thermistorSeriesResistor", "encoderPinA", "encoderPinB", "encoderPinSw", "lcdBeepPin", "lcdCSPin", "lcdDCPin", "panelButtonPin", "neopixelPin", "activity", "activityOn", "diagnostic", "diagnosticOn", "SetHigh", "SetLow", "VInDetectPin", "voltage", "loadConfig", "external", "internal", "aux", "aux2", "pins", "directionPins", "enablePins", "numSmartDrivers", "num5160Drivers", "stepPins", "TmcDiagPins", "TmcUartPins"],
|
|
4
|
+
keywordsTertiary: ["cardDetectPin", "csPin", "spiChannel", "spiFrequencyHz", "spiFrequencyHz", "rxTxPins", "rxTxPins"],
|
|
5
|
+
symbols: /[=><!~?:&|+\-*#\/\^%]+/,
|
|
6
|
+
operators: ['*', '/', '+', '-', "==", "!=", '=', "<=", '<', ">=", ">>>", ">>", '>', '!', "&&", '&', "||", '|', '^', '?', ':'],
|
|
7
|
+
includeLF: true,
|
|
8
|
+
tokenizer: {
|
|
9
|
+
root: [
|
|
10
|
+
// keywords
|
|
11
|
+
[/[a-zA-Z0-9_$][\w$]*/, {
|
|
12
|
+
cases: {
|
|
13
|
+
"@keywordsPrimary": { token: "keyword" },
|
|
14
|
+
"@keywordsSecondary": { token: "keyword" },
|
|
15
|
+
"@keywordsTertiary": { token: "keyword" }
|
|
16
|
+
}
|
|
17
|
+
}],
|
|
18
|
+
// comments
|
|
19
|
+
[/\/\/.*/, "comment"],
|
|
20
|
+
[/;.*/, "comment"],
|
|
21
|
+
// expressions
|
|
22
|
+
[/{/, "operator", "@curlyBracket"],
|
|
23
|
+
// expressions
|
|
24
|
+
[/=/, "operator", "@equals"],
|
|
25
|
+
],
|
|
26
|
+
expression: [
|
|
27
|
+
// numbers
|
|
28
|
+
[/\d+/, "number"],
|
|
29
|
+
// Pin Numbers
|
|
30
|
+
[/[a-iA-I]\.\d+/, "string"],
|
|
31
|
+
[/[a-iA-I]\_\d+/, "string"],
|
|
32
|
+
[/[a-iA-I]\d+/, "string"],
|
|
33
|
+
[/P[a-iA-I]\.\d+/, "string"],
|
|
34
|
+
[/P[a-iA-I]\_\d+/, "string"],
|
|
35
|
+
[/P[a-iA-I]\d+/, "string"],
|
|
36
|
+
[/NoPin/, "string"],
|
|
37
|
+
// strings
|
|
38
|
+
[/"(.|\"\")*?"/, "string"],
|
|
39
|
+
[/[a-zA-Z0-9_$][\w$]*/, "string"],
|
|
40
|
+
// operators
|
|
41
|
+
[/@symbols/, {
|
|
42
|
+
cases: {
|
|
43
|
+
"@operators": "operator",
|
|
44
|
+
"@default": ""
|
|
45
|
+
}
|
|
46
|
+
}],
|
|
47
|
+
// comments
|
|
48
|
+
[/;.*/, "comment"],
|
|
49
|
+
// EOL
|
|
50
|
+
[/\n/, "", "@popall"],
|
|
51
|
+
],
|
|
52
|
+
curlyBracket: [
|
|
53
|
+
// curly brackets contain expressions
|
|
54
|
+
{ include: "expression" },
|
|
55
|
+
// terminate when reaching a closing bracket
|
|
56
|
+
[/}/, "operator", "@pop"],
|
|
57
|
+
],
|
|
58
|
+
equals: [
|
|
59
|
+
// curly brackets contain expressions
|
|
60
|
+
{ include: "expression" },
|
|
61
|
+
// EOL
|
|
62
|
+
[/\n/, "", "@popall"],
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
export const stm32LanguageConfiguration = {
|
|
67
|
+
comments: {
|
|
68
|
+
lineComment: ";"
|
|
69
|
+
},
|
|
70
|
+
brackets: [
|
|
71
|
+
["{", "}"]
|
|
72
|
+
],
|
|
73
|
+
autoClosingPairs: [
|
|
74
|
+
{ open: "{", close: "}" },
|
|
75
|
+
{ open: "\"", close: "\"" }
|
|
76
|
+
],
|
|
77
|
+
surroundingPairs: [
|
|
78
|
+
{ open: "{", close: "}" },
|
|
79
|
+
{ open: "\"", close: "\"" }
|
|
80
|
+
]
|
|
81
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Look up the deprecation message for a full object-model path (with literal numeric indices) or any of its
|
|
3
|
+
* prefixes. Returns the deprecation message when the path itself or a containing path is deprecated (the
|
|
4
|
+
* shallowest match wins so the user sees the root cause, e.g. `move.rotation.angle` reports `move.rotation`
|
|
5
|
+
* as deprecated). Returns null when neither the path nor any prefix is deprecated.
|
|
6
|
+
*/
|
|
7
|
+
export declare function getPathDeprecation(path: string): string | null;
|
|
8
|
+
/**
|
|
9
|
+
* Look up the deprecation message for `parentPath + "." + field`. `parentPath` is the dotted path of the parent
|
|
10
|
+
* value from the root (e.g. `move.extruders[0]`), or empty for a top-level field. Returns null if not deprecated.
|
|
11
|
+
*/
|
|
12
|
+
export declare function getMemberDeprecation(parentPath: string, field: string): string | null;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import deprecationsJson from "@duet3d/objectmodel/deprecations.json";
|
|
2
|
+
import { normalisePath } from "./paths";
|
|
3
|
+
/**
|
|
4
|
+
* Map of full object-model paths (with `[]` standing for any array index) to the deprecation message extracted
|
|
5
|
+
* from the property's `@deprecated` JSDoc tag. Built by @duet3d/objectmodel's build script from its TS sources.
|
|
6
|
+
*/
|
|
7
|
+
const deprecations = deprecationsJson;
|
|
8
|
+
/**
|
|
9
|
+
* Look up the deprecation message for a full object-model path (with literal numeric indices) or any of its
|
|
10
|
+
* prefixes. Returns the deprecation message when the path itself or a containing path is deprecated (the
|
|
11
|
+
* shallowest match wins so the user sees the root cause, e.g. `move.rotation.angle` reports `move.rotation`
|
|
12
|
+
* as deprecated). Returns null when neither the path nor any prefix is deprecated.
|
|
13
|
+
*/
|
|
14
|
+
export function getPathDeprecation(path) {
|
|
15
|
+
if (!path) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
const key = normalisePath(path);
|
|
19
|
+
// Walk prefixes from shallowest to deepest; first hit wins
|
|
20
|
+
let cursor = 0;
|
|
21
|
+
while (cursor < key.length) {
|
|
22
|
+
// Advance to the next boundary (dot or closing bracket that ends a step)
|
|
23
|
+
let next = key.indexOf(".", cursor);
|
|
24
|
+
if (next < 0) {
|
|
25
|
+
next = key.length;
|
|
26
|
+
}
|
|
27
|
+
const prefix = key.substring(0, next);
|
|
28
|
+
if (Object.prototype.hasOwnProperty.call(deprecations, prefix)) {
|
|
29
|
+
return deprecations[prefix];
|
|
30
|
+
}
|
|
31
|
+
cursor = next + 1;
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Look up the deprecation message for `parentPath + "." + field`. `parentPath` is the dotted path of the parent
|
|
37
|
+
* value from the root (e.g. `move.extruders[0]`), or empty for a top-level field. Returns null if not deprecated.
|
|
38
|
+
*/
|
|
39
|
+
export function getMemberDeprecation(parentPath, field) {
|
|
40
|
+
const fullPath = parentPath ? `${parentPath}.${field}` : field;
|
|
41
|
+
return getPathDeprecation(fullPath);
|
|
42
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import enumValuesJson from "@duet3d/objectmodel/enums.json";
|
|
2
|
+
import { normalisePath } from "./paths";
|
|
3
|
+
/**
|
|
4
|
+
* Map of full object-model paths (with `[]` standing for any array index) to the list of valid enum / string-
|
|
5
|
+
* literal values the field can take. Generated by @duet3d/objectmodel's build script from its TS sources.
|
|
6
|
+
*/
|
|
7
|
+
const enumValues = enumValuesJson;
|
|
8
|
+
/**
|
|
9
|
+
* Return the list of valid values for a given object-model path, or null if the path has no known enum values.
|
|
10
|
+
*/
|
|
11
|
+
export function getEnumValuesForPath(path) {
|
|
12
|
+
if (!path) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
const key = normalisePath(path);
|
|
16
|
+
return Object.prototype.hasOwnProperty.call(enumValues, key) ? enumValues[key] : null;
|
|
17
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ObjectModel } from "@duet3d/objectmodel";
|
|
2
|
+
/**
|
|
3
|
+
* Runtime context describing the currently connected machine. Completion and hover providers read this to surface
|
|
4
|
+
* machine-specific information (visible axes, configured extruders, object-model fields) alongside the static
|
|
5
|
+
* gcode/expression datasets bundled with this package.
|
|
6
|
+
*
|
|
7
|
+
* Framework-agnostic: Vue, React, or any other consumer just calls `setMachineContext` when its model reference
|
|
8
|
+
* becomes available or changes. The reference is expected to stay stable - providers read field values through
|
|
9
|
+
* the reference at completion time so state mutations inside the object model are picked up automatically.
|
|
10
|
+
*/
|
|
11
|
+
export interface MachineContext {
|
|
12
|
+
/** Live machine object-model reference. */
|
|
13
|
+
readonly model: ObjectModel;
|
|
14
|
+
/**
|
|
15
|
+
* Optional callback that returns a Markdown/HTML description for an object-model path (with `[]` placeholders
|
|
16
|
+
* for collection items, e.g. `move.extruders[].pressureAdvance`). Used by the hover provider to surface the
|
|
17
|
+
* DuetAPI.xml documentation. Return `null` when no description is available. May be async - the hover provider
|
|
18
|
+
* awaits the result so callbacks can lazily fetch the docs on first hover without losing the popup.
|
|
19
|
+
*/
|
|
20
|
+
readonly getObjectModelDescription?: (path: string) => string | null | Promise<string | null>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Set (or clear) the runtime machine context. Pass `null` when the machine is disconnected.
|
|
24
|
+
*/
|
|
25
|
+
export declare function setMachineContext(context: MachineContext | null): void;
|
|
26
|
+
/**
|
|
27
|
+
* Get the currently installed machine context, or null when no machine is connected.
|
|
28
|
+
*/
|
|
29
|
+
export declare function getMachineContext(): MachineContext | null;
|
|
30
|
+
/**
|
|
31
|
+
* Subscribe to machine-context changes. Returns an unsubscribe function.
|
|
32
|
+
*/
|
|
33
|
+
export declare function onMachineContextChange(listener: () => void): () => void;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
let current = null;
|
|
2
|
+
const listeners = new Set();
|
|
3
|
+
/**
|
|
4
|
+
* Set (or clear) the runtime machine context. Pass `null` when the machine is disconnected.
|
|
5
|
+
*/
|
|
6
|
+
export function setMachineContext(context) {
|
|
7
|
+
current = context;
|
|
8
|
+
for (const listener of listeners) {
|
|
9
|
+
try {
|
|
10
|
+
listener();
|
|
11
|
+
}
|
|
12
|
+
catch (e) {
|
|
13
|
+
// Listener threw - don't let it break other listeners
|
|
14
|
+
console.error("[monacotokens] machine-context listener threw:", e);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get the currently installed machine context, or null when no machine is connected.
|
|
20
|
+
*/
|
|
21
|
+
export function getMachineContext() {
|
|
22
|
+
return current;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Subscribe to machine-context changes. Returns an unsubscribe function.
|
|
26
|
+
*/
|
|
27
|
+
export function onMachineContextChange(listener) {
|
|
28
|
+
listeners.add(listener);
|
|
29
|
+
return () => listeners.delete(listener);
|
|
30
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type * as monaco from "monaco-editor-core/esm/vs/editor/editor.api.js";
|
|
2
|
+
export { getMachineContext, onMachineContextChange } from "./objectmodel/machine-context";
|
|
3
|
+
/**
|
|
4
|
+
* Flatten a machine object-model snapshot into a list of dotted paths (with `[0]` placeholders for arrays).
|
|
5
|
+
* Walks the entire reachable subtree; arrays contribute a single representative `[0]` entry so the list
|
|
6
|
+
* doesn't explode on machines with many tools/axes. Cycles are guarded via a visited WeakSet.
|
|
7
|
+
*/
|
|
8
|
+
export declare function flattenObjectModel(root: any): string[];
|
|
9
|
+
/**
|
|
10
|
+
* Detect whether the cursor sits inside an RRF expression context:
|
|
11
|
+
* - inside a balanced-but-still-open `{ ... }` span, OR
|
|
12
|
+
* - after an `=` on a `set|var|global` line (whole line is expression territory), OR
|
|
13
|
+
* - after `if|elif|while` (condition is an expression).
|
|
14
|
+
*/
|
|
15
|
+
export declare function isInsideExpression(beforeCursor: string): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Find the closest G/M/T-code to the left of `column` on the given line.
|
|
18
|
+
* Returns the matched code (e.g. "G1") and the column where it starts, or null.
|
|
19
|
+
*
|
|
20
|
+
* A bare `T` is only treated as its own code when it's the first code on the line; otherwise it's a parameter
|
|
21
|
+
* letter of the preceding command (e.g. `M104 T1` - the T belongs to M104, not a separate `T` code).
|
|
22
|
+
*/
|
|
23
|
+
export declare function findCodeAtCursor(line: string, column: number): {
|
|
24
|
+
code: string;
|
|
25
|
+
startColumn: number;
|
|
26
|
+
} | null;
|
|
27
|
+
/**
|
|
28
|
+
* Register Duet-specific completion and hover providers for a language id.
|
|
29
|
+
*/
|
|
30
|
+
export declare function registerProvidersFor(monacoInstance: typeof monaco, languageId: string): monaco.IDisposable[];
|
|
31
|
+
/**
|
|
32
|
+
* Register Duet completion and hover providers for both gcode-fdm and gcode-cnc languages.
|
|
33
|
+
*/
|
|
34
|
+
export declare function registerDuetProviders(monacoInstance: typeof monaco): monaco.IDisposable[];
|
|
35
|
+
/**
|
|
36
|
+
* Attach a per-editor cursor-position watcher that closes the signature-help tooltip immediately when the cursor
|
|
37
|
+
* moves to a position where our provider would return null (between parameters, before the code, on a different line).
|
|
38
|
+
* Monaco only re-invokes the signature-help provider on content changes, so this bridges arrow-key / click movement.
|
|
39
|
+
* Call this once per editor right after `monaco.editor.create(...)`.
|
|
40
|
+
*/
|
|
41
|
+
export declare function attachGcodeSignatureHelpWatcher(editor: monaco.editor.IStandaloneCodeEditor): monaco.IDisposable;
|
|
42
|
+
/**
|
|
43
|
+
* Apply a strikethrough decoration (class `duet-deprecated-code`) to every occurrence of a deprecated G/M/T-code
|
|
44
|
+
* (e.g. `M557`) and to every deprecated parameter letter belonging to any G/M/T-code on that line (e.g. the `S` in
|
|
45
|
+
* `M84 S`). Re-runs on every content change; hover tooltip carries the deprecation reason.
|
|
46
|
+
* Call once per editor; the returned IDisposable removes the listener and clears the decorations.
|
|
47
|
+
*/
|
|
48
|
+
export declare function attachGcodeDeprecationDecorations(editor: monaco.editor.IStandaloneCodeEditor): monaco.IDisposable;
|
|
49
|
+
/**
|
|
50
|
+
* Strike-through deprecated object-model paths that appear in the editor. Matches dotted chains like
|
|
51
|
+
* `move.extruders[0].pressureAdvance`, normalises the bracket indices to `[]`, and highlights the chain if
|
|
52
|
+
* the normalised path is present in the deprecations map shipped by @duet3d/objectmodel. Re-runs on every
|
|
53
|
+
* content change; hover tooltip carries the deprecation reason.
|
|
54
|
+
*/
|
|
55
|
+
export declare function attachObjectModelDeprecationDecorations(editor: monaco.editor.IStandaloneCodeEditor): monaco.IDisposable;
|