sfmc-language-lsp 0.1.3 → 0.2.0
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/README.md +25 -0
- package/dist/cjs/codeActions/ampscript.cjs +17 -2
- package/dist/cjs/codeActions/ampscript.d.ts +7 -1
- package/dist/cjs/codeActions/ampscript.d.ts.map +1 -1
- package/dist/cjs/codeActions/ampscript.js.map +1 -1
- package/dist/cjs/completions/ampscript.cjs +18 -4
- package/dist/cjs/completions/ampscript.d.ts +11 -2
- package/dist/cjs/completions/ampscript.d.ts.map +1 -1
- package/dist/cjs/completions/ampscript.js.map +1 -1
- package/dist/cjs/completions/ssjs.cjs +221 -19
- package/dist/cjs/completions/ssjs.d.ts +5 -1
- package/dist/cjs/completions/ssjs.d.ts.map +1 -1
- package/dist/cjs/completions/ssjs.js.map +1 -1
- package/dist/cjs/data/ampscript.cjs +6 -1
- package/dist/cjs/data/ampscript.d.ts.map +1 -1
- package/dist/cjs/data/ampscript.js.map +1 -1
- package/dist/cjs/data/ssjs.cjs +14 -4
- package/dist/cjs/data/ssjs.d.ts +7 -1
- package/dist/cjs/data/ssjs.d.ts.map +1 -1
- package/dist/cjs/data/ssjs.js.map +1 -1
- package/dist/cjs/definitions/ssjs.cjs +15 -2
- package/dist/cjs/definitions/ssjs.d.ts +6 -0
- package/dist/cjs/definitions/ssjs.d.ts.map +1 -1
- package/dist/cjs/definitions/ssjs.js.map +1 -1
- package/dist/cjs/hover/ampscript.cjs +14 -3
- package/dist/cjs/hover/ampscript.d.ts +6 -1
- package/dist/cjs/hover/ampscript.d.ts.map +1 -1
- package/dist/cjs/hover/ampscript.js.map +1 -1
- package/dist/cjs/hover/ssjs.cjs +197 -35
- package/dist/cjs/hover/ssjs.d.ts +7 -1
- package/dist/cjs/hover/ssjs.d.ts.map +1 -1
- package/dist/cjs/hover/ssjs.js.map +1 -1
- package/dist/cjs/index.cjs +116 -27
- package/dist/cjs/index.d.ts +77 -16
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/signature/ampscript.cjs +11 -3
- package/dist/cjs/signature/ampscript.d.ts +7 -1
- package/dist/cjs/signature/ampscript.d.ts.map +1 -1
- package/dist/cjs/signature/ampscript.js.map +1 -1
- package/dist/cjs/signature/ssjs.cjs +41 -18
- package/dist/cjs/signature/ssjs.d.ts +8 -1
- package/dist/cjs/signature/ssjs.d.ts.map +1 -1
- package/dist/cjs/signature/ssjs.js.map +1 -1
- package/dist/cjs/utils/comments.cjs +11 -2
- package/dist/cjs/utils/comments.d.ts +11 -2
- package/dist/cjs/utils/comments.d.ts.map +1 -1
- package/dist/cjs/utils/comments.js.map +1 -1
- package/dist/cjs/utils/markdown.cjs +32 -7
- package/dist/cjs/utils/markdown.d.ts +30 -6
- package/dist/cjs/utils/markdown.d.ts.map +1 -1
- package/dist/cjs/utils/markdown.js.map +1 -1
- package/dist/cjs/utils/positions.cjs +19 -4
- package/dist/cjs/utils/positions.d.ts +18 -3
- package/dist/cjs/utils/positions.d.ts.map +1 -1
- package/dist/cjs/utils/positions.js.map +1 -1
- package/dist/cjs/utils/regions.cjs +8 -0
- package/dist/cjs/utils/regions.d.ts +8 -0
- package/dist/cjs/utils/regions.d.ts.map +1 -1
- package/dist/cjs/utils/regions.js.map +1 -1
- package/dist/cjs/utils/text.cjs +22 -2
- package/dist/cjs/utils/text.d.ts +22 -2
- package/dist/cjs/utils/text.d.ts.map +1 -1
- package/dist/cjs/utils/text.js.map +1 -1
- package/dist/cjs/validators/ampscript.cjs +105 -24
- package/dist/cjs/validators/ampscript.d.ts +6 -1
- package/dist/cjs/validators/ampscript.d.ts.map +1 -1
- package/dist/cjs/validators/ampscript.js.map +1 -1
- package/dist/cjs/validators/gtl.cjs +3 -0
- package/dist/cjs/validators/gtl.d.ts +3 -0
- package/dist/cjs/validators/gtl.d.ts.map +1 -1
- package/dist/cjs/validators/gtl.js.map +1 -1
- package/dist/cjs/validators/ssjs.cjs +64 -10
- package/dist/cjs/validators/ssjs.d.ts +6 -1
- package/dist/cjs/validators/ssjs.d.ts.map +1 -1
- package/dist/cjs/validators/ssjs.js.map +1 -1
- package/dist/esm/codeActions/ampscript.d.ts +7 -1
- package/dist/esm/codeActions/ampscript.d.ts.map +1 -1
- package/dist/esm/codeActions/ampscript.js +17 -2
- package/dist/esm/codeActions/ampscript.js.map +1 -1
- package/dist/esm/completions/ampscript.d.ts +11 -2
- package/dist/esm/completions/ampscript.d.ts.map +1 -1
- package/dist/esm/completions/ampscript.js +18 -4
- package/dist/esm/completions/ampscript.js.map +1 -1
- package/dist/esm/completions/ssjs.d.ts +5 -1
- package/dist/esm/completions/ssjs.d.ts.map +1 -1
- package/dist/esm/completions/ssjs.js +223 -21
- package/dist/esm/completions/ssjs.js.map +1 -1
- package/dist/esm/data/ampscript.d.ts.map +1 -1
- package/dist/esm/data/ampscript.js +6 -1
- package/dist/esm/data/ampscript.js.map +1 -1
- package/dist/esm/data/ssjs.d.ts +7 -1
- package/dist/esm/data/ssjs.d.ts.map +1 -1
- package/dist/esm/data/ssjs.js +14 -4
- package/dist/esm/data/ssjs.js.map +1 -1
- package/dist/esm/definitions/ssjs.d.ts +6 -0
- package/dist/esm/definitions/ssjs.d.ts.map +1 -1
- package/dist/esm/definitions/ssjs.js +15 -2
- package/dist/esm/definitions/ssjs.js.map +1 -1
- package/dist/esm/hover/ampscript.d.ts +6 -1
- package/dist/esm/hover/ampscript.d.ts.map +1 -1
- package/dist/esm/hover/ampscript.js +14 -3
- package/dist/esm/hover/ampscript.js.map +1 -1
- package/dist/esm/hover/ssjs.d.ts +7 -1
- package/dist/esm/hover/ssjs.d.ts.map +1 -1
- package/dist/esm/hover/ssjs.js +199 -37
- package/dist/esm/hover/ssjs.js.map +1 -1
- package/dist/esm/index.d.ts +77 -16
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +118 -29
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/signature/ampscript.d.ts +7 -1
- package/dist/esm/signature/ampscript.d.ts.map +1 -1
- package/dist/esm/signature/ampscript.js +11 -3
- package/dist/esm/signature/ampscript.js.map +1 -1
- package/dist/esm/signature/ssjs.d.ts +8 -1
- package/dist/esm/signature/ssjs.d.ts.map +1 -1
- package/dist/esm/signature/ssjs.js +42 -19
- package/dist/esm/signature/ssjs.js.map +1 -1
- package/dist/esm/utils/comments.d.ts +11 -2
- package/dist/esm/utils/comments.d.ts.map +1 -1
- package/dist/esm/utils/comments.js +11 -2
- package/dist/esm/utils/comments.js.map +1 -1
- package/dist/esm/utils/markdown.d.ts +30 -6
- package/dist/esm/utils/markdown.d.ts.map +1 -1
- package/dist/esm/utils/markdown.js +32 -7
- package/dist/esm/utils/markdown.js.map +1 -1
- package/dist/esm/utils/positions.d.ts +18 -3
- package/dist/esm/utils/positions.d.ts.map +1 -1
- package/dist/esm/utils/positions.js +19 -4
- package/dist/esm/utils/positions.js.map +1 -1
- package/dist/esm/utils/regions.d.ts +8 -0
- package/dist/esm/utils/regions.d.ts.map +1 -1
- package/dist/esm/utils/regions.js +8 -0
- package/dist/esm/utils/regions.js.map +1 -1
- package/dist/esm/utils/text.d.ts +22 -2
- package/dist/esm/utils/text.d.ts.map +1 -1
- package/dist/esm/utils/text.js +22 -2
- package/dist/esm/utils/text.js.map +1 -1
- package/dist/esm/validators/ampscript.d.ts +6 -1
- package/dist/esm/validators/ampscript.d.ts.map +1 -1
- package/dist/esm/validators/ampscript.js +106 -25
- package/dist/esm/validators/ampscript.js.map +1 -1
- package/dist/esm/validators/gtl.d.ts +3 -0
- package/dist/esm/validators/gtl.d.ts.map +1 -1
- package/dist/esm/validators/gtl.js +3 -0
- package/dist/esm/validators/gtl.js.map +1 -1
- package/dist/esm/validators/ssjs.d.ts +6 -1
- package/dist/esm/validators/ssjs.d.ts.map +1 -1
- package/dist/esm/validators/ssjs.js +65 -11
- package/dist/esm/validators/ssjs.js.map +1 -1
- package/dist/types/codeActions/ampscript.d.ts +7 -1
- package/dist/types/codeActions/ampscript.d.ts.map +1 -1
- package/dist/types/completions/ampscript.d.ts +11 -2
- package/dist/types/completions/ampscript.d.ts.map +1 -1
- package/dist/types/completions/ssjs.d.ts +5 -1
- package/dist/types/completions/ssjs.d.ts.map +1 -1
- package/dist/types/data/ampscript.d.ts.map +1 -1
- package/dist/types/data/ssjs.d.ts +7 -1
- package/dist/types/data/ssjs.d.ts.map +1 -1
- package/dist/types/definitions/ssjs.d.ts +6 -0
- package/dist/types/definitions/ssjs.d.ts.map +1 -1
- package/dist/types/hover/ampscript.d.ts +6 -1
- package/dist/types/hover/ampscript.d.ts.map +1 -1
- package/dist/types/hover/ssjs.d.ts +7 -1
- package/dist/types/hover/ssjs.d.ts.map +1 -1
- package/dist/types/index.d.ts +77 -16
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/signature/ampscript.d.ts +7 -1
- package/dist/types/signature/ampscript.d.ts.map +1 -1
- package/dist/types/signature/ssjs.d.ts +8 -1
- package/dist/types/signature/ssjs.d.ts.map +1 -1
- package/dist/types/utils/comments.d.ts +11 -2
- package/dist/types/utils/comments.d.ts.map +1 -1
- package/dist/types/utils/markdown.d.ts +30 -6
- package/dist/types/utils/markdown.d.ts.map +1 -1
- package/dist/types/utils/positions.d.ts +18 -3
- package/dist/types/utils/positions.d.ts.map +1 -1
- package/dist/types/utils/regions.d.ts +8 -0
- package/dist/types/utils/regions.d.ts.map +1 -1
- package/dist/types/utils/text.d.ts +22 -2
- package/dist/types/utils/text.d.ts.map +1 -1
- package/dist/types/validators/ampscript.d.ts +6 -1
- package/dist/types/validators/ampscript.d.ts.map +1 -1
- package/dist/types/validators/gtl.d.ts +3 -0
- package/dist/types/validators/gtl.d.ts.map +1 -1
- package/dist/types/validators/ssjs.d.ts +6 -1
- package/dist/types/validators/ssjs.d.ts.map +1 -1
- package/package.json +21 -6
|
@@ -3,17 +3,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.offsetToPosition = offsetToPosition;
|
|
4
4
|
exports.positionToOffset = positionToOffset;
|
|
5
5
|
exports.getTextInRange = getTextInRange;
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* Convert a character offset in `text` to an LSP Position.
|
|
8
|
+
* @param text - Source text.
|
|
9
|
+
* @param offset - Character offset.
|
|
10
|
+
* @returns LSP Position (line and character).
|
|
11
|
+
*/
|
|
7
12
|
function offsetToPosition(text, offset) {
|
|
8
13
|
const clamped = Math.max(0, Math.min(offset, text.length));
|
|
9
14
|
const before = text.slice(0, clamped);
|
|
10
15
|
const lines = before.split('\n');
|
|
11
16
|
return {
|
|
12
17
|
line: lines.length - 1,
|
|
13
|
-
character: lines
|
|
18
|
+
character: lines.at(-1).length,
|
|
14
19
|
};
|
|
15
20
|
}
|
|
16
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Convert an LSP Position in `text` to a character offset.
|
|
23
|
+
* @param text - Source text.
|
|
24
|
+
* @param position - LSP Position.
|
|
25
|
+
* @returns Character offset from the start of the text.
|
|
26
|
+
*/
|
|
17
27
|
function positionToOffset(text, position) {
|
|
18
28
|
const lines = text.split('\n');
|
|
19
29
|
let offset = 0;
|
|
@@ -22,7 +32,12 @@ function positionToOffset(text, position) {
|
|
|
22
32
|
}
|
|
23
33
|
return offset + Math.min(position.character, lines[position.line]?.length ?? 0);
|
|
24
34
|
}
|
|
25
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* Extract the text covered by a Range.
|
|
37
|
+
* @param text - Source text.
|
|
38
|
+
* @param range - LSP Range to extract.
|
|
39
|
+
* @returns Substring of `text` covered by the range.
|
|
40
|
+
*/
|
|
26
41
|
function getTextInRange(text, range) {
|
|
27
42
|
const start = positionToOffset(text, range.start);
|
|
28
43
|
const end = positionToOffset(text, range.end);
|
|
@@ -1,8 +1,23 @@
|
|
|
1
1
|
import type { Position, Range } from '../types.js';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Convert a character offset in `text` to an LSP Position.
|
|
4
|
+
* @param text - Source text.
|
|
5
|
+
* @param offset - Character offset.
|
|
6
|
+
* @returns LSP Position (line and character).
|
|
7
|
+
*/
|
|
3
8
|
export declare function offsetToPosition(text: string, offset: number): Position;
|
|
4
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Convert an LSP Position in `text` to a character offset.
|
|
11
|
+
* @param text - Source text.
|
|
12
|
+
* @param position - LSP Position.
|
|
13
|
+
* @returns Character offset from the start of the text.
|
|
14
|
+
*/
|
|
5
15
|
export declare function positionToOffset(text: string, position: Position): number;
|
|
6
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* Extract the text covered by a Range.
|
|
18
|
+
* @param text - Source text.
|
|
19
|
+
* @param range - LSP Range to extract.
|
|
20
|
+
* @returns Substring of `text` covered by the range.
|
|
21
|
+
*/
|
|
7
22
|
export declare function getTextInRange(text: string, range: Range): string;
|
|
8
23
|
//# sourceMappingURL=positions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"positions.d.ts","sourceRoot":"","sources":["../../../src/utils/positions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEnD
|
|
1
|
+
{"version":3,"file":"positions.d.ts","sourceRoot":"","sources":["../../../src/utils/positions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEnD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,QAAQ,CAQvE;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAOzE;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,MAAM,CAIjE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"positions.js","sourceRoot":"","sources":["../../../src/utils/positions.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"positions.js","sourceRoot":"","sources":["../../../src/utils/positions.ts"],"names":[],"mappings":";;AAQA,4CAQC;AAQD,4CAOC;AAQD,wCAIC;AAzCD;;;;;GAKG;AACH,SAAgB,gBAAgB,CAAC,IAAY,EAAE,MAAc;IACzD,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAC3D,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;IACtC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACjC,OAAO;QACH,IAAI,EAAE,KAAK,CAAC,MAAM,GAAG,CAAC;QACtB,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAE,CAAC,MAAM;KAClC,CAAC;AACN,CAAC;AAED;;;;;GAKG;AACH,SAAgB,gBAAgB,CAAC,IAAY,EAAE,QAAkB;IAC7D,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC/B,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,IAAI,IAAI,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACzD,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,YAAY;IAC/C,CAAC;IACD,OAAO,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC,CAAC;AACpF,CAAC;AAED;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,IAAY,EAAE,KAAY;IACrD,MAAM,KAAK,GAAG,gBAAgB,CAAC,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;IAClD,MAAM,GAAG,GAAG,gBAAgB,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IAC9C,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAClC,CAAC"}
|
|
@@ -10,6 +10,9 @@ exports.getSanitizedAmpscriptText = getSanitizedAmpscriptText;
|
|
|
10
10
|
* Returns true when the given character offset falls inside an AMPscript
|
|
11
11
|
* region: a %%[...]%% block, a %%=...=%% inline expression, or a
|
|
12
12
|
* <script language="ampscript"> ... </script> tag body.
|
|
13
|
+
* @param text - Full document text.
|
|
14
|
+
* @param offset - Character offset to test.
|
|
15
|
+
* @returns True if the offset is inside an AMPscript region.
|
|
13
16
|
*/
|
|
14
17
|
function isInsideAmpscript(text, offset) {
|
|
15
18
|
const before = text.slice(0, Math.max(0, offset));
|
|
@@ -41,6 +44,9 @@ function isInsideAmpscript(text, offset) {
|
|
|
41
44
|
}
|
|
42
45
|
/**
|
|
43
46
|
* Returns true when the given character offset falls inside a GTL {{...}} expression.
|
|
47
|
+
* @param text - Full document text.
|
|
48
|
+
* @param offset - Character offset to test.
|
|
49
|
+
* @returns True if the offset is inside a GTL expression.
|
|
44
50
|
*/
|
|
45
51
|
function isInsideGtl(text, offset) {
|
|
46
52
|
const before = text.slice(0, Math.max(0, offset));
|
|
@@ -54,6 +60,8 @@ function isInsideGtl(text, offset) {
|
|
|
54
60
|
* Everything outside AMPscript regions is replaced with spaces.
|
|
55
61
|
* This lets validators run regex safely without accidentally matching
|
|
56
62
|
* HTML content outside AMPscript blocks.
|
|
63
|
+
* @param text - Full document text.
|
|
64
|
+
* @returns Sanitized text with only AMPscript region content preserved.
|
|
57
65
|
*/
|
|
58
66
|
function getSanitizedAmpscriptText(text) {
|
|
59
67
|
const sanitizedChars = Array.from(text, () => ' ');
|
|
@@ -5,10 +5,16 @@
|
|
|
5
5
|
* Returns true when the given character offset falls inside an AMPscript
|
|
6
6
|
* region: a %%[...]%% block, a %%=...=%% inline expression, or a
|
|
7
7
|
* <script language="ampscript"> ... </script> tag body.
|
|
8
|
+
* @param text - Full document text.
|
|
9
|
+
* @param offset - Character offset to test.
|
|
10
|
+
* @returns True if the offset is inside an AMPscript region.
|
|
8
11
|
*/
|
|
9
12
|
export declare function isInsideAmpscript(text: string, offset: number): boolean;
|
|
10
13
|
/**
|
|
11
14
|
* Returns true when the given character offset falls inside a GTL {{...}} expression.
|
|
15
|
+
* @param text - Full document text.
|
|
16
|
+
* @param offset - Character offset to test.
|
|
17
|
+
* @returns True if the offset is inside a GTL expression.
|
|
12
18
|
*/
|
|
13
19
|
export declare function isInsideGtl(text: string, offset: number): boolean;
|
|
14
20
|
/**
|
|
@@ -17,6 +23,8 @@ export declare function isInsideGtl(text: string, offset: number): boolean;
|
|
|
17
23
|
* Everything outside AMPscript regions is replaced with spaces.
|
|
18
24
|
* This lets validators run regex safely without accidentally matching
|
|
19
25
|
* HTML content outside AMPscript blocks.
|
|
26
|
+
* @param text - Full document text.
|
|
27
|
+
* @returns Sanitized text with only AMPscript region content preserved.
|
|
20
28
|
*/
|
|
21
29
|
export declare function getSanitizedAmpscriptText(text: string): string;
|
|
22
30
|
//# sourceMappingURL=regions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"regions.d.ts","sourceRoot":"","sources":["../../../src/utils/regions.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH
|
|
1
|
+
{"version":3,"file":"regions.d.ts","sourceRoot":"","sources":["../../../src/utils/regions.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAgCvE;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAKjE;AAED;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAwB9D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"regions.js","sourceRoot":"","sources":["../../../src/utils/regions.ts"],"names":[],"mappings":";AAAA;;GAEG;;
|
|
1
|
+
{"version":3,"file":"regions.js","sourceRoot":"","sources":["../../../src/utils/regions.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAUH,8CAgCC;AAQD,kCAKC;AAWD,8DAwBC;AAxFD;;;;;;;GAOG;AACH,SAAgB,iBAAiB,CAAC,IAAY,EAAE,MAAc;IAC1D,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;IAElD,MAAM,aAAa,GAAG,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAChD,MAAM,cAAc,GAAG,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IACjD,IAAI,aAAa,KAAK,CAAC,CAAC,IAAI,aAAa,GAAG,cAAc,EAAE,CAAC;QACzD,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,MAAM,cAAc,GAAG,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IACjD,MAAM,eAAe,GAAG,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAClD,IAAI,cAAc,KAAK,CAAC,CAAC,IAAI,cAAc,GAAG,eAAe,EAAE,CAAC;QAC5D,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,MAAM,iBAAiB,GAAG,wDAAwD,CAAC;IACnF,MAAM,kBAAkB,GAAG,cAAc,CAAC;IAC1C,IAAI,cAAc,GAAG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C,SAAS,GAAG,CAAC,CAAC,KAAK,KAAK,EAAE,CAAC;gBACzD,cAAc,CAAC,SAAS,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC;YAC1C,CAAC;YACD,KAAK,GAAG,SAAS,CAAC;YAClB,SAAS;QACb,CAAC;QAED,cAAc,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;QACpC,KAAK,EAAE,CAAC;IACZ,CAAC;AACL,CAAC;AAED,SAAS,aAAa,CAAC,IAAY,EAAE,KAAa,EAAE,KAAa,EAAE,KAAa;IAC5E,IAAI,KAAK,GAAG,KAAK,CAAC;IAClB,OAAO,KAAK,GAAG,KAAK,EAAE,CAAC;QACnB,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,KAAK,EAAE,CAAC;YACxB,OAAO,KAAK,GAAG,CAAC,CAAC;QACrB,CAAC;QACD,KAAK,EAAE,CAAC;IACZ,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC"}
|
package/dist/cjs/utils/text.cjs
CHANGED
|
@@ -9,7 +9,12 @@ exports.extractFunctionArguments = extractFunctionArguments;
|
|
|
9
9
|
exports.inferLiteralType = inferLiteralType;
|
|
10
10
|
exports.getWordRangeAtPosition = getWordRangeAtPosition;
|
|
11
11
|
exports.findFunctionContext = findFunctionContext;
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* Returns all start offsets of `search` within `text`.
|
|
14
|
+
* @param text - Source text to search.
|
|
15
|
+
* @param search - Substring to find.
|
|
16
|
+
* @returns Array of start offsets where the substring occurs.
|
|
17
|
+
*/
|
|
13
18
|
function findAllOccurrences(text, search) {
|
|
14
19
|
const indices = [];
|
|
15
20
|
let index = text.indexOf(search);
|
|
@@ -24,6 +29,9 @@ function findAllOccurrences(text, search) {
|
|
|
24
29
|
* Runs on sanitized text so commas inside strings/comments don't produce false positives.
|
|
25
30
|
*
|
|
26
31
|
* Returns 0 for empty `()`, `commas + 1` otherwise, or -1 if no closing paren is found.
|
|
32
|
+
* @param text - Sanitized source text.
|
|
33
|
+
* @param openParenPos - Index of the opening parenthesis.
|
|
34
|
+
* @returns Argument count, or -1 if the argument list is unclosed.
|
|
27
35
|
*/
|
|
28
36
|
function countFunctionArguments(text, openParenPos) {
|
|
29
37
|
let depth = 1;
|
|
@@ -53,6 +61,9 @@ function countFunctionArguments(text, openParenPos) {
|
|
|
53
61
|
/**
|
|
54
62
|
* Extracts each top-level argument's text and absolute position from a function call.
|
|
55
63
|
* Returns null when the argument list is not properly closed.
|
|
64
|
+
* @param text - Source text.
|
|
65
|
+
* @param openParenPos - Index of the opening parenthesis.
|
|
66
|
+
* @returns Array of ArgumentSpan objects, or null if the list is unclosed.
|
|
56
67
|
*/
|
|
57
68
|
function extractFunctionArguments(text, openParenPos) {
|
|
58
69
|
let depth = 1;
|
|
@@ -90,6 +101,8 @@ function extractFunctionArguments(text, openParenPos) {
|
|
|
90
101
|
/**
|
|
91
102
|
* Infers the literal type of a trimmed argument string.
|
|
92
103
|
* Returns null for variables, expressions, or nested calls.
|
|
104
|
+
* @param arg - Trimmed argument string.
|
|
105
|
+
* @returns Literal type string, or null if not a literal.
|
|
93
106
|
*/
|
|
94
107
|
function inferLiteralType(arg) {
|
|
95
108
|
if (arg.startsWith('"') || arg.startsWith("'"))
|
|
@@ -100,7 +113,12 @@ function inferLiteralType(arg) {
|
|
|
100
113
|
return 'boolean';
|
|
101
114
|
return null;
|
|
102
115
|
}
|
|
103
|
-
/**
|
|
116
|
+
/**
|
|
117
|
+
* Returns the word boundaries around a character position in a line.
|
|
118
|
+
* @param line - The line text.
|
|
119
|
+
* @param character - The character offset within the line.
|
|
120
|
+
* @returns Start and end offsets of the word, or null if none.
|
|
121
|
+
*/
|
|
104
122
|
function getWordRangeAtPosition(line, character) {
|
|
105
123
|
const wordPattern = /[@]?[a-zA-Z_][a-zA-Z0-9_]*/g;
|
|
106
124
|
let match;
|
|
@@ -116,6 +134,8 @@ function getWordRangeAtPosition(line, character) {
|
|
|
116
134
|
/**
|
|
117
135
|
* Walk backward from the cursor to find the enclosing function call name
|
|
118
136
|
* and the current parameter index (0-based comma count).
|
|
137
|
+
* @param textUpToCursor - Document text from start up to the cursor position.
|
|
138
|
+
* @returns Function context object, or null if not inside a function call.
|
|
119
139
|
*/
|
|
120
140
|
function findFunctionContext(textUpToCursor) {
|
|
121
141
|
let depth = 0;
|
package/dist/cjs/utils/text.d.ts
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* General text-parsing utilities used across validators, completions, and hover providers.
|
|
3
3
|
*/
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* Returns all start offsets of `search` within `text`.
|
|
6
|
+
* @param text - Source text to search.
|
|
7
|
+
* @param search - Substring to find.
|
|
8
|
+
* @returns Array of start offsets where the substring occurs.
|
|
9
|
+
*/
|
|
5
10
|
export declare function findAllOccurrences(text: string, search: string): number[];
|
|
6
11
|
/**
|
|
7
12
|
* Counts the number of top-level arguments in a function call starting at `openParenPos`.
|
|
8
13
|
* Runs on sanitized text so commas inside strings/comments don't produce false positives.
|
|
9
14
|
*
|
|
10
15
|
* Returns 0 for empty `()`, `commas + 1` otherwise, or -1 if no closing paren is found.
|
|
16
|
+
* @param text - Sanitized source text.
|
|
17
|
+
* @param openParenPos - Index of the opening parenthesis.
|
|
18
|
+
* @returns Argument count, or -1 if the argument list is unclosed.
|
|
11
19
|
*/
|
|
12
20
|
export declare function countFunctionArguments(text: string, openParenPos: number): number;
|
|
13
21
|
export interface ArgumentSpan {
|
|
@@ -18,14 +26,24 @@ export interface ArgumentSpan {
|
|
|
18
26
|
/**
|
|
19
27
|
* Extracts each top-level argument's text and absolute position from a function call.
|
|
20
28
|
* Returns null when the argument list is not properly closed.
|
|
29
|
+
* @param text - Source text.
|
|
30
|
+
* @param openParenPos - Index of the opening parenthesis.
|
|
31
|
+
* @returns Array of ArgumentSpan objects, or null if the list is unclosed.
|
|
21
32
|
*/
|
|
22
33
|
export declare function extractFunctionArguments(text: string, openParenPos: number): ArgumentSpan[] | null;
|
|
23
34
|
/**
|
|
24
35
|
* Infers the literal type of a trimmed argument string.
|
|
25
36
|
* Returns null for variables, expressions, or nested calls.
|
|
37
|
+
* @param arg - Trimmed argument string.
|
|
38
|
+
* @returns Literal type string, or null if not a literal.
|
|
26
39
|
*/
|
|
27
40
|
export declare function inferLiteralType(arg: string): 'string' | 'number' | 'boolean' | null;
|
|
28
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* Returns the word boundaries around a character position in a line.
|
|
43
|
+
* @param line - The line text.
|
|
44
|
+
* @param character - The character offset within the line.
|
|
45
|
+
* @returns Start and end offsets of the word, or null if none.
|
|
46
|
+
*/
|
|
29
47
|
export declare function getWordRangeAtPosition(line: string, character: number): {
|
|
30
48
|
start: number;
|
|
31
49
|
end: number;
|
|
@@ -33,6 +51,8 @@ export declare function getWordRangeAtPosition(line: string, character: number):
|
|
|
33
51
|
/**
|
|
34
52
|
* Walk backward from the cursor to find the enclosing function call name
|
|
35
53
|
* and the current parameter index (0-based comma count).
|
|
54
|
+
* @param textUpToCursor - Document text from start up to the cursor position.
|
|
55
|
+
* @returns Function context object, or null if not inside a function call.
|
|
36
56
|
*/
|
|
37
57
|
export declare function findFunctionContext(textUpToCursor: string): {
|
|
38
58
|
functionName: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../../src/utils/text.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH
|
|
1
|
+
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../../src/utils/text.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAQzE;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAsBjF;AAED,MAAM,WAAW,YAAY;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACf;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACpC,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,MAAM,GACrB,YAAY,EAAE,GAAG,IAAI,CA+BvB;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,IAAI,CAKpF;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAClC,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,GAClB;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAWvC;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAC/B,cAAc,EAAE,MAAM,GACvB;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAuBrD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../../src/utils/text.ts"],"names":[],"mappings":";AAAA;;GAEG;;
|
|
1
|
+
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../../src/utils/text.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAQH,gDAQC;AAWD,wDAsBC;AAeD,4DAkCC;AAQD,4CAKC;AAQD,wDAcC;AAQD,kDAyBC;AApKD;;;;;GAKG;AACH,SAAgB,kBAAkB,CAAC,IAAY,EAAE,MAAc;IAC3D,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,IAAI,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACjC,OAAO,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;QAClB,OAAO,CAAC,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CAAC;AAChB,CAAC;AAED;;;;;GAKG;AACH,SAAgB,mBAAmB,CAC/B,cAAsB;IAEtB,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,UAAU,GAAG,CAAC,CAAC;IAEnB,KAAK,IAAI,KAAK,GAAG,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;QAC9D,MAAM,EAAE,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;QACjC,IAAI,EAAE,KAAK,GAAG,EAAE,CAAC;YACb,KAAK,EAAE,CAAC;QACZ,CAAC;aAAM,IAAI,EAAE,KAAK,GAAG,EAAE,CAAC;YACpB,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;gBACd,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;gBACrE,MAAM,aAAa,GAAG,MAAM,CAAC,KAAK,CAAC,2BAA2B,CAAC,CAAC;gBAChE,IAAI,aAAa,EAAE,CAAC;oBAChB,OAAO,EAAE,YAAY,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC;gBACtE,CAAC;gBACD,OAAO,IAAI,CAAC;YAChB,CAAC;YACD,KAAK,EAAE,CAAC;QACZ,CAAC;aAAM,IAAI,EAAE,KAAK,GAAG,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;YACnC,UAAU,EAAE,CAAC;QACjB,CAAC;IACL,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC"}
|
|
@@ -18,8 +18,23 @@ exports.DIAG_CODE_NESTED_DELIMITER_IN_SCRIPT = 'ampscript/nested-delimiter-in-sc
|
|
|
18
18
|
exports.DIAG_CODE_NESTED_DELIMITER = 'ampscript/nested-delimiter';
|
|
19
19
|
const ampscriptKeywordSet = new Set(ampscript_js_1.ampscriptKeywords.map((kw) => kw.name.toLowerCase()));
|
|
20
20
|
const controlFlowConstructSet = new Set([
|
|
21
|
-
'if',
|
|
22
|
-
'
|
|
21
|
+
'if',
|
|
22
|
+
'elseif',
|
|
23
|
+
'else',
|
|
24
|
+
'endif',
|
|
25
|
+
'for',
|
|
26
|
+
'next',
|
|
27
|
+
'then',
|
|
28
|
+
'do',
|
|
29
|
+
'to',
|
|
30
|
+
'downto',
|
|
31
|
+
'var',
|
|
32
|
+
'set',
|
|
33
|
+
'and',
|
|
34
|
+
'or',
|
|
35
|
+
'not',
|
|
36
|
+
'true',
|
|
37
|
+
'false',
|
|
23
38
|
]);
|
|
24
39
|
function isKnownAmpscriptConstruct(name) {
|
|
25
40
|
return (ampscript_js_1.functionLookup.has(name) ||
|
|
@@ -27,13 +42,38 @@ function isKnownAmpscriptConstruct(name) {
|
|
|
27
42
|
controlFlowConstructSet.has(name));
|
|
28
43
|
}
|
|
29
44
|
const variadicFunctionNames = new Set([
|
|
30
|
-
'lookup',
|
|
31
|
-
'
|
|
32
|
-
'
|
|
33
|
-
'
|
|
34
|
-
'
|
|
35
|
-
'
|
|
36
|
-
'
|
|
45
|
+
'lookup',
|
|
46
|
+
'lookuprows',
|
|
47
|
+
'lookuprowscs',
|
|
48
|
+
'lookuporderedrows',
|
|
49
|
+
'lookuporderedrowscs',
|
|
50
|
+
'insertdata',
|
|
51
|
+
'insertde',
|
|
52
|
+
'updatedata',
|
|
53
|
+
'updatede',
|
|
54
|
+
'upsertdata',
|
|
55
|
+
'upsertde',
|
|
56
|
+
'deletedata',
|
|
57
|
+
'deletede',
|
|
58
|
+
'claimrow',
|
|
59
|
+
'claimrowvalue',
|
|
60
|
+
'cloudpagesurl',
|
|
61
|
+
'micrositeurl',
|
|
62
|
+
'concat',
|
|
63
|
+
'replacelist',
|
|
64
|
+
'regexmatch',
|
|
65
|
+
'createsalesforceobject',
|
|
66
|
+
'updatesinglesalesforceobject',
|
|
67
|
+
'retrievesalesforceobjects',
|
|
68
|
+
'httppost',
|
|
69
|
+
'httppost2',
|
|
70
|
+
'httppostwithretry',
|
|
71
|
+
'createmscrm',
|
|
72
|
+
'buildoptionlist',
|
|
73
|
+
'wat',
|
|
74
|
+
'getsocialpublishurl',
|
|
75
|
+
'getsocialpublishurlbyname',
|
|
76
|
+
'upsertcontact',
|
|
37
77
|
]);
|
|
38
78
|
const functionArityLookup = new Map();
|
|
39
79
|
for (const fn of ampscript_js_1.ampscriptFunctions) {
|
|
@@ -41,7 +81,12 @@ for (const fn of ampscript_js_1.ampscriptFunctions) {
|
|
|
41
81
|
const maxArgs = variadicFunctionNames.has(fn.name.toLowerCase()) ? Infinity : fn.params.length;
|
|
42
82
|
functionArityLookup.set(fn.name.toLowerCase(), { minArgs, maxArgs });
|
|
43
83
|
}
|
|
44
|
-
/**
|
|
84
|
+
/**
|
|
85
|
+
* Validate an AMPscript document and return LSP Diagnostics.
|
|
86
|
+
* @param text - Full document text.
|
|
87
|
+
* @param settings - Validation settings.
|
|
88
|
+
* @returns Array of LSP Diagnostic objects.
|
|
89
|
+
*/
|
|
45
90
|
function validateAmpscript(text, settings = types_js_2.DEFAULT_SETTINGS) {
|
|
46
91
|
const sanitizedText = (0, regions_js_1.getSanitizedAmpscriptText)(text);
|
|
47
92
|
const diagnostics = [];
|
|
@@ -55,7 +100,10 @@ function validateAmpscript(text, settings = types_js_2.DEFAULT_SETTINGS) {
|
|
|
55
100
|
problems++;
|
|
56
101
|
diagnostics.push({
|
|
57
102
|
severity: types_js_1.DiagnosticSeverity.Error,
|
|
58
|
-
range: {
|
|
103
|
+
range: {
|
|
104
|
+
start: (0, positions_js_1.offsetToPosition)(text, blockOpens[i]),
|
|
105
|
+
end: (0, positions_js_1.offsetToPosition)(text, blockOpens[i] + 3),
|
|
106
|
+
},
|
|
59
107
|
message: 'Unclosed AMPscript block. Expected a matching ]%%.',
|
|
60
108
|
source: 'ampscript',
|
|
61
109
|
});
|
|
@@ -66,7 +114,10 @@ function validateAmpscript(text, settings = types_js_2.DEFAULT_SETTINGS) {
|
|
|
66
114
|
problems++;
|
|
67
115
|
diagnostics.push({
|
|
68
116
|
severity: types_js_1.DiagnosticSeverity.Error,
|
|
69
|
-
range: {
|
|
117
|
+
range: {
|
|
118
|
+
start: (0, positions_js_1.offsetToPosition)(text, blockCloses[i]),
|
|
119
|
+
end: (0, positions_js_1.offsetToPosition)(text, blockCloses[i] + 3),
|
|
120
|
+
},
|
|
70
121
|
message: 'Unexpected ]%% without a matching %%[ opener.',
|
|
71
122
|
source: 'ampscript',
|
|
72
123
|
});
|
|
@@ -80,7 +131,10 @@ function validateAmpscript(text, settings = types_js_2.DEFAULT_SETTINGS) {
|
|
|
80
131
|
problems++;
|
|
81
132
|
diagnostics.push({
|
|
82
133
|
severity: types_js_1.DiagnosticSeverity.Error,
|
|
83
|
-
range: {
|
|
134
|
+
range: {
|
|
135
|
+
start: (0, positions_js_1.offsetToPosition)(text, inlineOpens[i]),
|
|
136
|
+
end: (0, positions_js_1.offsetToPosition)(text, inlineOpens[i] + 3),
|
|
137
|
+
},
|
|
84
138
|
message: 'Unclosed inline AMPscript expression. Expected a matching =%%.',
|
|
85
139
|
source: 'ampscript',
|
|
86
140
|
});
|
|
@@ -91,7 +145,10 @@ function validateAmpscript(text, settings = types_js_2.DEFAULT_SETTINGS) {
|
|
|
91
145
|
problems++;
|
|
92
146
|
diagnostics.push({
|
|
93
147
|
severity: types_js_1.DiagnosticSeverity.Error,
|
|
94
|
-
range: {
|
|
148
|
+
range: {
|
|
149
|
+
start: (0, positions_js_1.offsetToPosition)(text, inlineCloses[i]),
|
|
150
|
+
end: (0, positions_js_1.offsetToPosition)(text, inlineCloses[i] + 3),
|
|
151
|
+
},
|
|
95
152
|
message: 'Unexpected =%% without a matching %%= opener.',
|
|
96
153
|
source: 'ampscript',
|
|
97
154
|
});
|
|
@@ -103,10 +160,12 @@ function validateAmpscript(text, settings = types_js_2.DEFAULT_SETTINGS) {
|
|
|
103
160
|
const forStack = [];
|
|
104
161
|
for (const [lineIndex, line] of lines.entries()) {
|
|
105
162
|
const lineLower = line.toLowerCase();
|
|
106
|
-
|
|
163
|
+
const ifLineCount = [...lineLower.matchAll(/\bif\b/g)].length;
|
|
164
|
+
for (let i = 0; i < ifLineCount; i++) {
|
|
107
165
|
ifStack.push(lineIndex);
|
|
108
166
|
}
|
|
109
|
-
|
|
167
|
+
const endifOnLine = [...lineLower.matchAll(/\bendif\b/g)];
|
|
168
|
+
for (let ei = 0; ei < endifOnLine.length; ei++) {
|
|
110
169
|
if (ifStack.length > 0) {
|
|
111
170
|
ifStack.pop();
|
|
112
171
|
}
|
|
@@ -114,16 +173,21 @@ function validateAmpscript(text, settings = types_js_2.DEFAULT_SETTINGS) {
|
|
|
114
173
|
problems++;
|
|
115
174
|
diagnostics.push({
|
|
116
175
|
severity: types_js_1.DiagnosticSeverity.Warning,
|
|
117
|
-
range: {
|
|
176
|
+
range: {
|
|
177
|
+
start: { line: lineIndex, character: 0 },
|
|
178
|
+
end: { line: lineIndex, character: line.length },
|
|
179
|
+
},
|
|
118
180
|
message: 'ENDIF without a matching IF.',
|
|
119
181
|
source: 'ampscript',
|
|
120
182
|
});
|
|
121
183
|
}
|
|
122
184
|
}
|
|
123
|
-
|
|
185
|
+
const forLineCount = [...lineLower.matchAll(/\bfor\b/g)].length;
|
|
186
|
+
for (let j = 0; j < forLineCount; j++) {
|
|
124
187
|
forStack.push(lineIndex);
|
|
125
188
|
}
|
|
126
|
-
|
|
189
|
+
const nextOnLine = [...lineLower.matchAll(/\bnext\b/g)];
|
|
190
|
+
for (let ni = 0; ni < nextOnLine.length; ni++) {
|
|
127
191
|
if (forStack.length > 0) {
|
|
128
192
|
forStack.pop();
|
|
129
193
|
}
|
|
@@ -131,7 +195,10 @@ function validateAmpscript(text, settings = types_js_2.DEFAULT_SETTINGS) {
|
|
|
131
195
|
problems++;
|
|
132
196
|
diagnostics.push({
|
|
133
197
|
severity: types_js_1.DiagnosticSeverity.Warning,
|
|
134
|
-
range: {
|
|
198
|
+
range: {
|
|
199
|
+
start: { line: lineIndex, character: 0 },
|
|
200
|
+
end: { line: lineIndex, character: line.length },
|
|
201
|
+
},
|
|
135
202
|
message: 'NEXT without a matching FOR.',
|
|
136
203
|
source: 'ampscript',
|
|
137
204
|
});
|
|
@@ -144,7 +211,10 @@ function validateAmpscript(text, settings = types_js_2.DEFAULT_SETTINGS) {
|
|
|
144
211
|
problems++;
|
|
145
212
|
diagnostics.push({
|
|
146
213
|
severity: types_js_1.DiagnosticSeverity.Warning,
|
|
147
|
-
range: {
|
|
214
|
+
range: {
|
|
215
|
+
start: { line: lineIndex, character: 0 },
|
|
216
|
+
end: { line: lineIndex, character: lines[lineIndex].length },
|
|
217
|
+
},
|
|
148
218
|
message: 'IF without a matching ENDIF.',
|
|
149
219
|
source: 'ampscript',
|
|
150
220
|
});
|
|
@@ -155,7 +225,10 @@ function validateAmpscript(text, settings = types_js_2.DEFAULT_SETTINGS) {
|
|
|
155
225
|
problems++;
|
|
156
226
|
diagnostics.push({
|
|
157
227
|
severity: types_js_1.DiagnosticSeverity.Warning,
|
|
158
|
-
range: {
|
|
228
|
+
range: {
|
|
229
|
+
start: { line: lineIndex, character: 0 },
|
|
230
|
+
end: { line: lineIndex, character: lines[lineIndex].length },
|
|
231
|
+
},
|
|
159
232
|
message: 'FOR without a matching NEXT.',
|
|
160
233
|
source: 'ampscript',
|
|
161
234
|
});
|
|
@@ -272,7 +345,13 @@ function validateAmpscript(text, settings = types_js_2.DEFAULT_SETTINGS) {
|
|
|
272
345
|
// 7. Bare subscriber attribute access warning
|
|
273
346
|
const directAttributeAccess = /\bset\s+@\w+\s*=\s*(\w+)\b/gi;
|
|
274
347
|
let attributeMatch;
|
|
275
|
-
const commonAttributes = new Set([
|
|
348
|
+
const commonAttributes = new Set([
|
|
349
|
+
'firstname',
|
|
350
|
+
'lastname',
|
|
351
|
+
'emailaddress',
|
|
352
|
+
'email_address',
|
|
353
|
+
'fullname',
|
|
354
|
+
]);
|
|
276
355
|
while ((attributeMatch = directAttributeAccess.exec(sanitizedText)) && problems < max) {
|
|
277
356
|
const attrName = attributeMatch[1].toLowerCase();
|
|
278
357
|
if (commonAttributes.has(attrName)) {
|
|
@@ -350,7 +429,9 @@ function validateAmpscript(text, settings = types_js_2.DEFAULT_SETTINGS) {
|
|
|
350
429
|
const innerOpenPattern = /<script\s[^>]*language\s*=\s*["']ampscript["'][^>]*>/gi;
|
|
351
430
|
innerOpenPattern.lastIndex = openTagEnd;
|
|
352
431
|
let innerMatch;
|
|
353
|
-
while ((innerMatch = innerOpenPattern.exec(text)) !== null &&
|
|
432
|
+
while ((innerMatch = innerOpenPattern.exec(text)) !== null &&
|
|
433
|
+
innerMatch.index < searchEnd &&
|
|
434
|
+
problems < max) {
|
|
354
435
|
problems++;
|
|
355
436
|
diagnostics.push({
|
|
356
437
|
severity: types_js_1.DiagnosticSeverity.Error,
|
|
@@ -6,6 +6,11 @@ export declare const DIAG_CODE_JS_LINE_COMMENT = "ampscript/js-line-comment";
|
|
|
6
6
|
export declare const DIAG_CODE_NESTED_SCRIPT_TAG = "ampscript/nested-script-tag";
|
|
7
7
|
export declare const DIAG_CODE_NESTED_DELIMITER_IN_SCRIPT = "ampscript/nested-delimiter-in-script";
|
|
8
8
|
export declare const DIAG_CODE_NESTED_DELIMITER = "ampscript/nested-delimiter";
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Validate an AMPscript document and return LSP Diagnostics.
|
|
11
|
+
* @param text - Full document text.
|
|
12
|
+
* @param settings - Validation settings.
|
|
13
|
+
* @returns Array of LSP Diagnostic objects.
|
|
14
|
+
*/
|
|
10
15
|
export declare function validateAmpscript(text: string, settings?: SfmcSettings): Diagnostic[];
|
|
11
16
|
//# sourceMappingURL=ampscript.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ampscript.d.ts","sourceRoot":"","sources":["../../../src/validators/ampscript.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"ampscript.d.ts","sourceRoot":"","sources":["../../../src/validators/ampscript.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAchD,eAAO,MAAM,8BAA8B,mCAAmC,CAAC;AAC/E,eAAO,MAAM,sBAAsB,2BAA2B,CAAC;AAC/D,eAAO,MAAM,yBAAyB,8BAA8B,CAAC;AACrE,eAAO,MAAM,2BAA2B,gCAAgC,CAAC;AACzE,eAAO,MAAM,oCAAoC,yCAAyC,CAAC;AAC3F,eAAO,MAAM,0BAA0B,+BAA+B,CAAC;AA6EvE;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC7B,IAAI,EAAE,MAAM,EACZ,QAAQ,GAAE,YAA+B,GAC1C,UAAU,EAAE,CAudd"}
|