brighterscript 1.0.0-alpha.23 → 1.0.0-alpha.24

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.
Files changed (126) hide show
  1. package/CHANGELOG.md +108 -1
  2. package/dist/DiagnosticMessages.d.ts +19 -3
  3. package/dist/DiagnosticMessages.js +23 -7
  4. package/dist/DiagnosticMessages.js.map +1 -1
  5. package/dist/LanguageServer.js +74 -20
  6. package/dist/LanguageServer.js.map +1 -1
  7. package/dist/Program.d.ts +7 -5
  8. package/dist/Program.js +84 -49
  9. package/dist/Program.js.map +1 -1
  10. package/dist/ProgramBuilder.js +2 -1
  11. package/dist/ProgramBuilder.js.map +1 -1
  12. package/dist/Scope.d.ts +22 -15
  13. package/dist/Scope.js +108 -122
  14. package/dist/Scope.js.map +1 -1
  15. package/dist/SymbolTable.d.ts +17 -6
  16. package/dist/SymbolTable.js +38 -9
  17. package/dist/SymbolTable.js.map +1 -1
  18. package/dist/XmlScope.js +3 -2
  19. package/dist/XmlScope.js.map +1 -1
  20. package/dist/astUtils/reflection.d.ts +5 -1
  21. package/dist/astUtils/reflection.js +15 -2
  22. package/dist/astUtils/reflection.js.map +1 -1
  23. package/dist/astUtils/visitors.d.ts +2 -1
  24. package/dist/astUtils/visitors.js.map +1 -1
  25. package/dist/bscPlugin/BscPlugin.d.ts +3 -1
  26. package/dist/bscPlugin/BscPlugin.js +8 -0
  27. package/dist/bscPlugin/BscPlugin.js.map +1 -1
  28. package/dist/bscPlugin/codeActions/CodeActionsProcessor.d.ts +1 -1
  29. package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +11 -5
  30. package/dist/bscPlugin/codeActions/CodeActionsProcessor.js.map +1 -1
  31. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js +75 -1
  32. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +1 -1
  33. package/dist/bscPlugin/completions/CompletionsProcessor.d.ts +6 -0
  34. package/dist/bscPlugin/completions/CompletionsProcessor.js +53 -0
  35. package/dist/bscPlugin/completions/CompletionsProcessor.js.map +1 -0
  36. package/dist/bscPlugin/hover/HoverProcessor.d.ts +17 -0
  37. package/dist/bscPlugin/hover/HoverProcessor.js +190 -0
  38. package/dist/bscPlugin/hover/HoverProcessor.js.map +1 -0
  39. package/dist/bscPlugin/hover/HoverProcessor.spec.d.ts +1 -0
  40. package/dist/bscPlugin/hover/HoverProcessor.spec.js +195 -0
  41. package/dist/bscPlugin/hover/HoverProcessor.spec.js.map +1 -0
  42. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.d.ts +1 -0
  43. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js +19 -8
  44. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js.map +1 -1
  45. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js +84 -0
  46. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js.map +1 -1
  47. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.d.ts +7 -1
  48. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js +81 -22
  49. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js.map +1 -1
  50. package/dist/bscPlugin/validation/BrsFileValidator.d.ts +14 -1
  51. package/dist/bscPlugin/validation/BrsFileValidator.js +104 -27
  52. package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -1
  53. package/dist/bscPlugin/validation/BrsFileValidator.spec.d.ts +1 -0
  54. package/dist/bscPlugin/validation/BrsFileValidator.spec.js +48 -0
  55. package/dist/bscPlugin/validation/BrsFileValidator.spec.js.map +1 -0
  56. package/dist/bscPlugin/validation/ScopeValidator.d.ts +24 -3
  57. package/dist/bscPlugin/validation/ScopeValidator.js +249 -48
  58. package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -1
  59. package/dist/cli.js +18 -10
  60. package/dist/cli.js.map +1 -1
  61. package/dist/files/BrsFile.Class.spec.js +51 -38
  62. package/dist/files/BrsFile.Class.spec.js.map +1 -1
  63. package/dist/files/BrsFile.d.ts +21 -10
  64. package/dist/files/BrsFile.js +158 -179
  65. package/dist/files/BrsFile.js.map +1 -1
  66. package/dist/files/BrsFile.spec.js +222 -126
  67. package/dist/files/BrsFile.spec.js.map +1 -1
  68. package/dist/files/XmlFile.d.ts +2 -2
  69. package/dist/files/XmlFile.js +1 -0
  70. package/dist/files/XmlFile.js.map +1 -1
  71. package/dist/files/tests/imports.spec.js +1 -1
  72. package/dist/files/tests/imports.spec.js.map +1 -1
  73. package/dist/files/tests/optionalChaning.spec.js +20 -16
  74. package/dist/files/tests/optionalChaning.spec.js.map +1 -1
  75. package/dist/globalCallables.js +3 -0
  76. package/dist/globalCallables.js.map +1 -1
  77. package/dist/index.d.ts +1 -1
  78. package/dist/index.js +3 -1
  79. package/dist/index.js.map +1 -1
  80. package/dist/interfaces.d.ts +65 -3
  81. package/dist/lexer/Lexer.spec.js +7 -0
  82. package/dist/lexer/Lexer.spec.js.map +1 -1
  83. package/dist/lexer/TokenKind.d.ts +1 -0
  84. package/dist/lexer/TokenKind.js +8 -3
  85. package/dist/lexer/TokenKind.js.map +1 -1
  86. package/dist/parser/Expression.d.ts +12 -3
  87. package/dist/parser/Expression.js +16 -4
  88. package/dist/parser/Expression.js.map +1 -1
  89. package/dist/parser/Parser.Class.spec.js +1 -1
  90. package/dist/parser/Parser.d.ts +10 -3
  91. package/dist/parser/Parser.js +107 -47
  92. package/dist/parser/Parser.js.map +1 -1
  93. package/dist/parser/Parser.spec.js +181 -108
  94. package/dist/parser/Parser.spec.js.map +1 -1
  95. package/dist/parser/Statement.d.ts +41 -7
  96. package/dist/parser/Statement.js +84 -11
  97. package/dist/parser/Statement.js.map +1 -1
  98. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +73 -31
  99. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
  100. package/dist/parser/tests/expression/TemplateStringExpression.spec.js +148 -47
  101. package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +1 -1
  102. package/dist/parser/tests/expression/TernaryExpression.spec.js +219 -37
  103. package/dist/parser/tests/expression/TernaryExpression.spec.js.map +1 -1
  104. package/dist/parser/tests/statement/ConstStatement.spec.d.ts +1 -0
  105. package/dist/parser/tests/statement/ConstStatement.spec.js +213 -0
  106. package/dist/parser/tests/statement/ConstStatement.spec.js.map +1 -0
  107. package/dist/parser/tests/statement/Enum.spec.js +17 -2
  108. package/dist/parser/tests/statement/Enum.spec.js.map +1 -1
  109. package/dist/parser/tests/statement/PrintStatement.spec.js +72 -57
  110. package/dist/parser/tests/statement/PrintStatement.spec.js.map +1 -1
  111. package/dist/preprocessor/Manifest.js +2 -2
  112. package/dist/preprocessor/Manifest.js.map +1 -1
  113. package/dist/preprocessor/Preprocessor.js +10 -6
  114. package/dist/preprocessor/Preprocessor.js.map +1 -1
  115. package/dist/roku-types/data.json +1002 -788
  116. package/dist/roku-types/index.d.ts +64 -239
  117. package/dist/types/DynamicType.d.ts +1 -0
  118. package/dist/types/DynamicType.js +1 -0
  119. package/dist/types/DynamicType.js.map +1 -1
  120. package/dist/util.d.ts +55 -14
  121. package/dist/util.js +131 -25
  122. package/dist/util.js.map +1 -1
  123. package/dist/validators/ClassValidator.d.ts +0 -1
  124. package/dist/validators/ClassValidator.js +15 -26
  125. package/dist/validators/ClassValidator.js.map +1 -1
  126. package/package.json +5 -2
@@ -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");
@@ -17,11 +18,12 @@ const Preprocessor_1 = require("../preprocessor/Preprocessor");
17
18
  const Logger_1 = require("../Logger");
18
19
  const serialize_error_1 = require("serialize-error");
19
20
  const reflection_1 = require("../astUtils/reflection");
21
+ const BscType_1 = require("../types/BscType");
20
22
  const visitors_1 = require("../astUtils/visitors");
21
23
  const CommentFlagProcessor_1 = require("../CommentFlagProcessor");
22
- const BscType_1 = require("../types/BscType");
23
- const UninitializedType_1 = require("../types/UninitializedType");
24
+ const vscode_uri_1 = require("vscode-uri");
24
25
  const InvalidType_1 = require("../types/InvalidType");
26
+ const UninitializedType_1 = require("../types/UninitializedType");
25
27
  /**
26
28
  * Holds all details about this file within the scope of the whole program
27
29
  */
@@ -86,16 +88,26 @@ class BrsFile {
86
88
  getDiagnostics() {
87
89
  return [...this.diagnostics];
88
90
  }
91
+ addDiagnostic(diagnostic) {
92
+ if (!diagnostic.file) {
93
+ diagnostic.file = this;
94
+ }
95
+ this.diagnostics.push(diagnostic);
96
+ }
89
97
  addDiagnostics(diagnostics) {
90
98
  this.diagnostics.push(...diagnostics);
91
99
  }
100
+ get cache() {
101
+ var _a;
102
+ // eslint-disable-next-line @typescript-eslint/dot-notation
103
+ return (_a = this._parser) === null || _a === void 0 ? void 0 : _a.references['cache'];
104
+ }
92
105
  /**
93
106
  * files referenced by import statements
94
107
  */
95
108
  get ownScriptImports() {
96
109
  var _a, _b;
97
- // eslint-disable-next-line @typescript-eslint/dot-notation
98
- const result = (_b = (_a = this._parser) === null || _a === void 0 ? void 0 : _a.references['cache'].getOrAdd('BrsFile_ownScriptImports', () => {
110
+ const result = (_b = (_a = this.cache) === null || _a === void 0 ? void 0 : _a.getOrAdd('BrsFile_ownScriptImports', () => {
99
111
  var _a, _b, _c, _d;
100
112
  const result = [];
101
113
  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 : []) {
@@ -119,6 +131,40 @@ class BrsFile {
119
131
  get ast() {
120
132
  return this.parser.ast;
121
133
  }
134
+ /**
135
+ * Get the token at the specified position
136
+ * @param position
137
+ */
138
+ getTokenAt(position) {
139
+ for (let token of this.parser.tokens) {
140
+ if (util_1.util.rangeContains(token.range, position)) {
141
+ return token;
142
+ }
143
+ }
144
+ }
145
+ /**
146
+ * Walk the AST and find the expression that this token is most specifically contained within
147
+ */
148
+ getClosestExpression(position) {
149
+ const handle = new vscode_languageserver_1.CancellationTokenSource();
150
+ let containingNode;
151
+ this.ast.walk((node) => {
152
+ const latestContainer = containingNode;
153
+ //bsc walks depth-first
154
+ if (util_1.util.rangeContains(node.range, position)) {
155
+ containingNode = node;
156
+ }
157
+ //we had a match before, and don't now. this means we've finished walking down the whole way, and found our match
158
+ if (latestContainer && !containingNode) {
159
+ containingNode = latestContainer;
160
+ handle.cancel();
161
+ }
162
+ }, {
163
+ walkMode: visitors_1.WalkMode.visitAllRecursive,
164
+ cancel: handle.token
165
+ });
166
+ return containingNode;
167
+ }
122
168
  get parser() {
123
169
  if (!this._parser) {
124
170
  //remove the typedef file (if it exists)
@@ -225,6 +271,7 @@ class BrsFile {
225
271
  }
226
272
  }
227
273
  validate() {
274
+ util_1.util.validateTooDeepFile(this);
228
275
  //only validate the file if it was actually parsed (skip files containing typedefs)
229
276
  if (!this.hasTypedef) {
230
277
  this.validateImportStatements();
@@ -289,7 +336,7 @@ class BrsFile {
289
336
  for (const key of Object.keys(propertyHints)) {
290
337
  results.push({
291
338
  label: propertyHints[key],
292
- kind: vscode_languageserver_1.CompletionItemKind.Text
339
+ kind: vscode_languageserver_2.CompletionItemKind.Text
293
340
  });
294
341
  }
295
342
  return results;
@@ -405,17 +452,22 @@ class BrsFile {
405
452
  }
406
453
  }
407
454
  }
455
+ getFunctionExpressionAtPosition(position) {
456
+ return this.cache.getOrAdd(`functionExpressionAtPosition-${position.line}:${position.character}`, () => {
457
+ return this._getFunctionExpressionAtPosition(position, this.parser.references.functionExpressions);
458
+ });
459
+ }
408
460
  /**
409
461
  * Find the function expression at the given position.
410
462
  */
411
- getFunctionExpressionAtPosition(position, functionExpressions) {
463
+ _getFunctionExpressionAtPosition(position, functionExpressions) {
412
464
  if (!functionExpressions) {
413
465
  functionExpressions = this.parser.references.functionExpressions;
414
466
  }
415
467
  for (let functionExpression of functionExpressions) {
416
468
  if (util_1.util.rangeContains(functionExpression.range, position)) {
417
469
  //see if any of that scope's children match the position also, and give them priority
418
- let childFunc = this.getFunctionExpressionAtPosition(position, functionExpression.childFunctionExpressions);
470
+ let childFunc = this._getFunctionExpressionAtPosition(position, functionExpression.childFunctionExpressions);
419
471
  if (childFunc) {
420
472
  return childFunc;
421
473
  }
@@ -432,11 +484,13 @@ class BrsFile {
432
484
  */
433
485
  getNamespaceStatementForPosition(position) {
434
486
  if (position) {
435
- for (const statement of this.parser.references.namespaceStatements) {
436
- if (util_1.util.rangeContains(statement.range, position)) {
437
- return statement;
487
+ return this.cache.getOrAdd(`namespaceStatementForPosition-${position.line}:${position.character}`, () => {
488
+ for (const statement of this.parser.references.namespaceStatements) {
489
+ if (util_1.util.rangeContains(statement.range, position)) {
490
+ return statement;
491
+ }
438
492
  }
439
- }
493
+ });
440
494
  }
441
495
  }
442
496
  /**
@@ -467,12 +521,12 @@ class BrsFile {
467
521
  const pkgPath = `${fileProtocol}:/${file.pkgPath.replace('pkg:/', '')}`;
468
522
  result.push({
469
523
  label: pkgPath,
470
- textEdit: vscode_languageserver_1.TextEdit.replace(util_1.util.createRange(currentToken.range.start.line,
524
+ textEdit: vscode_languageserver_2.TextEdit.replace(util_1.util.createRange(currentToken.range.start.line,
471
525
  //+1 to step past the opening quote
472
526
  currentToken.range.start.character + (openingQuote ? 1 : 0), currentToken.range.end.line,
473
527
  //-1 to exclude the closing quotemark (or the end character if there is no closing quotemark)
474
528
  currentToken.range.end.character + (currentToken.text.endsWith('"') ? -1 : 0)), pkgPath),
475
- kind: vscode_languageserver_1.CompletionItemKind.File
529
+ kind: vscode_languageserver_2.CompletionItemKind.File
476
530
  });
477
531
  }
478
532
  return result;
@@ -542,20 +596,23 @@ class BrsFile {
542
596
  }
543
597
  }
544
598
  else {
599
+ result.push(
545
600
  //include namespaces
546
- result.push(...namespaceCompletions);
601
+ ...namespaceCompletions,
547
602
  //include class names
548
- result.push(...classNameCompletions);
603
+ ...classNameCompletions,
549
604
  //include interfaces
550
- result.push(...interfaceNameCompletions);
605
+ ...interfaceNameCompletions,
551
606
  //include enums
552
- result.push(...this.getNonNamespacedEnumStatementCompletions(currentToken, this.parseMode, scope));
607
+ ...this.getNonNamespacedEnumStatementCompletions(currentToken, this.parseMode, scope),
608
+ //include constants
609
+ ...this.getNonNamespacedConstStatementCompletions(currentToken, this.parseMode, scope),
553
610
  //include the global callables
554
- result.push(...scope.getCallablesAsCompletions(this.parseMode));
611
+ ...scope.getCallablesAsCompletions(this.parseMode));
555
612
  //add `m` because that's always valid within a function
556
613
  result.push({
557
614
  label: 'm',
558
- kind: vscode_languageserver_1.CompletionItemKind.Variable
615
+ kind: vscode_languageserver_2.CompletionItemKind.Variable
559
616
  });
560
617
  names.m = true;
561
618
  result.push(...exports.KeywordCompletions);
@@ -573,7 +630,7 @@ class BrsFile {
573
630
  //TODO does this work?
574
631
  label: symbol.name,
575
632
  //TODO TYPES find type for local vars - SEE above
576
- kind: vscode_languageserver_1.CompletionItemKind.Variable
633
+ kind: vscode_languageserver_2.CompletionItemKind.Variable
577
634
  // kind: isFunctionType(foundType) ? CompletionItemKind.Function : CompletionItemKind.Variable
578
635
  });
579
636
  }
@@ -589,7 +646,7 @@ class BrsFile {
589
646
  names[firstPart.toLowerCase()] = true;
590
647
  result.push({
591
648
  label: firstPart,
592
- kind: vscode_languageserver_1.CompletionItemKind.Module
649
+ kind: vscode_languageserver_2.CompletionItemKind.Module
593
650
  });
594
651
  }
595
652
  }
@@ -600,14 +657,14 @@ class BrsFile {
600
657
  return symbolTable.getAllSymbols().map(bscType => {
601
658
  return {
602
659
  label: bscType.name,
603
- kind: (0, reflection_1.isTypedFunctionType)(bscType.type) ? vscode_languageserver_1.CompletionItemKind.Method : vscode_languageserver_1.CompletionItemKind.Field
660
+ kind: (0, reflection_1.isTypedFunctionType)(bscType.type) ? vscode_languageserver_2.CompletionItemKind.Method : vscode_languageserver_2.CompletionItemKind.Field
604
661
  };
605
662
  });
606
663
  }
607
664
  getLabelCompletion(func) {
608
665
  return func.labelStatements.map(label => ({
609
666
  label: label.tokens.identifier.text,
610
- kind: vscode_languageserver_1.CompletionItemKind.Reference
667
+ kind: vscode_languageserver_2.CompletionItemKind.Reference
611
668
  }));
612
669
  }
613
670
  getClassMemberCompletions(position, currentToken, functionExpression, scope) {
@@ -621,7 +678,7 @@ class BrsFile {
621
678
  if (!results.has(member.name.text.toLowerCase())) {
622
679
  results.set(member.name.text.toLowerCase(), {
623
680
  label: member.name.text,
624
- kind: (0, reflection_1.isFieldStatement)(member) ? vscode_languageserver_1.CompletionItemKind.Field : vscode_languageserver_1.CompletionItemKind.Method
681
+ kind: (0, reflection_1.isFieldStatement)(member) ? vscode_languageserver_2.CompletionItemKind.Field : vscode_languageserver_2.CompletionItemKind.Method
625
682
  });
626
683
  }
627
684
  }
@@ -780,6 +837,7 @@ class BrsFile {
780
837
  let symbolType;
781
838
  let tokenText = [];
782
839
  let justReturnDynamic = false;
840
+ let fullNamespaceName = nameSpacedTokenChain.namespaceContainer ? nameSpacedTokenChain.namespaceContainer.fullName + '.' : '';
783
841
  const typeContext = { file: this, scope: scope, position: (_c = tokenChain[0]) === null || _c === void 0 ? void 0 : _c.token.range.start };
784
842
  for (const tokenChainMember of tokenChain) {
785
843
  const token = tokenChainMember === null || tokenChainMember === void 0 ? void 0 : tokenChainMember.token;
@@ -891,7 +949,7 @@ class BrsFile {
891
949
  expandedTokenText = currentToken.text;
892
950
  }
893
951
  }
894
- const symbolData = { type: backUpReturnType, expandedTokenText: expandedTokenText };
952
+ const symbolData = { type: backUpReturnType, expandedTokenText: expandedTokenText, fullName: fullNamespaceName + expandedTokenText };
895
953
  scope.symbolCache.set(currentToken, symbolData);
896
954
  return symbolData;
897
955
  }
@@ -912,7 +970,7 @@ class BrsFile {
912
970
  if (!results.has(cs.name.text)) {
913
971
  results.set(cs.name.text, {
914
972
  label: cs.name.text,
915
- kind: vscode_languageserver_1.CompletionItemKind.Class
973
+ kind: vscode_languageserver_2.CompletionItemKind.Class
916
974
  });
917
975
  }
918
976
  }
@@ -933,7 +991,28 @@ class BrsFile {
933
991
  if (fullName.startsWith(containingNamespaceName) || !fullName.includes('.')) {
934
992
  results.set(fullName, {
935
993
  label: enumStatement.name,
936
- kind: vscode_languageserver_1.CompletionItemKind.Enum
994
+ kind: vscode_languageserver_2.CompletionItemKind.Enum
995
+ });
996
+ }
997
+ }
998
+ return [...results.values()];
999
+ }
1000
+ getNonNamespacedConstStatementCompletions(currentToken, parseMode, scope) {
1001
+ var _a, _b;
1002
+ if (parseMode !== Parser_1.ParseMode.BrighterScript) {
1003
+ return [];
1004
+ }
1005
+ 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) + '.';
1006
+ const results = new Map();
1007
+ const map = scope.getConstMap();
1008
+ for (const key of [...map.keys()]) {
1009
+ const statement = map.get(key).item;
1010
+ const fullName = statement.fullName;
1011
+ //if the item is contained within our own namespace, or if it's non-namespaced
1012
+ if (fullName.startsWith(containingNamespaceName) || !fullName.includes('.')) {
1013
+ results.set(fullName, {
1014
+ label: statement.name,
1015
+ kind: vscode_languageserver_2.CompletionItemKind.Constant
937
1016
  });
938
1017
  }
939
1018
  }
@@ -962,7 +1041,7 @@ class BrsFile {
962
1041
  const nameLower = name.toLowerCase();
963
1042
  results.set(nameLower, {
964
1043
  label: member.name,
965
- kind: vscode_languageserver_1.CompletionItemKind.EnumMember
1044
+ kind: vscode_languageserver_2.CompletionItemKind.EnumMember
966
1045
  });
967
1046
  }
968
1047
  }
@@ -984,7 +1063,7 @@ class BrsFile {
984
1063
  if (!results.has(cs.name.text)) {
985
1064
  results.set(cs.name.text, {
986
1065
  label: cs.name.text,
987
- kind: vscode_languageserver_1.CompletionItemKind.Interface
1066
+ kind: vscode_languageserver_2.CompletionItemKind.Interface
988
1067
  });
989
1068
  }
990
1069
  }
@@ -1018,7 +1097,7 @@ class BrsFile {
1018
1097
  if (!result.has(ns.lastPartName)) {
1019
1098
  result.set(ns.lastPartName, {
1020
1099
  label: ns.lastPartName,
1021
- kind: vscode_languageserver_1.CompletionItemKind.Module
1100
+ kind: vscode_languageserver_2.CompletionItemKind.Module
1022
1101
  });
1023
1102
  }
1024
1103
  }
@@ -1028,19 +1107,25 @@ class BrsFile {
1028
1107
  if ((0, reflection_1.isClassStatement)(stmt)) {
1029
1108
  result.set(stmt.name.text, {
1030
1109
  label: stmt.name.text,
1031
- kind: vscode_languageserver_1.CompletionItemKind.Class
1110
+ kind: vscode_languageserver_2.CompletionItemKind.Class
1032
1111
  });
1033
1112
  }
1034
1113
  else if ((0, reflection_1.isFunctionStatement)(stmt) && !newToken) {
1035
1114
  result.set(stmt.name.text, {
1036
1115
  label: stmt.name.text,
1037
- kind: vscode_languageserver_1.CompletionItemKind.Function
1116
+ kind: vscode_languageserver_2.CompletionItemKind.Function
1038
1117
  });
1039
1118
  }
1040
1119
  else if ((0, reflection_1.isEnumStatement)(stmt) && !newToken) {
1041
1120
  result.set(stmt.name, {
1042
1121
  label: stmt.name,
1043
- kind: vscode_languageserver_1.CompletionItemKind.Enum
1122
+ kind: vscode_languageserver_2.CompletionItemKind.Enum
1123
+ });
1124
+ }
1125
+ else if ((0, reflection_1.isConstStatement)(stmt) && !newToken) {
1126
+ result.set(stmt.name, {
1127
+ label: stmt.name,
1128
+ kind: vscode_languageserver_2.CompletionItemKind.Constant
1044
1129
  });
1045
1130
  }
1046
1131
  }
@@ -1062,7 +1147,7 @@ class BrsFile {
1062
1147
  const namespaceItemStatementHandler = (statement) => {
1063
1148
  if (!location && statement.name.text.toLowerCase() === endName) {
1064
1149
  const uri = util_1.util.pathToUri(file.srcPath);
1065
- location = vscode_languageserver_1.Location.create(uri, statement.range);
1150
+ location = util_1.util.createLocation(uri, statement.range);
1066
1151
  }
1067
1152
  };
1068
1153
  file.parser.ast.walk((0, visitors_1.createVisitor)({
@@ -1186,16 +1271,16 @@ class BrsFile {
1186
1271
  let symbolKind;
1187
1272
  const children = [];
1188
1273
  if ((0, reflection_1.isFunctionStatement)(statement)) {
1189
- symbolKind = vscode_languageserver_1.SymbolKind.Function;
1274
+ symbolKind = vscode_languageserver_2.SymbolKind.Function;
1190
1275
  }
1191
1276
  else if ((0, reflection_1.isMethodStatement)(statement)) {
1192
- symbolKind = vscode_languageserver_1.SymbolKind.Method;
1277
+ symbolKind = vscode_languageserver_2.SymbolKind.Method;
1193
1278
  }
1194
1279
  else if ((0, reflection_1.isFieldStatement)(statement)) {
1195
- symbolKind = vscode_languageserver_1.SymbolKind.Field;
1280
+ symbolKind = vscode_languageserver_2.SymbolKind.Field;
1196
1281
  }
1197
1282
  else if ((0, reflection_1.isNamespaceStatement)(statement)) {
1198
- symbolKind = vscode_languageserver_1.SymbolKind.Namespace;
1283
+ symbolKind = vscode_languageserver_2.SymbolKind.Namespace;
1199
1284
  for (const childStatement of statement.body.statements) {
1200
1285
  const symbol = this.getDocumentSymbol(childStatement);
1201
1286
  if (symbol) {
@@ -1204,7 +1289,7 @@ class BrsFile {
1204
1289
  }
1205
1290
  }
1206
1291
  else if ((0, reflection_1.isClassStatement)(statement)) {
1207
- symbolKind = vscode_languageserver_1.SymbolKind.Class;
1292
+ symbolKind = vscode_languageserver_2.SymbolKind.Class;
1208
1293
  for (const childStatement of statement.body) {
1209
1294
  const symbol = this.getDocumentSymbol(childStatement);
1210
1295
  if (symbol) {
@@ -1216,7 +1301,7 @@ class BrsFile {
1216
1301
  return;
1217
1302
  }
1218
1303
  const name = (0, reflection_1.isFieldStatement)(statement) ? statement.name.text : statement.getName(Parser_1.ParseMode.BrighterScript);
1219
- return vscode_languageserver_1.DocumentSymbol.create(name, '', symbolKind, statement.range, statement.range, children);
1304
+ return vscode_languageserver_2.DocumentSymbol.create(name, '', symbolKind, statement.range, statement.range, children);
1220
1305
  }
1221
1306
  /**
1222
1307
  * Builds a single SymbolInformation object for use by LanguageServer's onWorkspaceSymbol functionality
@@ -1225,13 +1310,13 @@ class BrsFile {
1225
1310
  let symbolKind;
1226
1311
  const symbols = [];
1227
1312
  if ((0, reflection_1.isFunctionStatement)(statement)) {
1228
- symbolKind = vscode_languageserver_1.SymbolKind.Function;
1313
+ symbolKind = vscode_languageserver_2.SymbolKind.Function;
1229
1314
  }
1230
1315
  else if ((0, reflection_1.isMethodStatement)(statement)) {
1231
- symbolKind = vscode_languageserver_1.SymbolKind.Method;
1316
+ symbolKind = vscode_languageserver_2.SymbolKind.Method;
1232
1317
  }
1233
1318
  else if ((0, reflection_1.isNamespaceStatement)(statement)) {
1234
- symbolKind = vscode_languageserver_1.SymbolKind.Namespace;
1319
+ symbolKind = vscode_languageserver_2.SymbolKind.Namespace;
1235
1320
  for (const childStatement of statement.body.statements) {
1236
1321
  for (const symbol of this.generateWorkspaceSymbols(childStatement, statement)) {
1237
1322
  symbols.push(symbol);
@@ -1239,7 +1324,7 @@ class BrsFile {
1239
1324
  }
1240
1325
  }
1241
1326
  else if ((0, reflection_1.isClassStatement)(statement)) {
1242
- symbolKind = vscode_languageserver_1.SymbolKind.Class;
1327
+ symbolKind = vscode_languageserver_2.SymbolKind.Class;
1243
1328
  for (const childStatement of statement.body) {
1244
1329
  for (const symbol of this.generateWorkspaceSymbols(childStatement, statement)) {
1245
1330
  symbols.push(symbol);
@@ -1251,7 +1336,7 @@ class BrsFile {
1251
1336
  }
1252
1337
  const name = statement.getName(Parser_1.ParseMode.BrighterScript);
1253
1338
  const uri = util_1.util.pathToUri(this.srcPath);
1254
- 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));
1339
+ 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));
1255
1340
  symbols.push(symbol);
1256
1341
  return symbols;
1257
1342
  }
@@ -1260,6 +1345,7 @@ class BrsFile {
1260
1345
  * go to the definition of that identifier (where this thing was first defined)
1261
1346
  */
1262
1347
  getDefinition(position) {
1348
+ var _a, _b;
1263
1349
  let results = [];
1264
1350
  //get the token at the position
1265
1351
  const token = this.parser.getTokenAt(position);
@@ -1272,14 +1358,28 @@ class BrsFile {
1272
1358
  if (!token || !definitionTokenTypes.includes(token.kind)) {
1273
1359
  return results;
1274
1360
  }
1361
+ const scopesForFile = this.program.getScopesForFile(this);
1362
+ const [scope] = scopesForFile;
1363
+ scope.linkSymbolTable();
1364
+ const expression = this.getClosestExpression(position);
1365
+ if (expression) {
1366
+ let containingNamespace = (_a = this.getNamespaceStatementForPosition(expression.range.start)) === null || _a === void 0 ? void 0 : _a.getName(Parser_1.ParseMode.BrighterScript);
1367
+ const fullName = (_b = util_1.util.getAllDottedGetParts(expression)) === null || _b === void 0 ? void 0 : _b.map(x => x.text).join('.');
1368
+ //find a constant with this name
1369
+ const constant = scope.getConstFileLink(fullName, containingNamespace);
1370
+ if (constant) {
1371
+ results.push(util_1.util.createLocation(vscode_uri_1.URI.file(constant.file.srcPath).toString(), constant.item.tokens.name.range));
1372
+ return results;
1373
+ }
1374
+ }
1275
1375
  let textToSearchFor = token.text.toLowerCase();
1276
1376
  const previousToken = this.parser.getTokenAt({ line: token.range.start.line, character: token.range.start.character });
1277
1377
  if ((previousToken === null || previousToken === void 0 ? void 0 : previousToken.kind) === TokenKind_1.TokenKind.Callfunc) {
1278
- for (const scope of this.program.getScopes()) {
1378
+ for (const scope of scopesForFile) {
1279
1379
  //to only get functions defined in interface methods
1280
1380
  const callable = scope.getAllCallables().find((c) => c.callable.name.toLowerCase() === textToSearchFor); // eslint-disable-line @typescript-eslint/no-loop-func
1281
1381
  if (callable) {
1282
- results.push(vscode_languageserver_1.Location.create(util_1.util.pathToUri(callable.callable.file.srcPath), callable.callable.functionStatement.range));
1382
+ results.push(util_1.util.createLocation(util_1.util.pathToUri(callable.callable.file.srcPath), callable.callable.functionStatement.range));
1283
1383
  }
1284
1384
  }
1285
1385
  return results;
@@ -1291,7 +1391,7 @@ class BrsFile {
1291
1391
  const nameParts = cs.parentClassName.getNameParts();
1292
1392
  let extendedClass = this.getClassFileLink(nameParts[nameParts.length - 1], nameParts.slice(0, -1).join('.'));
1293
1393
  if (extendedClass) {
1294
- results.push(vscode_languageserver_1.Location.create(util_1.util.pathToUri(extendedClass.file.srcPath), extendedClass.item.range));
1394
+ results.push(util_1.util.createLocation(util_1.util.pathToUri(extendedClass.file.srcPath), extendedClass.item.range));
1295
1395
  }
1296
1396
  }
1297
1397
  return results;
@@ -1313,21 +1413,21 @@ class BrsFile {
1313
1413
  //we found a variable declaration with this token text
1314
1414
  if (symbol.name.toLowerCase() === textToSearchFor) {
1315
1415
  const uri = util_1.util.pathToUri(this.srcPath);
1316
- results.push(vscode_languageserver_1.Location.create(uri, symbol.range));
1416
+ results.push(util_1.util.createLocation(uri, symbol.range));
1317
1417
  }
1318
1418
  }
1319
1419
  if (this.parser.tokenFollows(token, TokenKind_1.TokenKind.Goto)) {
1320
1420
  for (const label of func.labelStatements) {
1321
1421
  if (label.tokens.identifier.text.toLocaleLowerCase() === textToSearchFor) {
1322
1422
  const uri = util_1.util.pathToUri(this.srcPath);
1323
- results.push(vscode_languageserver_1.Location.create(uri, label.tokens.identifier.range));
1423
+ results.push(util_1.util.createLocation(uri, label.tokens.identifier.range));
1324
1424
  }
1325
1425
  }
1326
1426
  }
1327
1427
  }
1328
1428
  const filesSearched = new Set();
1329
1429
  //look through all files in scope for matches
1330
- for (const scope of this.program.getScopesForFile(this)) {
1430
+ for (const scope of scopesForFile) {
1331
1431
  for (const file of scope.getAllFiles()) {
1332
1432
  if ((0, reflection_1.isXmlFile)(file) || filesSearched.has(file)) {
1333
1433
  continue;
@@ -1343,7 +1443,7 @@ class BrsFile {
1343
1443
  const statementHandler = (statement) => {
1344
1444
  if (statement.getName(this.parseMode).toLowerCase() === textToSearchFor) {
1345
1445
  const uri = util_1.util.pathToUri(file.srcPath);
1346
- results.push(vscode_languageserver_1.Location.create(uri, statement.range));
1446
+ results.push(util_1.util.createLocation(uri, statement.range));
1347
1447
  }
1348
1448
  };
1349
1449
  file.parser.ast.walk((0, visitors_1.createVisitor)({
@@ -1361,12 +1461,12 @@ class BrsFile {
1361
1461
  file.parser.ast.walk((0, visitors_1.createVisitor)({
1362
1462
  MethodStatement: (statement) => {
1363
1463
  if (statement.getName(file.parseMode).toLowerCase() === textToSearchFor) {
1364
- results.push(vscode_languageserver_1.Location.create(util_1.util.pathToUri(file.srcPath), statement.range));
1464
+ results.push(util_1.util.createLocation(util_1.util.pathToUri(file.srcPath), statement.range));
1365
1465
  }
1366
1466
  },
1367
1467
  FieldStatement: (statement) => {
1368
1468
  if (statement.name.text.toLowerCase() === textToSearchFor) {
1369
- results.push(vscode_languageserver_1.Location.create(util_1.util.pathToUri(file.srcPath), statement.range));
1469
+ results.push(util_1.util.createLocation(util_1.util.pathToUri(file.srcPath), statement.range));
1370
1470
  }
1371
1471
  }
1372
1472
  }), {
@@ -1374,127 +1474,6 @@ class BrsFile {
1374
1474
  });
1375
1475
  return results;
1376
1476
  }
1377
- getHover(position) {
1378
- var _a, _b, _c;
1379
- const fence = (code) => util_1.util.mdFence(code, 'brightscript');
1380
- //get the token at the position
1381
- let token = this.parser.getTokenAt(position);
1382
- let hoverTokenTypes = [
1383
- TokenKind_1.TokenKind.Identifier,
1384
- TokenKind_1.TokenKind.Function,
1385
- TokenKind_1.TokenKind.EndFunction,
1386
- TokenKind_1.TokenKind.Sub,
1387
- TokenKind_1.TokenKind.EndSub
1388
- ];
1389
- //throw out invalid tokens and the wrong kind of tokens
1390
- if (!token || !hoverTokenTypes.includes(token.kind)) {
1391
- return null;
1392
- }
1393
- let lowerTokenText = token.text.toLowerCase();
1394
- //look through local variables first
1395
- {
1396
- const func = this.getFunctionExpressionAtPosition(position);
1397
- if (func) {
1398
- // this identifier could possibly be a class field, so no function expression is available
1399
- for (const labelStatement of (_a = func === null || func === void 0 ? void 0 : func.labelStatements) !== null && _a !== void 0 ? _a : []) {
1400
- if (labelStatement.tokens.identifier.text.toLocaleLowerCase() === lowerTokenText) {
1401
- return {
1402
- range: token.range,
1403
- contents: `${labelStatement.tokens.identifier.text}: label`
1404
- };
1405
- }
1406
- }
1407
- }
1408
- const typeTexts = new Set();
1409
- 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); });
1410
- const callables = [];
1411
- for (const scope of fileScopes) {
1412
- scope.linkSymbolTable();
1413
- const typeContext = { file: this, scope: scope, position: position };
1414
- const typeTextPair = this.getSymbolTypeFromToken(token, func, scope);
1415
- if (typeTextPair) {
1416
- let scopeTypeText = '';
1417
- if ((0, reflection_1.isTypedFunctionType)(typeTextPair.type)) {
1418
- scopeTypeText = (_b = typeTextPair.type) === null || _b === void 0 ? void 0 : _b.toString(typeContext);
1419
- //keep unique references to the callables for this function
1420
- if (!typeTexts.has(scopeTypeText)) {
1421
- callables.push(scope.getCallableByName(lowerTokenText));
1422
- }
1423
- }
1424
- else if (typeTextPair.useExpandedTextOnly) {
1425
- scopeTypeText = typeTextPair.expandedTokenText;
1426
- }
1427
- else {
1428
- scopeTypeText = `${typeTextPair.expandedTokenText} as ${(_c = typeTextPair.type) === null || _c === void 0 ? void 0 : _c.toString(typeContext)}`;
1429
- }
1430
- if (scopeTypeText) {
1431
- typeTexts.add(scopeTypeText);
1432
- }
1433
- }
1434
- scope.unlinkSymbolTable();
1435
- }
1436
- if (callables.length === typeTexts.size) {
1437
- //this is a function in all scopes, so build the function hover
1438
- return {
1439
- range: token.range,
1440
- contents: this.getCallableDocumentation([...typeTexts], callables)
1441
- };
1442
- }
1443
- else if ((typeTexts === null || typeTexts === void 0 ? void 0 : typeTexts.size) > 0) {
1444
- const typeText = [...typeTexts].join(' | ');
1445
- return {
1446
- range: token.range,
1447
- contents: fence(typeText)
1448
- };
1449
- }
1450
- }
1451
- // //look through all callables in relevant scopes
1452
- // {
1453
- // let scopes = this.program.getScopesForFile(this);
1454
- // for (let scope of scopes) {
1455
- // let callable = scope.getCallableByName(lowerTokenText);
1456
- // if (callable) {
1457
- // return {
1458
- // range: token.range,
1459
- // contents: this.getCallableDocumentation(callables)
1460
- // };
1461
- // }
1462
- // }
1463
- // }
1464
- }
1465
- /**
1466
- * Build a hover documentation for a callable.
1467
- */
1468
- getCallableDocumentation(typeTexts, callables) {
1469
- var _a;
1470
- const callable = callables[0];
1471
- const typeText = typeTexts[0];
1472
- const comments = [];
1473
- const tokens = callable === null || callable === void 0 ? void 0 : callable.file.parser.tokens;
1474
- const idx = tokens === null || tokens === void 0 ? void 0 : tokens.indexOf((_a = callable.functionStatement) === null || _a === void 0 ? void 0 : _a.func.functionType);
1475
- for (let i = idx - 1; i >= 0; i--) {
1476
- const token = tokens[i];
1477
- //skip whitespace and newline chars
1478
- if (token.kind === TokenKind_1.TokenKind.Comment) {
1479
- comments.push(token);
1480
- }
1481
- else if (token.kind === TokenKind_1.TokenKind.Newline || token.kind === TokenKind_1.TokenKind.Whitespace) {
1482
- //skip these tokens
1483
- continue;
1484
- //any other token means there are no more comments
1485
- }
1486
- else {
1487
- break;
1488
- }
1489
- }
1490
- //message indicating if there are variations. example: (+3 variations) if there are 4 unique function signatures
1491
- const multiText = callables.length > 1 ? ` (+${callables.length - 1} variations)` : '';
1492
- let result = util_1.util.mdFence(typeText + multiText, 'brightscript');
1493
- if (comments.length > 0) {
1494
- result += '\n***\n' + comments.reverse().map(x => x.text.replace(/^('|rem)/i, '')).join('\n');
1495
- }
1496
- return result;
1497
- }
1498
1477
  getSignatureHelpForNamespaceMethods(callableName, dottedGetText, scope) {
1499
1478
  var _a;
1500
1479
  if (!dottedGetText) {
@@ -1565,11 +1544,11 @@ class BrsFile {
1565
1544
  let key = statement.name.text + documentation;
1566
1545
  const params = [];
1567
1546
  for (const param of func.parameters) {
1568
- params.push(vscode_languageserver_1.ParameterInformation.create(param.name.text));
1547
+ params.push(vscode_languageserver_2.ParameterInformation.create(param.name.text));
1569
1548
  key += param.name.text;
1570
1549
  }
1571
1550
  const label = util_1.util.getTextForRange(lines, func.functionDeclarationRange).trim();
1572
- const signature = vscode_languageserver_1.SignatureInformation.create(label, documentation, ...params);
1551
+ const signature = vscode_languageserver_2.SignatureInformation.create(label, documentation, ...params);
1573
1552
  const index = 1;
1574
1553
  return { key: key, signature: signature, index: index };
1575
1554
  }
@@ -1626,7 +1605,7 @@ class BrsFile {
1626
1605
  file.ast.walk((0, visitors_1.createVisitor)({
1627
1606
  VariableExpression: (e) => {
1628
1607
  if (e.name.text.toLowerCase() === searchFor) {
1629
- locations.push(vscode_languageserver_1.Location.create(util_1.util.pathToUri(file.srcPath), e.range));
1608
+ locations.push(util_1.util.createLocation(util_1.util.pathToUri(file.srcPath), e.range));
1630
1609
  }
1631
1610
  }
1632
1611
  }), {
@@ -1699,7 +1678,7 @@ exports.KeywordCompletions = Object.keys(TokenKind_1.Keywords)
1699
1678
  .map(x => {
1700
1679
  return {
1701
1680
  label: x,
1702
- kind: vscode_languageserver_1.CompletionItemKind.Keyword
1681
+ kind: vscode_languageserver_2.CompletionItemKind.Keyword
1703
1682
  };
1704
1683
  });
1705
1684
  //# sourceMappingURL=BrsFile.js.map