brighterscript 1.0.0-alpha.10 → 1.0.0-alpha.14
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/CHANGELOG.md +247 -267
- package/README.md +2 -2
- package/dist/Cache.d.ts +3 -3
- package/dist/Cache.js +10 -6
- package/dist/Cache.js.map +1 -1
- package/dist/CodeActionUtil.js.map +1 -1
- package/dist/CommentFlagProcessor.d.ts +4 -4
- package/dist/CommentFlagProcessor.js +5 -3
- package/dist/CommentFlagProcessor.js.map +1 -1
- package/dist/DependencyGraph.js.map +1 -1
- package/dist/DiagnosticFilterer.js +1 -1
- package/dist/DiagnosticFilterer.js.map +1 -1
- package/dist/LanguageServer.d.ts +1 -6
- package/dist/LanguageServer.js +5 -14
- package/dist/LanguageServer.js.map +1 -1
- package/dist/Logger.js.map +1 -1
- package/dist/PluginInterface.d.ts +3 -3
- package/dist/PluginInterface.js +3 -0
- package/dist/PluginInterface.js.map +1 -1
- package/dist/Program.d.ts +35 -20
- package/dist/Program.js +132 -67
- package/dist/Program.js.map +1 -1
- package/dist/ProgramBuilder.js +4 -4
- package/dist/ProgramBuilder.js.map +1 -1
- package/dist/Scope.d.ts +22 -13
- package/dist/Scope.js +85 -70
- package/dist/Scope.js.map +1 -1
- package/dist/SymbolTable.d.ts +1 -1
- package/dist/SymbolTable.js +2 -2
- package/dist/SymbolTable.js.map +1 -1
- package/dist/XmlScope.d.ts +2 -2
- package/dist/XmlScope.js +5 -5
- package/dist/XmlScope.js.map +1 -1
- package/dist/astUtils/AstEditor.d.ts +27 -0
- package/dist/astUtils/AstEditor.js +97 -0
- package/dist/astUtils/AstEditor.js.map +1 -0
- package/dist/{bscPlugin/semanticTokens/SemanticTokensProcessor.spec.d.ts → astUtils/AstEditor.spec.d.ts} +0 -0
- package/dist/astUtils/AstEditor.spec.js +133 -0
- package/dist/astUtils/AstEditor.spec.js.map +1 -0
- package/dist/astUtils/creators.spec.js +4 -4
- package/dist/astUtils/creators.spec.js.map +1 -1
- package/dist/astUtils/reflection.d.ts +4 -2
- package/dist/astUtils/reflection.js +10 -1
- package/dist/astUtils/reflection.js.map +1 -1
- package/dist/astUtils/reflection.spec.js +116 -116
- package/dist/astUtils/reflection.spec.js.map +1 -1
- package/dist/astUtils/stackedVisitor.js.map +1 -1
- package/dist/astUtils/stackedVisitor.spec.js +13 -13
- package/dist/astUtils/stackedVisitor.spec.js.map +1 -1
- package/dist/astUtils/visitors.js +1 -1
- package/dist/astUtils/visitors.js.map +1 -1
- package/dist/astUtils/visitors.spec.js +26 -26
- package/dist/astUtils/visitors.spec.js.map +1 -1
- package/dist/astUtils/xml.d.ts +1 -0
- package/dist/astUtils/xml.js +6 -1
- package/dist/astUtils/xml.js.map +1 -1
- package/dist/bscPlugin/BscPlugin.js +5 -2
- package/dist/bscPlugin/BscPlugin.js.map +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +3 -3
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js.map +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js +17 -17
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.d.ts +8 -0
- package/dist/bscPlugin/semanticTokens/{SemanticTokensProcessor.js → BrsFileSemanticTokensProcessor.js} +13 -15
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js.map +1 -0
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.d.ts +1 -0
- package/dist/bscPlugin/semanticTokens/{SemanticTokensProcessor.spec.js → BrsFileSemanticTokensProcessor.spec.js} +5 -5
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js.map +1 -0
- package/dist/diagnosticUtils.d.ts +1 -0
- package/dist/diagnosticUtils.js +14 -7
- package/dist/diagnosticUtils.js.map +1 -1
- package/dist/examples/plugins/removePrint.js +2 -2
- package/dist/examples/plugins/removePrint.js.map +1 -1
- package/dist/files/BrsFile.Class.spec.js +444 -269
- package/dist/files/BrsFile.Class.spec.js.map +1 -1
- package/dist/files/BrsFile.d.ts +17 -11
- package/dist/files/BrsFile.js +220 -153
- package/dist/files/BrsFile.js.map +1 -1
- package/dist/files/BrsFile.spec.js +620 -272
- package/dist/files/BrsFile.spec.js.map +1 -1
- package/dist/files/XmlFile.d.ts +6 -5
- package/dist/files/XmlFile.js +14 -9
- package/dist/files/XmlFile.js.map +1 -1
- package/dist/files/XmlFile.spec.js +238 -191
- package/dist/files/XmlFile.spec.js.map +1 -1
- package/dist/files/tests/imports.spec.js +29 -27
- package/dist/files/tests/imports.spec.js.map +1 -1
- package/dist/globalCallables.d.ts +3 -1
- package/dist/globalCallables.js +198 -99
- package/dist/globalCallables.js.map +1 -1
- package/dist/index.d.ts +12 -3
- package/dist/index.js +22 -4
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +71 -10
- package/dist/lexer/Lexer.d.ts +5 -1
- package/dist/lexer/Lexer.js +52 -35
- package/dist/lexer/Lexer.js.map +1 -1
- package/dist/lexer/Lexer.spec.js +564 -534
- package/dist/lexer/Lexer.spec.js.map +1 -1
- package/dist/lexer/TokenKind.d.ts +4 -0
- package/dist/lexer/TokenKind.js +44 -1
- package/dist/lexer/TokenKind.js.map +1 -1
- package/dist/parser/Expression.d.ts +1 -1
- package/dist/parser/Expression.js +66 -66
- package/dist/parser/Expression.js.map +1 -1
- package/dist/parser/Parser.Class.spec.js +107 -106
- package/dist/parser/Parser.Class.spec.js.map +1 -1
- package/dist/parser/Parser.d.ts +17 -5
- package/dist/parser/Parser.js +431 -315
- package/dist/parser/Parser.js.map +1 -1
- package/dist/parser/Parser.spec.js +418 -296
- package/dist/parser/Parser.spec.js.map +1 -1
- package/dist/parser/SGParser.js +2 -2
- package/dist/parser/SGParser.js.map +1 -1
- package/dist/parser/SGParser.spec.js +22 -22
- package/dist/parser/SGParser.spec.js.map +1 -1
- package/dist/parser/SGTypes.d.ts +3 -0
- package/dist/parser/SGTypes.js +12 -7
- package/dist/parser/SGTypes.js.map +1 -1
- package/dist/parser/SGTypes.spec.js +84 -84
- package/dist/parser/SGTypes.spec.js.map +1 -1
- package/dist/parser/Statement.d.ts +3 -3
- package/dist/parser/Statement.js +61 -61
- package/dist/parser/Statement.js.map +1 -1
- package/dist/parser/Statement.spec.js +10 -10
- package/dist/parser/Statement.spec.js.map +1 -1
- package/dist/parser/tests/Parser.spec.d.ts +3 -3
- package/dist/parser/tests/Parser.spec.js +4 -4
- package/dist/parser/tests/Parser.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/For.spec.js +58 -58
- package/dist/parser/tests/controlFlow/For.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/ForEach.spec.js +40 -39
- package/dist/parser/tests/controlFlow/ForEach.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/If.spec.js +201 -200
- package/dist/parser/tests/controlFlow/If.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/While.spec.js +37 -37
- package/dist/parser/tests/controlFlow/While.spec.js.map +1 -1
- package/dist/parser/tests/expression/Additive.spec.js +30 -30
- package/dist/parser/tests/expression/Additive.spec.js.map +1 -1
- package/dist/parser/tests/expression/ArrayLiterals.spec.js +119 -119
- package/dist/parser/tests/expression/ArrayLiterals.spec.js.map +1 -1
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +141 -141
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +1 -1
- package/dist/parser/tests/expression/Boolean.spec.js +24 -24
- package/dist/parser/tests/expression/Boolean.spec.js.map +1 -1
- package/dist/parser/tests/expression/Call.spec.js +41 -40
- package/dist/parser/tests/expression/Call.spec.js.map +1 -1
- package/dist/parser/tests/expression/Exponential.spec.js +17 -17
- package/dist/parser/tests/expression/Exponential.spec.js.map +1 -1
- package/dist/parser/tests/expression/Function.spec.js +256 -256
- package/dist/parser/tests/expression/Function.spec.js.map +1 -1
- package/dist/parser/tests/expression/Indexing.spec.js +87 -87
- package/dist/parser/tests/expression/Indexing.spec.js.map +1 -1
- package/dist/parser/tests/expression/Multiplicative.spec.js +37 -37
- package/dist/parser/tests/expression/Multiplicative.spec.js.map +1 -1
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +74 -62
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/PrefixUnary.spec.js +41 -41
- package/dist/parser/tests/expression/PrefixUnary.spec.js.map +1 -1
- package/dist/parser/tests/expression/Primary.spec.js +41 -41
- package/dist/parser/tests/expression/Primary.spec.js.map +1 -1
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.js +110 -2
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/Relational.spec.js +43 -43
- package/dist/parser/tests/expression/Relational.spec.js.map +1 -1
- package/dist/parser/tests/expression/SourceLiteralExpression.spec.js +6 -6
- package/dist/parser/tests/expression/SourceLiteralExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js +18 -18
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TernaryExpression.spec.js +100 -100
- package/dist/parser/tests/expression/TernaryExpression.spec.js.map +1 -1
- package/dist/parser/tests/statement/AssignmentOperators.spec.js +36 -36
- package/dist/parser/tests/statement/AssignmentOperators.spec.js.map +1 -1
- package/dist/parser/tests/statement/Declaration.spec.js +44 -44
- package/dist/parser/tests/statement/Declaration.spec.js.map +1 -1
- package/dist/parser/tests/statement/Dim.spec.js +21 -21
- package/dist/parser/tests/statement/Dim.spec.js.map +1 -1
- package/dist/parser/tests/statement/Function.spec.js +198 -197
- package/dist/parser/tests/statement/Function.spec.js.map +1 -1
- package/dist/parser/tests/statement/Goto.spec.js +15 -14
- package/dist/parser/tests/statement/Goto.spec.js.map +1 -1
- package/dist/parser/tests/statement/Increment.spec.js +50 -50
- package/dist/parser/tests/statement/Increment.spec.js.map +1 -1
- package/dist/parser/tests/statement/InterfaceStatement.spec.js +14 -2
- package/dist/parser/tests/statement/InterfaceStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/LibraryStatement.spec.js +17 -17
- package/dist/parser/tests/statement/LibraryStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/Misc.spec.js +91 -90
- package/dist/parser/tests/statement/Misc.spec.js.map +1 -1
- package/dist/parser/tests/statement/PrintStatement.spec.js +34 -34
- package/dist/parser/tests/statement/PrintStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/ReturnStatement.spec.js +46 -46
- package/dist/parser/tests/statement/ReturnStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/Set.spec.js +83 -83
- package/dist/parser/tests/statement/Set.spec.js.map +1 -1
- package/dist/parser/tests/statement/Stop.spec.js +12 -11
- package/dist/parser/tests/statement/Stop.spec.js.map +1 -1
- package/dist/parser/tests/statement/Throw.spec.js +5 -5
- package/dist/parser/tests/statement/Throw.spec.js.map +1 -1
- package/dist/parser/tests/statement/TryCatch.spec.js +13 -13
- package/dist/parser/tests/statement/TryCatch.spec.js.map +1 -1
- package/dist/preprocessor/Chunk.d.ts +1 -1
- package/dist/preprocessor/Chunk.js.map +1 -1
- package/dist/preprocessor/Manifest.d.ts +1 -1
- package/dist/preprocessor/Preprocessor.d.ts +1 -1
- package/dist/preprocessor/Preprocessor.js +8 -8
- package/dist/preprocessor/Preprocessor.js.map +1 -1
- package/dist/preprocessor/Preprocessor.spec.js +49 -49
- package/dist/preprocessor/Preprocessor.spec.js.map +1 -1
- package/dist/preprocessor/PreprocessorParser.spec.js +72 -72
- package/dist/preprocessor/PreprocessorParser.spec.js.map +1 -1
- package/dist/types/ArrayType.d.ts +8 -5
- package/dist/types/ArrayType.js +48 -12
- package/dist/types/ArrayType.js.map +1 -1
- package/dist/types/ArrayType.spec.js +69 -10
- package/dist/types/ArrayType.spec.js.map +1 -1
- package/dist/types/BooleanType.js +3 -3
- package/dist/types/BooleanType.js.map +1 -1
- package/dist/types/BooleanType.spec.js +2 -2
- package/dist/types/BooleanType.spec.js.map +1 -1
- package/dist/types/BscType.d.ts +1 -1
- package/dist/types/BscType.js +1 -1
- package/dist/types/BscType.js.map +1 -1
- package/dist/types/CustomType.d.ts +1 -1
- package/dist/types/CustomType.js +6 -4
- package/dist/types/CustomType.js.map +1 -1
- package/dist/types/DoubleType.js +7 -7
- package/dist/types/DoubleType.js.map +1 -1
- package/dist/types/DoubleType.spec.js +2 -2
- package/dist/types/DoubleType.spec.js.map +1 -1
- package/dist/types/DynamicType.js +1 -1
- package/dist/types/DynamicType.js.map +1 -1
- package/dist/types/DynamicType.spec.js +2 -2
- package/dist/types/DynamicType.spec.js.map +1 -1
- package/dist/types/FloatType.js +7 -7
- package/dist/types/FloatType.js.map +1 -1
- package/dist/types/FloatType.spec.js +2 -2
- package/dist/types/FloatType.spec.js.map +1 -1
- package/dist/types/FunctionType.d.ts +5 -5
- package/dist/types/FunctionType.js +13 -13
- package/dist/types/FunctionType.js.map +1 -1
- package/dist/types/FunctionType.spec.js +7 -7
- package/dist/types/FunctionType.spec.js.map +1 -1
- package/dist/types/IntegerType.js +7 -7
- package/dist/types/IntegerType.js.map +1 -1
- package/dist/types/IntegerType.spec.js +2 -2
- package/dist/types/IntegerType.spec.js.map +1 -1
- package/dist/types/InterfaceType.js +3 -3
- package/dist/types/InterfaceType.js.map +1 -1
- package/dist/types/InterfaceType.spec.js +7 -7
- package/dist/types/InterfaceType.spec.js.map +1 -1
- package/dist/types/InvalidType.js +4 -4
- package/dist/types/InvalidType.js.map +1 -1
- package/dist/types/InvalidType.spec.js +2 -2
- package/dist/types/InvalidType.spec.js.map +1 -1
- package/dist/types/LazyType.d.ts +1 -2
- package/dist/types/LazyType.js +1 -5
- package/dist/types/LazyType.js.map +1 -1
- package/dist/types/LongIntegerType.js +8 -8
- package/dist/types/LongIntegerType.js.map +1 -1
- package/dist/types/LongIntegerType.spec.js +2 -2
- package/dist/types/LongIntegerType.spec.js.map +1 -1
- package/dist/types/ObjectType.js +3 -3
- package/dist/types/ObjectType.js.map +1 -1
- package/dist/types/ObjectType.spec.js +2 -2
- package/dist/types/ObjectType.spec.js.map +1 -1
- package/dist/types/StringType.js +3 -3
- package/dist/types/StringType.js.map +1 -1
- package/dist/types/StringType.spec.js +2 -2
- package/dist/types/StringType.spec.js.map +1 -1
- package/dist/types/UninitializedType.js +3 -3
- package/dist/types/UninitializedType.js.map +1 -1
- package/dist/types/VoidType.js +3 -3
- package/dist/types/VoidType.js.map +1 -1
- package/dist/types/VoidType.spec.js +2 -2
- package/dist/types/VoidType.spec.js.map +1 -1
- package/dist/types/helpers.js +6 -6
- package/dist/types/helpers.js.map +1 -1
- package/dist/util.d.ts +15 -9
- package/dist/util.js +104 -57
- package/dist/util.js.map +1 -1
- package/dist/validators/ClassValidator.js +40 -40
- package/dist/validators/ClassValidator.js.map +1 -1
- package/package.json +10 -9
- package/dist/astUtils/index.d.ts +0 -7
- package/dist/astUtils/index.js +0 -26
- package/dist/astUtils/index.js.map +0 -1
- package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.d.ts +0 -7
- package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.js.map +0 -1
- package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.spec.js.map +0 -1
- package/dist/lexer/index.d.ts +0 -3
- package/dist/lexer/index.js +0 -17
- package/dist/lexer/index.js.map +0 -1
- package/dist/parser/index.d.ts +0 -3
- package/dist/parser/index.js +0 -16
- package/dist/parser/index.js.map +0 -1
- package/dist/preprocessor/index.d.ts +0 -3
- package/dist/preprocessor/index.js +0 -16
- package/dist/preprocessor/index.js.map +0 -1
package/dist/files/BrsFile.js
CHANGED
|
@@ -6,8 +6,11 @@ const vscode_languageserver_1 = require("vscode-languageserver");
|
|
|
6
6
|
const chalk_1 = require("chalk");
|
|
7
7
|
const path = require("path");
|
|
8
8
|
const DiagnosticMessages_1 = require("../DiagnosticMessages");
|
|
9
|
-
const
|
|
10
|
-
const
|
|
9
|
+
const Token_1 = require("../lexer/Token");
|
|
10
|
+
const Lexer_1 = require("../lexer/Lexer");
|
|
11
|
+
const TokenKind_1 = require("../lexer/TokenKind");
|
|
12
|
+
const Parser_1 = require("../parser/Parser");
|
|
13
|
+
const DynamicType_1 = require("../types/DynamicType");
|
|
11
14
|
const util_1 = require("../util");
|
|
12
15
|
const BrsTranspileState_1 = require("../parser/BrsTranspileState");
|
|
13
16
|
const Preprocessor_1 = require("../preprocessor/Preprocessor");
|
|
@@ -19,8 +22,6 @@ const CommentFlagProcessor_1 = require("../CommentFlagProcessor");
|
|
|
19
22
|
const BscType_1 = require("../types/BscType");
|
|
20
23
|
const UninitializedType_1 = require("../types/UninitializedType");
|
|
21
24
|
const InvalidType_1 = require("../types/InvalidType");
|
|
22
|
-
const globalCallables_1 = require("../globalCallables");
|
|
23
|
-
const DynamicType_1 = require("../types/DynamicType");
|
|
24
25
|
/**
|
|
25
26
|
* Holds all details about this file within the scope of the whole program
|
|
26
27
|
*/
|
|
@@ -41,9 +42,10 @@ class BrsFile {
|
|
|
41
42
|
/**
|
|
42
43
|
* The parseMode used for the parser for this file
|
|
43
44
|
*/
|
|
44
|
-
this.parseMode =
|
|
45
|
+
this.parseMode = Parser_1.ParseMode.BrightScript;
|
|
45
46
|
/**
|
|
46
47
|
* Indicates whether this file needs to be validated.
|
|
48
|
+
* Files are only ever validated a single time
|
|
47
49
|
*/
|
|
48
50
|
this.isValidated = false;
|
|
49
51
|
this.diagnostics = [];
|
|
@@ -58,13 +60,13 @@ class BrsFile {
|
|
|
58
60
|
* Does this file need to be transpiled?
|
|
59
61
|
*/
|
|
60
62
|
this.needsTranspiled = false;
|
|
61
|
-
this.srcPath = util_1.standardizePath `${this.srcPath}`;
|
|
63
|
+
this.srcPath = (0, util_1.standardizePath) `${this.srcPath}`;
|
|
62
64
|
this.dependencyGraphKey = this.pkgPath.toLowerCase();
|
|
63
65
|
this.extension = util_1.util.getExtension(this.srcPath);
|
|
64
66
|
//all BrighterScript files need to be transpiled
|
|
65
67
|
if ((_a = this.extension) === null || _a === void 0 ? void 0 : _a.endsWith('.bs')) {
|
|
66
68
|
this.needsTranspiled = true;
|
|
67
|
-
this.parseMode =
|
|
69
|
+
this.parseMode = Parser_1.ParseMode.BrighterScript;
|
|
68
70
|
}
|
|
69
71
|
this.isTypedef = this.extension === '.d.bs';
|
|
70
72
|
if (!this.isTypedef) {
|
|
@@ -135,11 +137,13 @@ class BrsFile {
|
|
|
135
137
|
this.diagnostics = [];
|
|
136
138
|
//if we have a typedef file, skip parsing this file
|
|
137
139
|
if (this.hasTypedef) {
|
|
140
|
+
//skip validation since the typedef is shadowing this file
|
|
141
|
+
this.isValidated = true;
|
|
138
142
|
return;
|
|
139
143
|
}
|
|
140
144
|
//tokenize the input file
|
|
141
145
|
let lexer = this.program.logger.time(Logger_1.LogLevel.debug, ['lexer.lex', chalk_1.default.green(this.srcPath)], () => {
|
|
142
|
-
return
|
|
146
|
+
return Lexer_1.Lexer.scan(fileContents, {
|
|
143
147
|
includeWhitespace: false
|
|
144
148
|
});
|
|
145
149
|
});
|
|
@@ -162,7 +166,7 @@ class BrsFile {
|
|
|
162
166
|
//if the preprocessor generated tokens, use them.
|
|
163
167
|
let tokens = preprocessor.processedTokens.length > 0 ? preprocessor.processedTokens : lexer.tokens;
|
|
164
168
|
this.program.logger.time(Logger_1.LogLevel.debug, ['parser.parse', chalk_1.default.green(this.srcPath)], () => {
|
|
165
|
-
this._parser =
|
|
169
|
+
this._parser = Parser_1.Parser.parse(tokens, {
|
|
166
170
|
mode: this.parseMode,
|
|
167
171
|
logger: this.program.logger
|
|
168
172
|
});
|
|
@@ -173,28 +177,47 @@ class BrsFile {
|
|
|
173
177
|
this.findCallables();
|
|
174
178
|
//find all places where a sub/function is being called
|
|
175
179
|
this.findFunctionCalls();
|
|
176
|
-
|
|
180
|
+
//register all import statements for use in the rest of the program
|
|
181
|
+
this.registerImports();
|
|
177
182
|
//attach this file to every diagnostic
|
|
178
183
|
for (let diagnostic of this.diagnostics) {
|
|
179
184
|
diagnostic.file = this;
|
|
180
185
|
}
|
|
181
186
|
}
|
|
182
187
|
catch (e) {
|
|
183
|
-
this._parser = new
|
|
184
|
-
this.diagnostics.push(Object.assign({ file: this, range: util_1.util.createRange(0, 0, 0, Number.MAX_VALUE) }, DiagnosticMessages_1.DiagnosticMessages.genericParserMessage('Critical error parsing file: ' + JSON.stringify(serialize_error_1.serializeError(e)))));
|
|
188
|
+
this._parser = new Parser_1.Parser();
|
|
189
|
+
this.diagnostics.push(Object.assign({ file: this, range: util_1.util.createRange(0, 0, 0, Number.MAX_VALUE) }, DiagnosticMessages_1.DiagnosticMessages.genericParserMessage('Critical error parsing file: ' + JSON.stringify((0, serialize_error_1.serializeError)(e)))));
|
|
185
190
|
}
|
|
186
191
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
192
|
+
registerImports() {
|
|
193
|
+
var _a, _b, _c, _d;
|
|
194
|
+
for (const statement of (_c = (_b = (_a = this.parser) === null || _a === void 0 ? void 0 : _a.references) === null || _b === void 0 ? void 0 : _b.importStatements) !== null && _c !== void 0 ? _c : []) {
|
|
195
|
+
//register import statements
|
|
196
|
+
if ((0, reflection_1.isImportStatement)(statement) && statement.filePathToken) {
|
|
197
|
+
this.ownScriptImports.push({
|
|
198
|
+
filePathRange: statement.filePathToken.range,
|
|
199
|
+
pkgPath: util_1.util.getPkgPathFromTarget(this.pkgPath, statement.filePath),
|
|
200
|
+
sourceFile: this,
|
|
201
|
+
text: (_d = statement.filePathToken) === null || _d === void 0 ? void 0 : _d.text
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
validate() {
|
|
207
|
+
//only validate the file if it was actually parsed (skip files containing typedefs)
|
|
208
|
+
if (!this.hasTypedef) {
|
|
209
|
+
this.validateImportStatements();
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
validateImportStatements() {
|
|
190
213
|
let topOfFileIncludeStatements = [];
|
|
191
214
|
for (let stmt of this.ast.statements) {
|
|
192
215
|
//skip comments
|
|
193
|
-
if (reflection_1.isCommentStatement(stmt)) {
|
|
216
|
+
if ((0, reflection_1.isCommentStatement)(stmt)) {
|
|
194
217
|
continue;
|
|
195
218
|
}
|
|
196
219
|
//if we found a non-library statement, this statement is not at the top of the file
|
|
197
|
-
if (reflection_1.isLibraryStatement(stmt) || reflection_1.isImportStatement(stmt)) {
|
|
220
|
+
if ((0, reflection_1.isLibraryStatement)(stmt) || (0, reflection_1.isImportStatement)(stmt)) {
|
|
198
221
|
topOfFileIncludeStatements.push(stmt);
|
|
199
222
|
}
|
|
200
223
|
else {
|
|
@@ -207,22 +230,13 @@ class BrsFile {
|
|
|
207
230
|
...this._parser.references.importStatements
|
|
208
231
|
];
|
|
209
232
|
for (let result of statements) {
|
|
210
|
-
//register import statements
|
|
211
|
-
if (reflection_1.isImportStatement(result) && result.filePathToken) {
|
|
212
|
-
this.ownScriptImports.push({
|
|
213
|
-
filePathRange: result.filePathToken.range,
|
|
214
|
-
pkgPath: util_1.util.getPkgPathFromTarget(this.pkgPath, result.filePath),
|
|
215
|
-
sourceFile: this,
|
|
216
|
-
text: (_a = result.filePathToken) === null || _a === void 0 ? void 0 : _a.text
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
233
|
//if this statement is not one of the top-of-file statements,
|
|
220
234
|
//then add a diagnostic explaining that it is invalid
|
|
221
235
|
if (!topOfFileIncludeStatements.includes(result)) {
|
|
222
|
-
if (reflection_1.isLibraryStatement(result)) {
|
|
236
|
+
if ((0, reflection_1.isLibraryStatement)(result)) {
|
|
223
237
|
this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.libraryStatementMustBeDeclaredAtTopOfFile()), { range: result.range, file: this }));
|
|
224
238
|
}
|
|
225
|
-
else if (reflection_1.isImportStatement(result)) {
|
|
239
|
+
else if ((0, reflection_1.isImportStatement)(result)) {
|
|
226
240
|
this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.importStatementMustBeDeclaredAtTopOfFile()), { range: result.range, file: this }));
|
|
227
241
|
}
|
|
228
242
|
}
|
|
@@ -273,7 +287,7 @@ class BrsFile {
|
|
|
273
287
|
const processor = new CommentFlagProcessor_1.CommentFlagProcessor(this, ['rem', `'`], DiagnosticMessages_1.diagnosticCodes, [DiagnosticMessages_1.DiagnosticCodeMap.unknownDiagnosticCode]);
|
|
274
288
|
this.commentFlags = [];
|
|
275
289
|
for (let token of tokens) {
|
|
276
|
-
if (token.kind ===
|
|
290
|
+
if (token.kind === TokenKind_1.TokenKind.Comment) {
|
|
277
291
|
processor.tryAdd(token.text, token.range);
|
|
278
292
|
}
|
|
279
293
|
}
|
|
@@ -300,6 +314,7 @@ class BrsFile {
|
|
|
300
314
|
}
|
|
301
315
|
}
|
|
302
316
|
findFunctionCalls() {
|
|
317
|
+
var _a;
|
|
303
318
|
this.functionCalls = [];
|
|
304
319
|
//for every function in the file
|
|
305
320
|
for (let func of this._parser.references.functionExpressions) {
|
|
@@ -308,6 +323,8 @@ class BrsFile {
|
|
|
308
323
|
if (
|
|
309
324
|
//filter out method calls on method calls for now (i.e. getSomething().getSomethingElse())
|
|
310
325
|
expression.callee.callee ||
|
|
326
|
+
//filter out method calls on regexp literals for now
|
|
327
|
+
(0, reflection_1.isRegexLiteralExpression)((_a = expression.callee) === null || _a === void 0 ? void 0 : _a.obj) ||
|
|
311
328
|
//filter out callees without a name (immediately-invoked function expressions)
|
|
312
329
|
!expression.callee.name) {
|
|
313
330
|
continue;
|
|
@@ -322,7 +339,7 @@ class BrsFile {
|
|
|
322
339
|
let args = [];
|
|
323
340
|
//TODO convert if stmts to use instanceof instead
|
|
324
341
|
for (let arg of expression.args) {
|
|
325
|
-
let inferredType =
|
|
342
|
+
let inferredType = (0, Parser_1.getBscTypeFromExpression)(arg, func);
|
|
326
343
|
let argText = '';
|
|
327
344
|
// Get the text to display for the arg
|
|
328
345
|
if (arg.token) {
|
|
@@ -330,7 +347,7 @@ class BrsFile {
|
|
|
330
347
|
//is a function call being passed into argument
|
|
331
348
|
}
|
|
332
349
|
else if (arg.name) {
|
|
333
|
-
if (
|
|
350
|
+
if ((0, Token_1.isToken)(arg.name)) {
|
|
334
351
|
argText = arg.name.text;
|
|
335
352
|
}
|
|
336
353
|
}
|
|
@@ -342,7 +359,7 @@ class BrsFile {
|
|
|
342
359
|
}
|
|
343
360
|
}
|
|
344
361
|
//wrap the value in quotes because that's how it appears in the code
|
|
345
|
-
if (argText && reflection_1.isStringType(inferredType)) {
|
|
362
|
+
if (argText && (0, reflection_1.isStringType)(inferredType)) {
|
|
346
363
|
argText = '"' + argText + '"';
|
|
347
364
|
}
|
|
348
365
|
}
|
|
@@ -401,10 +418,10 @@ class BrsFile {
|
|
|
401
418
|
//if cursor is within a comment, disable completions
|
|
402
419
|
let currentToken = this.parser.getTokenAt(position);
|
|
403
420
|
const tokenKind = currentToken === null || currentToken === void 0 ? void 0 : currentToken.kind;
|
|
404
|
-
if (tokenKind ===
|
|
421
|
+
if (tokenKind === TokenKind_1.TokenKind.Comment) {
|
|
405
422
|
return [];
|
|
406
423
|
}
|
|
407
|
-
else if (tokenKind ===
|
|
424
|
+
else if (tokenKind === TokenKind_1.TokenKind.StringLiteral || tokenKind === TokenKind_1.TokenKind.TemplateStringQuasi) {
|
|
408
425
|
const match = /^("?)(pkg|libpkg):/.exec(currentToken.text);
|
|
409
426
|
if (match) {
|
|
410
427
|
const [, openingQuote, fileProtocol] = match;
|
|
@@ -436,7 +453,7 @@ class BrsFile {
|
|
|
436
453
|
let functionExpression = this.getFunctionExpressionAtPosition(position);
|
|
437
454
|
if (!functionExpression) {
|
|
438
455
|
//we aren't in any function scope, so return the keyword completions and namespaces
|
|
439
|
-
if (this.parser.getTokenBefore(currentToken,
|
|
456
|
+
if (this.parser.getTokenBefore(currentToken, TokenKind_1.TokenKind.New)) {
|
|
440
457
|
// there's a new keyword, so only class types are viable here
|
|
441
458
|
return [...this.getGlobalClassStatementCompletions(currentToken, this.parseMode)];
|
|
442
459
|
}
|
|
@@ -445,17 +462,17 @@ class BrsFile {
|
|
|
445
462
|
}
|
|
446
463
|
}
|
|
447
464
|
const classNameCompletions = this.getGlobalClassStatementCompletions(currentToken, this.parseMode);
|
|
448
|
-
const newToken = this.parser.getTokenBefore(currentToken,
|
|
465
|
+
const newToken = this.parser.getTokenBefore(currentToken, TokenKind_1.TokenKind.New);
|
|
449
466
|
if (newToken) {
|
|
450
467
|
//we are after a new keyword; so we can only be namespaces or classes at this point
|
|
451
468
|
result.push(...classNameCompletions);
|
|
452
469
|
result.push(...namespaceCompletions);
|
|
453
470
|
return result;
|
|
454
471
|
}
|
|
455
|
-
if (this.parser.tokenFollows(currentToken,
|
|
472
|
+
if (this.parser.tokenFollows(currentToken, TokenKind_1.TokenKind.Goto)) {
|
|
456
473
|
return this.getLabelCompletion(functionExpression);
|
|
457
474
|
}
|
|
458
|
-
if (this.parser.isPositionNextToTokenKind(position,
|
|
475
|
+
if (this.parser.isPositionNextToTokenKind(position, TokenKind_1.TokenKind.Dot)) {
|
|
459
476
|
if (namespaceCompletions.length > 0) {
|
|
460
477
|
//if we matched a namespace, after a dot, it can't be anything else but something from our namespace completions
|
|
461
478
|
return namespaceCompletions;
|
|
@@ -511,7 +528,7 @@ class BrsFile {
|
|
|
511
528
|
// kind: isFunctionType(foundType) ? CompletionItemKind.Function : CompletionItemKind.Variable
|
|
512
529
|
});
|
|
513
530
|
}
|
|
514
|
-
if (this.parseMode ===
|
|
531
|
+
if (this.parseMode === Parser_1.ParseMode.BrighterScript) {
|
|
515
532
|
//include the first part of namespaces
|
|
516
533
|
let namespaces = scope.getAllNamespaceStatements();
|
|
517
534
|
for (let stmt of namespaces) {
|
|
@@ -534,7 +551,7 @@ class BrsFile {
|
|
|
534
551
|
return symbolTable.getAllSymbols().map(bscType => {
|
|
535
552
|
return {
|
|
536
553
|
label: bscType.name,
|
|
537
|
-
kind: reflection_1.isFunctionType(bscType.type) ? vscode_languageserver_1.CompletionItemKind.Method : vscode_languageserver_1.CompletionItemKind.Field
|
|
554
|
+
kind: (0, reflection_1.isFunctionType)(bscType.type) ? vscode_languageserver_1.CompletionItemKind.Method : vscode_languageserver_1.CompletionItemKind.Field
|
|
538
555
|
};
|
|
539
556
|
});
|
|
540
557
|
}
|
|
@@ -545,17 +562,17 @@ class BrsFile {
|
|
|
545
562
|
}));
|
|
546
563
|
}
|
|
547
564
|
getClassMemberCompletions(position, currentToken, functionExpression, scope) {
|
|
548
|
-
var _a, _b;
|
|
565
|
+
var _a, _b, _c, _d;
|
|
549
566
|
let classStatement = this.getClassFromToken(currentToken, functionExpression, scope);
|
|
550
567
|
let results = new Map();
|
|
551
568
|
if (classStatement) {
|
|
552
|
-
let classes = scope.getClassHierarchy(classStatement.item.getName(
|
|
569
|
+
let classes = scope.getClassHierarchy(classStatement.item.getName(Parser_1.ParseMode.BrighterScript).toLowerCase());
|
|
553
570
|
for (let cs of classes) {
|
|
554
|
-
for (let member of [...(_a = cs === null || cs === void 0 ? void 0 : cs.item) === null || _a === void 0 ? void 0 : _a.fields, ...(
|
|
571
|
+
for (let member of [...(_b = (_a = cs === null || cs === void 0 ? void 0 : cs.item) === null || _a === void 0 ? void 0 : _a.fields) !== null && _b !== void 0 ? _b : [], ...(_d = (_c = cs === null || cs === void 0 ? void 0 : cs.item) === null || _c === void 0 ? void 0 : _c.methods) !== null && _d !== void 0 ? _d : []]) {
|
|
555
572
|
if (!results.has(member.name.text.toLowerCase())) {
|
|
556
573
|
results.set(member.name.text.toLowerCase(), {
|
|
557
574
|
label: member.name.text,
|
|
558
|
-
kind: reflection_1.isClassFieldStatement(member) ? vscode_languageserver_1.CompletionItemKind.Field : vscode_languageserver_1.CompletionItemKind.Function
|
|
575
|
+
kind: (0, reflection_1.isClassFieldStatement)(member) ? vscode_languageserver_1.CompletionItemKind.Field : vscode_languageserver_1.CompletionItemKind.Function
|
|
559
576
|
});
|
|
560
577
|
}
|
|
561
578
|
}
|
|
@@ -583,10 +600,10 @@ class BrsFile {
|
|
|
583
600
|
*/
|
|
584
601
|
getClassFromTokenLookup(tokenLookup, scope) {
|
|
585
602
|
const currentClass = tokenLookup === null || tokenLookup === void 0 ? void 0 : tokenLookup.symbolContainer;
|
|
586
|
-
if (reflection_1.isClassStatement(currentClass)) {
|
|
603
|
+
if ((0, reflection_1.isClassStatement)(currentClass)) {
|
|
587
604
|
return { item: currentClass, file: this };
|
|
588
605
|
}
|
|
589
|
-
else if (reflection_1.isCustomType(currentClass)) {
|
|
606
|
+
else if ((0, reflection_1.isCustomType)(currentClass)) {
|
|
590
607
|
const foundClass = scope.getClass(currentClass.name);
|
|
591
608
|
if (foundClass) {
|
|
592
609
|
return { item: foundClass, file: this };
|
|
@@ -599,9 +616,9 @@ class BrsFile {
|
|
|
599
616
|
let startsWithNamespace = '';
|
|
600
617
|
let namespaceContainer;
|
|
601
618
|
let tokenChain = [...originalTokenChain];
|
|
602
|
-
while (tokenChain[0] && tokenChain[0].usage ===
|
|
619
|
+
while (tokenChain[0] && tokenChain[0].usage === Parser_1.TokenUsage.Direct) {
|
|
603
620
|
const namespaceNameToCheck = `${startsWithNamespace}${startsWithNamespace.length > 0 ? '.' : ''}${tokenChain[0].token.text}`.toLowerCase();
|
|
604
|
-
const foundNamespace = scope.namespaceLookup
|
|
621
|
+
const foundNamespace = scope.namespaceLookup.get(namespaceNameToCheck);
|
|
605
622
|
if (foundNamespace) {
|
|
606
623
|
namespaceContainer = foundNamespace;
|
|
607
624
|
namespaceTokens.push(tokenChain[0].token);
|
|
@@ -613,7 +630,7 @@ class BrsFile {
|
|
|
613
630
|
}
|
|
614
631
|
}
|
|
615
632
|
if (namespaceTokens.length > 0) {
|
|
616
|
-
namespaceContainer = scope.namespaceLookup
|
|
633
|
+
namespaceContainer = scope.namespaceLookup.get(startsWithNamespace.toLowerCase());
|
|
617
634
|
}
|
|
618
635
|
return { namespaceContainer: namespaceContainer, tokenChain: tokenChain };
|
|
619
636
|
}
|
|
@@ -630,7 +647,7 @@ class BrsFile {
|
|
|
630
647
|
let useExpandedTextOnly = false;
|
|
631
648
|
if (containingClass.name === currentToken) {
|
|
632
649
|
symbolType = containingClass.getCustomType();
|
|
633
|
-
expandedText = `class ${containingClass.getName(
|
|
650
|
+
expandedText = `class ${containingClass.getName(Parser_1.ParseMode.BrighterScript)}`;
|
|
634
651
|
useExpandedTextOnly = true;
|
|
635
652
|
currentClassRef = containingClass;
|
|
636
653
|
}
|
|
@@ -640,8 +657,8 @@ class BrsFile {
|
|
|
640
657
|
currentClassRef = containingClass;
|
|
641
658
|
}
|
|
642
659
|
else if (currentTokenLower === 'super') {
|
|
643
|
-
symbolType = BscType_1.getTypeFromContext(containingClass.symbolTable.getSymbolType(currentTokenLower, true, typeContext), typeContext);
|
|
644
|
-
if (reflection_1.isFunctionType(symbolType)) {
|
|
660
|
+
symbolType = (0, BscType_1.getTypeFromContext)(containingClass.symbolTable.getSymbolType(currentTokenLower, true, typeContext), typeContext);
|
|
661
|
+
if ((0, reflection_1.isFunctionType)(symbolType)) {
|
|
645
662
|
currentClassRef = scope.getParentClass(containingClass);
|
|
646
663
|
}
|
|
647
664
|
}
|
|
@@ -649,13 +666,13 @@ class BrsFile {
|
|
|
649
666
|
// check if this is a method declaration
|
|
650
667
|
currentClassRef = containingClass;
|
|
651
668
|
symbolType = containingClass === null || containingClass === void 0 ? void 0 : containingClass.memberTable.getSymbolType(currentTokenLower, true, { file: this, scope: scope });
|
|
652
|
-
expandedText = [containingClass.getName(
|
|
669
|
+
expandedText = [containingClass.getName(Parser_1.ParseMode.BrighterScript), currentToken.text].join('.');
|
|
653
670
|
}
|
|
654
671
|
else if (!func) {
|
|
655
672
|
// check if this is a field declaration
|
|
656
673
|
currentClassRef = containingClass;
|
|
657
674
|
symbolType = containingClass === null || containingClass === void 0 ? void 0 : containingClass.memberTable.getSymbolType(currentTokenLower, true, { file: this, scope: scope });
|
|
658
|
-
expandedText = [containingClass.getName(
|
|
675
|
+
expandedText = [containingClass.getName(Parser_1.ParseMode.BrighterScript), currentToken.text].join('.');
|
|
659
676
|
}
|
|
660
677
|
if (symbolType) {
|
|
661
678
|
return { type: symbolType, expandedTokenText: expandedText, symbolContainer: currentClassRef, useExpandedTextOnly: useExpandedTextOnly };
|
|
@@ -687,7 +704,7 @@ class BrsFile {
|
|
|
687
704
|
*/
|
|
688
705
|
getSymbolTypeFromToken(currentToken, functionExpression, scope) {
|
|
689
706
|
var _a, _b, _c, _d, _e;
|
|
690
|
-
if (!scope) {
|
|
707
|
+
if (!scope || !currentToken) {
|
|
691
708
|
return undefined;
|
|
692
709
|
}
|
|
693
710
|
const cachedSymbolData = scope.symbolCache.get(currentToken);
|
|
@@ -717,13 +734,14 @@ class BrsFile {
|
|
|
717
734
|
const typeContext = { file: this, scope: scope, position: (_c = tokenChain[0]) === null || _c === void 0 ? void 0 : _c.token.range.start };
|
|
718
735
|
for (const tokenChainMember of tokenChain) {
|
|
719
736
|
const token = tokenChainMember === null || tokenChainMember === void 0 ? void 0 : tokenChainMember.token;
|
|
737
|
+
const tokenUsage = tokenChainMember === null || tokenChainMember === void 0 ? void 0 : tokenChainMember.usage;
|
|
720
738
|
const tokenLowerText = token.text.toLowerCase();
|
|
721
|
-
if (tokenLowerText === 'super' && reflection_1.isClassStatement(symbolContainer) && tokenFoundCount === 0) {
|
|
739
|
+
if (tokenLowerText === 'super' && (0, reflection_1.isClassStatement)(symbolContainer) && tokenFoundCount === 0) {
|
|
722
740
|
/// Special cases for first item in chain inside a class
|
|
723
741
|
symbolContainer = scope === null || scope === void 0 ? void 0 : scope.getParentClass(symbolContainer);
|
|
724
742
|
currentSymbolTable = (_d = symbolContainer) === null || _d === void 0 ? void 0 : _d.memberTable;
|
|
725
743
|
if (symbolContainer && currentSymbolTable) {
|
|
726
|
-
tokenText.push(symbolContainer.getName(
|
|
744
|
+
tokenText.push(symbolContainer.getName(Parser_1.ParseMode.BrighterScript));
|
|
727
745
|
tokenFoundCount++;
|
|
728
746
|
continue;
|
|
729
747
|
}
|
|
@@ -735,24 +753,27 @@ class BrsFile {
|
|
|
735
753
|
symbolType = currentSymbolTable.getSymbolType(tokenLowerText, true, typeContext);
|
|
736
754
|
if (tokenFoundCount === 0 && !symbolType) {
|
|
737
755
|
//check for global callable
|
|
738
|
-
symbolType = (_e =
|
|
756
|
+
symbolType = (_e = scope.getGlobalCallableByName(tokenLowerText)) === null || _e === void 0 ? void 0 : _e.type;
|
|
739
757
|
}
|
|
740
758
|
if (symbolType) {
|
|
741
759
|
// found this symbol, and it's valid. increase found counter
|
|
742
760
|
tokenFoundCount++;
|
|
743
761
|
}
|
|
744
762
|
symbolTypeBeforeReference = symbolType;
|
|
745
|
-
if (reflection_1.isFunctionType(symbolType)) {
|
|
763
|
+
if ((0, reflection_1.isFunctionType)(symbolType)) {
|
|
746
764
|
// this is a function, and it is in the start or middle of the chain
|
|
747
765
|
// the next symbol to check will be the return value of this function
|
|
748
|
-
symbolType = BscType_1.getTypeFromContext(symbolType.returnType, typeContext);
|
|
766
|
+
symbolType = (0, BscType_1.getTypeFromContext)(symbolType.returnType, typeContext);
|
|
749
767
|
if (tokenFoundCount < tokenChain.length) {
|
|
750
|
-
// We
|
|
768
|
+
// We still have more tokens, but remember the last known reference
|
|
751
769
|
symbolTypeBeforeReference = symbolType;
|
|
752
770
|
}
|
|
753
771
|
}
|
|
772
|
+
if ((0, reflection_1.isArrayType)(symbolType) && tokenUsage === Parser_1.TokenUsage.ArrayReference) {
|
|
773
|
+
symbolType = (0, BscType_1.getTypeFromContext)(symbolType.getDefaultType(typeContext), typeContext);
|
|
774
|
+
}
|
|
754
775
|
if (symbolType === null || symbolType === void 0 ? void 0 : symbolType.memberTable) {
|
|
755
|
-
if (reflection_1.isCustomType(symbolType)) {
|
|
776
|
+
if ((0, reflection_1.isCustomType)(symbolType)) {
|
|
756
777
|
// we're currently looking at a customType, that has it's own symbol table
|
|
757
778
|
// use the name of the custom type
|
|
758
779
|
// TODO TYPES: get proper parent name for methods/fields defined in super classes
|
|
@@ -765,7 +786,7 @@ class BrsFile {
|
|
|
765
786
|
symbolContainer = symbolType;
|
|
766
787
|
currentSymbolTable = symbolContainer === null || symbolContainer === void 0 ? void 0 : symbolContainer.memberTable;
|
|
767
788
|
}
|
|
768
|
-
else if (reflection_1.isObjectType(symbolType) || reflection_1.isArrayType(symbolType) || reflection_1.isDynamicType(symbolType)) {
|
|
789
|
+
else if ((0, reflection_1.isObjectType)(symbolType) || (0, reflection_1.isArrayType)(symbolType) || (0, reflection_1.isDynamicType)(symbolType)) {
|
|
769
790
|
// this is an object that has no member table
|
|
770
791
|
// this could happen if a parameter is marked as object
|
|
771
792
|
// assume all fields are dynamic
|
|
@@ -780,9 +801,12 @@ class BrsFile {
|
|
|
780
801
|
tokenText.push(token.text);
|
|
781
802
|
break;
|
|
782
803
|
}
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
804
|
+
}
|
|
805
|
+
if (tokenText.length > 2) {
|
|
806
|
+
// TokenText is used for hovers. We only need the last two tokens for a hover
|
|
807
|
+
// So in a long chain (e.g. klass.getData()[0].anotherKlass.property), the hover
|
|
808
|
+
// for the last token should just be "AnotherKlass.property", not the whole chain
|
|
809
|
+
tokenText = tokenText.slice(-2);
|
|
786
810
|
}
|
|
787
811
|
let expandedTokenText = tokenText.join('.');
|
|
788
812
|
let backUpReturnType;
|
|
@@ -792,12 +816,12 @@ class BrsFile {
|
|
|
792
816
|
scope.symbolCache.set(currentToken, symbolData);
|
|
793
817
|
return symbolData;
|
|
794
818
|
}
|
|
795
|
-
if (reflection_1.isDynamicType(symbolTypeBeforeReference) || reflection_1.isArrayType(symbolTypeBeforeReference) || justReturnDynamic) {
|
|
819
|
+
if ((0, reflection_1.isDynamicType)(symbolTypeBeforeReference) || (0, reflection_1.isArrayType)(symbolTypeBeforeReference) || justReturnDynamic) {
|
|
796
820
|
// last type in chain is dynamic... so currentToken could be anything.
|
|
797
821
|
backUpReturnType = new DynamicType_1.DynamicType();
|
|
798
822
|
expandedTokenText = currentToken.text;
|
|
799
823
|
}
|
|
800
|
-
else if (reflection_1.isPrimitiveType(symbolTypeBeforeReference)) {
|
|
824
|
+
else if ((0, reflection_1.isPrimitiveType)(symbolTypeBeforeReference)) {
|
|
801
825
|
// last type in chain is dynamic... so currentToken could be anything.
|
|
802
826
|
backUpReturnType = new DynamicType_1.DynamicType();
|
|
803
827
|
expandedTokenText = currentToken.text;
|
|
@@ -824,11 +848,11 @@ class BrsFile {
|
|
|
824
848
|
}
|
|
825
849
|
getGlobalClassStatementCompletions(currentToken, parseMode) {
|
|
826
850
|
var _a;
|
|
827
|
-
if (parseMode ===
|
|
851
|
+
if (parseMode === Parser_1.ParseMode.BrightScript) {
|
|
828
852
|
return [];
|
|
829
853
|
}
|
|
830
854
|
let results = new Map();
|
|
831
|
-
let completionName = (_a = this.getPartialVariableName(currentToken, [
|
|
855
|
+
let completionName = (_a = this.getPartialVariableName(currentToken, [TokenKind_1.TokenKind.New])) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
832
856
|
if (completionName === null || completionName === void 0 ? void 0 : completionName.includes('.')) {
|
|
833
857
|
return [];
|
|
834
858
|
}
|
|
@@ -850,21 +874,19 @@ class BrsFile {
|
|
|
850
874
|
}
|
|
851
875
|
getNamespaceCompletions(currentToken, parseMode, scope) {
|
|
852
876
|
//BrightScript does not support namespaces, so return an empty list in that case
|
|
853
|
-
if (parseMode ===
|
|
877
|
+
if (parseMode === Parser_1.ParseMode.BrightScript) {
|
|
854
878
|
return [];
|
|
855
879
|
}
|
|
856
|
-
let completionName = this.getPartialVariableName(currentToken, [
|
|
880
|
+
let completionName = this.getPartialVariableName(currentToken, [TokenKind_1.TokenKind.New]);
|
|
857
881
|
if (!completionName) {
|
|
858
882
|
return [];
|
|
859
883
|
}
|
|
860
884
|
//remove any trailing identifer and then any trailing dot, to give us the
|
|
861
885
|
//name of its immediate parent namespace
|
|
862
886
|
let closestParentNamespaceName = completionName.replace(/\.([a-z0-9_]*)?$/gi, '');
|
|
863
|
-
let newToken = this.parser.getTokenBefore(currentToken,
|
|
864
|
-
let namespaceLookup = scope.namespaceLookup;
|
|
887
|
+
let newToken = this.parser.getTokenBefore(currentToken, TokenKind_1.TokenKind.New);
|
|
865
888
|
let result = new Map();
|
|
866
|
-
for (let
|
|
867
|
-
let namespace = namespaceLookup[key.toLowerCase()];
|
|
889
|
+
for (let [, namespace] of scope.namespaceLookup) {
|
|
868
890
|
//completionName = "NameA."
|
|
869
891
|
//completionName = "NameA.Na
|
|
870
892
|
//NameA
|
|
@@ -872,9 +894,8 @@ class BrsFile {
|
|
|
872
894
|
//NameA.NameB.NameC
|
|
873
895
|
if (namespace.fullName.toLowerCase() === closestParentNamespaceName.toLowerCase()) {
|
|
874
896
|
//add all of this namespace's immediate child namespaces, bearing in mind if we are after a new keyword
|
|
875
|
-
for (let
|
|
876
|
-
|
|
877
|
-
if (!newToken || ns.statements.find((s) => reflection_1.isClassStatement(s))) {
|
|
897
|
+
for (let [, ns] of namespace.namespaces) {
|
|
898
|
+
if (!newToken || ns.statements.find((s) => (0, reflection_1.isClassStatement)(s))) {
|
|
878
899
|
if (!result.has(ns.lastPartName)) {
|
|
879
900
|
result.set(ns.lastPartName, {
|
|
880
901
|
label: ns.lastPartName,
|
|
@@ -885,7 +906,7 @@ class BrsFile {
|
|
|
885
906
|
}
|
|
886
907
|
//add function and class statement completions
|
|
887
908
|
for (let stmt of namespace.statements) {
|
|
888
|
-
if (reflection_1.isClassStatement(stmt)) {
|
|
909
|
+
if ((0, reflection_1.isClassStatement)(stmt)) {
|
|
889
910
|
if (!result.has(stmt.name.text)) {
|
|
890
911
|
result.set(stmt.name.text, {
|
|
891
912
|
label: stmt.name.text,
|
|
@@ -893,7 +914,7 @@ class BrsFile {
|
|
|
893
914
|
});
|
|
894
915
|
}
|
|
895
916
|
}
|
|
896
|
-
else if (reflection_1.isFunctionStatement(stmt) && !newToken) {
|
|
917
|
+
else if ((0, reflection_1.isFunctionStatement)(stmt) && !newToken) {
|
|
897
918
|
if (!result.has(stmt.name.text)) {
|
|
898
919
|
result.set(stmt.name.text, {
|
|
899
920
|
label: stmt.name.text,
|
|
@@ -912,18 +933,18 @@ class BrsFile {
|
|
|
912
933
|
return undefined;
|
|
913
934
|
}
|
|
914
935
|
let location;
|
|
915
|
-
const nameParts = this.getPartialVariableName(token, [
|
|
936
|
+
const nameParts = this.getPartialVariableName(token, [TokenKind_1.TokenKind.New]).split('.');
|
|
916
937
|
const endName = nameParts[nameParts.length - 1].toLowerCase();
|
|
917
938
|
const namespaceName = nameParts.slice(0, -1).join('.').toLowerCase();
|
|
918
939
|
const statementHandler = (statement) => {
|
|
919
|
-
if (!location && statement.getName(
|
|
940
|
+
if (!location && statement.getName(Parser_1.ParseMode.BrighterScript).toLowerCase() === namespaceName) {
|
|
920
941
|
const namespaceItemStatementHandler = (statement) => {
|
|
921
942
|
if (!location && statement.name.text.toLowerCase() === endName) {
|
|
922
943
|
const uri = util_1.util.pathToUri(file.srcPath);
|
|
923
944
|
location = vscode_languageserver_1.Location.create(uri, statement.range);
|
|
924
945
|
}
|
|
925
946
|
};
|
|
926
|
-
file.parser.ast.walk(visitors_1.createVisitor({
|
|
947
|
+
file.parser.ast.walk((0, visitors_1.createVisitor)({
|
|
927
948
|
ClassStatement: namespaceItemStatementHandler,
|
|
928
949
|
FunctionStatement: namespaceItemStatementHandler
|
|
929
950
|
}), {
|
|
@@ -931,7 +952,7 @@ class BrsFile {
|
|
|
931
952
|
});
|
|
932
953
|
}
|
|
933
954
|
};
|
|
934
|
-
file.parser.ast.walk(visitors_1.createVisitor({
|
|
955
|
+
file.parser.ast.walk((0, visitors_1.createVisitor)({
|
|
935
956
|
NamespaceStatement: statementHandler
|
|
936
957
|
}), {
|
|
937
958
|
walkMode: visitors_1.WalkMode.visitStatements
|
|
@@ -942,7 +963,7 @@ class BrsFile {
|
|
|
942
963
|
* Given a current token, walk
|
|
943
964
|
*/
|
|
944
965
|
getPartialVariableName(currentToken, excludeTokens = null) {
|
|
945
|
-
let identifierAndDotKinds = [
|
|
966
|
+
let identifierAndDotKinds = [TokenKind_1.TokenKind.Identifier, ...TokenKind_1.AllowedLocalIdentifiers, TokenKind_1.TokenKind.Dot];
|
|
946
967
|
//consume tokens backwards until we find something other than a dot or an identifier
|
|
947
968
|
let tokens = [];
|
|
948
969
|
const parser = this.parser;
|
|
@@ -969,15 +990,15 @@ class BrsFile {
|
|
|
969
990
|
*/
|
|
970
991
|
calleeStartsWithNamespace(callee) {
|
|
971
992
|
let left = callee;
|
|
972
|
-
while (reflection_1.isDottedGetExpression(left)) {
|
|
993
|
+
while ((0, reflection_1.isDottedGetExpression)(left)) {
|
|
973
994
|
left = left.obj;
|
|
974
995
|
}
|
|
975
|
-
if (reflection_1.isVariableExpression(left)) {
|
|
996
|
+
if ((0, reflection_1.isVariableExpression)(left)) {
|
|
976
997
|
let lowerName = left.name.text.toLowerCase();
|
|
977
998
|
//find the first scope that contains this namespace
|
|
978
999
|
let scopes = this.program.getScopesForFile(this);
|
|
979
1000
|
for (let scope of scopes) {
|
|
980
|
-
if (scope.namespaceLookup
|
|
1001
|
+
if (scope.namespaceLookup.has(lowerName)) {
|
|
981
1002
|
return true;
|
|
982
1003
|
}
|
|
983
1004
|
}
|
|
@@ -990,12 +1011,12 @@ class BrsFile {
|
|
|
990
1011
|
calleeIsKnownNamespaceFunction(callee, namespaceName) {
|
|
991
1012
|
var _a, _b;
|
|
992
1013
|
//if we have a variable and a namespace
|
|
993
|
-
if (reflection_1.isVariableExpression(callee) && namespaceName) {
|
|
1014
|
+
if ((0, reflection_1.isVariableExpression)(callee) && namespaceName) {
|
|
994
1015
|
let lowerCalleeName = (_b = (_a = callee === null || callee === void 0 ? void 0 : callee.name) === null || _a === void 0 ? void 0 : _a.text) === null || _b === void 0 ? void 0 : _b.toLowerCase();
|
|
995
1016
|
if (lowerCalleeName) {
|
|
996
1017
|
let scopes = this.program.getScopesForFile(this);
|
|
997
1018
|
for (let scope of scopes) {
|
|
998
|
-
let namespace = scope.namespaceLookup
|
|
1019
|
+
let namespace = scope.namespaceLookup.get(namespaceName.toLowerCase());
|
|
999
1020
|
if (namespace.functionStatements[lowerCalleeName]) {
|
|
1000
1021
|
return true;
|
|
1001
1022
|
}
|
|
@@ -1043,16 +1064,16 @@ class BrsFile {
|
|
|
1043
1064
|
getDocumentSymbol(statement) {
|
|
1044
1065
|
let symbolKind;
|
|
1045
1066
|
const children = [];
|
|
1046
|
-
if (reflection_1.isFunctionStatement(statement)) {
|
|
1067
|
+
if ((0, reflection_1.isFunctionStatement)(statement)) {
|
|
1047
1068
|
symbolKind = vscode_languageserver_1.SymbolKind.Function;
|
|
1048
1069
|
}
|
|
1049
|
-
else if (reflection_1.isClassMethodStatement(statement)) {
|
|
1070
|
+
else if ((0, reflection_1.isClassMethodStatement)(statement)) {
|
|
1050
1071
|
symbolKind = vscode_languageserver_1.SymbolKind.Method;
|
|
1051
1072
|
}
|
|
1052
|
-
else if (reflection_1.isClassFieldStatement(statement)) {
|
|
1073
|
+
else if ((0, reflection_1.isClassFieldStatement)(statement)) {
|
|
1053
1074
|
symbolKind = vscode_languageserver_1.SymbolKind.Field;
|
|
1054
1075
|
}
|
|
1055
|
-
else if (reflection_1.isNamespaceStatement(statement)) {
|
|
1076
|
+
else if ((0, reflection_1.isNamespaceStatement)(statement)) {
|
|
1056
1077
|
symbolKind = vscode_languageserver_1.SymbolKind.Namespace;
|
|
1057
1078
|
for (const childStatement of statement.body.statements) {
|
|
1058
1079
|
const symbol = this.getDocumentSymbol(childStatement);
|
|
@@ -1061,7 +1082,7 @@ class BrsFile {
|
|
|
1061
1082
|
}
|
|
1062
1083
|
}
|
|
1063
1084
|
}
|
|
1064
|
-
else if (reflection_1.isClassStatement(statement)) {
|
|
1085
|
+
else if ((0, reflection_1.isClassStatement)(statement)) {
|
|
1065
1086
|
symbolKind = vscode_languageserver_1.SymbolKind.Class;
|
|
1066
1087
|
for (const childStatement of statement.body) {
|
|
1067
1088
|
const symbol = this.getDocumentSymbol(childStatement);
|
|
@@ -1073,7 +1094,7 @@ class BrsFile {
|
|
|
1073
1094
|
else {
|
|
1074
1095
|
return;
|
|
1075
1096
|
}
|
|
1076
|
-
const name = reflection_1.isClassFieldStatement(statement) ? statement.name.text : statement.getName(
|
|
1097
|
+
const name = (0, reflection_1.isClassFieldStatement)(statement) ? statement.name.text : statement.getName(Parser_1.ParseMode.BrighterScript);
|
|
1077
1098
|
return vscode_languageserver_1.DocumentSymbol.create(name, '', symbolKind, statement.range, statement.range, children);
|
|
1078
1099
|
}
|
|
1079
1100
|
/**
|
|
@@ -1082,13 +1103,13 @@ class BrsFile {
|
|
|
1082
1103
|
generateWorkspaceSymbols(statement, containerStatement) {
|
|
1083
1104
|
let symbolKind;
|
|
1084
1105
|
const symbols = [];
|
|
1085
|
-
if (reflection_1.isFunctionStatement(statement)) {
|
|
1106
|
+
if ((0, reflection_1.isFunctionStatement)(statement)) {
|
|
1086
1107
|
symbolKind = vscode_languageserver_1.SymbolKind.Function;
|
|
1087
1108
|
}
|
|
1088
|
-
else if (reflection_1.isClassMethodStatement(statement)) {
|
|
1109
|
+
else if ((0, reflection_1.isClassMethodStatement)(statement)) {
|
|
1089
1110
|
symbolKind = vscode_languageserver_1.SymbolKind.Method;
|
|
1090
1111
|
}
|
|
1091
|
-
else if (reflection_1.isNamespaceStatement(statement)) {
|
|
1112
|
+
else if ((0, reflection_1.isNamespaceStatement)(statement)) {
|
|
1092
1113
|
symbolKind = vscode_languageserver_1.SymbolKind.Namespace;
|
|
1093
1114
|
for (const childStatement of statement.body.statements) {
|
|
1094
1115
|
for (const symbol of this.generateWorkspaceSymbols(childStatement, statement)) {
|
|
@@ -1096,7 +1117,7 @@ class BrsFile {
|
|
|
1096
1117
|
}
|
|
1097
1118
|
}
|
|
1098
1119
|
}
|
|
1099
|
-
else if (reflection_1.isClassStatement(statement)) {
|
|
1120
|
+
else if ((0, reflection_1.isClassStatement)(statement)) {
|
|
1100
1121
|
symbolKind = vscode_languageserver_1.SymbolKind.Class;
|
|
1101
1122
|
for (const childStatement of statement.body) {
|
|
1102
1123
|
for (const symbol of this.generateWorkspaceSymbols(childStatement, statement)) {
|
|
@@ -1107,9 +1128,9 @@ class BrsFile {
|
|
|
1107
1128
|
else {
|
|
1108
1129
|
return symbols;
|
|
1109
1130
|
}
|
|
1110
|
-
const name = statement.getName(
|
|
1131
|
+
const name = statement.getName(Parser_1.ParseMode.BrighterScript);
|
|
1111
1132
|
const uri = util_1.util.pathToUri(this.srcPath);
|
|
1112
|
-
const symbol = vscode_languageserver_1.SymbolInformation.create(name, symbolKind, statement.range, uri, containerStatement === null || containerStatement === void 0 ? void 0 : containerStatement.getName(
|
|
1133
|
+
const symbol = vscode_languageserver_1.SymbolInformation.create(name, symbolKind, statement.range, uri, containerStatement === null || containerStatement === void 0 ? void 0 : containerStatement.getName(Parser_1.ParseMode.BrighterScript));
|
|
1113
1134
|
symbols.push(symbol);
|
|
1114
1135
|
return symbols;
|
|
1115
1136
|
}
|
|
@@ -1123,8 +1144,8 @@ class BrsFile {
|
|
|
1123
1144
|
const token = this.parser.getTokenAt(position);
|
|
1124
1145
|
// While certain other tokens are allowed as local variables (AllowedLocalIdentifiers: https://github.com/rokucommunity/brighterscript/blob/master/src/lexer/TokenKind.ts#L418), these are converted by the parser to TokenKind.Identifier by the time we retrieve the token using getTokenAt
|
|
1125
1146
|
let definitionTokenTypes = [
|
|
1126
|
-
|
|
1127
|
-
|
|
1147
|
+
TokenKind_1.TokenKind.Identifier,
|
|
1148
|
+
TokenKind_1.TokenKind.StringLiteral
|
|
1128
1149
|
];
|
|
1129
1150
|
//throw out invalid tokens and the wrong kind of tokens
|
|
1130
1151
|
if (!token || !definitionTokenTypes.includes(token.kind)) {
|
|
@@ -1132,7 +1153,7 @@ class BrsFile {
|
|
|
1132
1153
|
}
|
|
1133
1154
|
let textToSearchFor = token.text.toLowerCase();
|
|
1134
1155
|
const previousToken = this.parser.getTokenAt({ line: token.range.start.line, character: token.range.start.character });
|
|
1135
|
-
if ((previousToken === null || previousToken === void 0 ? void 0 : previousToken.kind) ===
|
|
1156
|
+
if ((previousToken === null || previousToken === void 0 ? void 0 : previousToken.kind) === TokenKind_1.TokenKind.Callfunc) {
|
|
1136
1157
|
for (const scope of this.program.getScopes()) {
|
|
1137
1158
|
//to only get functions defined in interface methods
|
|
1138
1159
|
const callable = scope.getAllCallables().find((c) => c.callable.name.toLowerCase() === textToSearchFor); // eslint-disable-line @typescript-eslint/no-loop-func
|
|
@@ -1142,7 +1163,7 @@ class BrsFile {
|
|
|
1142
1163
|
}
|
|
1143
1164
|
return results;
|
|
1144
1165
|
}
|
|
1145
|
-
let classToken = this.parser.getTokenBefore(token,
|
|
1166
|
+
let classToken = this.parser.getTokenBefore(token, TokenKind_1.TokenKind.Class);
|
|
1146
1167
|
if (classToken) {
|
|
1147
1168
|
let cs = this.parser.references.classStatements.find((cs) => cs.classKeyword.range === classToken.range);
|
|
1148
1169
|
if (cs === null || cs === void 0 ? void 0 : cs.parentClassName) {
|
|
@@ -1154,7 +1175,7 @@ class BrsFile {
|
|
|
1154
1175
|
}
|
|
1155
1176
|
return results;
|
|
1156
1177
|
}
|
|
1157
|
-
if (token.kind ===
|
|
1178
|
+
if (token.kind === TokenKind_1.TokenKind.StringLiteral) {
|
|
1158
1179
|
// We need to strip off the quotes but only if present
|
|
1159
1180
|
const startIndex = textToSearchFor.startsWith('"') ? 1 : 0;
|
|
1160
1181
|
let endIndex = textToSearchFor.length;
|
|
@@ -1173,7 +1194,7 @@ class BrsFile {
|
|
|
1173
1194
|
results.push(vscode_languageserver_1.Location.create(uri, symbol.range));
|
|
1174
1195
|
}
|
|
1175
1196
|
}
|
|
1176
|
-
if (this.parser.tokenFollows(token,
|
|
1197
|
+
if (this.parser.tokenFollows(token, TokenKind_1.TokenKind.Goto)) {
|
|
1177
1198
|
for (const label of func.labelStatements) {
|
|
1178
1199
|
if (label.tokens.identifier.text.toLocaleLowerCase() === textToSearchFor) {
|
|
1179
1200
|
const uri = util_1.util.pathToUri(this.srcPath);
|
|
@@ -1185,11 +1206,11 @@ class BrsFile {
|
|
|
1185
1206
|
//look through all files in scope for matches
|
|
1186
1207
|
for (const scope of this.program.getScopesForFile(this)) {
|
|
1187
1208
|
for (const file of scope.getAllFiles()) {
|
|
1188
|
-
if (reflection_1.isXmlFile(file) || filesSearched.has(file)) {
|
|
1209
|
+
if ((0, reflection_1.isXmlFile)(file) || filesSearched.has(file)) {
|
|
1189
1210
|
continue;
|
|
1190
1211
|
}
|
|
1191
1212
|
filesSearched.add(file);
|
|
1192
|
-
if ((previousToken === null || previousToken === void 0 ? void 0 : previousToken.kind) ===
|
|
1213
|
+
if ((previousToken === null || previousToken === void 0 ? void 0 : previousToken.kind) === TokenKind_1.TokenKind.Dot && file.parseMode === Parser_1.ParseMode.BrighterScript) {
|
|
1193
1214
|
results.push(...this.getClassMemberDefinitions(textToSearchFor, file));
|
|
1194
1215
|
const namespaceDefinition = this.getNamespaceDefinitions(token, file);
|
|
1195
1216
|
if (namespaceDefinition) {
|
|
@@ -1202,7 +1223,7 @@ class BrsFile {
|
|
|
1202
1223
|
results.push(vscode_languageserver_1.Location.create(uri, statement.range));
|
|
1203
1224
|
}
|
|
1204
1225
|
};
|
|
1205
|
-
file.parser.ast.walk(visitors_1.createVisitor({
|
|
1226
|
+
file.parser.ast.walk((0, visitors_1.createVisitor)({
|
|
1206
1227
|
FunctionStatement: statementHandler
|
|
1207
1228
|
}), {
|
|
1208
1229
|
walkMode: visitors_1.WalkMode.visitStatements
|
|
@@ -1224,7 +1245,7 @@ class BrsFile {
|
|
|
1224
1245
|
results.push(vscode_languageserver_1.Location.create(util_1.util.pathToUri(file.srcPath), statement.range));
|
|
1225
1246
|
}
|
|
1226
1247
|
};
|
|
1227
|
-
file.parser.ast.walk(visitors_1.createVisitor({
|
|
1248
|
+
file.parser.ast.walk((0, visitors_1.createVisitor)({
|
|
1228
1249
|
ClassMethodStatement: statementHandler,
|
|
1229
1250
|
ClassFieldStatement: fieldStatementHandler
|
|
1230
1251
|
}), {
|
|
@@ -1233,15 +1254,16 @@ class BrsFile {
|
|
|
1233
1254
|
return results;
|
|
1234
1255
|
}
|
|
1235
1256
|
getHover(position) {
|
|
1236
|
-
var _a, _b;
|
|
1257
|
+
var _a, _b, _c;
|
|
1258
|
+
const fence = (code) => util_1.util.mdFence(code, 'brightscript');
|
|
1237
1259
|
//get the token at the position
|
|
1238
1260
|
let token = this.parser.getTokenAt(position);
|
|
1239
1261
|
let hoverTokenTypes = [
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1262
|
+
TokenKind_1.TokenKind.Identifier,
|
|
1263
|
+
TokenKind_1.TokenKind.Function,
|
|
1264
|
+
TokenKind_1.TokenKind.EndFunction,
|
|
1265
|
+
TokenKind_1.TokenKind.Sub,
|
|
1266
|
+
TokenKind_1.TokenKind.EndSub
|
|
1245
1267
|
];
|
|
1246
1268
|
//throw out invalid tokens and the wrong kind of tokens
|
|
1247
1269
|
if (!token || !hoverTokenTypes.includes(token.kind)) {
|
|
@@ -1253,7 +1275,7 @@ class BrsFile {
|
|
|
1253
1275
|
const func = this.getFunctionExpressionAtPosition(position);
|
|
1254
1276
|
if (func) {
|
|
1255
1277
|
// this identifier could possibly be a class field, so no function expression is available
|
|
1256
|
-
for (const labelStatement of func === null || func === void 0 ? void 0 : func.labelStatements) {
|
|
1278
|
+
for (const labelStatement of (_a = func === null || func === void 0 ? void 0 : func.labelStatements) !== null && _a !== void 0 ? _a : []) {
|
|
1257
1279
|
if (labelStatement.tokens.identifier.text.toLocaleLowerCase() === lowerTokenText) {
|
|
1258
1280
|
return {
|
|
1259
1281
|
range: token.range,
|
|
@@ -1262,58 +1284,103 @@ class BrsFile {
|
|
|
1262
1284
|
}
|
|
1263
1285
|
}
|
|
1264
1286
|
}
|
|
1265
|
-
const typeTexts =
|
|
1266
|
-
|
|
1287
|
+
const typeTexts = new Set();
|
|
1288
|
+
const fileScopes = this.program.getScopesForFile(this).sort((a, b) => { var _a; return (_a = a.dependencyGraphKey) === null || _a === void 0 ? void 0 : _a.localeCompare(b.dependencyGraphKey); });
|
|
1289
|
+
const callables = [];
|
|
1290
|
+
for (const scope of fileScopes) {
|
|
1267
1291
|
scope.linkSymbolTable();
|
|
1292
|
+
const typeContext = { file: this, scope: scope, position: position };
|
|
1268
1293
|
const typeTextPair = this.getSymbolTypeFromToken(token, func, scope);
|
|
1269
1294
|
if (typeTextPair) {
|
|
1270
1295
|
let scopeTypeText = '';
|
|
1271
|
-
if (reflection_1.isFunctionType(typeTextPair.type)) {
|
|
1272
|
-
scopeTypeText = (
|
|
1296
|
+
if ((0, reflection_1.isFunctionType)(typeTextPair.type)) {
|
|
1297
|
+
scopeTypeText = (_b = typeTextPair.type) === null || _b === void 0 ? void 0 : _b.toString(typeContext);
|
|
1298
|
+
//keep unique references to the callables for this function
|
|
1299
|
+
if (!typeTexts.has(scopeTypeText)) {
|
|
1300
|
+
callables.push(scope.getCallableByName(lowerTokenText));
|
|
1301
|
+
}
|
|
1273
1302
|
}
|
|
1274
1303
|
else if (typeTextPair.useExpandedTextOnly) {
|
|
1275
1304
|
scopeTypeText = typeTextPair.expandedTokenText;
|
|
1276
1305
|
}
|
|
1277
1306
|
else {
|
|
1278
|
-
scopeTypeText = `${typeTextPair.expandedTokenText} as ${(
|
|
1307
|
+
scopeTypeText = `${typeTextPair.expandedTokenText} as ${(_c = typeTextPair.type) === null || _c === void 0 ? void 0 : _c.toString(typeContext)}`;
|
|
1279
1308
|
}
|
|
1280
|
-
if (scopeTypeText
|
|
1281
|
-
typeTexts.
|
|
1309
|
+
if (scopeTypeText) {
|
|
1310
|
+
typeTexts.add(scopeTypeText);
|
|
1282
1311
|
}
|
|
1283
1312
|
}
|
|
1284
1313
|
scope.unlinkSymbolTable();
|
|
1285
1314
|
}
|
|
1286
|
-
|
|
1287
|
-
|
|
1315
|
+
if (callables.length === typeTexts.size) {
|
|
1316
|
+
//this is a function in all scopes, so build the function hover
|
|
1317
|
+
return {
|
|
1318
|
+
range: token.range,
|
|
1319
|
+
contents: this.getCallableDocumentation([...typeTexts], callables)
|
|
1320
|
+
};
|
|
1321
|
+
}
|
|
1322
|
+
else if ((typeTexts === null || typeTexts === void 0 ? void 0 : typeTexts.size) > 0) {
|
|
1323
|
+
const typeText = [...typeTexts].join(' | ');
|
|
1288
1324
|
return {
|
|
1289
1325
|
range: token.range,
|
|
1290
|
-
contents: typeText
|
|
1326
|
+
contents: fence(typeText)
|
|
1291
1327
|
};
|
|
1292
1328
|
}
|
|
1293
1329
|
}
|
|
1294
|
-
//look through all callables in relevant scopes
|
|
1295
|
-
{
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1330
|
+
// //look through all callables in relevant scopes
|
|
1331
|
+
// {
|
|
1332
|
+
// let scopes = this.program.getScopesForFile(this);
|
|
1333
|
+
// for (let scope of scopes) {
|
|
1334
|
+
// let callable = scope.getCallableByName(lowerTokenText);
|
|
1335
|
+
// if (callable) {
|
|
1336
|
+
// return {
|
|
1337
|
+
// range: token.range,
|
|
1338
|
+
// contents: this.getCallableDocumentation(callables)
|
|
1339
|
+
// };
|
|
1340
|
+
// }
|
|
1341
|
+
// }
|
|
1342
|
+
// }
|
|
1343
|
+
}
|
|
1344
|
+
/**
|
|
1345
|
+
* Build a hover documentation for a callable.
|
|
1346
|
+
*/
|
|
1347
|
+
getCallableDocumentation(typeTexts, callables) {
|
|
1348
|
+
var _a;
|
|
1349
|
+
const callable = callables[0];
|
|
1350
|
+
const typeText = typeTexts[0];
|
|
1351
|
+
const comments = [];
|
|
1352
|
+
const tokens = callable === null || callable === void 0 ? void 0 : callable.file.parser.tokens;
|
|
1353
|
+
const idx = tokens === null || tokens === void 0 ? void 0 : tokens.indexOf((_a = callable.functionStatement) === null || _a === void 0 ? void 0 : _a.func.functionType);
|
|
1354
|
+
for (let i = idx - 1; i >= 0; i--) {
|
|
1355
|
+
const token = tokens[i];
|
|
1356
|
+
//skip whitespace and newline chars
|
|
1357
|
+
if (token.kind === TokenKind_1.TokenKind.Comment) {
|
|
1358
|
+
comments.push(token);
|
|
1359
|
+
}
|
|
1360
|
+
else if (token.kind === TokenKind_1.TokenKind.Newline || token.kind === TokenKind_1.TokenKind.Whitespace) {
|
|
1361
|
+
//skip these tokens
|
|
1362
|
+
continue;
|
|
1363
|
+
//any other token means there are no more comments
|
|
1364
|
+
}
|
|
1365
|
+
else {
|
|
1366
|
+
break;
|
|
1305
1367
|
}
|
|
1306
1368
|
}
|
|
1369
|
+
//message indicating if there are variations. example: (+3 variations) if there are 4 unique function signatures
|
|
1370
|
+
const multiText = callables.length > 1 ? ` (+${callables.length - 1} variations)` : '';
|
|
1371
|
+
let result = util_1.util.mdFence(typeText + multiText, 'brightscript');
|
|
1372
|
+
if (comments.length > 0) {
|
|
1373
|
+
result += '\n***\n' + comments.reverse().map(x => x.text.replace(/^('|rem)/i, '')).join('\n');
|
|
1374
|
+
}
|
|
1375
|
+
return result;
|
|
1307
1376
|
}
|
|
1308
1377
|
getSignatureHelpForNamespaceMethods(callableName, dottedGetText, scope) {
|
|
1309
1378
|
var _a;
|
|
1310
1379
|
if (!dottedGetText) {
|
|
1311
1380
|
return [];
|
|
1312
1381
|
}
|
|
1313
|
-
let namespaceLookup = scope.namespaceLookup;
|
|
1314
1382
|
let resultsMap = new Map();
|
|
1315
|
-
for (let
|
|
1316
|
-
let namespace = namespaceLookup[key.toLowerCase()];
|
|
1383
|
+
for (let [, namespace] of scope.namespaceLookup) {
|
|
1317
1384
|
//completionName = "NameA."
|
|
1318
1385
|
//completionName = "NameA.Na
|
|
1319
1386
|
//NameA
|
|
@@ -1322,7 +1389,7 @@ class BrsFile {
|
|
|
1322
1389
|
if (namespace.fullName.toLowerCase() === dottedGetText.toLowerCase()) {
|
|
1323
1390
|
//add function and class statement completions
|
|
1324
1391
|
for (let stmt of namespace.statements) {
|
|
1325
|
-
if (reflection_1.isFunctionStatement(stmt) && stmt.name.text.toLowerCase() === callableName.toLowerCase()) {
|
|
1392
|
+
if ((0, reflection_1.isFunctionStatement)(stmt) && stmt.name.text.toLowerCase() === callableName.toLowerCase()) {
|
|
1326
1393
|
const result = (_a = namespace.file) === null || _a === void 0 ? void 0 : _a.getSignatureHelpForStatement(stmt);
|
|
1327
1394
|
if (!resultsMap.has(result.key)) {
|
|
1328
1395
|
resultsMap.set(result.key, result);
|
|
@@ -1334,7 +1401,7 @@ class BrsFile {
|
|
|
1334
1401
|
return [...resultsMap.values()];
|
|
1335
1402
|
}
|
|
1336
1403
|
getSignatureHelpForStatement(statement) {
|
|
1337
|
-
if (!reflection_1.isFunctionStatement(statement) && !reflection_1.isClassMethodStatement(statement)) {
|
|
1404
|
+
if (!(0, reflection_1.isFunctionStatement)(statement) && !(0, reflection_1.isClassMethodStatement)(statement)) {
|
|
1338
1405
|
return undefined;
|
|
1339
1406
|
}
|
|
1340
1407
|
const func = statement.func;
|
|
@@ -1353,12 +1420,12 @@ class BrsFile {
|
|
|
1353
1420
|
}
|
|
1354
1421
|
}
|
|
1355
1422
|
const kind = currentToken.kind;
|
|
1356
|
-
if (kind ===
|
|
1423
|
+
if (kind === TokenKind_1.TokenKind.Comment) {
|
|
1357
1424
|
// Strip off common leading characters to make it easier to read
|
|
1358
1425
|
const commentText = currentToken.text.replace(/^[' *\/]+/, '');
|
|
1359
1426
|
functionComments.unshift(commentText);
|
|
1360
1427
|
}
|
|
1361
|
-
else if (kind ===
|
|
1428
|
+
else if (kind === TokenKind_1.TokenKind.Newline) {
|
|
1362
1429
|
if (functionComments.length === 0) {
|
|
1363
1430
|
continue;
|
|
1364
1431
|
}
|
|
@@ -1396,7 +1463,7 @@ class BrsFile {
|
|
|
1396
1463
|
}
|
|
1397
1464
|
};
|
|
1398
1465
|
while (classStatement) {
|
|
1399
|
-
classStatement.walk(visitors_1.createVisitor({
|
|
1466
|
+
classStatement.walk((0, visitors_1.createVisitor)({
|
|
1400
1467
|
ClassMethodStatement: statementHandler
|
|
1401
1468
|
}), {
|
|
1402
1469
|
walkMode: visitors_1.WalkMode.visitStatements
|
|
@@ -1418,7 +1485,7 @@ class BrsFile {
|
|
|
1418
1485
|
const classConstructor = this.getClassMethod(classStatement, 'new');
|
|
1419
1486
|
let sigHelp = classConstructor ? this.getSignatureHelpForStatement(classConstructor) : undefined;
|
|
1420
1487
|
if (sigHelp) {
|
|
1421
|
-
sigHelp.key = classStatement.getName(
|
|
1488
|
+
sigHelp.key = classStatement.getName(Parser_1.ParseMode.BrighterScript);
|
|
1422
1489
|
sigHelp.signature.label = sigHelp.signature.label.replace(/(function|sub) new/, sigHelp.key);
|
|
1423
1490
|
}
|
|
1424
1491
|
return sigHelp;
|
|
@@ -1431,11 +1498,11 @@ class BrsFile {
|
|
|
1431
1498
|
for (const scope of scopes) {
|
|
1432
1499
|
const processedFiles = new Set();
|
|
1433
1500
|
for (const file of scope.getAllFiles()) {
|
|
1434
|
-
if (reflection_1.isXmlFile(file) || processedFiles.has(file)) {
|
|
1501
|
+
if ((0, reflection_1.isXmlFile)(file) || processedFiles.has(file)) {
|
|
1435
1502
|
continue;
|
|
1436
1503
|
}
|
|
1437
1504
|
processedFiles.add(file);
|
|
1438
|
-
file.ast.walk(visitors_1.createVisitor({
|
|
1505
|
+
file.ast.walk((0, visitors_1.createVisitor)({
|
|
1439
1506
|
VariableExpression: (e) => {
|
|
1440
1507
|
if (e.name.text.toLowerCase() === searchFor) {
|
|
1441
1508
|
locations.push(vscode_languageserver_1.Location.create(util_1.util.pathToUri(file.srcPath), e.range));
|
|
@@ -1495,7 +1562,7 @@ exports.BrsFile = BrsFile;
|
|
|
1495
1562
|
* List of completions for all valid keywords/reserved words.
|
|
1496
1563
|
* Build this list once because it won't change for the lifetime of this process
|
|
1497
1564
|
*/
|
|
1498
|
-
exports.KeywordCompletions = Object.keys(
|
|
1565
|
+
exports.KeywordCompletions = Object.keys(TokenKind_1.Keywords)
|
|
1499
1566
|
//remove any keywords with whitespace
|
|
1500
1567
|
.filter(x => !x.includes(' '))
|
|
1501
1568
|
//create completions
|