@xano/xanoscript-language-server 11.6.2 → 11.6.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xano/xanoscript-language-server",
3
- "version": "11.6.2",
3
+ "version": "11.6.4",
4
4
  "description": "Language Server Protocol implementation for XanoScript",
5
5
  "type": "module",
6
6
  "main": "server.js",
@@ -3,6 +3,7 @@ import { LCurly, RCurly } from "../lexer/control.js";
3
3
  import { FunctionToken } from "../lexer/function.js";
4
4
  import { StringLiteral } from "../lexer/literal.js";
5
5
  import { Identifier, NewlineToken } from "../lexer/tokens.js";
6
+ import { getVarName } from "./generic/utils.js";
6
7
 
7
8
  export function functionDeclaration($) {
8
9
  return () => {
@@ -22,10 +23,15 @@ export function functionDeclaration($) {
22
23
  // Allow leading comments and newlines before the function declaration
23
24
  $.SUBRULE($.optionalCommentBlockFn);
24
25
  const parent = $.CONSUME(FunctionToken);
25
- $.OR([
26
+ const nameToken = $.OR([
26
27
  { ALT: () => $.CONSUME(Identifier) },
27
28
  { ALT: () => $.CONSUME(StringLiteral) },
28
29
  ]);
30
+
31
+ if (nameToken?.image && getVarName(nameToken).startsWith("/")) {
32
+ $.addInvalidValueError(nameToken, "function name must not start with '/'");
33
+ }
34
+
29
35
  $.CONSUME(LCurly); // "{"
30
36
  $.MANY(() => {
31
37
  $.AT_LEAST_ONE(() => $.CONSUME(NewlineToken)); // at least one new line
@@ -16,6 +16,19 @@ describe("function_parser", () => {
16
16
  expect(parser.errors).to.be.empty;
17
17
  });
18
18
 
19
+ it("should raise an error when a function name starts with /", () => {
20
+ const parser = xanoscriptParser(`function "/foo" {
21
+ input {
22
+ }
23
+
24
+ stack {
25
+ }
26
+
27
+ response = null
28
+ }`);
29
+ expect(parser.errors).to.not.be.empty;
30
+ });
31
+
19
32
  it("should parse a function with a test", () => {
20
33
  const parser = xanoscriptParser(`function foo {
21
34
  input {
@@ -55,8 +55,7 @@ export function tryCatchFn($) {
55
55
  }
56
56
 
57
57
  if (!hasCatch) {
58
- $.CONSUME(CatchToken);
59
- $.SUBRULE($.nakedStackFn);
58
+ $.addWarning("try_catch without a catch block will not handle errors");
60
59
  }
61
60
 
62
61
  $.MANY1(() => $.CONSUME1(NewlineToken));
@@ -20,6 +20,18 @@ describe("tryCatchFn", () => {
20
20
  expect(parser.errors).to.be.empty;
21
21
  });
22
22
 
23
+ it("tryCatchFn only try is required, catch and finally are optional", () => {
24
+ const parser = parse(`try_catch {
25
+ try {
26
+ var $x1 {
27
+ value = "try"
28
+ }
29
+ }
30
+ }`);
31
+ expect(parser.errors).to.be.empty;
32
+ expect(parser.warnings).to.not.be.empty;
33
+ });
34
+
23
35
  it("tryCatchFn try and catch can contain a stack", () => {
24
36
  const parser = parse(`try_catch {
25
37
  try {
@@ -166,7 +178,7 @@ describe("tryCatchFn", () => {
166
178
  expect(parser.errors).to.not.be.empty;
167
179
  });
168
180
 
169
- it("tryCatchFn requires a catch block", () => {
181
+ it("tryCatchFn warns when catch block is missing", () => {
170
182
  const parser = parse(`try_catch {
171
183
  try {
172
184
  var $x1 {
@@ -174,6 +186,8 @@ describe("tryCatchFn", () => {
174
186
  }
175
187
  }
176
188
  }`);
177
- expect(parser.errors).to.not.be.empty;
189
+ expect(parser.errors).to.be.empty;
190
+ expect(parser.warnings).to.not.be.empty;
191
+ expect(parser.warnings[0].message).to.include("catch");
178
192
  });
179
193
  });
@@ -37,10 +37,15 @@ export function queryDeclaration($) {
37
37
  $.SUBRULE($.optionalCommentBlockFn);
38
38
 
39
39
  const parent = $.CONSUME(QueryToken);
40
- $.OR([
40
+ const nameToken = $.OR([
41
41
  { ALT: () => $.CONSUME(StringLiteral) }, // "foo/bar"
42
42
  { ALT: () => $.CONSUME(Identifier) }, // foo
43
43
  ]);
44
+
45
+ if (nameToken?.image && getVarName(nameToken).startsWith("/")) {
46
+ $.addInvalidValueError(nameToken, "query name must not start with '/'");
47
+ }
48
+
44
49
  $.CONSUME(VerbToken);
45
50
  $.CONSUME(EqualToken);
46
51
  $.OR1([
@@ -16,6 +16,19 @@ describe("query_parser", () => {
16
16
  expect(parser.errors).to.be.empty;
17
17
  });
18
18
 
19
+ it("should raise an error when a query starts with /", () => {
20
+ const parser = xanoscriptParser(`query "/foo" verb=GET {
21
+ input {
22
+ }
23
+
24
+ stack {
25
+ }
26
+
27
+ response = null
28
+ }`);
29
+ expect(parser.errors).to.not.be.empty;
30
+ });
31
+
19
32
  it("should accept an api_group", () => {
20
33
  const parser = xanoscriptParser(`query foo verb=GET {
21
34
  api_group = "Authentication";
@@ -36,7 +36,7 @@ export function runJobClause($) {
36
36
  {
37
37
  main: {
38
38
  name: "[string]",
39
- input: { "[string]?": "[constant]" },
39
+ "input?": { "[string]?": "[constant]" },
40
40
  },
41
41
  "env?": ["[string]"],
42
42
  },
@@ -5,7 +5,7 @@ import { xanoscriptParser } from "./parser.js";
5
5
  describe("run", () => {
6
6
  it("should parse a basic run.job", () => {
7
7
  const parser = xanoscriptParser(`run.job "Average of values" {
8
- main = {name: "avg_value", input: {}}
8
+ main = {name: "avg_value"}
9
9
  }`);
10
10
  expect(parser.errors).to.be.empty;
11
11
  });