@xano/xanoscript-language-server 11.12.3 → 12.0.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.
@@ -1,43 +1,50 @@
1
1
  import { xanoscriptParser } from "../parser/parser";
2
2
  import { getSchemeFromContent } from "../utils";
3
3
 
4
+ export const SEVERITY = {
5
+ ERROR: 1,
6
+ WARNING: 2,
7
+ };
8
+
9
+ function toDiagnostic(text, item, severity) {
10
+ const startOffset = item.token?.startOffset ?? 0;
11
+ const endOffset = item.token?.endOffset ?? (startOffset + 5);
12
+ const lines = text.substring(0, startOffset).split("\n");
13
+ const line = lines.length - 1;
14
+ const character = lines[lines.length - 1].length;
15
+
16
+ const endLines = text.substring(0, endOffset + 1).split("\n");
17
+ const endLine = endLines.length - 1;
18
+ const endCharacter = endLines[endLines.length - 1].length;
19
+
20
+ return {
21
+ severity,
22
+ range: {
23
+ start: { line, character },
24
+ end: { line: endLine, character: endCharacter },
25
+ },
26
+ message: item.message,
27
+ source: item.name || "XanoScript Parser",
28
+ };
29
+ }
30
+
4
31
  export function onCheckError(text, objectType) {
5
32
  const scheme = getSchemeFromContent(objectType ?? text);
6
33
 
7
34
  try {
8
- // Parse the XanoScript file
9
35
  const parser = xanoscriptParser(text, scheme);
10
36
 
11
- if (parser.errors.length === 0) {
12
- // If parsing succeeds, send an empty diagnostics array (no errors)
13
- return [];
14
- }
37
+ const diagnostics = [];
15
38
 
16
- // If parsing fails, create a diagnostic (error message) to display in VS Code
17
- const diagnostics = parser.errors.map((error) => {
18
- const startOffset = error.token?.startOffset ?? 0;
19
- const endOffset = error.token?.endOffset ?? 5;
20
- // Calculate line and character positions from offset
21
- const lines = text.substring(0, startOffset).split("\n");
22
- const line = lines.length - 1;
23
- const character = lines[lines.length - 1].length;
24
-
25
- const endLines = text.substring(0, endOffset + 1).split("\n");
26
- const endLine = endLines.length - 1;
27
- const endCharacter = endLines[endLines.length - 1].length;
28
-
29
- return {
30
- range: {
31
- start: { line, character },
32
- end: { line: endLine, character: endCharacter },
33
- },
34
- message: error.message,
35
- source: error.name || "XanoScript Parser",
36
- };
37
- });
39
+ for (const error of parser.errors) {
40
+ diagnostics.push(toDiagnostic(text, error, SEVERITY.ERROR));
41
+ }
42
+ for (const warning of parser.warnings ?? []) {
43
+ diagnostics.push(toDiagnostic(text, warning, SEVERITY.WARNING));
44
+ }
38
45
 
39
46
  return diagnostics;
40
47
  } catch (error) {
41
- console.error("Error checking for XanoScripterrors:", error);
48
+ console.error("Error checking for XanoScript errors:", error);
42
49
  }
43
50
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xano/xanoscript-language-server",
3
- "version": "11.12.3",
3
+ "version": "12.0.0",
4
4
  "description": "Language Server Protocol implementation for XanoScript",
5
5
  "type": "module",
6
6
  "main": "server.js",