brighterscript 0.52.3 → 0.54.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/dist/DiagnosticMessages.d.ts +14 -3
- package/dist/DiagnosticMessages.js +14 -3
- package/dist/DiagnosticMessages.js.map +1 -1
- package/dist/LanguageServer.js +51 -9
- package/dist/LanguageServer.js.map +1 -1
- package/dist/Program.d.ts +8 -4
- package/dist/Program.js +70 -35
- package/dist/Program.js.map +1 -1
- package/dist/Scope.d.ts +24 -9
- package/dist/Scope.js +96 -50
- package/dist/Scope.js.map +1 -1
- package/dist/SymbolTable.d.ts +62 -0
- package/dist/SymbolTable.js +101 -0
- package/dist/SymbolTable.js.map +1 -0
- package/dist/astUtils/reflection.d.ts +2 -1
- package/dist/astUtils/reflection.js +6 -2
- package/dist/astUtils/reflection.js.map +1 -1
- package/dist/astUtils/visitors.d.ts +2 -1
- package/dist/astUtils/visitors.js.map +1 -1
- package/dist/bscPlugin/BscPlugin.d.ts +3 -1
- package/dist/bscPlugin/BscPlugin.js +8 -0
- package/dist/bscPlugin/BscPlugin.js.map +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.d.ts +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +11 -5
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js.map +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js +75 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/completions/CompletionsProcessor.d.ts +6 -0
- package/dist/bscPlugin/completions/CompletionsProcessor.js +45 -0
- package/dist/bscPlugin/completions/CompletionsProcessor.js.map +1 -0
- package/dist/bscPlugin/hover/HoverProcessor.d.ts +13 -0
- package/dist/bscPlugin/hover/HoverProcessor.js +146 -0
- package/dist/bscPlugin/hover/HoverProcessor.js.map +1 -0
- package/dist/bscPlugin/hover/HoverProcessor.spec.d.ts +1 -0
- package/dist/bscPlugin/hover/HoverProcessor.spec.js +167 -0
- package/dist/bscPlugin/hover/HoverProcessor.spec.js.map +1 -0
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.d.ts +7 -1
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js +81 -22
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js.map +1 -1
- package/dist/bscPlugin/validation/BrsFileValidator.d.ts +5 -1
- package/dist/bscPlugin/validation/BrsFileValidator.js +28 -2
- package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -1
- package/dist/bscPlugin/validation/ScopeValidator.d.ts +18 -3
- package/dist/bscPlugin/validation/ScopeValidator.js +139 -47
- package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -1
- package/dist/files/BrsFile.Class.spec.js +10 -10
- package/dist/files/BrsFile.Class.spec.js.map +1 -1
- package/dist/files/BrsFile.d.ts +14 -9
- package/dist/files/BrsFile.js +121 -142
- package/dist/files/BrsFile.js.map +1 -1
- package/dist/files/BrsFile.spec.js +164 -109
- package/dist/files/BrsFile.spec.js.map +1 -1
- package/dist/files/XmlFile.d.ts +1 -2
- package/dist/files/XmlFile.js +0 -5
- package/dist/files/XmlFile.js.map +1 -1
- package/dist/files/tests/imports.spec.js +1 -1
- package/dist/files/tests/imports.spec.js.map +1 -1
- package/dist/files/tests/optionalChaning.spec.js +20 -16
- package/dist/files/tests/optionalChaning.spec.js.map +1 -1
- package/dist/globalCallables.js +3 -0
- package/dist/globalCallables.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +44 -2
- package/dist/lexer/Lexer.spec.js +7 -0
- package/dist/lexer/Lexer.spec.js.map +1 -1
- package/dist/lexer/TokenKind.d.ts +1 -0
- package/dist/lexer/TokenKind.js +7 -3
- package/dist/lexer/TokenKind.js.map +1 -1
- package/dist/parser/Expression.d.ts +4 -1
- package/dist/parser/Expression.js +8 -2
- package/dist/parser/Expression.js.map +1 -1
- package/dist/parser/Parser.Class.spec.js +1 -1
- package/dist/parser/Parser.d.ts +13 -2
- package/dist/parser/Parser.js +137 -60
- package/dist/parser/Parser.js.map +1 -1
- package/dist/parser/Statement.d.ts +29 -1
- package/dist/parser/Statement.js +66 -4
- package/dist/parser/Statement.js.map +1 -1
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +73 -31
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js +148 -47
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TernaryExpression.spec.js +219 -37
- package/dist/parser/tests/expression/TernaryExpression.spec.js.map +1 -1
- package/dist/parser/tests/statement/ConstStatement.spec.d.ts +1 -0
- package/dist/parser/tests/statement/ConstStatement.spec.js +182 -0
- package/dist/parser/tests/statement/ConstStatement.spec.js.map +1 -0
- package/dist/parser/tests/statement/Enum.spec.js +17 -2
- package/dist/parser/tests/statement/Enum.spec.js.map +1 -1
- package/dist/parser/tests/statement/PrintStatement.spec.js +72 -57
- package/dist/parser/tests/statement/PrintStatement.spec.js.map +1 -1
- package/dist/types/DynamicType.d.ts +1 -0
- package/dist/types/DynamicType.js +1 -0
- package/dist/types/DynamicType.js.map +1 -1
- package/dist/util.d.ts +37 -6
- package/dist/util.js +90 -6
- package/dist/util.js.map +1 -1
- package/dist/validators/ClassValidator.js +4 -6
- package/dist/validators/ClassValidator.js.map +1 -1
- package/package.json +1 -1
package/dist/files/BrsFile.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.KeywordCompletions = exports.BrsFile = void 0;
|
|
4
4
|
const source_map_1 = require("source-map");
|
|
5
5
|
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
6
|
+
const vscode_languageserver_2 = require("vscode-languageserver");
|
|
6
7
|
const chalk_1 = require("chalk");
|
|
7
8
|
const path = require("path");
|
|
8
9
|
const DiagnosticMessages_1 = require("../DiagnosticMessages");
|
|
@@ -83,6 +84,12 @@ class BrsFile {
|
|
|
83
84
|
getDiagnostics() {
|
|
84
85
|
return [...this.diagnostics];
|
|
85
86
|
}
|
|
87
|
+
addDiagnostic(diagnostic) {
|
|
88
|
+
if (!diagnostic.file) {
|
|
89
|
+
diagnostic.file = this;
|
|
90
|
+
}
|
|
91
|
+
this.diagnostics.push(diagnostic);
|
|
92
|
+
}
|
|
86
93
|
addDiagnostics(diagnostics) {
|
|
87
94
|
this.diagnostics.push(...diagnostics);
|
|
88
95
|
}
|
|
@@ -92,13 +99,17 @@ class BrsFile {
|
|
|
92
99
|
}
|
|
93
100
|
return this._functionScopes;
|
|
94
101
|
}
|
|
102
|
+
get cache() {
|
|
103
|
+
var _a;
|
|
104
|
+
// eslint-disable-next-line @typescript-eslint/dot-notation
|
|
105
|
+
return (_a = this._parser) === null || _a === void 0 ? void 0 : _a.references['cache'];
|
|
106
|
+
}
|
|
95
107
|
/**
|
|
96
108
|
* files referenced by import statements
|
|
97
109
|
*/
|
|
98
110
|
get ownScriptImports() {
|
|
99
111
|
var _a, _b;
|
|
100
|
-
|
|
101
|
-
const result = (_b = (_a = this._parser) === null || _a === void 0 ? void 0 : _a.references['cache'].getOrAdd('BrsFile_ownScriptImports', () => {
|
|
112
|
+
const result = (_b = (_a = this.cache) === null || _a === void 0 ? void 0 : _a.getOrAdd('BrsFile_ownScriptImports', () => {
|
|
102
113
|
var _a, _b, _c, _d;
|
|
103
114
|
const result = [];
|
|
104
115
|
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 : []) {
|
|
@@ -133,6 +144,29 @@ class BrsFile {
|
|
|
133
144
|
}
|
|
134
145
|
}
|
|
135
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* Walk the AST and find the expression that this token is most specifically contained within
|
|
149
|
+
*/
|
|
150
|
+
getClosestExpression(position) {
|
|
151
|
+
const handle = new vscode_languageserver_1.CancellationTokenSource();
|
|
152
|
+
let containingNode;
|
|
153
|
+
this.ast.walk((node) => {
|
|
154
|
+
const latestContainer = containingNode;
|
|
155
|
+
//bsc walks depth-first
|
|
156
|
+
if (util_1.util.rangeContains(node.range, position)) {
|
|
157
|
+
containingNode = node;
|
|
158
|
+
}
|
|
159
|
+
//we had a match before, and don't now. this means we've finished walking down the whole way, and found our match
|
|
160
|
+
if (latestContainer && !containingNode) {
|
|
161
|
+
containingNode = latestContainer;
|
|
162
|
+
handle.cancel();
|
|
163
|
+
}
|
|
164
|
+
}, {
|
|
165
|
+
walkMode: visitors_1.WalkMode.visitAllRecursive,
|
|
166
|
+
cancel: handle.token
|
|
167
|
+
});
|
|
168
|
+
return containingNode;
|
|
169
|
+
}
|
|
136
170
|
get parser() {
|
|
137
171
|
if (!this._parser) {
|
|
138
172
|
//remove the typedef file (if it exists)
|
|
@@ -295,7 +329,7 @@ class BrsFile {
|
|
|
295
329
|
for (const key of Object.keys(propertyHints)) {
|
|
296
330
|
results.push({
|
|
297
331
|
label: propertyHints[key],
|
|
298
|
-
kind:
|
|
332
|
+
kind: vscode_languageserver_2.CompletionItemKind.Text
|
|
299
333
|
});
|
|
300
334
|
}
|
|
301
335
|
return results;
|
|
@@ -576,14 +610,19 @@ class BrsFile {
|
|
|
576
610
|
* @param position
|
|
577
611
|
* @param functionScopes
|
|
578
612
|
*/
|
|
579
|
-
getFunctionScopeAtPosition(position
|
|
613
|
+
getFunctionScopeAtPosition(position) {
|
|
614
|
+
return this.cache.getOrAdd(`functionScope-${position.line}:${position.character}`, () => {
|
|
615
|
+
return this._getFunctionScopeAtPosition(position, this.functionScopes);
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
_getFunctionScopeAtPosition(position, functionScopes) {
|
|
580
619
|
if (!functionScopes) {
|
|
581
620
|
functionScopes = this.functionScopes;
|
|
582
621
|
}
|
|
583
622
|
for (let scope of functionScopes) {
|
|
584
623
|
if (util_1.util.rangeContains(scope.range, position)) {
|
|
585
624
|
//see if any of that scope's children match the position also, and give them priority
|
|
586
|
-
let childScope = this.
|
|
625
|
+
let childScope = this._getFunctionScopeAtPosition(position, scope.childrenScopes);
|
|
587
626
|
if (childScope) {
|
|
588
627
|
return childScope;
|
|
589
628
|
}
|
|
@@ -600,11 +639,13 @@ class BrsFile {
|
|
|
600
639
|
*/
|
|
601
640
|
getNamespaceStatementForPosition(position) {
|
|
602
641
|
if (position) {
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
642
|
+
return this.cache.getOrAdd(`namespaceStatementForPosition-${position.line}:${position.character}`, () => {
|
|
643
|
+
for (const statement of this.parser.references.namespaceStatements) {
|
|
644
|
+
if (util_1.util.rangeContains(statement.range, position)) {
|
|
645
|
+
return statement;
|
|
646
|
+
}
|
|
606
647
|
}
|
|
607
|
-
}
|
|
648
|
+
});
|
|
608
649
|
}
|
|
609
650
|
}
|
|
610
651
|
/**
|
|
@@ -634,12 +675,12 @@ class BrsFile {
|
|
|
634
675
|
const pkgPath = `${fileProtocol}:/${file.pkgPath.replace(/\\/g, '/')}`;
|
|
635
676
|
result.push({
|
|
636
677
|
label: pkgPath,
|
|
637
|
-
textEdit:
|
|
678
|
+
textEdit: vscode_languageserver_2.TextEdit.replace(util_1.util.createRange(currentToken.range.start.line,
|
|
638
679
|
//+1 to step past the opening quote
|
|
639
680
|
currentToken.range.start.character + (openingQuote ? 1 : 0), currentToken.range.end.line,
|
|
640
681
|
//-1 to exclude the closing quotemark (or the end character if there is no closing quotemark)
|
|
641
682
|
currentToken.range.end.character + (currentToken.text.endsWith('"') ? -1 : 0)), pkgPath),
|
|
642
|
-
kind:
|
|
683
|
+
kind: vscode_languageserver_2.CompletionItemKind.File
|
|
643
684
|
});
|
|
644
685
|
}
|
|
645
686
|
return result;
|
|
@@ -702,18 +743,21 @@ class BrsFile {
|
|
|
702
743
|
}
|
|
703
744
|
}
|
|
704
745
|
else {
|
|
746
|
+
result.push(
|
|
705
747
|
//include namespaces
|
|
706
|
-
|
|
748
|
+
...namespaceCompletions,
|
|
707
749
|
//include class names
|
|
708
|
-
|
|
750
|
+
...classNameCompletions,
|
|
709
751
|
//include enums
|
|
710
|
-
|
|
752
|
+
...this.getNonNamespacedEnumStatementCompletions(currentToken, this.parseMode, scope),
|
|
753
|
+
//include constants
|
|
754
|
+
...this.getNonNamespacedConstStatementCompletions(currentToken, this.parseMode, scope),
|
|
711
755
|
//include the global callables
|
|
712
|
-
|
|
756
|
+
...scope.getCallablesAsCompletions(this.parseMode));
|
|
713
757
|
//add `m` because that's always valid within a function
|
|
714
758
|
result.push({
|
|
715
759
|
label: 'm',
|
|
716
|
-
kind:
|
|
760
|
+
kind: vscode_languageserver_2.CompletionItemKind.Variable
|
|
717
761
|
});
|
|
718
762
|
names.m = true;
|
|
719
763
|
result.push(...exports.KeywordCompletions);
|
|
@@ -727,7 +771,7 @@ class BrsFile {
|
|
|
727
771
|
names[variable.name.toLowerCase()] = true;
|
|
728
772
|
result.push({
|
|
729
773
|
label: variable.name,
|
|
730
|
-
kind: (0, reflection_1.isFunctionType)(variable.type) ?
|
|
774
|
+
kind: (0, reflection_1.isFunctionType)(variable.type) ? vscode_languageserver_2.CompletionItemKind.Function : vscode_languageserver_2.CompletionItemKind.Variable
|
|
731
775
|
});
|
|
732
776
|
}
|
|
733
777
|
if (this.parseMode === Parser_1.ParseMode.BrighterScript) {
|
|
@@ -742,7 +786,7 @@ class BrsFile {
|
|
|
742
786
|
names[firstPart.toLowerCase()] = true;
|
|
743
787
|
result.push({
|
|
744
788
|
label: firstPart,
|
|
745
|
-
kind:
|
|
789
|
+
kind: vscode_languageserver_2.CompletionItemKind.Module
|
|
746
790
|
});
|
|
747
791
|
}
|
|
748
792
|
}
|
|
@@ -752,7 +796,7 @@ class BrsFile {
|
|
|
752
796
|
getLabelCompletion(functionScope) {
|
|
753
797
|
return functionScope.labelStatements.map(label => ({
|
|
754
798
|
label: label.name,
|
|
755
|
-
kind:
|
|
799
|
+
kind: vscode_languageserver_2.CompletionItemKind.Reference
|
|
756
800
|
}));
|
|
757
801
|
}
|
|
758
802
|
getClassMemberCompletions(position, currentToken, functionScope, scope) {
|
|
@@ -766,7 +810,7 @@ class BrsFile {
|
|
|
766
810
|
if (!results.has(member.name.text.toLowerCase())) {
|
|
767
811
|
results.set(member.name.text.toLowerCase(), {
|
|
768
812
|
label: member.name.text,
|
|
769
|
-
kind: (0, reflection_1.isClassFieldStatement)(member) ?
|
|
813
|
+
kind: (0, reflection_1.isClassFieldStatement)(member) ? vscode_languageserver_2.CompletionItemKind.Field : vscode_languageserver_2.CompletionItemKind.Function
|
|
770
814
|
});
|
|
771
815
|
}
|
|
772
816
|
}
|
|
@@ -802,7 +846,7 @@ class BrsFile {
|
|
|
802
846
|
if (!results.has(cs.name.text)) {
|
|
803
847
|
results.set(cs.name.text, {
|
|
804
848
|
label: cs.name.text,
|
|
805
|
-
kind:
|
|
849
|
+
kind: vscode_languageserver_2.CompletionItemKind.Class
|
|
806
850
|
});
|
|
807
851
|
}
|
|
808
852
|
}
|
|
@@ -824,7 +868,28 @@ class BrsFile {
|
|
|
824
868
|
if (fullName.startsWith(containingNamespaceName) || !fullName.includes('.')) {
|
|
825
869
|
results.set(fullName, {
|
|
826
870
|
label: enumStatement.name,
|
|
827
|
-
kind:
|
|
871
|
+
kind: vscode_languageserver_2.CompletionItemKind.Enum
|
|
872
|
+
});
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
return [...results.values()];
|
|
876
|
+
}
|
|
877
|
+
getNonNamespacedConstStatementCompletions(currentToken, parseMode, scope) {
|
|
878
|
+
var _a, _b;
|
|
879
|
+
if (parseMode !== Parser_1.ParseMode.BrighterScript) {
|
|
880
|
+
return [];
|
|
881
|
+
}
|
|
882
|
+
const containingNamespaceName = ((_b = this.getNamespaceStatementForPosition((_a = currentToken === null || currentToken === void 0 ? void 0 : currentToken.range) === null || _a === void 0 ? void 0 : _a.start)) === null || _b === void 0 ? void 0 : _b.name) + '.';
|
|
883
|
+
const results = new Map();
|
|
884
|
+
const map = scope.getConstMap();
|
|
885
|
+
for (const key of [...map.keys()]) {
|
|
886
|
+
const statement = map.get(key).item;
|
|
887
|
+
const fullName = statement.fullName;
|
|
888
|
+
//if the item is contained within our own namespace, or if it's non-namespaced
|
|
889
|
+
if (fullName.startsWith(containingNamespaceName) || !fullName.includes('.')) {
|
|
890
|
+
results.set(fullName, {
|
|
891
|
+
label: statement.name,
|
|
892
|
+
kind: vscode_languageserver_2.CompletionItemKind.Constant
|
|
828
893
|
});
|
|
829
894
|
}
|
|
830
895
|
}
|
|
@@ -853,7 +918,7 @@ class BrsFile {
|
|
|
853
918
|
const nameLower = name.toLowerCase();
|
|
854
919
|
results.set(nameLower, {
|
|
855
920
|
label: member.name,
|
|
856
|
-
kind:
|
|
921
|
+
kind: vscode_languageserver_2.CompletionItemKind.EnumMember
|
|
857
922
|
});
|
|
858
923
|
}
|
|
859
924
|
}
|
|
@@ -887,7 +952,7 @@ class BrsFile {
|
|
|
887
952
|
if (!result.has(ns.lastPartName)) {
|
|
888
953
|
result.set(ns.lastPartName, {
|
|
889
954
|
label: ns.lastPartName,
|
|
890
|
-
kind:
|
|
955
|
+
kind: vscode_languageserver_2.CompletionItemKind.Module
|
|
891
956
|
});
|
|
892
957
|
}
|
|
893
958
|
}
|
|
@@ -897,19 +962,25 @@ class BrsFile {
|
|
|
897
962
|
if ((0, reflection_1.isClassStatement)(stmt)) {
|
|
898
963
|
result.set(stmt.name.text, {
|
|
899
964
|
label: stmt.name.text,
|
|
900
|
-
kind:
|
|
965
|
+
kind: vscode_languageserver_2.CompletionItemKind.Class
|
|
901
966
|
});
|
|
902
967
|
}
|
|
903
968
|
else if ((0, reflection_1.isFunctionStatement)(stmt) && !newToken) {
|
|
904
969
|
result.set(stmt.name.text, {
|
|
905
970
|
label: stmt.name.text,
|
|
906
|
-
kind:
|
|
971
|
+
kind: vscode_languageserver_2.CompletionItemKind.Function
|
|
907
972
|
});
|
|
908
973
|
}
|
|
909
974
|
else if ((0, reflection_1.isEnumStatement)(stmt) && !newToken) {
|
|
910
975
|
result.set(stmt.name, {
|
|
911
976
|
label: stmt.name,
|
|
912
|
-
kind:
|
|
977
|
+
kind: vscode_languageserver_2.CompletionItemKind.Enum
|
|
978
|
+
});
|
|
979
|
+
}
|
|
980
|
+
else if ((0, reflection_1.isConstStatement)(stmt) && !newToken) {
|
|
981
|
+
result.set(stmt.name, {
|
|
982
|
+
label: stmt.name,
|
|
983
|
+
kind: vscode_languageserver_2.CompletionItemKind.Constant
|
|
913
984
|
});
|
|
914
985
|
}
|
|
915
986
|
}
|
|
@@ -931,7 +1002,7 @@ class BrsFile {
|
|
|
931
1002
|
const namespaceItemStatementHandler = (statement) => {
|
|
932
1003
|
if (!location && statement.name.text.toLowerCase() === endName) {
|
|
933
1004
|
const uri = util_1.util.pathToUri(file.srcPath);
|
|
934
|
-
location =
|
|
1005
|
+
location = util_1.util.createLocation(uri, statement.range);
|
|
935
1006
|
}
|
|
936
1007
|
};
|
|
937
1008
|
file.parser.ast.walk((0, visitors_1.createVisitor)({
|
|
@@ -1135,16 +1206,16 @@ class BrsFile {
|
|
|
1135
1206
|
let symbolKind;
|
|
1136
1207
|
const children = [];
|
|
1137
1208
|
if ((0, reflection_1.isFunctionStatement)(statement)) {
|
|
1138
|
-
symbolKind =
|
|
1209
|
+
symbolKind = vscode_languageserver_2.SymbolKind.Function;
|
|
1139
1210
|
}
|
|
1140
1211
|
else if ((0, reflection_1.isClassMethodStatement)(statement)) {
|
|
1141
|
-
symbolKind =
|
|
1212
|
+
symbolKind = vscode_languageserver_2.SymbolKind.Method;
|
|
1142
1213
|
}
|
|
1143
1214
|
else if ((0, reflection_1.isClassFieldStatement)(statement)) {
|
|
1144
|
-
symbolKind =
|
|
1215
|
+
symbolKind = vscode_languageserver_2.SymbolKind.Field;
|
|
1145
1216
|
}
|
|
1146
1217
|
else if ((0, reflection_1.isNamespaceStatement)(statement)) {
|
|
1147
|
-
symbolKind =
|
|
1218
|
+
symbolKind = vscode_languageserver_2.SymbolKind.Namespace;
|
|
1148
1219
|
for (const childStatement of statement.body.statements) {
|
|
1149
1220
|
const symbol = this.getDocumentSymbol(childStatement);
|
|
1150
1221
|
if (symbol) {
|
|
@@ -1153,7 +1224,7 @@ class BrsFile {
|
|
|
1153
1224
|
}
|
|
1154
1225
|
}
|
|
1155
1226
|
else if ((0, reflection_1.isClassStatement)(statement)) {
|
|
1156
|
-
symbolKind =
|
|
1227
|
+
symbolKind = vscode_languageserver_2.SymbolKind.Class;
|
|
1157
1228
|
for (const childStatement of statement.body) {
|
|
1158
1229
|
const symbol = this.getDocumentSymbol(childStatement);
|
|
1159
1230
|
if (symbol) {
|
|
@@ -1165,7 +1236,7 @@ class BrsFile {
|
|
|
1165
1236
|
return;
|
|
1166
1237
|
}
|
|
1167
1238
|
const name = (0, reflection_1.isClassFieldStatement)(statement) ? statement.name.text : statement.getName(Parser_1.ParseMode.BrighterScript);
|
|
1168
|
-
return
|
|
1239
|
+
return vscode_languageserver_2.DocumentSymbol.create(name, '', symbolKind, statement.range, statement.range, children);
|
|
1169
1240
|
}
|
|
1170
1241
|
/**
|
|
1171
1242
|
* Builds a single SymbolInformation object for use by LanguageServer's onWorkspaceSymbol functionality
|
|
@@ -1174,13 +1245,13 @@ class BrsFile {
|
|
|
1174
1245
|
let symbolKind;
|
|
1175
1246
|
const symbols = [];
|
|
1176
1247
|
if ((0, reflection_1.isFunctionStatement)(statement)) {
|
|
1177
|
-
symbolKind =
|
|
1248
|
+
symbolKind = vscode_languageserver_2.SymbolKind.Function;
|
|
1178
1249
|
}
|
|
1179
1250
|
else if ((0, reflection_1.isClassMethodStatement)(statement)) {
|
|
1180
|
-
symbolKind =
|
|
1251
|
+
symbolKind = vscode_languageserver_2.SymbolKind.Method;
|
|
1181
1252
|
}
|
|
1182
1253
|
else if ((0, reflection_1.isNamespaceStatement)(statement)) {
|
|
1183
|
-
symbolKind =
|
|
1254
|
+
symbolKind = vscode_languageserver_2.SymbolKind.Namespace;
|
|
1184
1255
|
for (const childStatement of statement.body.statements) {
|
|
1185
1256
|
for (const symbol of this.generateWorkspaceSymbols(childStatement, statement)) {
|
|
1186
1257
|
symbols.push(symbol);
|
|
@@ -1188,7 +1259,7 @@ class BrsFile {
|
|
|
1188
1259
|
}
|
|
1189
1260
|
}
|
|
1190
1261
|
else if ((0, reflection_1.isClassStatement)(statement)) {
|
|
1191
|
-
symbolKind =
|
|
1262
|
+
symbolKind = vscode_languageserver_2.SymbolKind.Class;
|
|
1192
1263
|
for (const childStatement of statement.body) {
|
|
1193
1264
|
for (const symbol of this.generateWorkspaceSymbols(childStatement, statement)) {
|
|
1194
1265
|
symbols.push(symbol);
|
|
@@ -1200,7 +1271,7 @@ class BrsFile {
|
|
|
1200
1271
|
}
|
|
1201
1272
|
const name = statement.getName(Parser_1.ParseMode.BrighterScript);
|
|
1202
1273
|
const uri = util_1.util.pathToUri(this.srcPath);
|
|
1203
|
-
const symbol =
|
|
1274
|
+
const symbol = vscode_languageserver_2.SymbolInformation.create(name, symbolKind, statement.range, uri, containerStatement === null || containerStatement === void 0 ? void 0 : containerStatement.getName(Parser_1.ParseMode.BrighterScript));
|
|
1204
1275
|
symbols.push(symbol);
|
|
1205
1276
|
return symbols;
|
|
1206
1277
|
}
|
|
@@ -1228,7 +1299,7 @@ class BrsFile {
|
|
|
1228
1299
|
//to only get functions defined in interface methods
|
|
1229
1300
|
const callable = scope.getAllCallables().find((c) => c.callable.name.toLowerCase() === textToSearchFor); // eslint-disable-line @typescript-eslint/no-loop-func
|
|
1230
1301
|
if (callable) {
|
|
1231
|
-
results.push(
|
|
1302
|
+
results.push(util_1.util.createLocation(util_1.util.pathToUri(callable.callable.file.srcPath), callable.callable.functionStatement.range));
|
|
1232
1303
|
}
|
|
1233
1304
|
}
|
|
1234
1305
|
return results;
|
|
@@ -1240,7 +1311,7 @@ class BrsFile {
|
|
|
1240
1311
|
const nameParts = cs.parentClassName.getNameParts();
|
|
1241
1312
|
let extendedClass = this.getClassFileLink(nameParts[nameParts.length - 1], nameParts.slice(0, -1).join('.'));
|
|
1242
1313
|
if (extendedClass) {
|
|
1243
|
-
results.push(
|
|
1314
|
+
results.push(util_1.util.createLocation(util_1.util.pathToUri(extendedClass.file.srcPath), extendedClass.item.range));
|
|
1244
1315
|
}
|
|
1245
1316
|
}
|
|
1246
1317
|
return results;
|
|
@@ -1262,14 +1333,14 @@ class BrsFile {
|
|
|
1262
1333
|
//we found a variable declaration with this token text!
|
|
1263
1334
|
if (varDeclaration.name.toLowerCase() === textToSearchFor) {
|
|
1264
1335
|
const uri = util_1.util.pathToUri(this.srcPath);
|
|
1265
|
-
results.push(
|
|
1336
|
+
results.push(util_1.util.createLocation(uri, varDeclaration.nameRange));
|
|
1266
1337
|
}
|
|
1267
1338
|
}
|
|
1268
1339
|
if (this.tokenFollows(token, TokenKind_1.TokenKind.Goto)) {
|
|
1269
1340
|
for (const label of functionScope.labelStatements) {
|
|
1270
1341
|
if (label.name.toLocaleLowerCase() === textToSearchFor) {
|
|
1271
1342
|
const uri = util_1.util.pathToUri(this.srcPath);
|
|
1272
|
-
results.push(
|
|
1343
|
+
results.push(util_1.util.createLocation(uri, label.nameRange));
|
|
1273
1344
|
}
|
|
1274
1345
|
}
|
|
1275
1346
|
}
|
|
@@ -1292,7 +1363,7 @@ class BrsFile {
|
|
|
1292
1363
|
const statementHandler = (statement) => {
|
|
1293
1364
|
if (statement.getName(this.parseMode).toLowerCase() === textToSearchFor) {
|
|
1294
1365
|
const uri = util_1.util.pathToUri(file.srcPath);
|
|
1295
|
-
results.push(
|
|
1366
|
+
results.push(util_1.util.createLocation(uri, statement.range));
|
|
1296
1367
|
}
|
|
1297
1368
|
};
|
|
1298
1369
|
file.parser.ast.walk((0, visitors_1.createVisitor)({
|
|
@@ -1309,12 +1380,12 @@ class BrsFile {
|
|
|
1309
1380
|
//get class fields and members
|
|
1310
1381
|
const statementHandler = (statement) => {
|
|
1311
1382
|
if (statement.getName(file.parseMode).toLowerCase() === textToSearchFor) {
|
|
1312
|
-
results.push(
|
|
1383
|
+
results.push(util_1.util.createLocation(util_1.util.pathToUri(file.srcPath), statement.range));
|
|
1313
1384
|
}
|
|
1314
1385
|
};
|
|
1315
1386
|
const fieldStatementHandler = (statement) => {
|
|
1316
1387
|
if (statement.name.text.toLowerCase() === textToSearchFor) {
|
|
1317
|
-
results.push(
|
|
1388
|
+
results.push(util_1.util.createLocation(util_1.util.pathToUri(file.srcPath), statement.range));
|
|
1318
1389
|
}
|
|
1319
1390
|
};
|
|
1320
1391
|
file.parser.ast.walk((0, visitors_1.createVisitor)({
|
|
@@ -1325,98 +1396,6 @@ class BrsFile {
|
|
|
1325
1396
|
});
|
|
1326
1397
|
return results;
|
|
1327
1398
|
}
|
|
1328
|
-
getHover(position) {
|
|
1329
|
-
const fence = (code) => util_1.util.mdFence(code, 'brightscript');
|
|
1330
|
-
//get the token at the position
|
|
1331
|
-
let token = this.getTokenAt(position);
|
|
1332
|
-
let hoverTokenTypes = [
|
|
1333
|
-
TokenKind_1.TokenKind.Identifier,
|
|
1334
|
-
TokenKind_1.TokenKind.Function,
|
|
1335
|
-
TokenKind_1.TokenKind.EndFunction,
|
|
1336
|
-
TokenKind_1.TokenKind.Sub,
|
|
1337
|
-
TokenKind_1.TokenKind.EndSub
|
|
1338
|
-
];
|
|
1339
|
-
//throw out invalid tokens and the wrong kind of tokens
|
|
1340
|
-
if (!token || !hoverTokenTypes.includes(token.kind)) {
|
|
1341
|
-
return null;
|
|
1342
|
-
}
|
|
1343
|
-
let lowerTokenText = token.text.toLowerCase();
|
|
1344
|
-
//look through local variables first
|
|
1345
|
-
{
|
|
1346
|
-
//get the function scope for this position (if exists)
|
|
1347
|
-
let functionScope = this.getFunctionScopeAtPosition(position);
|
|
1348
|
-
if (functionScope) {
|
|
1349
|
-
//find any variable with this name
|
|
1350
|
-
for (const varDeclaration of functionScope.variableDeclarations) {
|
|
1351
|
-
//we found a variable declaration with this token text!
|
|
1352
|
-
if (varDeclaration.name.toLowerCase() === lowerTokenText) {
|
|
1353
|
-
let typeText;
|
|
1354
|
-
if ((0, reflection_1.isFunctionType)(varDeclaration.type)) {
|
|
1355
|
-
typeText = varDeclaration.type.toString();
|
|
1356
|
-
}
|
|
1357
|
-
else {
|
|
1358
|
-
typeText = `${varDeclaration.name} as ${varDeclaration.type.toString()}`;
|
|
1359
|
-
}
|
|
1360
|
-
return {
|
|
1361
|
-
range: token.range,
|
|
1362
|
-
//append the variable name to the front for scope
|
|
1363
|
-
contents: fence(typeText)
|
|
1364
|
-
};
|
|
1365
|
-
}
|
|
1366
|
-
}
|
|
1367
|
-
for (const labelStatement of functionScope.labelStatements) {
|
|
1368
|
-
if (labelStatement.name.toLocaleLowerCase() === lowerTokenText) {
|
|
1369
|
-
return {
|
|
1370
|
-
range: token.range,
|
|
1371
|
-
contents: fence(`${labelStatement.name}: label`)
|
|
1372
|
-
};
|
|
1373
|
-
}
|
|
1374
|
-
}
|
|
1375
|
-
}
|
|
1376
|
-
}
|
|
1377
|
-
//look through all callables in relevant scopes
|
|
1378
|
-
{
|
|
1379
|
-
let scopes = this.program.getScopesForFile(this);
|
|
1380
|
-
for (let scope of scopes) {
|
|
1381
|
-
let callable = scope.getCallableByName(lowerTokenText);
|
|
1382
|
-
if (callable) {
|
|
1383
|
-
return {
|
|
1384
|
-
range: token.range,
|
|
1385
|
-
contents: this.getCallableDocumentation(callable)
|
|
1386
|
-
};
|
|
1387
|
-
}
|
|
1388
|
-
}
|
|
1389
|
-
}
|
|
1390
|
-
}
|
|
1391
|
-
/**
|
|
1392
|
-
* Build a hover documentation for a callable.
|
|
1393
|
-
*/
|
|
1394
|
-
getCallableDocumentation(callable) {
|
|
1395
|
-
var _a;
|
|
1396
|
-
const comments = [];
|
|
1397
|
-
const tokens = callable.file.parser.tokens;
|
|
1398
|
-
const idx = tokens.indexOf((_a = callable.functionStatement) === null || _a === void 0 ? void 0 : _a.func.functionType);
|
|
1399
|
-
for (let i = idx - 1; i >= 0; i--) {
|
|
1400
|
-
const token = tokens[i];
|
|
1401
|
-
//skip whitespace and newline chars
|
|
1402
|
-
if (token.kind === TokenKind_1.TokenKind.Comment) {
|
|
1403
|
-
comments.push(token);
|
|
1404
|
-
}
|
|
1405
|
-
else if (token.kind === TokenKind_1.TokenKind.Newline || token.kind === TokenKind_1.TokenKind.Whitespace) {
|
|
1406
|
-
//skip these tokens
|
|
1407
|
-
continue;
|
|
1408
|
-
//any other token means there are no more comments
|
|
1409
|
-
}
|
|
1410
|
-
else {
|
|
1411
|
-
break;
|
|
1412
|
-
}
|
|
1413
|
-
}
|
|
1414
|
-
let result = util_1.util.mdFence(callable.type.toString(), 'brightscript');
|
|
1415
|
-
if (comments.length > 0) {
|
|
1416
|
-
result += '\n***\n' + comments.reverse().map(x => x.text.replace(/^('|rem)/i, '')).join('\n');
|
|
1417
|
-
}
|
|
1418
|
-
return result;
|
|
1419
|
-
}
|
|
1420
1399
|
getSignatureHelpForNamespaceMethods(callableName, dottedGetText, scope) {
|
|
1421
1400
|
var _a;
|
|
1422
1401
|
if (!dottedGetText) {
|
|
@@ -1487,11 +1466,11 @@ class BrsFile {
|
|
|
1487
1466
|
let key = statement.name.text + documentation;
|
|
1488
1467
|
const params = [];
|
|
1489
1468
|
for (const param of func.parameters) {
|
|
1490
|
-
params.push(
|
|
1469
|
+
params.push(vscode_languageserver_2.ParameterInformation.create(param.name.text));
|
|
1491
1470
|
key += param.name.text;
|
|
1492
1471
|
}
|
|
1493
1472
|
const label = util_1.util.getTextForRange(lines, util_1.util.createRangeFromPositions(func.functionType.range.start, func.body.range.start)).trim();
|
|
1494
|
-
const signature =
|
|
1473
|
+
const signature = vscode_languageserver_2.SignatureInformation.create(label, documentation, ...params);
|
|
1495
1474
|
const index = 1;
|
|
1496
1475
|
return { key: key, signature: signature, index: index };
|
|
1497
1476
|
}
|
|
@@ -1547,7 +1526,7 @@ class BrsFile {
|
|
|
1547
1526
|
file.ast.walk((0, visitors_1.createVisitor)({
|
|
1548
1527
|
VariableExpression: (e) => {
|
|
1549
1528
|
if (e.name.text.toLowerCase() === searchFor) {
|
|
1550
|
-
locations.push(
|
|
1529
|
+
locations.push(util_1.util.createLocation(util_1.util.pathToUri(file.srcPath), e.range));
|
|
1551
1530
|
}
|
|
1552
1531
|
}
|
|
1553
1532
|
}), {
|
|
@@ -1622,7 +1601,7 @@ exports.KeywordCompletions = Object.keys(TokenKind_1.Keywords)
|
|
|
1622
1601
|
.map(x => {
|
|
1623
1602
|
return {
|
|
1624
1603
|
label: x,
|
|
1625
|
-
kind:
|
|
1604
|
+
kind: vscode_languageserver_2.CompletionItemKind.Keyword
|
|
1626
1605
|
};
|
|
1627
1606
|
});
|
|
1628
1607
|
//# sourceMappingURL=BrsFile.js.map
|