ifc-expressions 2.3.0 → 3.0.0-beta.2
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 +255 -30
- package/dist/IfcExpression.d.ts +24 -26
- package/dist/IfcExpressionErrorListener.d.ts +3 -3
- package/dist/IfcExpressionOptions.d.ts +4 -0
- package/dist/autocomplete/CompletionItem.d.ts +24 -0
- package/dist/autocomplete/IfcExpressionAutocomplete.d.ts +11 -0
- package/dist/builtin/BuiltinRuntimeValueConverter.d.ts +7 -0
- package/dist/builtin/BuiltinVariableRegistry.d.ts +50 -0
- package/dist/cjs/IfcExpression.js +112 -37
- package/dist/cjs/IfcExpression.js.map +1 -1
- package/dist/cjs/IfcExpressionErrorListener.js +3 -8
- package/dist/cjs/IfcExpressionErrorListener.js.map +1 -1
- package/dist/cjs/IfcExpressionOptions.js +3 -0
- package/dist/cjs/IfcExpressionOptions.js.map +1 -0
- package/dist/cjs/autocomplete/CompletionItem.js +3 -0
- package/dist/cjs/autocomplete/CompletionItem.js.map +1 -0
- package/dist/cjs/autocomplete/IfcExpressionAutocomplete.js +654 -0
- package/dist/cjs/autocomplete/IfcExpressionAutocomplete.js.map +1 -0
- package/dist/cjs/builtin/BuiltinRuntimeValueConverter.js +124 -0
- package/dist/cjs/builtin/BuiltinRuntimeValueConverter.js.map +1 -0
- package/dist/cjs/builtin/BuiltinVariableRegistry.js +405 -0
- package/dist/cjs/builtin/BuiltinVariableRegistry.js.map +1 -0
- package/dist/cjs/compiler/ExprCompiler.js +44 -41
- package/dist/cjs/compiler/ExprCompiler.js.map +1 -1
- package/dist/cjs/compiler/ExprManager.js.map +1 -1
- package/dist/cjs/compiler/IfcExpressionValidationListener.js +85 -25
- package/dist/cjs/compiler/IfcExpressionValidationListener.js.map +1 -1
- package/dist/cjs/compiler/TypeManager.js.map +1 -1
- package/dist/cjs/context/IfcExpressionContext.js.map +1 -1
- package/dist/cjs/context/NopContext.js +3 -0
- package/dist/cjs/context/NopContext.js.map +1 -1
- package/dist/cjs/documentation/Documentation.js +11 -0
- package/dist/cjs/documentation/Documentation.js.map +1 -0
- package/dist/cjs/error/ExpressionTypeError.js.map +1 -1
- package/dist/cjs/error/IfcExpressionBuiltinConfigException.js +10 -0
- package/dist/cjs/error/IfcExpressionBuiltinConfigException.js.map +1 -0
- package/dist/cjs/error/InvalidSyntaxException.js.map +1 -1
- package/dist/cjs/error/NoSuchFunctionException.js.map +1 -1
- package/dist/cjs/error/NoSuchMemberException.js +13 -0
- package/dist/cjs/error/NoSuchMemberException.js.map +1 -0
- package/dist/cjs/error/ValidationException.js.map +1 -1
- package/dist/cjs/error/WrongFunctionArgumentTypeException.js.map +1 -1
- package/dist/cjs/expression/ExprKind.js +3 -0
- package/dist/cjs/expression/ExprKind.js.map +1 -1
- package/dist/cjs/expression/function/Func.js +18 -14
- package/dist/cjs/expression/function/Func.js.map +1 -1
- package/dist/cjs/expression/function/FuncArg.js +11 -5
- package/dist/cjs/expression/function/FuncArg.js.map +1 -1
- package/dist/cjs/expression/function/IfcExpressionFunctions.js +198 -42
- package/dist/cjs/expression/function/IfcExpressionFunctions.js.map +1 -1
- package/dist/cjs/expression/function/impl/CHOOSE.js.map +1 -1
- package/dist/cjs/expression/function/impl/IF.js.map +1 -1
- package/dist/cjs/expression/function/impl/MAP.js.map +1 -1
- package/dist/cjs/expression/function/impl/ReplacePattern.js +20 -2
- package/dist/cjs/expression/function/impl/ReplacePattern.js.map +1 -1
- package/dist/cjs/expression/reference/BuiltinFunctionCallExpr.js +59 -0
- package/dist/cjs/expression/reference/BuiltinFunctionCallExpr.js.map +1 -0
- package/dist/cjs/expression/reference/BuiltinPropertyAccessExpr.js +34 -0
- package/dist/cjs/expression/reference/BuiltinPropertyAccessExpr.js.map +1 -0
- package/dist/cjs/expression/reference/BuiltinRootReferenceExpr.js +29 -0
- package/dist/cjs/expression/reference/BuiltinRootReferenceExpr.js.map +1 -0
- package/dist/cjs/gen/parser/IfcExpressionLexer.js +126 -104
- package/dist/cjs/gen/parser/IfcExpressionLexer.js.map +1 -1
- package/dist/cjs/gen/parser/IfcExpressionListener.js +7 -4
- package/dist/cjs/gen/parser/IfcExpressionListener.js.map +1 -1
- package/dist/cjs/gen/parser/IfcExpressionParser.js +739 -682
- package/dist/cjs/gen/parser/IfcExpressionParser.js.map +1 -1
- package/dist/cjs/gen/parser/IfcExpressionVisitor.js +4 -4
- package/dist/cjs/gen/parser/IfcExpressionVisitor.js.map +1 -1
- package/dist/cjs/index.js +4 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/type/ContextObjectType.js +45 -0
- package/dist/cjs/type/ContextObjectType.js.map +1 -0
- package/dist/cjs/type/Types.js +4 -6
- package/dist/cjs/type/Types.js.map +1 -1
- package/dist/cjs/value/ContextObjectValue.js +23 -0
- package/dist/cjs/value/ContextObjectValue.js.map +1 -0
- package/dist/cjs/value/ExpressionValue.js.map +1 -1
- package/dist/cjs/value/Value.js.map +1 -1
- package/dist/compiler/ExprCompiler.d.ts +8 -3
- package/dist/compiler/ExprManager.d.ts +1 -1
- package/dist/compiler/IfcExpressionValidationListener.d.ts +9 -3
- package/dist/compiler/TypeManager.d.ts +1 -1
- package/dist/context/IfcExpressionContext.d.ts +3 -4
- package/dist/context/NopContext.d.ts +1 -0
- package/dist/documentation/Documentation.d.ts +12 -0
- package/dist/error/ExpressionTypeError.d.ts +1 -1
- package/dist/error/IfcExpressionBuiltinConfigException.d.ts +3 -0
- package/dist/error/InvalidSyntaxException.d.ts +1 -1
- package/dist/error/NoSuchFunctionException.d.ts +1 -1
- package/dist/error/NoSuchMemberException.d.ts +6 -0
- package/dist/error/ValidationException.d.ts +1 -1
- package/dist/error/WrongFunctionArgumentTypeException.d.ts +1 -1
- package/dist/expression/ExprKind.d.ts +3 -0
- package/dist/expression/function/Func.d.ts +7 -21
- package/dist/expression/function/FuncArg.d.ts +6 -5
- package/dist/expression/function/IfcExpressionFunctions.d.ts +1 -0
- package/dist/expression/function/impl/CHOOSE.d.ts +1 -1
- package/dist/expression/function/impl/IF.d.ts +1 -1
- package/dist/expression/function/impl/MAP.d.ts +1 -1
- package/dist/expression/reference/BuiltinFunctionCallExpr.d.ts +19 -0
- package/dist/expression/reference/BuiltinPropertyAccessExpr.d.ts +15 -0
- package/dist/expression/reference/BuiltinRootReferenceExpr.d.ts +14 -0
- package/dist/gen/parser/IfcExpressionLexer.d.ts +9 -8
- package/dist/gen/parser/IfcExpressionListener.d.ts +89 -59
- package/dist/gen/parser/IfcExpressionParser.d.ts +192 -169
- package/dist/gen/parser/IfcExpressionVisitor.d.ts +51 -35
- package/dist/index.d.ts +2 -2
- package/dist/mjs/IfcExpression.js +104 -32
- package/dist/mjs/IfcExpression.js.map +1 -1
- package/dist/mjs/IfcExpressionErrorListener.js +3 -8
- package/dist/mjs/IfcExpressionErrorListener.js.map +1 -1
- package/dist/mjs/IfcExpressionOptions.js +2 -0
- package/dist/mjs/IfcExpressionOptions.js.map +1 -0
- package/dist/mjs/autocomplete/CompletionItem.js +2 -0
- package/dist/mjs/autocomplete/CompletionItem.js.map +1 -0
- package/dist/mjs/autocomplete/IfcExpressionAutocomplete.js +650 -0
- package/dist/mjs/autocomplete/IfcExpressionAutocomplete.js.map +1 -0
- package/dist/mjs/builtin/BuiltinRuntimeValueConverter.js +117 -0
- package/dist/mjs/builtin/BuiltinRuntimeValueConverter.js.map +1 -0
- package/dist/mjs/builtin/BuiltinVariableRegistry.js +399 -0
- package/dist/mjs/builtin/BuiltinVariableRegistry.js.map +1 -0
- package/dist/mjs/compiler/ExprCompiler.js +43 -40
- package/dist/mjs/compiler/ExprCompiler.js.map +1 -1
- package/dist/mjs/compiler/ExprManager.js.map +1 -1
- package/dist/mjs/compiler/IfcExpressionValidationListener.js +85 -22
- package/dist/mjs/compiler/IfcExpressionValidationListener.js.map +1 -1
- package/dist/mjs/compiler/TypeManager.js.map +1 -1
- package/dist/mjs/context/IfcExpressionContext.js.map +1 -1
- package/dist/mjs/context/NopContext.js +3 -0
- package/dist/mjs/context/NopContext.js.map +1 -1
- package/dist/mjs/documentation/Documentation.js +7 -0
- package/dist/mjs/documentation/Documentation.js.map +1 -0
- package/dist/mjs/error/ExpressionTypeError.js.map +1 -1
- package/dist/mjs/error/IfcExpressionBuiltinConfigException.js +6 -0
- package/dist/mjs/error/IfcExpressionBuiltinConfigException.js.map +1 -0
- package/dist/mjs/error/InvalidSyntaxException.js.map +1 -1
- package/dist/mjs/error/NoSuchFunctionException.js.map +1 -1
- package/dist/mjs/error/NoSuchMemberException.js +9 -0
- package/dist/mjs/error/NoSuchMemberException.js.map +1 -0
- package/dist/mjs/error/ValidationException.js.map +1 -1
- package/dist/mjs/error/WrongFunctionArgumentTypeException.js.map +1 -1
- package/dist/mjs/expression/ExprKind.js +3 -0
- package/dist/mjs/expression/ExprKind.js.map +1 -1
- package/dist/mjs/expression/function/Func.js +18 -14
- package/dist/mjs/expression/function/Func.js.map +1 -1
- package/dist/mjs/expression/function/FuncArg.js +11 -5
- package/dist/mjs/expression/function/FuncArg.js.map +1 -1
- package/dist/mjs/expression/function/IfcExpressionFunctions.js +198 -42
- package/dist/mjs/expression/function/IfcExpressionFunctions.js.map +1 -1
- package/dist/mjs/expression/function/impl/CHOOSE.js.map +1 -1
- package/dist/mjs/expression/function/impl/IF.js.map +1 -1
- package/dist/mjs/expression/function/impl/MAP.js.map +1 -1
- package/dist/mjs/expression/function/impl/ReplacePattern.js +20 -2
- package/dist/mjs/expression/function/impl/ReplacePattern.js.map +1 -1
- package/dist/mjs/expression/reference/BuiltinFunctionCallExpr.js +55 -0
- package/dist/mjs/expression/reference/BuiltinFunctionCallExpr.js.map +1 -0
- package/dist/mjs/expression/reference/BuiltinPropertyAccessExpr.js +30 -0
- package/dist/mjs/expression/reference/BuiltinPropertyAccessExpr.js.map +1 -0
- package/dist/mjs/expression/reference/BuiltinRootReferenceExpr.js +25 -0
- package/dist/mjs/expression/reference/BuiltinRootReferenceExpr.js.map +1 -0
- package/dist/mjs/gen/parser/IfcExpressionLexer.js +101 -104
- package/dist/mjs/gen/parser/IfcExpressionLexer.js.map +1 -1
- package/dist/mjs/gen/parser/IfcExpressionListener.js +5 -3
- package/dist/mjs/gen/parser/IfcExpressionListener.js.map +1 -1
- package/dist/mjs/gen/parser/IfcExpressionParser.js +700 -670
- package/dist/mjs/gen/parser/IfcExpressionParser.js.map +1 -1
- package/dist/mjs/gen/parser/IfcExpressionVisitor.js +2 -3
- package/dist/mjs/gen/parser/IfcExpressionVisitor.js.map +1 -1
- package/dist/mjs/index.js +1 -1
- package/dist/mjs/index.js.map +1 -1
- package/dist/mjs/type/ContextObjectType.js +41 -0
- package/dist/mjs/type/ContextObjectType.js.map +1 -0
- package/dist/mjs/type/Types.js +4 -6
- package/dist/mjs/type/Types.js.map +1 -1
- package/dist/mjs/value/ContextObjectValue.js +19 -0
- package/dist/mjs/value/ContextObjectValue.js.map +1 -0
- package/dist/mjs/value/ExpressionValue.js.map +1 -1
- package/dist/mjs/value/Value.js.map +1 -1
- package/dist/type/ContextObjectType.d.ts +17 -0
- package/dist/type/Types.d.ts +2 -6
- package/dist/value/ContextObjectValue.d.ts +11 -0
- package/dist/value/ExpressionValue.d.ts +2 -1
- package/dist/value/Value.d.ts +1 -1
- package/package.json +5 -3
|
@@ -0,0 +1,654 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IfcExpressionAutocomplete = void 0;
|
|
4
|
+
const antlr4ng_1 = require("antlr4ng");
|
|
5
|
+
const antlr4_c3_1 = require("antlr4-c3");
|
|
6
|
+
const BuiltinVariableRegistry_js_1 = require("../builtin/BuiltinVariableRegistry.js");
|
|
7
|
+
const IfcExpressionLexer_js_1 = require("../gen/parser/IfcExpressionLexer.js");
|
|
8
|
+
const IfcExpressionParser_js_1 = require("../gen/parser/IfcExpressionParser.js");
|
|
9
|
+
const IfcExpressionFunctions_js_1 = require("../expression/function/IfcExpressionFunctions.js");
|
|
10
|
+
const ContextObjectType_js_1 = require("../type/ContextObjectType.js");
|
|
11
|
+
const Documentation_js_1 = require("../documentation/Documentation.js");
|
|
12
|
+
function isIdentifierChar(char) {
|
|
13
|
+
return typeof char === "string" && /[a-zA-Z0-9_\-$&]/.test(char);
|
|
14
|
+
}
|
|
15
|
+
function toBuiltinLabel(name) {
|
|
16
|
+
return name.startsWith("$") ? name : `$${name}`;
|
|
17
|
+
}
|
|
18
|
+
function normalizeForMatch(value) {
|
|
19
|
+
return value.toUpperCase();
|
|
20
|
+
}
|
|
21
|
+
function toCompletionTypeName(type) {
|
|
22
|
+
return type.getName().replace(/^\$/, "");
|
|
23
|
+
}
|
|
24
|
+
function isChainableType(type) {
|
|
25
|
+
return type instanceof ContextObjectType_js_1.ContextObjectType;
|
|
26
|
+
}
|
|
27
|
+
const unsupportedPrimitiveMethodFunctionNames = new Set([
|
|
28
|
+
"NAME",
|
|
29
|
+
"GUID",
|
|
30
|
+
"IFCCLASS",
|
|
31
|
+
"DESCRIPTION",
|
|
32
|
+
"VALUE",
|
|
33
|
+
]);
|
|
34
|
+
const preferredMethodLabels = new Map([
|
|
35
|
+
["MAP", "map"],
|
|
36
|
+
["CHOOSE", "choose"],
|
|
37
|
+
["AT", "at"],
|
|
38
|
+
["IF", "if"],
|
|
39
|
+
["ROUND", "round"],
|
|
40
|
+
["NAME", "name"],
|
|
41
|
+
["GUID", "guid"],
|
|
42
|
+
["IFCCLASS", "ifcClass"],
|
|
43
|
+
["DESCRIPTION", "description"],
|
|
44
|
+
["VALUE", "value"],
|
|
45
|
+
["PROPERTYSET", "propertySet"],
|
|
46
|
+
["PROPERTY", "property"],
|
|
47
|
+
["TYPE", "type"],
|
|
48
|
+
["NOT", "not"],
|
|
49
|
+
["TOSTRING", "toString"],
|
|
50
|
+
["TONUMERIC", "toNumeric"],
|
|
51
|
+
["TONUMBER", "toNumber"],
|
|
52
|
+
["TOBOOLEAN", "toBoolean"],
|
|
53
|
+
["TOLOGICAL", "toLogical"],
|
|
54
|
+
["NOTFOUNDASUNKNOWN", "notFoundAsUnknown"],
|
|
55
|
+
["TOIFCDATE", "toIfcDate"],
|
|
56
|
+
["TOIFCTIME", "toIfcTime"],
|
|
57
|
+
["TOIFCDATETIME", "toIfcDateTime"],
|
|
58
|
+
["TOIFCDURATION", "toIfcDuration"],
|
|
59
|
+
["TOIFCTIMESTAMP", "toIfcTimeStamp"],
|
|
60
|
+
["ADDDURATION", "addDuration"],
|
|
61
|
+
["TOLOWERCASE", "toLowerCase"],
|
|
62
|
+
["TOUPPERCASE", "toUpperCase"],
|
|
63
|
+
["SUBSTRING", "substring"],
|
|
64
|
+
["SPLIT", "split"],
|
|
65
|
+
["EXISTS", "exists"],
|
|
66
|
+
["AND", "and"],
|
|
67
|
+
["OR", "or"],
|
|
68
|
+
["XOR", "xor"],
|
|
69
|
+
["IMPLIES", "implies"],
|
|
70
|
+
["EQUALS", "equals"],
|
|
71
|
+
["GREATERTHAN", "greaterThan"],
|
|
72
|
+
["GREATERTHANOREQUAL", "greaterThanOrEqual"],
|
|
73
|
+
["LESSTHAN", "lessThan"],
|
|
74
|
+
["LESSTHANOREQUAL", "lessThanOrEqual"],
|
|
75
|
+
["CONTAINS", "contains"],
|
|
76
|
+
["MATCHES", "matches"],
|
|
77
|
+
["REGEXCONTAINS", "regexContains"],
|
|
78
|
+
["REGEXMATCHES", "regexMatches"],
|
|
79
|
+
["REPLACE", "replace"],
|
|
80
|
+
["REGEXREPLACE", "regexReplace"],
|
|
81
|
+
]);
|
|
82
|
+
const emptyExpressionStarterFunctionNames = [
|
|
83
|
+
"IF",
|
|
84
|
+
"EXISTS",
|
|
85
|
+
"ROUND",
|
|
86
|
+
"CONTAINS",
|
|
87
|
+
"MATCHES",
|
|
88
|
+
"REPLACE",
|
|
89
|
+
"TOSTRING",
|
|
90
|
+
"TONUMERIC",
|
|
91
|
+
"TOBOOLEAN",
|
|
92
|
+
];
|
|
93
|
+
function isExtendableTokenType(tokenType) {
|
|
94
|
+
return tokenType === IfcExpressionParser_js_1.IfcExpressionParser.IDENTIFIER;
|
|
95
|
+
}
|
|
96
|
+
function findCaretTokenIndex(tokens, cursorOffset) {
|
|
97
|
+
if (tokens.length === 0) {
|
|
98
|
+
return 0;
|
|
99
|
+
}
|
|
100
|
+
const cursor = Math.max(0, cursorOffset);
|
|
101
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
102
|
+
const token = tokens[i];
|
|
103
|
+
if (token.type === antlr4ng_1.Token.EOF) {
|
|
104
|
+
return token.tokenIndex;
|
|
105
|
+
}
|
|
106
|
+
if (cursor < token.start) {
|
|
107
|
+
return token.tokenIndex;
|
|
108
|
+
}
|
|
109
|
+
if (cursor <= token.stop) {
|
|
110
|
+
return token.tokenIndex;
|
|
111
|
+
}
|
|
112
|
+
if (cursor === token.stop + 1) {
|
|
113
|
+
if (isExtendableTokenType(token.type)) {
|
|
114
|
+
return token.tokenIndex;
|
|
115
|
+
}
|
|
116
|
+
const nextToken = tokens[i + 1];
|
|
117
|
+
return nextToken?.tokenIndex ?? token.tokenIndex;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return tokens[tokens.length - 1].tokenIndex;
|
|
121
|
+
}
|
|
122
|
+
function parseAutocompleteInput(input, cursorOffset) {
|
|
123
|
+
const chars = antlr4ng_1.CharStream.fromString(input);
|
|
124
|
+
const lexer = new IfcExpressionLexer_js_1.IfcExpressionLexer(chars);
|
|
125
|
+
const tokenStream = new antlr4ng_1.CommonTokenStream(lexer);
|
|
126
|
+
const parser = new IfcExpressionParser_js_1.IfcExpressionParser(tokenStream);
|
|
127
|
+
lexer.removeErrorListeners();
|
|
128
|
+
parser.removeErrorListeners();
|
|
129
|
+
const parseTree = parser.expr();
|
|
130
|
+
tokenStream.fill();
|
|
131
|
+
const tokens = tokenStream.getTokens();
|
|
132
|
+
return {
|
|
133
|
+
parser,
|
|
134
|
+
parseTree,
|
|
135
|
+
tokens,
|
|
136
|
+
caretTokenIndex: findCaretTokenIndex(tokens, cursorOffset),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function findBuiltinRootReplaceRange(input, cursorOffset) {
|
|
140
|
+
const cursor = Math.max(0, Math.min(cursorOffset, input.length));
|
|
141
|
+
let i = cursor - 1;
|
|
142
|
+
while (i >= 0 && isIdentifierChar(input[i]) && input[i] !== "$") {
|
|
143
|
+
i--;
|
|
144
|
+
}
|
|
145
|
+
if (i >= 0 && input[i] === "$") {
|
|
146
|
+
return { from: i, to: cursor };
|
|
147
|
+
}
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
function findIdentifierReplaceRange(input, cursorOffset) {
|
|
151
|
+
const cursor = Math.max(0, Math.min(cursorOffset, input.length));
|
|
152
|
+
let from = cursor;
|
|
153
|
+
while (from > 0 && isIdentifierChar(input[from - 1])) {
|
|
154
|
+
from--;
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
from,
|
|
158
|
+
to: cursor,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
function findMemberReplaceRange(input, cursorOffset) {
|
|
162
|
+
const range = findIdentifierReplaceRange(input, cursorOffset);
|
|
163
|
+
if (range.from === 0 || input[range.from - 1] !== ".") {
|
|
164
|
+
return undefined;
|
|
165
|
+
}
|
|
166
|
+
return range;
|
|
167
|
+
}
|
|
168
|
+
function findFunctionReplaceRange(input, cursorOffset) {
|
|
169
|
+
const range = findIdentifierReplaceRange(input, cursorOffset);
|
|
170
|
+
const prefixChar = range.from > 0 ? input[range.from - 1] : undefined;
|
|
171
|
+
const hasIdentifierFragment = range.from < range.to || isIdentifierChar(input[Math.max(0, range.to)]);
|
|
172
|
+
if (!hasIdentifierFragment || prefixChar === "." || prefixChar === "$") {
|
|
173
|
+
return undefined;
|
|
174
|
+
}
|
|
175
|
+
return range;
|
|
176
|
+
}
|
|
177
|
+
function countExprListArguments(exprList) {
|
|
178
|
+
if (!exprList) {
|
|
179
|
+
return 0;
|
|
180
|
+
}
|
|
181
|
+
const rest = exprList.exprList();
|
|
182
|
+
return 1 + (rest ? countExprListArguments(rest) : 0);
|
|
183
|
+
}
|
|
184
|
+
function toMethodAccessorStep(methodAccessor) {
|
|
185
|
+
if (methodAccessor instanceof IfcExpressionParser_js_1.MethodPropertyAccessContext) {
|
|
186
|
+
const identifier = methodAccessor.IDENTIFIER()?.getText();
|
|
187
|
+
if (!identifier) {
|
|
188
|
+
return undefined;
|
|
189
|
+
}
|
|
190
|
+
return {
|
|
191
|
+
name: identifier,
|
|
192
|
+
kind: "property",
|
|
193
|
+
startTokenIndex: methodAccessor.start?.tokenIndex ?? -1,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
if (methodAccessor instanceof IfcExpressionParser_js_1.MethodFunctionCallContext) {
|
|
197
|
+
const functionCall = methodAccessor.functionCall();
|
|
198
|
+
const name = functionCall.IDENTIFIER()?.getText();
|
|
199
|
+
if (!name) {
|
|
200
|
+
return undefined;
|
|
201
|
+
}
|
|
202
|
+
return {
|
|
203
|
+
name,
|
|
204
|
+
kind: "function",
|
|
205
|
+
argumentCount: countExprListArguments(functionCall.exprList()),
|
|
206
|
+
startTokenIndex: functionCall.start?.tokenIndex ?? -1,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
return undefined;
|
|
210
|
+
}
|
|
211
|
+
function collectMethodCallChainSteps(methodCallChain) {
|
|
212
|
+
if (methodCallChain instanceof IfcExpressionParser_js_1.MethodCallChainInnerContext) {
|
|
213
|
+
const current = toMethodAccessorStep(methodCallChain.methodAccessor());
|
|
214
|
+
const rest = collectMethodCallChainSteps(methodCallChain.methodCallChain());
|
|
215
|
+
if (!current || !rest) {
|
|
216
|
+
return undefined;
|
|
217
|
+
}
|
|
218
|
+
return [current, ...rest];
|
|
219
|
+
}
|
|
220
|
+
if (methodCallChain instanceof IfcExpressionParser_js_1.MethodCallChainEndContext) {
|
|
221
|
+
const current = toMethodAccessorStep(methodCallChain.methodAccessor());
|
|
222
|
+
return current ? [current] : undefined;
|
|
223
|
+
}
|
|
224
|
+
const dot = methodCallChain.getToken(IfcExpressionParser_js_1.IfcExpressionParser.DOT, 0);
|
|
225
|
+
if (dot) {
|
|
226
|
+
return [
|
|
227
|
+
{
|
|
228
|
+
kind: "incomplete",
|
|
229
|
+
startTokenIndex: dot.symbol.tokenIndex + 1,
|
|
230
|
+
},
|
|
231
|
+
];
|
|
232
|
+
}
|
|
233
|
+
return [];
|
|
234
|
+
}
|
|
235
|
+
function getMemberResultType(definition) {
|
|
236
|
+
return definition.kind === "property"
|
|
237
|
+
? definition.valueType
|
|
238
|
+
: definition.returnType;
|
|
239
|
+
}
|
|
240
|
+
function resolveCompletedAccessorStep(currentType, step) {
|
|
241
|
+
if (!(currentType instanceof ContextObjectType_js_1.ContextObjectType)) {
|
|
242
|
+
return undefined;
|
|
243
|
+
}
|
|
244
|
+
const memberDefinition = currentType.getMemberDefinition(step.name);
|
|
245
|
+
if (!memberDefinition) {
|
|
246
|
+
return undefined;
|
|
247
|
+
}
|
|
248
|
+
if (step.kind === "property") {
|
|
249
|
+
return memberDefinition.kind === "property"
|
|
250
|
+
? memberDefinition.valueType
|
|
251
|
+
: undefined;
|
|
252
|
+
}
|
|
253
|
+
if (memberDefinition.kind !== "function") {
|
|
254
|
+
return undefined;
|
|
255
|
+
}
|
|
256
|
+
if (memberDefinition.argumentTypes.length !== step.argumentCount) {
|
|
257
|
+
return undefined;
|
|
258
|
+
}
|
|
259
|
+
return memberDefinition.returnType;
|
|
260
|
+
}
|
|
261
|
+
function resolveSingleExprType(singleExpr, builtinVariableRegistry) {
|
|
262
|
+
if (singleExpr instanceof IfcExpressionParser_js_1.SEVariableRefContext) {
|
|
263
|
+
const identifier = singleExpr.variableRef()?.IDENTIFIER()?.getText();
|
|
264
|
+
return identifier
|
|
265
|
+
? builtinVariableRegistry.getDefinition(`$${identifier}`)?.type
|
|
266
|
+
: undefined;
|
|
267
|
+
}
|
|
268
|
+
if (singleExpr instanceof IfcExpressionParser_js_1.SEParenthesisContext) {
|
|
269
|
+
return resolveSingleExprType(singleExpr.singleExpr(), builtinVariableRegistry);
|
|
270
|
+
}
|
|
271
|
+
if (singleExpr instanceof IfcExpressionParser_js_1.SEMethodCallContext) {
|
|
272
|
+
const baseType = resolveSingleExprType(singleExpr.singleExpr(), builtinVariableRegistry);
|
|
273
|
+
const steps = collectMethodCallChainSteps(singleExpr.methodCallChain());
|
|
274
|
+
if (!baseType || !steps) {
|
|
275
|
+
return undefined;
|
|
276
|
+
}
|
|
277
|
+
let currentType = baseType;
|
|
278
|
+
for (const step of steps) {
|
|
279
|
+
if (step.kind === "incomplete") {
|
|
280
|
+
return undefined;
|
|
281
|
+
}
|
|
282
|
+
currentType = resolveCompletedAccessorStep(currentType, step);
|
|
283
|
+
if (!currentType) {
|
|
284
|
+
return undefined;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
return currentType;
|
|
288
|
+
}
|
|
289
|
+
return undefined;
|
|
290
|
+
}
|
|
291
|
+
function findReceiverTypeForMemberSlot(node, startTokenIndex, builtinVariableRegistry) {
|
|
292
|
+
if (node instanceof IfcExpressionParser_js_1.SEMethodCallContext) {
|
|
293
|
+
const steps = collectMethodCallChainSteps(node.methodCallChain());
|
|
294
|
+
if (steps) {
|
|
295
|
+
const slotIndex = steps.findIndex((step) => step.startTokenIndex === startTokenIndex);
|
|
296
|
+
if (slotIndex >= 0) {
|
|
297
|
+
let currentType = resolveSingleExprType(node.singleExpr(), builtinVariableRegistry);
|
|
298
|
+
for (const step of steps.slice(0, slotIndex)) {
|
|
299
|
+
if (!currentType || step.kind === "incomplete") {
|
|
300
|
+
return undefined;
|
|
301
|
+
}
|
|
302
|
+
currentType = resolveCompletedAccessorStep(currentType, step);
|
|
303
|
+
}
|
|
304
|
+
return currentType;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
for (let i = 0; i < node.getChildCount(); i++) {
|
|
309
|
+
const child = node.getChild(i);
|
|
310
|
+
if (child instanceof antlr4ng_1.ParserRuleContext) {
|
|
311
|
+
const receiverType = findReceiverTypeForMemberSlot(child, startTokenIndex, builtinVariableRegistry);
|
|
312
|
+
if (receiverType) {
|
|
313
|
+
return receiverType;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
return undefined;
|
|
318
|
+
}
|
|
319
|
+
function isEmptyExpressionInput(input) {
|
|
320
|
+
return input.trim().length === 0;
|
|
321
|
+
}
|
|
322
|
+
function toFunctionInsertText(name) {
|
|
323
|
+
return `${name}()`;
|
|
324
|
+
}
|
|
325
|
+
function buildSignatureLabel(name, argumentLabels) {
|
|
326
|
+
return `${name}(${argumentLabels.join(", ")})`;
|
|
327
|
+
}
|
|
328
|
+
function buildFunctionDocumentation(name, localizer, displayName = name) {
|
|
329
|
+
const func = IfcExpressionFunctions_js_1.IfcExpressionFunctions.getFunction(name);
|
|
330
|
+
const documentation = func?.getDocumentation();
|
|
331
|
+
if (!func || !documentation) {
|
|
332
|
+
return undefined;
|
|
333
|
+
}
|
|
334
|
+
const fallback = `${func.getSignatureLabel(displayName)}: ${documentation.fallback}`;
|
|
335
|
+
return localizer ? localizer.t(documentation.key, fallback) : fallback;
|
|
336
|
+
}
|
|
337
|
+
function buildMemberDocumentation(definition, localizer) {
|
|
338
|
+
if (!definition.documentation) {
|
|
339
|
+
return undefined;
|
|
340
|
+
}
|
|
341
|
+
const fallback = definition.kind === "property"
|
|
342
|
+
? `${definition.name}: ${definition.documentation.fallback}`
|
|
343
|
+
: `${buildSignatureLabel(definition.name, (definition.argumentDocumentation ?? []).map((argument, index) => argument.label.fallback ?? `arg${index}`))}: ${definition.documentation.fallback}`;
|
|
344
|
+
return localizer
|
|
345
|
+
? localizer.t(definition.documentation.key, fallback)
|
|
346
|
+
: fallback;
|
|
347
|
+
}
|
|
348
|
+
function buildRootDocumentation(name, documentation, localizer) {
|
|
349
|
+
const key = documentation?.key ?? `builtin.${name}.summary`;
|
|
350
|
+
const fallback = documentation?.fallback ??
|
|
351
|
+
`${name}: built-in value from the evaluation context`;
|
|
352
|
+
return localizer ? localizer.t(key, fallback) : fallback;
|
|
353
|
+
}
|
|
354
|
+
function findActiveCallFrame(tokens, cursorOffset) {
|
|
355
|
+
const stack = [];
|
|
356
|
+
let previousSignificantToken;
|
|
357
|
+
for (const token of tokens) {
|
|
358
|
+
if (token.type === antlr4ng_1.Token.EOF || token.start >= cursorOffset) {
|
|
359
|
+
break;
|
|
360
|
+
}
|
|
361
|
+
if (token.type === IfcExpressionParser_js_1.IfcExpressionParser.WS ||
|
|
362
|
+
token.type === IfcExpressionParser_js_1.IfcExpressionParser.NEWLINE) {
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
if (token.type === IfcExpressionParser_js_1.IfcExpressionParser.T__1) {
|
|
366
|
+
stack.push(previousSignificantToken?.type === IfcExpressionParser_js_1.IfcExpressionParser.IDENTIFIER
|
|
367
|
+
? {
|
|
368
|
+
kind: "function",
|
|
369
|
+
name: previousSignificantToken.text ?? undefined,
|
|
370
|
+
argumentIndex: 0,
|
|
371
|
+
startTokenIndex: previousSignificantToken.tokenIndex,
|
|
372
|
+
}
|
|
373
|
+
: { kind: "group", argumentIndex: 0 });
|
|
374
|
+
}
|
|
375
|
+
else if (token.type === IfcExpressionParser_js_1.IfcExpressionParser.T__10) {
|
|
376
|
+
stack.push({ kind: "array", argumentIndex: 0 });
|
|
377
|
+
}
|
|
378
|
+
else if (token.type === IfcExpressionParser_js_1.IfcExpressionParser.T__2 ||
|
|
379
|
+
token.type === IfcExpressionParser_js_1.IfcExpressionParser.T__11) {
|
|
380
|
+
stack.pop();
|
|
381
|
+
}
|
|
382
|
+
else if (token.type === IfcExpressionParser_js_1.IfcExpressionParser.T__9) {
|
|
383
|
+
const currentFrame = stack[stack.length - 1];
|
|
384
|
+
if (currentFrame?.kind === "function") {
|
|
385
|
+
currentFrame.argumentIndex += 1;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
previousSignificantToken = token;
|
|
389
|
+
}
|
|
390
|
+
for (let i = stack.length - 1; i >= 0; i--) {
|
|
391
|
+
if (stack[i].kind === "function") {
|
|
392
|
+
return stack[i];
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
return undefined;
|
|
396
|
+
}
|
|
397
|
+
function buildMemberSignatureLabel(definition) {
|
|
398
|
+
return buildSignatureLabel(definition.name, (definition.argumentDocumentation ?? []).map((argument, index) => argument.label.fallback ?? `arg${index}`));
|
|
399
|
+
}
|
|
400
|
+
function buildActiveMemberHelp(parseTree, builtinVariableRegistry, activeFrame, localizer) {
|
|
401
|
+
if (activeFrame.startTokenIndex === undefined || !activeFrame.name) {
|
|
402
|
+
return undefined;
|
|
403
|
+
}
|
|
404
|
+
const receiverType = findReceiverTypeForMemberSlot(parseTree, activeFrame.startTokenIndex, builtinVariableRegistry);
|
|
405
|
+
if (!(receiverType instanceof ContextObjectType_js_1.ContextObjectType)) {
|
|
406
|
+
return undefined;
|
|
407
|
+
}
|
|
408
|
+
const memberDefinition = receiverType.getMemberDefinition(activeFrame.name);
|
|
409
|
+
if (memberDefinition?.kind !== "function" ||
|
|
410
|
+
!memberDefinition.documentation) {
|
|
411
|
+
return undefined;
|
|
412
|
+
}
|
|
413
|
+
const label = buildMemberSignatureLabel(memberDefinition);
|
|
414
|
+
const fallback = memberDefinition.documentation.fallback.startsWith(`${label}: `)
|
|
415
|
+
? memberDefinition.documentation.fallback
|
|
416
|
+
: `${label}: ${memberDefinition.documentation.fallback}`;
|
|
417
|
+
const activeArgument = memberDefinition.argumentDocumentation?.[activeFrame.argumentIndex];
|
|
418
|
+
return {
|
|
419
|
+
label,
|
|
420
|
+
documentation: localizer
|
|
421
|
+
? localizer.t(memberDefinition.documentation.key, fallback)
|
|
422
|
+
: fallback,
|
|
423
|
+
activeParameterIndex: activeFrame.argumentIndex,
|
|
424
|
+
activeParameterLabel: activeArgument
|
|
425
|
+
? (0, Documentation_js_1.resolveLocalizedText)(activeArgument.label, localizer) ??
|
|
426
|
+
activeArgument.label.fallback
|
|
427
|
+
: undefined,
|
|
428
|
+
activeParameterDocumentation: activeArgument
|
|
429
|
+
? (0, Documentation_js_1.resolveLocalizedText)(activeArgument.documentation, localizer)
|
|
430
|
+
: undefined,
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
function buildActiveHelp(parseTree, builtinVariableRegistry, tokens, cursorOffset, localizer) {
|
|
434
|
+
const activeFrame = findActiveCallFrame(tokens, cursorOffset);
|
|
435
|
+
if (!activeFrame?.name) {
|
|
436
|
+
return undefined;
|
|
437
|
+
}
|
|
438
|
+
const memberHelp = buildActiveMemberHelp(parseTree, builtinVariableRegistry, activeFrame, localizer);
|
|
439
|
+
if (memberHelp) {
|
|
440
|
+
return memberHelp;
|
|
441
|
+
}
|
|
442
|
+
const func = IfcExpressionFunctions_js_1.IfcExpressionFunctions.getFunction(activeFrame.name);
|
|
443
|
+
const documentation = func?.getDocumentation();
|
|
444
|
+
if (!func || !documentation) {
|
|
445
|
+
return undefined;
|
|
446
|
+
}
|
|
447
|
+
const activeArgument = func.getFormalArguments()[activeFrame.argumentIndex];
|
|
448
|
+
const label = func.getSignatureLabel(activeFrame.name);
|
|
449
|
+
const fallback = `${label}: ${documentation.fallback}`;
|
|
450
|
+
return {
|
|
451
|
+
label,
|
|
452
|
+
documentation: localizer
|
|
453
|
+
? localizer.t(documentation.key, fallback)
|
|
454
|
+
: fallback,
|
|
455
|
+
activeParameterIndex: activeFrame.argumentIndex,
|
|
456
|
+
activeParameterLabel: activeArgument
|
|
457
|
+
? (0, Documentation_js_1.resolveLocalizedText)(activeArgument.displayLabel, localizer) ??
|
|
458
|
+
activeArgument.displayLabel?.fallback ??
|
|
459
|
+
activeArgument.name
|
|
460
|
+
: undefined,
|
|
461
|
+
activeParameterDocumentation: activeArgument
|
|
462
|
+
? (0, Documentation_js_1.resolveLocalizedText)(activeArgument.documentation, localizer)
|
|
463
|
+
: undefined,
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
function toFunctionItem(name, localizer, label = name) {
|
|
467
|
+
const insertText = toFunctionInsertText(label);
|
|
468
|
+
return {
|
|
469
|
+
kind: "builtinFunction",
|
|
470
|
+
label,
|
|
471
|
+
insertText,
|
|
472
|
+
cursorOffset: insertText.length - 1,
|
|
473
|
+
documentation: buildFunctionDocumentation(name, localizer, label),
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
function getPreferredMethodLabel(name) {
|
|
477
|
+
return preferredMethodLabels.get(name) ?? name;
|
|
478
|
+
}
|
|
479
|
+
function isApplicablePrimitiveMethodFunction(name, receiverType) {
|
|
480
|
+
if (unsupportedPrimitiveMethodFunctionNames.has(name)) {
|
|
481
|
+
return false;
|
|
482
|
+
}
|
|
483
|
+
const func = IfcExpressionFunctions_js_1.IfcExpressionFunctions.getFunction(name);
|
|
484
|
+
const firstArgument = func?.getFormalArguments()[0];
|
|
485
|
+
if (!func || !firstArgument) {
|
|
486
|
+
return false;
|
|
487
|
+
}
|
|
488
|
+
const firstArgumentType = firstArgument.getType();
|
|
489
|
+
return (firstArgumentType.isAssignableFrom(receiverType) ||
|
|
490
|
+
firstArgumentType.overlapsWith(receiverType));
|
|
491
|
+
}
|
|
492
|
+
function getPrimitiveMethodItems(receiverType, localizer) {
|
|
493
|
+
return IfcExpressionFunctions_js_1.IfcExpressionFunctions.getBuiltinFunctionNames()
|
|
494
|
+
.filter((name) => isApplicablePrimitiveMethodFunction(name, receiverType))
|
|
495
|
+
.map((name) => toFunctionItem(name, localizer, getPreferredMethodLabel(name)));
|
|
496
|
+
}
|
|
497
|
+
function toBuiltinRootItem(name, builtinVariableRegistry, localizer) {
|
|
498
|
+
const normalizedName = name.startsWith("$") ? name : `${name}`;
|
|
499
|
+
const definition = builtinVariableRegistry.getDefinition(normalizedName);
|
|
500
|
+
if (!definition) {
|
|
501
|
+
return undefined;
|
|
502
|
+
}
|
|
503
|
+
return {
|
|
504
|
+
kind: "builtinRoot",
|
|
505
|
+
label: toBuiltinLabel(definition.name),
|
|
506
|
+
documentation: buildRootDocumentation(definition.name, definition.documentation, localizer),
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
function toEmptyExpressionStarterItem(name, builtinVariableRegistry, localizer) {
|
|
510
|
+
if (name.startsWith("$")) {
|
|
511
|
+
return toBuiltinRootItem(name, builtinVariableRegistry, localizer);
|
|
512
|
+
}
|
|
513
|
+
return IfcExpressionFunctions_js_1.IfcExpressionFunctions.getFunction(name)
|
|
514
|
+
? toFunctionItem(name, localizer)
|
|
515
|
+
: undefined;
|
|
516
|
+
}
|
|
517
|
+
function getEmptyExpressionStarterItems(builtinVariableRegistry, localizer, starterNames = [
|
|
518
|
+
...builtinVariableRegistry
|
|
519
|
+
.getDefinitions()
|
|
520
|
+
.map((definition) => toBuiltinLabel(definition.name)),
|
|
521
|
+
...emptyExpressionStarterFunctionNames,
|
|
522
|
+
]) {
|
|
523
|
+
return starterNames
|
|
524
|
+
.map((name) => toEmptyExpressionStarterItem(name, builtinVariableRegistry, localizer))
|
|
525
|
+
.filter((item) => item !== undefined);
|
|
526
|
+
}
|
|
527
|
+
function toMemberItem(definition, localizer) {
|
|
528
|
+
if (definition.kind === "property") {
|
|
529
|
+
return {
|
|
530
|
+
kind: "builtinMemberProperty",
|
|
531
|
+
label: definition.name,
|
|
532
|
+
returnTypeName: toCompletionTypeName(definition.valueType),
|
|
533
|
+
chainable: isChainableType(definition.valueType),
|
|
534
|
+
documentation: buildMemberDocumentation(definition, localizer),
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
const insertText = toFunctionInsertText(definition.name);
|
|
538
|
+
return {
|
|
539
|
+
kind: "builtinMemberFunction",
|
|
540
|
+
label: definition.name,
|
|
541
|
+
insertText,
|
|
542
|
+
cursorOffset: insertText.length - 1,
|
|
543
|
+
argumentTypeNames: definition.argumentTypes.map((type) => type.getName()),
|
|
544
|
+
returnTypeName: toCompletionTypeName(definition.returnType),
|
|
545
|
+
chainable: isChainableType(definition.returnType),
|
|
546
|
+
documentation: buildMemberDocumentation(definition, localizer),
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
function collectRuleCandidates(parser, caretTokenIndex, parseTree) {
|
|
550
|
+
const completionCore = new antlr4_c3_1.CodeCompletionCore(parser);
|
|
551
|
+
completionCore.preferredRules = new Set([
|
|
552
|
+
IfcExpressionParser_js_1.IfcExpressionParser.RULE_variableRef,
|
|
553
|
+
IfcExpressionParser_js_1.IfcExpressionParser.RULE_methodAccessor,
|
|
554
|
+
]);
|
|
555
|
+
return completionCore.collectCandidates(caretTokenIndex, parseTree);
|
|
556
|
+
}
|
|
557
|
+
function getMemberRuleCandidate(ruleCandidates) {
|
|
558
|
+
return ruleCandidates.get(IfcExpressionParser_js_1.IfcExpressionParser.RULE_methodAccessor);
|
|
559
|
+
}
|
|
560
|
+
function hasBuiltinRootRuleCandidate(ruleCandidates) {
|
|
561
|
+
return ruleCandidates.has(IfcExpressionParser_js_1.IfcExpressionParser.RULE_variableRef);
|
|
562
|
+
}
|
|
563
|
+
function hasIdentifierTokenCandidate(tokenCandidates) {
|
|
564
|
+
return tokenCandidates.has(IfcExpressionParser_js_1.IfcExpressionParser.IDENTIFIER);
|
|
565
|
+
}
|
|
566
|
+
class IfcExpressionAutocomplete {
|
|
567
|
+
static complete(input, cursorOffset, options = {}) {
|
|
568
|
+
const builtinVariableRegistry = options.builtinVariableRegistry ??
|
|
569
|
+
BuiltinVariableRegistry_js_1.BuiltinVariableRegistry.getDefaultRegistry();
|
|
570
|
+
if (isEmptyExpressionInput(input)) {
|
|
571
|
+
return {
|
|
572
|
+
items: getEmptyExpressionStarterItems(builtinVariableRegistry, options.localizer, options.emptyExpressionStarters),
|
|
573
|
+
replaceFrom: 0,
|
|
574
|
+
replaceTo: input.length,
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
const parsed = parseAutocompleteInput(input, cursorOffset);
|
|
578
|
+
const candidates = collectRuleCandidates(parsed.parser, parsed.caretTokenIndex, parsed.parseTree);
|
|
579
|
+
const ruleCandidates = candidates.rules;
|
|
580
|
+
const activeHelp = buildActiveHelp(parsed.parseTree, builtinVariableRegistry, parsed.tokens, cursorOffset, options.localizer);
|
|
581
|
+
const memberCandidate = getMemberRuleCandidate(ruleCandidates);
|
|
582
|
+
if (memberCandidate) {
|
|
583
|
+
const range = findMemberReplaceRange(input, cursorOffset);
|
|
584
|
+
if (!range) {
|
|
585
|
+
return {
|
|
586
|
+
items: [],
|
|
587
|
+
replaceFrom: cursorOffset,
|
|
588
|
+
replaceTo: cursorOffset,
|
|
589
|
+
activeHelp,
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
const receiverType = findReceiverTypeForMemberSlot(parsed.parseTree, memberCandidate.startTokenIndex, builtinVariableRegistry);
|
|
593
|
+
const typedPrefix = normalizeForMatch(input.slice(range.from, range.to));
|
|
594
|
+
const items = (receiverType instanceof ContextObjectType_js_1.ContextObjectType
|
|
595
|
+
? receiverType
|
|
596
|
+
.getMemberDefinitions()
|
|
597
|
+
.map((definition) => toMemberItem(definition, options.localizer))
|
|
598
|
+
: receiverType
|
|
599
|
+
? getPrimitiveMethodItems(receiverType, options.localizer)
|
|
600
|
+
: [])
|
|
601
|
+
.filter((item) => normalizeForMatch(item.label).startsWith(typedPrefix))
|
|
602
|
+
.sort((left, right) => left.label.localeCompare(right.label));
|
|
603
|
+
return {
|
|
604
|
+
items,
|
|
605
|
+
replaceFrom: range.from,
|
|
606
|
+
replaceTo: range.to,
|
|
607
|
+
activeHelp,
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
const functionRange = findFunctionReplaceRange(input, cursorOffset);
|
|
611
|
+
if (functionRange && hasIdentifierTokenCandidate(candidates.tokens)) {
|
|
612
|
+
const typedPrefix = normalizeForMatch(input.slice(functionRange.from, functionRange.to));
|
|
613
|
+
const items = IfcExpressionFunctions_js_1.IfcExpressionFunctions.getBuiltinFunctionNames()
|
|
614
|
+
.map((name) => toFunctionItem(name, options.localizer))
|
|
615
|
+
.filter((item) => normalizeForMatch(item.label).startsWith(typedPrefix))
|
|
616
|
+
.sort((left, right) => left.label.localeCompare(right.label));
|
|
617
|
+
if (items.length > 0) {
|
|
618
|
+
return {
|
|
619
|
+
items,
|
|
620
|
+
replaceFrom: functionRange.from,
|
|
621
|
+
replaceTo: functionRange.to,
|
|
622
|
+
activeHelp,
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
const range = findBuiltinRootReplaceRange(input, cursorOffset);
|
|
627
|
+
if (!range || !hasBuiltinRootRuleCandidate(ruleCandidates)) {
|
|
628
|
+
return {
|
|
629
|
+
items: [],
|
|
630
|
+
replaceFrom: cursorOffset,
|
|
631
|
+
replaceTo: cursorOffset,
|
|
632
|
+
activeHelp,
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
const typedPrefix = normalizeForMatch(input.slice(range.from, range.to));
|
|
636
|
+
const items = builtinVariableRegistry
|
|
637
|
+
.getDefinitions()
|
|
638
|
+
.map((definition) => ({
|
|
639
|
+
kind: "builtinRoot",
|
|
640
|
+
label: toBuiltinLabel(definition.name),
|
|
641
|
+
documentation: buildRootDocumentation(definition.name, definition.documentation, options.localizer),
|
|
642
|
+
}))
|
|
643
|
+
.filter((item) => normalizeForMatch(item.label).startsWith(typedPrefix))
|
|
644
|
+
.sort((left, right) => left.label.localeCompare(right.label));
|
|
645
|
+
return {
|
|
646
|
+
items,
|
|
647
|
+
replaceFrom: range.from,
|
|
648
|
+
replaceTo: range.to,
|
|
649
|
+
activeHelp,
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
exports.IfcExpressionAutocomplete = IfcExpressionAutocomplete;
|
|
654
|
+
//# sourceMappingURL=IfcExpressionAutocomplete.js.map
|