@xano/xanoscript-language-server 11.6.0 → 11.6.1

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.
@@ -5,7 +5,8 @@
5
5
  "Bash(node -e:*)",
6
6
  "Bash(node --input-type=module -e:*)",
7
7
  "Bash(git checkout:*)",
8
- "Bash(ls:*)"
8
+ "Bash(ls:*)",
9
+ "Bash(npm run lint:*)"
9
10
  ]
10
11
  }
11
12
  }
package/lexer/literal.js CHANGED
@@ -24,7 +24,7 @@ export const SingleQuotedStringLiteral = createUniqToken({
24
24
  export const FloatLiteral = createUniqToken({
25
25
  name: "FloatLiteral",
26
26
  label: "floating point number",
27
- pattern: /-?\d+\.\d+/,
27
+ pattern: /-?\d+\.\d+([eE][+-]?\d+)?/,
28
28
  });
29
29
 
30
30
  export const IntegerLiteral = createUniqToken({
@@ -62,7 +62,7 @@ export function onDidChangeContent(params, connection) {
62
62
  if (!document) {
63
63
  console.error(
64
64
  "onDidChangeContent(): Document not found for URI:",
65
- params.textDocument.uri
65
+ params.textDocument.uri,
66
66
  );
67
67
  return null;
68
68
  }
@@ -74,7 +74,7 @@ export function onDidChangeContent(params, connection) {
74
74
  const { parser, scheme } = documentCache.getOrParse(
75
75
  document.uri,
76
76
  document.version,
77
- text
77
+ text,
78
78
  );
79
79
 
80
80
  if (parser.errors.length === 0) {
@@ -84,7 +84,7 @@ export function onDidChangeContent(params, connection) {
84
84
 
85
85
  for (const error of parser.errors) {
86
86
  console.error(
87
- `onDidChangeContent(): Error parsing document: ${error.name}`
87
+ `onDidChangeContent(): Error parsing document: ${error.name}`,
88
88
  );
89
89
  }
90
90
 
@@ -93,7 +93,7 @@ export function onDidChangeContent(params, connection) {
93
93
 
94
94
  console.log(
95
95
  `onDidChangeContent(): sending diagnostic (${parser.errors.length} errors) for scheme:`,
96
- scheme
96
+ scheme,
97
97
  );
98
98
 
99
99
  connection.sendDiagnostics({
@@ -39,7 +39,7 @@ export function onHoverDocument(params, documents, hoverProviders = []) {
39
39
  if (!document) {
40
40
  console.error(
41
41
  "onHover(): Document not found for URI:",
42
- params.textDocument.uri
42
+ params.textDocument.uri,
43
43
  );
44
44
  return null;
45
45
  }
@@ -51,7 +51,7 @@ export function onHoverDocument(params, documents, hoverProviders = []) {
51
51
  const { lexResult, parser } = documentCache.getOrParse(
52
52
  params.textDocument.uri,
53
53
  document.version,
54
- text
54
+ text,
55
55
  );
56
56
 
57
57
  if (lexResult.errors.length > 0) return null;
@@ -67,7 +67,7 @@ export function onHoverDocument(params, documents, hoverProviders = []) {
67
67
 
68
68
  // Find the hover provider that matches the token
69
69
  const messageProvider = hoverProviders.find((provider) =>
70
- provider.isMatch(tokenIdx, tokens, parser)
70
+ provider.isMatch(tokenIdx, tokens, parser),
71
71
  );
72
72
 
73
73
  if (messageProvider) {
@@ -30,13 +30,13 @@ function higlightDefault(text, SemanticTokensBuilder) {
30
30
  character,
31
31
  token.image.length, // Length of the token
32
32
  encodeTokenType(tokenType), // Numeric ID for the token type
33
- 0 // No modifiers for now
33
+ 0, // No modifiers for now
34
34
  );
35
35
  } else if (tokenType === undefined) {
36
36
  console.log(
37
37
  `token type not mapped to a type: ${JSON.stringify(
38
- token.tokenType.name
39
- )}`
38
+ token.tokenType.name,
39
+ )}`,
40
40
  );
41
41
  }
42
42
  });
@@ -13,7 +13,7 @@ export function onSemanticCheck(params, documents, SemanticTokensBuilder) {
13
13
  if (!document) {
14
14
  console.error(
15
15
  "onSemanticCheck(): Document not found for URI:",
16
- params.textDocument.uri
16
+ params.textDocument.uri,
17
17
  );
18
18
  return null;
19
19
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xano/xanoscript-language-server",
3
- "version": "11.6.0",
3
+ "version": "11.6.1",
4
4
  "description": "Language Server Protocol implementation for XanoScript",
5
5
  "type": "module",
6
6
  "main": "server.js",
@@ -12,7 +12,7 @@ export function utilGetRawInputFn($) {
12
12
  ARGS: [
13
13
  fnToken,
14
14
  {
15
- "encoding?": ["json", "yaml", "x-www-form-urlencoded", ""],
15
+ "encoding?": ["json", "none", "yaml", "x-www-form-urlencoded", ""],
16
16
  "description?": "[string]",
17
17
  "disabled?": "[boolean]",
18
18
  "exclude_middleware?": "[boolean]",
@@ -19,6 +19,13 @@ describe("utilGetRawInputFn", () => {
19
19
  expect(parser.errors).to.be.empty;
20
20
  });
21
21
 
22
+ it("utilGetRawInputFn accepts none as an encoding attribute", () => {
23
+ const parser = parse(`get_raw_input {
24
+ encoding = "none"
25
+ } as $x4`);
26
+ expect(parser.errors).to.be.empty;
27
+ });
28
+
22
29
  it("utilGetRawInputFn encoding attribute is optional", () => {
23
30
  const parser = parse(`get_raw_input as $x4`);
24
31
  expect(parser.errors).to.be.empty;
@@ -1,6 +1,23 @@
1
1
  import { DotToken } from "../../lexer/tokens.js";
2
2
  import { UpdateToken, VarToken } from "../../lexer/var.js";
3
- import { ShortFormVariable } from "../../lexer/variables.js";
3
+ import {
4
+ ApiBaseUrlVariable,
5
+ BranchVariable,
6
+ DatasourceVariable,
7
+ HttpHeadersVariable,
8
+ RemoteHostVariable,
9
+ RemoteIpVariable,
10
+ RemotePasswordVariable,
11
+ RemotePortVariable,
12
+ RemoteUserVariable,
13
+ RequestAuthTokenVariable,
14
+ RequestMethod,
15
+ RequestQuerystringVariable,
16
+ RequestUriVariable,
17
+ ShortFormVariable,
18
+ TenantVariable,
19
+ WebflowVariable,
20
+ } from "../../lexer/variables.js";
4
21
 
5
22
  /**
6
23
  * represent $var.x or $x, the only format accepting an assigment
@@ -15,7 +32,27 @@ export function varFn($) {
15
32
  {
16
33
  // "var $users"
17
34
  ALT: () => {
18
- const variable = $.CONSUME(ShortFormVariable);
35
+ // "$users" or env property tokens like "$http_headers"
36
+ // TODO: probably a good idea to add a warning when an reserved env property
37
+ // token is used as a variable name
38
+ const variable = $.OR1([
39
+ { ALT: () => $.CONSUME(ShortFormVariable) },
40
+ { ALT: () => $.CONSUME(ApiBaseUrlVariable) },
41
+ { ALT: () => $.CONSUME(BranchVariable) },
42
+ { ALT: () => $.CONSUME(DatasourceVariable) },
43
+ { ALT: () => $.CONSUME(HttpHeadersVariable) },
44
+ { ALT: () => $.CONSUME(RemoteHostVariable) },
45
+ { ALT: () => $.CONSUME(RemoteIpVariable) },
46
+ { ALT: () => $.CONSUME(RemotePasswordVariable) },
47
+ { ALT: () => $.CONSUME(RemotePortVariable) },
48
+ { ALT: () => $.CONSUME(RemoteUserVariable) },
49
+ { ALT: () => $.CONSUME(RequestAuthTokenVariable) },
50
+ { ALT: () => $.CONSUME(RequestMethod) },
51
+ { ALT: () => $.CONSUME(RequestQuerystringVariable) },
52
+ { ALT: () => $.CONSUME(RequestUriVariable) },
53
+ { ALT: () => $.CONSUME(TenantVariable) },
54
+ { ALT: () => $.CONSUME(WebflowVariable) },
55
+ ]);
19
56
  if (variable.image) {
20
57
  // we can directly add the variable here but
21
58
  // not necessary for the `assignableVariableProperty` below
@@ -84,6 +84,13 @@ describe("varFn", () => {
84
84
  expect(parser.errors).to.be.empty;
85
85
  });
86
86
 
87
+ it("varFn accept scientific notation", () => {
88
+ const parser = parse(` var $x1 {
89
+ value = 4.21E-6
90
+ }`);
91
+ expect(parser.errors).to.be.empty;
92
+ });
93
+
87
94
  it("varFn expect a variable name", () => {
88
95
  const parser = parse(`var {
89
96
  value = "email"
@@ -92,6 +99,13 @@ describe("varFn", () => {
92
99
  expect(parser.errors).to.not.be.empty;
93
100
  });
94
101
 
102
+ it("varFn accepts an $env.$http_headers object as the value", () => {
103
+ const parser = parse(`var $http_headers {
104
+ value = $env.$http_headers
105
+ }`);
106
+ expect(parser.errors).to.be.empty;
107
+ });
108
+
95
109
  it("varFn expect an as variable to be an identifier", () => {
96
110
  const parser = parse(`var "user" {
97
111
  value = "email"
@@ -107,6 +121,13 @@ describe("varFn", () => {
107
121
  expect(parser.errors).to.be.empty;
108
122
  });
109
123
 
124
+ it("varFn can update a value", () => {
125
+ const parser = parse(`var.update $http_headers.Referer {
126
+ value = "example.com"
127
+ }`);
128
+ expect(parser.errors).to.be.empty;
129
+ });
130
+
110
131
  it("should allow accessing a property from an object defined in place", () => {
111
132
  let parser = parse(`var $config {
112
133
  value = {
@@ -1,6 +1,24 @@
1
1
  import { PipeToken } from "../../lexer/control.js";
2
2
  import { DotToken, Identifier, NewlineToken } from "../../lexer/tokens.js";
3
- import { LongFormVariable, ShortFormVariable } from "../../lexer/variables.js";
3
+ import {
4
+ ApiBaseUrlVariable,
5
+ BranchVariable,
6
+ DatasourceVariable,
7
+ HttpHeadersVariable,
8
+ LongFormVariable,
9
+ RemoteHostVariable,
10
+ RemoteIpVariable,
11
+ RemotePasswordVariable,
12
+ RemotePortVariable,
13
+ RemoteUserVariable,
14
+ RequestAuthTokenVariable,
15
+ RequestMethod,
16
+ RequestQuerystringVariable,
17
+ RequestUriVariable,
18
+ ShortFormVariable,
19
+ TenantVariable,
20
+ WebflowVariable,
21
+ } from "../../lexer/variables.js";
4
22
 
5
23
  /**
6
24
  * represent $var.x or $x, the only format accepting an assigment
@@ -11,10 +29,29 @@ export function assignableVariableProperty($) {
11
29
  let variableName = "";
12
30
  $.OR({
13
31
  DEF: [
14
- // "$users"
32
+ // "$users" or env property tokens like "$http_headers"
33
+ // TODO: probably a good idea to add a warning when an reserved env property
34
+ // token is used as a variable name
15
35
  {
16
36
  ALT: () => {
17
- const variable = $.CONSUME(ShortFormVariable);
37
+ const variable = $.OR1([
38
+ { ALT: () => $.CONSUME(ShortFormVariable) },
39
+ { ALT: () => $.CONSUME(ApiBaseUrlVariable) },
40
+ { ALT: () => $.CONSUME(BranchVariable) },
41
+ { ALT: () => $.CONSUME(DatasourceVariable) },
42
+ { ALT: () => $.CONSUME(HttpHeadersVariable) },
43
+ { ALT: () => $.CONSUME(RemoteHostVariable) },
44
+ { ALT: () => $.CONSUME(RemoteIpVariable) },
45
+ { ALT: () => $.CONSUME(RemotePasswordVariable) },
46
+ { ALT: () => $.CONSUME(RemotePortVariable) },
47
+ { ALT: () => $.CONSUME(RemoteUserVariable) },
48
+ { ALT: () => $.CONSUME(RequestAuthTokenVariable) },
49
+ { ALT: () => $.CONSUME(RequestMethod) },
50
+ { ALT: () => $.CONSUME(RequestQuerystringVariable) },
51
+ { ALT: () => $.CONSUME(RequestUriVariable) },
52
+ { ALT: () => $.CONSUME(TenantVariable) },
53
+ { ALT: () => $.CONSUME(WebflowVariable) },
54
+ ]);
18
55
  variableName = variable.image;
19
56
  },
20
57
  },
@@ -38,7 +38,7 @@ export function completeEnvVariable($) {
38
38
  {
39
39
  ALT: () => {
40
40
  $.CONSUME(HttpHeadersVariable);
41
- $.SUBRULE($.singleChainedIdentifier);
41
+ $.OPTION(() => $.SUBRULE($.singleChainedIdentifier));
42
42
  },
43
43
  },
44
44
  { ALT: () => $.CONSUME(RemoteHostVariable) },
@@ -62,6 +62,11 @@ describe("completeEnvVariable", () => {
62
62
  expect(parser.errors).to.be.empty;
63
63
  });
64
64
 
65
+ it("completeEnvVariable accepts $http_headers without property access", () => {
66
+ const parser = parse("$env.$http_headers");
67
+ expect(parser.errors).to.be.empty;
68
+ });
69
+
65
70
  it("completeEnvVariable warn when using env variable starting with $", () => {
66
71
  const parser = parse("$env.$my_custom_variable");
67
72
  expect(parser.errors).to.be.empty;
@@ -187,6 +187,11 @@ describe("expressionFn", () => {
187
187
  expect(parser.errors).to.be.empty;
188
188
  });
189
189
 
190
+ it("expressionFn can be a scientific notation", () => {
191
+ const parser = parse("4.21E-6");
192
+ expect(parser.errors).to.be.empty;
193
+ });
194
+
190
195
  it("expressionFn accepts a JSON", () => {
191
196
  const parser = parse(`[
192
197
  {
@@ -270,7 +275,7 @@ describe("expressionFn", () => {
270
275
 
271
276
  it("expressionFn accepts a rich boolean test expression", () => {
272
277
  const parser = parse(
273
- `($event_type == "app_mention") || (($event_type == "message") && ($channel_type == "im")) || $thread_replies.ai_bot_thread`
278
+ `($event_type == "app_mention") || (($event_type == "message") && ($channel_type == "im")) || $thread_replies.ai_bot_thread`,
274
279
  );
275
280
  expect(parser.errors).to.be.empty;
276
281
  });
@@ -323,7 +328,7 @@ describe("expressionFn", () => {
323
328
 
324
329
  it("expressionFn allow concat operator", () => {
325
330
  const parser = parse(
326
- `"Given the conversation history and the latest message:\\n\\"" ~ $latestMessage ~ "\\"\\n\\nWho should act next? Or should we FINISH? Select one of: " ~ ($memberOptions|join:", ") ~ "."`
331
+ `"Given the conversation history and the latest message:\\n\\"" ~ $latestMessage ~ "\\"\\n\\nWho should act next? Or should we FINISH? Select one of: " ~ ($memberOptions|join:", ") ~ "."`,
327
332
  );
328
333
  expect(parser.errors).to.be.empty;
329
334
  });
@@ -374,14 +379,14 @@ describe("expressionFn", () => {
374
379
 
375
380
  it("expressionFn should accept chained filters in parenthesis", () => {
376
381
  const parser = parse(
377
- `(now|to_timestamp|add:2:2|add:2|transform_timestamp:"24 hours ago":"UTC")`
382
+ `(now|to_timestamp|add:2:2|add:2|transform_timestamp:"24 hours ago":"UTC")`,
378
383
  );
379
384
  expect(parser.errors).to.be.empty;
380
385
  });
381
386
 
382
387
  it("expressionFn should accept chained filters with comparison", () => {
383
388
  const parser = parse(
384
- `(now|to_timestamp|transform_timestamp:"24 hours ago":"UTC") > (335|add:2)`
389
+ `(now|to_timestamp|transform_timestamp:"24 hours ago":"UTC") > (335|add:2)`,
385
390
  );
386
391
  expect(parser.errors).to.be.empty;
387
392
  });
package/server.js CHANGED
@@ -44,10 +44,10 @@ connection.onInitialize(() => {
44
44
  connection.onHover((params) => onHover(params, documents));
45
45
  connection.onCompletion((params) => onCompletion(params, documents));
46
46
  connection.onRequest("textDocument/semanticTokens/full", (params) =>
47
- onSemanticCheck(params, documents, SemanticTokensBuilder)
47
+ onSemanticCheck(params, documents, SemanticTokensBuilder),
48
48
  );
49
49
  documents.onDidChangeContent((params) =>
50
- onDidChangeContent(params, connection)
50
+ onDidChangeContent(params, connection),
51
51
  );
52
52
  connection.onDidOpenTextDocument((params) => {
53
53
  console.log("Document opened:", params.textDocument.uri);