@xano/xanoscript-language-server 11.8.4 → 11.8.5
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/.claude/settings.local.json +2 -1
- package/cache/documentCache.js +58 -10
- package/lexer/db.js +1 -2
- package/lexer/security.js +16 -0
- package/onCompletion/onCompletion.js +61 -1
- package/onDefinition/onDefinition.js +150 -0
- package/onDefinition/onDefinition.spec.js +313 -0
- package/onDidChangeContent/onDidChangeContent.js +52 -5
- package/onHover/functions.md +28 -0
- package/package.json +1 -1
- package/parser/base_parser.js +61 -3
- package/parser/clauses/middlewareClause.js +16 -0
- package/parser/definitions/columnDefinition.js +5 -0
- package/parser/functions/api/apiCallFn.js +5 -3
- package/parser/functions/controls/functionCallFn.js +5 -3
- package/parser/functions/controls/functionRunFn.js +61 -5
- package/parser/functions/controls/taskCallFn.js +5 -3
- package/parser/functions/db/captureFieldName.js +63 -0
- package/parser/functions/db/dbAddFn.js +5 -3
- package/parser/functions/db/dbAddOrEditFn.js +13 -3
- package/parser/functions/db/dbBulkAddFn.js +5 -3
- package/parser/functions/db/dbBulkDeleteFn.js +5 -3
- package/parser/functions/db/dbBulkPatchFn.js +5 -3
- package/parser/functions/db/dbBulkUpdateFn.js +5 -3
- package/parser/functions/db/dbDelFn.js +10 -3
- package/parser/functions/db/dbEditFn.js +13 -3
- package/parser/functions/db/dbGetFn.js +10 -3
- package/parser/functions/db/dbHasFn.js +9 -3
- package/parser/functions/db/dbPatchFn.js +10 -3
- package/parser/functions/db/dbQueryFn.js +29 -3
- package/parser/functions/db/dbSchemaFn.js +5 -3
- package/parser/functions/db/dbTruncateFn.js +5 -3
- package/parser/functions/middlewareCallFn.js +3 -1
- package/parser/functions/security/register.js +19 -9
- package/parser/functions/security/securityCreateAuthTokenFn.js +22 -0
- package/parser/functions/security/securityJweDecodeLegacyFn.js +24 -0
- package/parser/functions/security/securityJweDecodeLegacyFn.spec.js +26 -0
- package/parser/functions/security/securityJweEncodeLegacyFn.js +24 -0
- package/parser/functions/security/securityJweEncodeLegacyFn.spec.js +25 -0
- package/parser/functions/securityFn.js +2 -0
- package/parser/functions/varFn.js +1 -1
- package/parser/generic/asVariable.js +2 -0
- package/parser/generic/assignableVariableAs.js +1 -0
- package/parser/generic/assignableVariableProperty.js +5 -2
- package/parser/tests/variable_test/coverage_check.xs +293 -0
- package/parser/variableScanner.js +64 -0
- package/parser/variableValidator.js +44 -0
- package/parser/variableValidator.spec.js +179 -0
- package/server.js +164 -10
- package/utils.js +32 -0
- package/utils.spec.js +93 -1
- package/workspace/crossFileValidator.js +166 -0
- package/workspace/crossFileValidator.spec.js +654 -0
- package/workspace/referenceTracking.spec.js +420 -0
- package/workspace/workspaceIndex.js +149 -0
- package/workspace/workspaceIndex.spec.js +189 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { beforeEach, describe, it } from "mocha";
|
|
3
|
+
import { xanoscriptParser } from "../parser/parser.js";
|
|
4
|
+
import { getSchemeFromContent } from "../utils.js";
|
|
5
|
+
import { WorkspaceIndex } from "./workspaceIndex.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Helper to add a file with pre-parsed inputs (simulates what onDidChangeContent does).
|
|
9
|
+
*/
|
|
10
|
+
function addWithInputs(index, uri, content) {
|
|
11
|
+
const scheme = getSchemeFromContent(content);
|
|
12
|
+
const parser = xanoscriptParser(content, scheme);
|
|
13
|
+
return index.addParsed(uri, content, parser.__symbolTable);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
describe("WorkspaceIndex", () => {
|
|
17
|
+
let index;
|
|
18
|
+
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
index = new WorkspaceIndex();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe("addFile (lightweight indexing)", () => {
|
|
24
|
+
it("should index type and name from a function file", () => {
|
|
25
|
+
index.addFile(
|
|
26
|
+
"file:///workspace/my_func.xs",
|
|
27
|
+
`function "my_func" {
|
|
28
|
+
input {
|
|
29
|
+
int user_id
|
|
30
|
+
text? name
|
|
31
|
+
}
|
|
32
|
+
}`
|
|
33
|
+
);
|
|
34
|
+
expect(index.has("function", "my_func")).to.be.true;
|
|
35
|
+
const entry = index.getByUri("file:///workspace/my_func.xs");
|
|
36
|
+
expect(entry.type).to.equal("function");
|
|
37
|
+
expect(entry.name).to.equal("my_func");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("should index a query file", () => {
|
|
41
|
+
index.addFile(
|
|
42
|
+
"file:///workspace/get_users.xs",
|
|
43
|
+
'query "/users" GET {\n}'
|
|
44
|
+
);
|
|
45
|
+
expect(index.has("query", "/users")).to.be.true;
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("should index a task file", () => {
|
|
49
|
+
index.addFile(
|
|
50
|
+
"file:///workspace/cleanup.xs",
|
|
51
|
+
'task "daily_cleanup" {\n}'
|
|
52
|
+
);
|
|
53
|
+
expect(index.has("task", "daily_cleanup")).to.be.true;
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("should return false for unparseable content", () => {
|
|
57
|
+
const result = index.addFile("file:///workspace/bad.xs", "not valid");
|
|
58
|
+
expect(result).to.be.false;
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("should update entry when file content changes", () => {
|
|
62
|
+
index.addFile(
|
|
63
|
+
"file:///workspace/my_func.xs",
|
|
64
|
+
'function "my_func" {\n}'
|
|
65
|
+
);
|
|
66
|
+
index.addFile(
|
|
67
|
+
"file:///workspace/my_func.xs",
|
|
68
|
+
'function "renamed" {\n}'
|
|
69
|
+
);
|
|
70
|
+
expect(index.has("function", "my_func")).to.be.false;
|
|
71
|
+
expect(index.has("function", "renamed")).to.be.true;
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe("addParsed (with inputs)", () => {
|
|
76
|
+
it("should index a function file with inputs", () => {
|
|
77
|
+
const content = `function "my_func" {
|
|
78
|
+
input {
|
|
79
|
+
int user_id
|
|
80
|
+
text? name
|
|
81
|
+
}
|
|
82
|
+
}`;
|
|
83
|
+
addWithInputs(index, "file:///workspace/my_func.xs", content);
|
|
84
|
+
const entry = index.get("function", "my_func");
|
|
85
|
+
expect(entry).to.exist;
|
|
86
|
+
expect(entry.uri).to.equal("file:///workspace/my_func.xs");
|
|
87
|
+
expect(entry.type).to.equal("function");
|
|
88
|
+
expect(entry.name).to.equal("my_func");
|
|
89
|
+
expect(entry.inputs).to.have.property("user_id");
|
|
90
|
+
expect(entry.inputs.user_id.type).to.equal("int");
|
|
91
|
+
expect(entry.inputs.name.nullable).to.be.true;
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("should index a table file with columns", () => {
|
|
95
|
+
const content = `table users {
|
|
96
|
+
schema {
|
|
97
|
+
int id
|
|
98
|
+
text name
|
|
99
|
+
timestamp created_at?=now
|
|
100
|
+
}
|
|
101
|
+
}`;
|
|
102
|
+
addWithInputs(index, "file:///workspace/users.xs", content);
|
|
103
|
+
const entry = index.get("table", "users");
|
|
104
|
+
expect(entry).to.exist;
|
|
105
|
+
expect(entry.name).to.equal("users");
|
|
106
|
+
expect(entry.inputs).to.have.property("id");
|
|
107
|
+
expect(entry.inputs.id.type).to.equal("int");
|
|
108
|
+
expect(entry.inputs).to.have.property("name");
|
|
109
|
+
expect(entry.inputs.name.type).to.equal("text");
|
|
110
|
+
expect(entry.inputs.created_at.optional).to.be.true;
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
describe("removeFile", () => {
|
|
115
|
+
it("should remove an indexed file", () => {
|
|
116
|
+
index.addFile(
|
|
117
|
+
"file:///workspace/my_func.xs",
|
|
118
|
+
'function "my_func" {\n}'
|
|
119
|
+
);
|
|
120
|
+
index.removeFile("file:///workspace/my_func.xs");
|
|
121
|
+
expect(index.get("function", "my_func")).to.be.undefined;
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("should be a no-op for unknown URIs", () => {
|
|
125
|
+
index.removeFile("file:///workspace/unknown.xs");
|
|
126
|
+
// No error thrown
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
describe("getByType", () => {
|
|
131
|
+
it("should return all entries for a type", () => {
|
|
132
|
+
index.addFile("file:///workspace/a.xs", 'function "func_a" {\n}');
|
|
133
|
+
index.addFile("file:///workspace/b.xs", 'function "func_b" {\n}');
|
|
134
|
+
index.addFile("file:///workspace/t.xs", "table users {\n}");
|
|
135
|
+
|
|
136
|
+
const functions = index.getByType("function");
|
|
137
|
+
expect(functions).to.have.length(2);
|
|
138
|
+
expect(functions.map((f) => f.name)).to.include.members([
|
|
139
|
+
"func_a",
|
|
140
|
+
"func_b",
|
|
141
|
+
]);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("should return empty array for unknown type", () => {
|
|
145
|
+
expect(index.getByType("function")).to.deep.equal([]);
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
describe("has", () => {
|
|
150
|
+
it("should return true for indexed entries", () => {
|
|
151
|
+
index.addFile("file:///workspace/a.xs", 'function "my_func" {\n}');
|
|
152
|
+
expect(index.has("function", "my_func")).to.be.true;
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it("should return false for missing entries", () => {
|
|
156
|
+
expect(index.has("function", "nonexistent")).to.be.false;
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
describe("getAllNames", () => {
|
|
161
|
+
it("should return all names for a type", () => {
|
|
162
|
+
index.addFile("file:///workspace/a.xs", 'function "func_a" {\n}');
|
|
163
|
+
index.addFile("file:///workspace/b.xs", 'function "func_b" {\n}');
|
|
164
|
+
const names = index.getAllNames("function");
|
|
165
|
+
expect(names).to.include.members(["func_a", "func_b"]);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
describe("uri reverse lookup", () => {
|
|
170
|
+
it("should find entry by URI", () => {
|
|
171
|
+
index.addFile("file:///workspace/a.xs", 'function "my_func" {\n}');
|
|
172
|
+
const entry = index.getByUri("file:///workspace/a.xs");
|
|
173
|
+
expect(entry).to.exist;
|
|
174
|
+
expect(entry.name).to.equal("my_func");
|
|
175
|
+
expect(entry.type).to.equal("function");
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
describe("name collision", () => {
|
|
180
|
+
it("should overwrite when two files define same type+name", () => {
|
|
181
|
+
index.addFile("file:///workspace/a.xs", 'function "helper" {\n}');
|
|
182
|
+
index.addFile("file:///workspace/b.xs", 'function "helper" {\n}');
|
|
183
|
+
const entry = index.get("function", "helper");
|
|
184
|
+
expect(entry).to.exist;
|
|
185
|
+
expect(entry.uri).to.equal("file:///workspace/b.xs");
|
|
186
|
+
expect(index.getByUri("file:///workspace/a.xs")).to.be.undefined;
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
});
|