brighterscript 0.72.1 → 0.72.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (289) hide show
  1. package/package.json +17 -14
  2. package/dist/astUtils/AstEditor.spec.d.ts +0 -1
  3. package/dist/astUtils/AstEditor.spec.js +0 -254
  4. package/dist/astUtils/AstEditor.spec.js.map +0 -1
  5. package/dist/astUtils/creators.spec.d.ts +0 -1
  6. package/dist/astUtils/creators.spec.js +0 -21
  7. package/dist/astUtils/creators.spec.js.map +0 -1
  8. package/dist/astUtils/reflection.spec.d.ts +0 -1
  9. package/dist/astUtils/reflection.spec.js +0 -308
  10. package/dist/astUtils/reflection.spec.js.map +0 -1
  11. package/dist/astUtils/stackedVisitor.spec.d.ts +0 -1
  12. package/dist/astUtils/stackedVisitor.spec.js +0 -79
  13. package/dist/astUtils/stackedVisitor.spec.js.map +0 -1
  14. package/dist/astUtils/visitors.spec.d.ts +0 -1
  15. package/dist/astUtils/visitors.spec.js +0 -1197
  16. package/dist/astUtils/visitors.spec.js.map +0 -1
  17. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.d.ts +0 -1
  18. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js +0 -1237
  19. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +0 -1
  20. package/dist/bscPlugin/definition/DefinitionProvider.spec.d.ts +0 -1
  21. package/dist/bscPlugin/definition/DefinitionProvider.spec.js +0 -171
  22. package/dist/bscPlugin/definition/DefinitionProvider.spec.js.map +0 -1
  23. package/dist/bscPlugin/hover/HoverProcessor.spec.d.ts +0 -1
  24. package/dist/bscPlugin/hover/HoverProcessor.spec.js +0 -201
  25. package/dist/bscPlugin/hover/HoverProcessor.spec.js.map +0 -1
  26. package/dist/bscPlugin/references/ReferencesProvider.spec.d.ts +0 -1
  27. package/dist/bscPlugin/references/ReferencesProvider.spec.js +0 -51
  28. package/dist/bscPlugin/references/ReferencesProvider.spec.js.map +0 -1
  29. package/dist/bscPlugin/selectionRanges/SelectionRangesProcessor.spec.d.ts +0 -1
  30. package/dist/bscPlugin/selectionRanges/SelectionRangesProcessor.spec.js +0 -298
  31. package/dist/bscPlugin/selectionRanges/SelectionRangesProcessor.spec.js.map +0 -1
  32. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.d.ts +0 -1
  33. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js +0 -399
  34. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js.map +0 -1
  35. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.d.ts +0 -1
  36. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.js +0 -290
  37. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.js.map +0 -1
  38. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.d.ts +0 -1
  39. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.js +0 -245
  40. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.js.map +0 -1
  41. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.d.ts +0 -1
  42. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js +0 -46
  43. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js.map +0 -1
  44. package/dist/bscPlugin/validation/BrsFileValidator.spec.d.ts +0 -1
  45. package/dist/bscPlugin/validation/BrsFileValidator.spec.js +0 -702
  46. package/dist/bscPlugin/validation/BrsFileValidator.spec.js.map +0 -1
  47. package/dist/common/Sequencer.spec.d.ts +0 -1
  48. package/dist/common/Sequencer.spec.js +0 -75
  49. package/dist/common/Sequencer.spec.js.map +0 -1
  50. package/dist/files/BrsFile.Class.spec.d.ts +0 -1
  51. package/dist/files/BrsFile.Class.spec.js +0 -1805
  52. package/dist/files/BrsFile.Class.spec.js.map +0 -1
  53. package/dist/files/BrsFile.spec.d.ts +0 -1
  54. package/dist/files/BrsFile.spec.js +0 -4611
  55. package/dist/files/BrsFile.spec.js.map +0 -1
  56. package/dist/files/XmlFile.spec.d.ts +0 -1
  57. package/dist/files/XmlFile.spec.js +0 -1219
  58. package/dist/files/XmlFile.spec.js.map +0 -1
  59. package/dist/files/tests/imports.spec.d.ts +0 -1
  60. package/dist/files/tests/imports.spec.js +0 -241
  61. package/dist/files/tests/imports.spec.js.map +0 -1
  62. package/dist/files/tests/optionalChaning.spec.d.ts +0 -1
  63. package/dist/files/tests/optionalChaning.spec.js +0 -152
  64. package/dist/files/tests/optionalChaning.spec.js.map +0 -1
  65. package/dist/lexer/Character.spec.d.ts +0 -1
  66. package/dist/lexer/Character.spec.js +0 -27
  67. package/dist/lexer/Character.spec.js.map +0 -1
  68. package/dist/lexer/Lexer.spec.d.ts +0 -1
  69. package/dist/lexer/Lexer.spec.js +0 -1300
  70. package/dist/lexer/Lexer.spec.js.map +0 -1
  71. package/dist/lsp/ActionQueue.spec.d.ts +0 -1
  72. package/dist/lsp/ActionQueue.spec.js +0 -80
  73. package/dist/lsp/ActionQueue.spec.js.map +0 -1
  74. package/dist/lsp/DocumentManager.spec.d.ts +0 -1
  75. package/dist/lsp/DocumentManager.spec.js +0 -103
  76. package/dist/lsp/DocumentManager.spec.js.map +0 -1
  77. package/dist/lsp/PathFilterer.spec.d.ts +0 -1
  78. package/dist/lsp/PathFilterer.spec.js +0 -182
  79. package/dist/lsp/PathFilterer.spec.js.map +0 -1
  80. package/dist/lsp/Project.spec.d.ts +0 -1
  81. package/dist/lsp/Project.spec.js +0 -400
  82. package/dist/lsp/Project.spec.js.map +0 -1
  83. package/dist/lsp/ProjectManager.spec.d.ts +0 -1
  84. package/dist/lsp/ProjectManager.spec.js +0 -1183
  85. package/dist/lsp/ProjectManager.spec.js.map +0 -1
  86. package/dist/lsp/worker/MessageHandler.spec.d.ts +0 -1
  87. package/dist/lsp/worker/MessageHandler.spec.js +0 -64
  88. package/dist/lsp/worker/MessageHandler.spec.js.map +0 -1
  89. package/dist/lsp/worker/WorkerPool.spec.d.ts +0 -1
  90. package/dist/lsp/worker/WorkerPool.spec.js +0 -59
  91. package/dist/lsp/worker/WorkerPool.spec.js.map +0 -1
  92. package/dist/lsp/worker/WorkerThreadProject.spec.d.ts +0 -2
  93. package/dist/lsp/worker/WorkerThreadProject.spec.js +0 -72
  94. package/dist/lsp/worker/WorkerThreadProject.spec.js.map +0 -1
  95. package/dist/parser/AstNode.spec.d.ts +0 -1
  96. package/dist/parser/AstNode.spec.js +0 -1452
  97. package/dist/parser/AstNode.spec.js.map +0 -1
  98. package/dist/parser/Expression.spec.d.ts +0 -1
  99. package/dist/parser/Expression.spec.js +0 -40
  100. package/dist/parser/Expression.spec.js.map +0 -1
  101. package/dist/parser/Parser.Class.spec.d.ts +0 -1
  102. package/dist/parser/Parser.Class.spec.js +0 -495
  103. package/dist/parser/Parser.Class.spec.js.map +0 -1
  104. package/dist/parser/Parser.spec.d.ts +0 -4
  105. package/dist/parser/Parser.spec.js +0 -1985
  106. package/dist/parser/Parser.spec.js.map +0 -1
  107. package/dist/parser/SGParser.spec.d.ts +0 -1
  108. package/dist/parser/SGParser.spec.js +0 -131
  109. package/dist/parser/SGParser.spec.js.map +0 -1
  110. package/dist/parser/Statement.spec.d.ts +0 -1
  111. package/dist/parser/Statement.spec.js +0 -118
  112. package/dist/parser/Statement.spec.js.map +0 -1
  113. package/dist/parser/tests/Parser.spec.d.ts +0 -19
  114. package/dist/parser/tests/Parser.spec.js +0 -38
  115. package/dist/parser/tests/Parser.spec.js.map +0 -1
  116. package/dist/parser/tests/controlFlow/For.spec.d.ts +0 -1
  117. package/dist/parser/tests/controlFlow/For.spec.js +0 -208
  118. package/dist/parser/tests/controlFlow/For.spec.js.map +0 -1
  119. package/dist/parser/tests/controlFlow/ForEach.spec.d.ts +0 -1
  120. package/dist/parser/tests/controlFlow/ForEach.spec.js +0 -143
  121. package/dist/parser/tests/controlFlow/ForEach.spec.js.map +0 -1
  122. package/dist/parser/tests/controlFlow/If.spec.d.ts +0 -1
  123. package/dist/parser/tests/controlFlow/If.spec.js +0 -570
  124. package/dist/parser/tests/controlFlow/If.spec.js.map +0 -1
  125. package/dist/parser/tests/controlFlow/While.spec.d.ts +0 -1
  126. package/dist/parser/tests/controlFlow/While.spec.js +0 -156
  127. package/dist/parser/tests/controlFlow/While.spec.js.map +0 -1
  128. package/dist/parser/tests/expression/Additive.spec.d.ts +0 -1
  129. package/dist/parser/tests/expression/Additive.spec.js +0 -99
  130. package/dist/parser/tests/expression/Additive.spec.js.map +0 -1
  131. package/dist/parser/tests/expression/ArrayLiterals.spec.d.ts +0 -1
  132. package/dist/parser/tests/expression/ArrayLiterals.spec.js +0 -291
  133. package/dist/parser/tests/expression/ArrayLiterals.spec.js.map +0 -1
  134. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.d.ts +0 -1
  135. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +0 -401
  136. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +0 -1
  137. package/dist/parser/tests/expression/Boolean.spec.d.ts +0 -1
  138. package/dist/parser/tests/expression/Boolean.spec.js +0 -83
  139. package/dist/parser/tests/expression/Boolean.spec.js.map +0 -1
  140. package/dist/parser/tests/expression/Call.spec.d.ts +0 -1
  141. package/dist/parser/tests/expression/Call.spec.js +0 -242
  142. package/dist/parser/tests/expression/Call.spec.js.map +0 -1
  143. package/dist/parser/tests/expression/Exponential.spec.d.ts +0 -1
  144. package/dist/parser/tests/expression/Exponential.spec.js +0 -37
  145. package/dist/parser/tests/expression/Exponential.spec.js.map +0 -1
  146. package/dist/parser/tests/expression/Function.spec.d.ts +0 -1
  147. package/dist/parser/tests/expression/Function.spec.js +0 -403
  148. package/dist/parser/tests/expression/Function.spec.js.map +0 -1
  149. package/dist/parser/tests/expression/Indexing.spec.d.ts +0 -1
  150. package/dist/parser/tests/expression/Indexing.spec.js +0 -289
  151. package/dist/parser/tests/expression/Indexing.spec.js.map +0 -1
  152. package/dist/parser/tests/expression/Multiplicative.spec.d.ts +0 -1
  153. package/dist/parser/tests/expression/Multiplicative.spec.js +0 -67
  154. package/dist/parser/tests/expression/Multiplicative.spec.js.map +0 -1
  155. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.d.ts +0 -1
  156. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +0 -346
  157. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +0 -1
  158. package/dist/parser/tests/expression/PrefixUnary.spec.d.ts +0 -1
  159. package/dist/parser/tests/expression/PrefixUnary.spec.js +0 -105
  160. package/dist/parser/tests/expression/PrefixUnary.spec.js.map +0 -1
  161. package/dist/parser/tests/expression/Primary.spec.d.ts +0 -1
  162. package/dist/parser/tests/expression/Primary.spec.js +0 -149
  163. package/dist/parser/tests/expression/Primary.spec.js.map +0 -1
  164. package/dist/parser/tests/expression/RegexLiteralExpression.spec.d.ts +0 -1
  165. package/dist/parser/tests/expression/RegexLiteralExpression.spec.js +0 -171
  166. package/dist/parser/tests/expression/RegexLiteralExpression.spec.js.map +0 -1
  167. package/dist/parser/tests/expression/Relational.spec.d.ts +0 -1
  168. package/dist/parser/tests/expression/Relational.spec.js +0 -83
  169. package/dist/parser/tests/expression/Relational.spec.js.map +0 -1
  170. package/dist/parser/tests/expression/SourceLiteralExpression.spec.d.ts +0 -1
  171. package/dist/parser/tests/expression/SourceLiteralExpression.spec.js +0 -201
  172. package/dist/parser/tests/expression/SourceLiteralExpression.spec.js.map +0 -1
  173. package/dist/parser/tests/expression/TemplateStringExpression.spec.d.ts +0 -1
  174. package/dist/parser/tests/expression/TemplateStringExpression.spec.js +0 -389
  175. package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +0 -1
  176. package/dist/parser/tests/expression/TernaryExpression.spec.d.ts +0 -1
  177. package/dist/parser/tests/expression/TernaryExpression.spec.js +0 -876
  178. package/dist/parser/tests/expression/TernaryExpression.spec.js.map +0 -1
  179. package/dist/parser/tests/expression/UnaryExpression.spec.d.ts +0 -1
  180. package/dist/parser/tests/expression/UnaryExpression.spec.js +0 -52
  181. package/dist/parser/tests/expression/UnaryExpression.spec.js.map +0 -1
  182. package/dist/parser/tests/statement/AssignmentOperators.spec.d.ts +0 -1
  183. package/dist/parser/tests/statement/AssignmentOperators.spec.js +0 -79
  184. package/dist/parser/tests/statement/AssignmentOperators.spec.js.map +0 -1
  185. package/dist/parser/tests/statement/ConstStatement.spec.d.ts +0 -1
  186. package/dist/parser/tests/statement/ConstStatement.spec.js +0 -708
  187. package/dist/parser/tests/statement/ConstStatement.spec.js.map +0 -1
  188. package/dist/parser/tests/statement/Continue.spec.d.ts +0 -1
  189. package/dist/parser/tests/statement/Continue.spec.js +0 -119
  190. package/dist/parser/tests/statement/Continue.spec.js.map +0 -1
  191. package/dist/parser/tests/statement/Declaration.spec.d.ts +0 -1
  192. package/dist/parser/tests/statement/Declaration.spec.js +0 -108
  193. package/dist/parser/tests/statement/Declaration.spec.js.map +0 -1
  194. package/dist/parser/tests/statement/Dim.spec.d.ts +0 -1
  195. package/dist/parser/tests/statement/Dim.spec.js +0 -73
  196. package/dist/parser/tests/statement/Dim.spec.js.map +0 -1
  197. package/dist/parser/tests/statement/Enum.spec.d.ts +0 -1
  198. package/dist/parser/tests/statement/Enum.spec.js +0 -1307
  199. package/dist/parser/tests/statement/Enum.spec.js.map +0 -1
  200. package/dist/parser/tests/statement/For.spec.d.ts +0 -1
  201. package/dist/parser/tests/statement/For.spec.js +0 -45
  202. package/dist/parser/tests/statement/For.spec.js.map +0 -1
  203. package/dist/parser/tests/statement/ForEach.spec.d.ts +0 -1
  204. package/dist/parser/tests/statement/ForEach.spec.js +0 -36
  205. package/dist/parser/tests/statement/ForEach.spec.js.map +0 -1
  206. package/dist/parser/tests/statement/Function.spec.d.ts +0 -1
  207. package/dist/parser/tests/statement/Function.spec.js +0 -342
  208. package/dist/parser/tests/statement/Function.spec.js.map +0 -1
  209. package/dist/parser/tests/statement/Goto.spec.d.ts +0 -1
  210. package/dist/parser/tests/statement/Goto.spec.js +0 -51
  211. package/dist/parser/tests/statement/Goto.spec.js.map +0 -1
  212. package/dist/parser/tests/statement/Increment.spec.d.ts +0 -1
  213. package/dist/parser/tests/statement/Increment.spec.js +0 -117
  214. package/dist/parser/tests/statement/Increment.spec.js.map +0 -1
  215. package/dist/parser/tests/statement/InterfaceStatement.spec.d.ts +0 -1
  216. package/dist/parser/tests/statement/InterfaceStatement.spec.js +0 -102
  217. package/dist/parser/tests/statement/InterfaceStatement.spec.js.map +0 -1
  218. package/dist/parser/tests/statement/LibraryStatement.spec.d.ts +0 -1
  219. package/dist/parser/tests/statement/LibraryStatement.spec.js +0 -74
  220. package/dist/parser/tests/statement/LibraryStatement.spec.js.map +0 -1
  221. package/dist/parser/tests/statement/Misc.spec.d.ts +0 -1
  222. package/dist/parser/tests/statement/Misc.spec.js +0 -335
  223. package/dist/parser/tests/statement/Misc.spec.js.map +0 -1
  224. package/dist/parser/tests/statement/PrintStatement.spec.d.ts +0 -1
  225. package/dist/parser/tests/statement/PrintStatement.spec.js +0 -195
  226. package/dist/parser/tests/statement/PrintStatement.spec.js.map +0 -1
  227. package/dist/parser/tests/statement/ReturnStatement.spec.d.ts +0 -1
  228. package/dist/parser/tests/statement/ReturnStatement.spec.js +0 -94
  229. package/dist/parser/tests/statement/ReturnStatement.spec.js.map +0 -1
  230. package/dist/parser/tests/statement/Set.spec.d.ts +0 -1
  231. package/dist/parser/tests/statement/Set.spec.js +0 -218
  232. package/dist/parser/tests/statement/Set.spec.js.map +0 -1
  233. package/dist/parser/tests/statement/Stop.spec.d.ts +0 -1
  234. package/dist/parser/tests/statement/Stop.spec.js +0 -38
  235. package/dist/parser/tests/statement/Stop.spec.js.map +0 -1
  236. package/dist/parser/tests/statement/Throw.spec.d.ts +0 -1
  237. package/dist/parser/tests/statement/Throw.spec.js +0 -35
  238. package/dist/parser/tests/statement/Throw.spec.js.map +0 -1
  239. package/dist/parser/tests/statement/TryCatch.spec.d.ts +0 -1
  240. package/dist/parser/tests/statement/TryCatch.spec.js +0 -142
  241. package/dist/parser/tests/statement/TryCatch.spec.js.map +0 -1
  242. package/dist/preprocessor/Manifest.spec.d.ts +0 -1
  243. package/dist/preprocessor/Manifest.spec.js +0 -80
  244. package/dist/preprocessor/Manifest.spec.js.map +0 -1
  245. package/dist/preprocessor/Preprocessor.spec.d.ts +0 -1
  246. package/dist/preprocessor/Preprocessor.spec.js +0 -152
  247. package/dist/preprocessor/Preprocessor.spec.js.map +0 -1
  248. package/dist/preprocessor/PreprocessorParser.spec.d.ts +0 -1
  249. package/dist/preprocessor/PreprocessorParser.spec.js +0 -116
  250. package/dist/preprocessor/PreprocessorParser.spec.js.map +0 -1
  251. package/dist/types/ArrayType.spec.d.ts +0 -1
  252. package/dist/types/ArrayType.spec.js +0 -30
  253. package/dist/types/ArrayType.spec.js.map +0 -1
  254. package/dist/types/BooleanType.spec.d.ts +0 -1
  255. package/dist/types/BooleanType.spec.js +0 -12
  256. package/dist/types/BooleanType.spec.js.map +0 -1
  257. package/dist/types/DoubleType.spec.d.ts +0 -1
  258. package/dist/types/DoubleType.spec.js +0 -12
  259. package/dist/types/DoubleType.spec.js.map +0 -1
  260. package/dist/types/DynamicType.spec.d.ts +0 -1
  261. package/dist/types/DynamicType.spec.js +0 -12
  262. package/dist/types/DynamicType.spec.js.map +0 -1
  263. package/dist/types/FloatType.spec.d.ts +0 -1
  264. package/dist/types/FloatType.spec.js +0 -12
  265. package/dist/types/FloatType.spec.js.map +0 -1
  266. package/dist/types/FunctionType.spec.d.ts +0 -1
  267. package/dist/types/FunctionType.spec.js +0 -23
  268. package/dist/types/FunctionType.spec.js.map +0 -1
  269. package/dist/types/IntegerType.spec.d.ts +0 -1
  270. package/dist/types/IntegerType.spec.js +0 -12
  271. package/dist/types/IntegerType.spec.js.map +0 -1
  272. package/dist/types/InterfaceType.spec.d.ts +0 -1
  273. package/dist/types/InterfaceType.spec.js +0 -175
  274. package/dist/types/InterfaceType.spec.js.map +0 -1
  275. package/dist/types/InvalidType.spec.d.ts +0 -1
  276. package/dist/types/InvalidType.spec.js +0 -12
  277. package/dist/types/InvalidType.spec.js.map +0 -1
  278. package/dist/types/LongIntegerType.spec.d.ts +0 -1
  279. package/dist/types/LongIntegerType.spec.js +0 -12
  280. package/dist/types/LongIntegerType.spec.js.map +0 -1
  281. package/dist/types/ObjectType.spec.d.ts +0 -1
  282. package/dist/types/ObjectType.spec.js +0 -12
  283. package/dist/types/ObjectType.spec.js.map +0 -1
  284. package/dist/types/StringType.spec.d.ts +0 -1
  285. package/dist/types/StringType.spec.js +0 -12
  286. package/dist/types/StringType.spec.js.map +0 -1
  287. package/dist/types/VoidType.spec.d.ts +0 -1
  288. package/dist/types/VoidType.spec.js +0 -12
  289. package/dist/types/VoidType.spec.js.map +0 -1
@@ -1,1237 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const chai_config_spec_1 = require("../../chai-config.spec");
4
- const vscode_uri_1 = require("vscode-uri");
5
- const Program_1 = require("../../Program");
6
- const testHelpers_spec_1 = require("../../testHelpers.spec");
7
- const util_1 = require("../../util");
8
- const testHelpers_spec_2 = require("../../testHelpers.spec");
9
- const CodeActionsProcessor_1 = require("./CodeActionsProcessor");
10
- describe('CodeActionsProcessor', () => {
11
- let program;
12
- beforeEach(() => {
13
- program = new Program_1.Program({
14
- rootDir: testHelpers_spec_2.rootDir,
15
- autoImportComponentScript: true
16
- });
17
- });
18
- afterEach(() => {
19
- program.dispose();
20
- });
21
- /**
22
- * Helper function for testing code actions. By default it filters out the generic
23
- * `Disable {code} for this line/file` quick fixes because every diagnostic gets them
24
- * and the per-feature tests below only care about feature-specific actions.
25
- */
26
- function testGetCodeActions(file, range, expected, options) {
27
- program.validate();
28
- const titles = program.getCodeActions(typeof file === 'string' ? file : file.srcPath, range).map(x => x.title);
29
- (0, chai_config_spec_1.expect)(filterDisableActions(titles, options).sort()).to.eql(expected);
30
- }
31
- /**
32
- * Drops the generic `Disable {code} for this line/file` titles from a list so feature-level
33
- * assertions can stay focused on their own actions.
34
- */
35
- function filterDisableActions(titles, options) {
36
- if (options === null || options === void 0 ? void 0 : options.includeDisableDirectives) {
37
- return titles;
38
- }
39
- return titles.filter(t => !/^Disable .+ for this (line|file)/.test(t));
40
- }
41
- describe('getCodeActions', () => {
42
- it('suggests `extends=Group`', () => {
43
- const file = program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
44
- <?xml version="1.0" encoding="utf-8" ?>
45
- <component name="comp1">
46
- </component>
47
- `);
48
- program.validate();
49
- (0, testHelpers_spec_1.expectCodeActions)(() => {
50
- program.getCodeActions(file.srcPath,
51
- //<comp|onent name="comp1">
52
- util_1.util.createRange(1, 5, 1, 5));
53
- }, [{
54
- title: `Extend "Group"`,
55
- isPreferred: true,
56
- kind: 'quickfix',
57
- changes: [{
58
- filePath: (0, util_1.standardizePath) `${testHelpers_spec_2.rootDir}/components/comp1.xml`,
59
- newText: ' extends="Group"',
60
- type: 'insert',
61
- //<component name="comp1"|>
62
- position: util_1.util.createPosition(1, 23)
63
- }]
64
- }, {
65
- title: `Extend "Task"`,
66
- kind: 'quickfix',
67
- changes: [{
68
- filePath: (0, util_1.standardizePath) `${testHelpers_spec_2.rootDir}/components/comp1.xml`,
69
- newText: ' extends="Task"',
70
- type: 'insert',
71
- //<component name="comp1"|>
72
- position: util_1.util.createPosition(1, 23)
73
- }]
74
- }, {
75
- title: `Extend "ContentNode"`,
76
- kind: 'quickfix',
77
- changes: [{
78
- filePath: (0, util_1.standardizePath) `${testHelpers_spec_2.rootDir}/components/comp1.xml`,
79
- newText: ' extends="ContentNode"',
80
- type: 'insert',
81
- //<component name="comp1"|>
82
- position: util_1.util.createPosition(1, 23)
83
- }]
84
- }]);
85
- });
86
- it('adds attribute at end of component with multiple attributes`', () => {
87
- const file = program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
88
- <?xml version="1.0" encoding="utf-8" ?>
89
- <component name="comp1" attr2="attr3" attr3="attr3">
90
- </component>
91
- `);
92
- program.validate();
93
- const codeActions = program.getCodeActions(file.srcPath,
94
- //<comp|onent name="comp1">
95
- util_1.util.createRange(1, 5, 1, 5));
96
- (0, chai_config_spec_1.expect)(codeActions[0].edit.changes[vscode_uri_1.URI.file((0, util_1.standardizePath) `${testHelpers_spec_2.rootDir}/components/comp1.xml`).toString()][0].range).to.eql(util_1.util.createRange(1, 51, 1, 51));
97
- });
98
- it('does not produce duplicate code actions for bs imports', () => {
99
- //define the function in two files
100
- program.setFile('components/lib1.brs', `
101
- sub doSomething()
102
- end sub
103
- `);
104
- program.setFile('components/lib2.brs', `
105
- sub doSomething()
106
- end sub
107
- `);
108
- //use the function in this file
109
- const componentCommonFile = program.setFile('components/ComponentCommon.bs', `
110
- sub init()
111
- doSomething()
112
- end sub
113
- `);
114
- //import the file in two scopes
115
- program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
116
- <?xml version="1.0" encoding="utf-8" ?>
117
- <component name="ChildScene">
118
- <script uri="ComponentCommon.bs" />
119
- </component>
120
- `);
121
- program.setFile('components/comp2.xml', (0, testHelpers_spec_1.trim) `
122
- <?xml version="1.0" encoding="utf-8" ?>
123
- <component name="ChildScene">
124
- <script uri="ComponentCommon.bs" />
125
- </component>
126
- `);
127
- program.validate();
128
- //we should only get each file import suggestion exactly once
129
- const codeActions = program.getCodeActions(componentCommonFile.srcPath,
130
- // doSome|thing()
131
- util_1.util.createRange(2, 22, 2, 22));
132
- (0, chai_config_spec_1.expect)(filterDisableActions(codeActions.map(x => x.title)).sort()).to.eql([
133
- `import "pkg:/components/lib1.brs"`,
134
- `import "pkg:/components/lib2.brs"`
135
- ]);
136
- });
137
- it('does not suggest imports for brs files', () => {
138
- //import the file in two scopes
139
- program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
140
- <?xml version="1.0" encoding="utf-8" ?>
141
- <component name="ChildScene">
142
- <script uri="comp1.brs" />
143
- </component>
144
- `);
145
- //import the function here
146
- const file = program.setFile('components/comp1.brs', `
147
- sub init()
148
- DoSomething()
149
- end sub
150
- `);
151
- //define the function here
152
- program.setFile('source/lib.brs', `
153
- sub DoSomething()
154
- end sub
155
- `);
156
- program.validate();
157
- //there should be no import code actions since this is a brs file (disable directives still appear for any diagnostic)
158
- const codeActions = program.getCodeActions(file.srcPath,
159
- // DoSometh|ing()
160
- util_1.util.createRange(2, 28, 2, 28));
161
- (0, chai_config_spec_1.expect)(filterDisableActions(codeActions.map(x => x.title))).to.be.empty;
162
- });
163
- it('suggests class imports', () => {
164
- //import the file in two scopes
165
- program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
166
- <?xml version="1.0" encoding="utf-8" ?>
167
- <component name="ChildScene">
168
- <script uri="comp1.bs" />
169
- </component>
170
- `);
171
- const file = program.setFile('components/comp1.bs', `
172
- sub init()
173
- dude = new Person()
174
- end sub
175
- `);
176
- program.setFile('source/Person.bs', `
177
- class Person
178
- end class
179
- `);
180
- program.validate();
181
- (0, chai_config_spec_1.expect)(filterDisableActions(program.getCodeActions(file.srcPath,
182
- // new Per|son()
183
- util_1.util.createRange(2, 34, 2, 34)).map(x => x.title)).sort()).to.eql([
184
- `import "pkg:/source/Person.bs"`
185
- ]);
186
- });
187
- it('suggests class imports', () => {
188
- //import the file in two scopes
189
- program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
190
- <?xml version="1.0" encoding="utf-8" ?>
191
- <component name="ChildScene">
192
- <script uri="comp1.bs" />
193
- </component>
194
- `);
195
- //import the function here
196
- const file = program.setFile('components/comp1.bs', `
197
- sub init()
198
- kitty = new Animals.Cat()
199
- end sub
200
- `);
201
- program.setFile('source/Animals.bs', `
202
- namespace Animals
203
- class Cat
204
- end class
205
- end namespace
206
- `);
207
- program.validate();
208
- (0, chai_config_spec_1.expect)(filterDisableActions(program.getCodeActions(file.srcPath,
209
- // new Anim|als.Cat()
210
- util_1.util.createRange(2, 36, 2, 36)).map(x => x.title)).sort()).to.eql([
211
- `import "pkg:/source/Animals.bs"`
212
- ]);
213
- });
214
- it('suggests all files for a root namespace name', () => {
215
- program.setFile('source/first.bs', `
216
- namespace alpha
217
- function firstAction()
218
- end function
219
- end namespace
220
- `);
221
- program.setFile('source/second.bs', `
222
- namespace alpha.beta
223
- function secondAction()
224
- end function
225
- end namespace
226
- `);
227
- program.setFile('components/MainScene.xml', (0, testHelpers_spec_1.trim) `<component name="MainScene"></component>`);
228
- const file = program.setFile('components/MainScene.bs', `
229
- sub init()
230
- print alpha.secondAction()
231
- end sub
232
- `);
233
- // print al|pha.secondAction()
234
- testGetCodeActions(file, util_1.util.createRange(2, 28, 2, 28), [
235
- `import "pkg:/source/first.bs"`,
236
- `import "pkg:/source/second.bs"`
237
- ]);
238
- });
239
- it('clears suggestedImports after process() so the same instance could be reused in the future', () => {
240
- program.setFile('source/lib.bs', `
241
- function doSomething()
242
- end function
243
- `);
244
- program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
245
- <?xml version="1.0" encoding="utf-8" ?>
246
- <component name="comp1" extends="Scene">
247
- <script uri="comp1.bs" />
248
- </component>
249
- `);
250
- const file = program.setFile('components/comp1.bs', `
251
- sub init()
252
- doSomething()
253
- end sub
254
- `);
255
- program.validate();
256
- const range = util_1.util.createRange(2, 24, 2, 24);
257
- const event = {
258
- program: program,
259
- file: file,
260
- range: range,
261
- scopes: program.getScopesForFile(file),
262
- diagnostics: program.getDiagnostics().filter(d => d.file === file && util_1.util.rangesIntersectOrTouch(d.range, range)),
263
- codeActions: []
264
- };
265
- const processor = new CodeActionsProcessor_1.CodeActionsProcessor(event);
266
- processor.process();
267
- const firstCallTitles = event.codeActions.map(x => x.title).sort();
268
- // Reset codeActions and call process() again on the same instance.
269
- // If suggestedImports were NOT cleared, the second call would return no import suggestions.
270
- event.codeActions = [];
271
- processor.process();
272
- const secondCallTitles = event.codeActions.map(x => x.title).sort();
273
- (0, chai_config_spec_1.expect)(secondCallTitles).to.eql(firstCallTitles);
274
- });
275
- it('suggests files for second part of missing namespace', () => {
276
- program.setFile('source/first.bs', `
277
- namespace alpha
278
- function firstAction()
279
- end function
280
- end namespace
281
- `);
282
- program.setFile('source/second.bs', `
283
- namespace alpha.beta
284
- function secondAction()
285
- end function
286
- end namespace
287
- `);
288
- program.setFile('components/MainScene.xml', (0, testHelpers_spec_1.trim) `<component name="MainScene"></component>`);
289
- const file = program.setFile('components/MainScene.bs', `
290
- import "pkg:/source/first.bs"
291
- sub init()
292
- print alpha.beta.secondAction()
293
- end sub
294
- `);
295
- // print alpha.be|ta.secondAction()
296
- testGetCodeActions(file, util_1.util.createRange(3, 34, 3, 34), [`import "pkg:/source/second.bs"`]);
297
- });
298
- });
299
- describe('Fix all: Auto fixable missing imports', () => {
300
- it('offers fix-all when multiple unambiguous imports are missing', () => {
301
- program.setFile('source/lib1.bs', `
302
- function doSomething()
303
- end function
304
- `);
305
- program.setFile('source/lib2.bs', `
306
- function doSomethingElse()
307
- end function
308
- `);
309
- program.setFile('components/MainScene.xml', (0, testHelpers_spec_1.trim) `<component name="MainScene"></component>`);
310
- const file = program.setFile('components/MainScene.bs', `
311
- sub init()
312
- doSomething()
313
- doSomethingElse()
314
- end sub
315
- `);
316
- // doSome|thing()
317
- testGetCodeActions(file, util_1.util.createRange(2, 26, 2, 26), [
318
- `Fix all: Auto fixable missing imports`,
319
- `import "pkg:/source/lib1.bs"`
320
- ]);
321
- });
322
- it('does not offer fix-all when only one import is missing', () => {
323
- program.setFile('source/lib1.bs', `
324
- function doSomething()
325
- end function
326
- `);
327
- program.setFile('components/MainScene.xml', (0, testHelpers_spec_1.trim) `<component name="MainScene"></component>`);
328
- const file = program.setFile('components/MainScene.bs', `
329
- sub init()
330
- doSomething()
331
- end sub
332
- `);
333
- // doSome|thing()
334
- testGetCodeActions(file, util_1.util.createRange(2, 26, 2, 26), [
335
- `import "pkg:/source/lib1.bs"`
336
- ]);
337
- });
338
- it('excludes ambiguous names from fix-all', () => {
339
- program.setFile('source/lib1.bs', `
340
- function doSomething()
341
- end function
342
- `);
343
- program.setFile('source/lib2.bs', `
344
- function doSomething()
345
- end function
346
- `);
347
- program.setFile('source/lib3.bs', `
348
- function doSomethingUnambiguous()
349
- end function
350
- `);
351
- program.setFile('components/MainScene.xml', (0, testHelpers_spec_1.trim) `<component name="MainScene"></component>`);
352
- const file = program.setFile('components/MainScene.bs', `
353
- sub init()
354
- doSomething()
355
- doSomethingUnambiguous()
356
- end sub
357
- `);
358
- program.validate();
359
- const actions = program.getCodeActions(file.srcPath, util_1.util.createRange(2, 26, 2, 26));
360
- // fix-all only has the unambiguous import, not doSomething (which has 2 options)
361
- const fixAll = actions.find(a => a.title === 'Fix all: Auto fixable missing imports');
362
- (0, chai_config_spec_1.expect)(fixAll).to.be.undefined;
363
- });
364
- it('includes class imports in fix-all', () => {
365
- program.setFile('source/lib1.bs', `
366
- function doSomething()
367
- end function
368
- `);
369
- program.setFile('source/MyClass.bs', `
370
- class MyClass
371
- end class
372
- `);
373
- program.setFile('components/MainScene.xml', (0, testHelpers_spec_1.trim) `<component name="MainScene"></component>`);
374
- const file = program.setFile('components/MainScene.bs', `
375
- sub init()
376
- doSomething()
377
- obj = new MyClass()
378
- end sub
379
- `);
380
- // doSome|thing()
381
- testGetCodeActions(file, util_1.util.createRange(2, 26, 2, 26), [
382
- `Fix all: Auto fixable missing imports`,
383
- `import "pkg:/source/lib1.bs"`
384
- ]);
385
- });
386
- it('deduplicates when multiple missing names resolve to the same file', () => {
387
- program.setFile('source/lib1.bs', `
388
- function doSomething()
389
- end function
390
- function doSomethingElse()
391
- end function
392
- `);
393
- program.setFile('source/lib2.bs', `
394
- function doThird()
395
- end function
396
- `);
397
- program.setFile('components/MainScene.xml', (0, testHelpers_spec_1.trim) `<component name="MainScene"></component>`);
398
- const file = program.setFile('components/MainScene.bs', `
399
- sub init()
400
- doSomething()
401
- doSomethingElse()
402
- doThird()
403
- end sub
404
- `);
405
- program.validate();
406
- const actions = program.getCodeActions(file.srcPath, util_1.util.createRange(2, 26, 2, 26));
407
- const fixAll = actions.find(a => a.title === 'Fix all: Auto fixable missing imports');
408
- // lib1.bs and lib2.bs — only 2 changes despite 3 missing names
409
- (0, chai_config_spec_1.expect)(Object.values(fixAll.edit.changes)[0]).to.have.lengthOf(2);
410
- });
411
- });
412
- it('suggests imports at very start and very end of diagnostic', () => {
413
- program.setFile('source/first.bs', `
414
- namespace alpha
415
- function firstAction()
416
- end function
417
- end namespace
418
- `);
419
- program.setFile('components/MainScene.xml', (0, testHelpers_spec_1.trim) `<component name="MainScene"></component>`);
420
- const file = program.setFile('components/MainScene.bs', `
421
- sub init()
422
- print alpha.firstAction()
423
- end sub
424
- `);
425
- // print |alpha.firstAction()
426
- testGetCodeActions(file, util_1.util.createRange(2, 22, 2, 22), [`import "pkg:/source/first.bs"`]);
427
- // print alpha|.firstAction()
428
- testGetCodeActions(file, util_1.util.createRange(2, 27, 2, 27), [`import "pkg:/source/first.bs"`]);
429
- });
430
- describe('void function return value', () => {
431
- it('suggests deleting the return value and converting the sub to a function', () => {
432
- const file = program.setFile('source/main.brs', `
433
- sub test()
434
- 'should not have a return value here...
435
- return true
436
- end sub
437
- `);
438
- // return tr|ue
439
- testGetCodeActions(file, util_1.util.createRange(3, 29, 3, 29), [`Convert sub to function`, `Remove return value`]);
440
- });
441
- it('suggests converting sub to function with inline body', () => {
442
- const file = program.setFile('source/main.brs', `
443
- sub test() : print "onItemContentChange"
444
- return true
445
- end sub
446
- `);
447
- // return tr|ue
448
- testGetCodeActions(file, util_1.util.createRange(2, 28, 2, 28), [`Convert sub to function`, `Remove return value`]);
449
- // verify only the `sub` and `end sub` keywords are replaced, not the `: print ...` inline body
450
- program.validate();
451
- const actions = program.getCodeActions(file.srcPath, util_1.util.createRange(2, 28, 2, 28));
452
- const convertAction = actions.find(a => a.title === 'Convert sub to function');
453
- const changes = Object.values(convertAction.edit.changes)[0];
454
- // change[0] replaces `sub` keyword only
455
- (0, chai_config_spec_1.expect)(changes[0].range).to.eql(util_1.util.createRange(1, 16, 1, 19));
456
- (0, chai_config_spec_1.expect)(changes[0].newText).to.eql('function');
457
- // change[1] replaces `end sub` keyword only
458
- (0, chai_config_spec_1.expect)(changes[1].range).to.eql(util_1.util.createRange(3, 16, 3, 23));
459
- (0, chai_config_spec_1.expect)(changes[1].newText).to.eql('end function');
460
- });
461
- it('suggests deleting the return type from void function', () => {
462
- const file = program.setFile('source/main.brs', `
463
- function test() as void
464
- 'should not have a return value here...
465
- return true
466
- end function
467
- `);
468
- // return tr|ue
469
- testGetCodeActions(file, util_1.util.createRange(3, 29, 3, 29), [`Remove return type from function declaration`, `Remove return value`]);
470
- });
471
- it('suggests deleting only the return type from void function with inline body', () => {
472
- const file = program.setFile('source/main.brs', `
473
- function test() as void : print "onItemContentChange"
474
- return "test"
475
- end function
476
- `);
477
- // return |"test"
478
- testGetCodeActions(file, util_1.util.createRange(2, 28, 2, 28), [`Remove return type from function declaration`, `Remove return value`]);
479
- // verify only ` as void` is deleted, not the `: print ...` inline body
480
- program.validate();
481
- const actions = program.getCodeActions(file.srcPath, util_1.util.createRange(2, 28, 2, 28));
482
- const removeTypeAction = actions.find(a => a.title === 'Remove return type from function declaration');
483
- const changes = Object.values(removeTypeAction.edit.changes)[0];
484
- // range should span ` as void` only, starting after `)` and ending at the close of `void`
485
- (0, chai_config_spec_1.expect)(changes[0].range).to.eql(util_1.util.createRange(1, 31, 1, 39));
486
- });
487
- it('offers fix-all when multiple void-return violations exist in the file', () => {
488
- const file = program.setFile('source/main.brs', `
489
- sub test1()
490
- return true
491
- end sub
492
- sub test2()
493
- return false
494
- end sub
495
- `);
496
- // return tr|ue (first violation)
497
- testGetCodeActions(file, util_1.util.createRange(2, 27, 2, 27), [
498
- `Convert sub to function`,
499
- `Fix all: Remove void return values`,
500
- `Remove return value`
501
- ]);
502
- });
503
- it('does not offer fix-all when only one void-return violation exists', () => {
504
- const file = program.setFile('source/main.brs', `
505
- sub test1()
506
- return true
507
- end sub
508
- sub test2()
509
- end sub
510
- `);
511
- // return tr|ue
512
- testGetCodeActions(file, util_1.util.createRange(2, 27, 2, 27), [`Convert sub to function`, `Remove return value`]);
513
- });
514
- it('does not duplicate fix-all when multiple violations are at the cursor range', () => {
515
- const file = program.setFile('source/main.brs', `
516
- sub test1()
517
- return true
518
- end sub
519
- sub test2()
520
- return false
521
- end sub
522
- `);
523
- program.validate();
524
- const actions = program.getCodeActions(file.srcPath, util_1.util.createRange(2, 20, 4, 20));
525
- (0, chai_config_spec_1.expect)(actions.filter(a => a.title === 'Fix all: Remove void return values')).to.have.lengthOf(1);
526
- });
527
- });
528
- describe('typed function/sub empty return', () => {
529
- it('suggests deleting the return value and converting the sub to a function', () => {
530
- const file = program.setFile('source/main.brs', `
531
- function test()
532
- 'need a return value here...
533
- return
534
- end function
535
- `);
536
- // ret|urn
537
- testGetCodeActions(file, util_1.util.createRange(3, 23, 3, 23), [`Add void return type to function declaration`, `Convert function to sub`]);
538
- });
539
- it('suggests adding void return type to function with inline body', () => {
540
- const file = program.setFile('source/main.brs', `
541
- function test() : print "onItemContentChange"
542
- return
543
- end function
544
- `);
545
- // ret|urn
546
- testGetCodeActions(file, util_1.util.createRange(2, 23, 2, 23), [`Add void return type to function declaration`, `Convert function to sub`]);
547
- // verify ` as void` is inserted after `)`, not after the inline body
548
- program.validate();
549
- const actions = program.getCodeActions(file.srcPath, util_1.util.createRange(2, 23, 2, 23));
550
- const addVoidAction = actions.find(a => a.title === 'Add void return type to function declaration');
551
- const changes = Object.values(addVoidAction.edit.changes)[0];
552
- // insert position should be immediately after `)`, before ` : print ...`
553
- (0, chai_config_spec_1.expect)(changes[0].range).to.eql(util_1.util.createRange(1, 31, 1, 31));
554
- (0, chai_config_spec_1.expect)(changes[0].newText).to.eql(' as void');
555
- });
556
- it('suggests deleting the return type from void function', () => {
557
- const file = program.setFile('source/main.brs', `
558
- sub test() as integer
559
- 'need a return value here...
560
- return
561
- end sub
562
- `);
563
- // ret|urn
564
- testGetCodeActions(file, util_1.util.createRange(3, 23, 3, 23), [`Remove return type from sub declaration`]);
565
- });
566
- it('suggests deleting only the return type from sub with inline body', () => {
567
- const file = program.setFile('source/main.brs', `
568
- sub test() as integer : print "onItemContentChange"
569
- return
570
- end sub
571
- `);
572
- // ret|urn
573
- testGetCodeActions(file, util_1.util.createRange(2, 23, 2, 23), [`Remove return type from sub declaration`]);
574
- // verify only ` as integer` is deleted, not the `: print ...` inline body
575
- program.validate();
576
- const actions = program.getCodeActions(file.srcPath, util_1.util.createRange(2, 23, 2, 23));
577
- const removeTypeAction = actions.find(a => a.title === 'Remove return type from sub declaration');
578
- const changes = Object.values(removeTypeAction.edit.changes)[0];
579
- // range should span ` as integer` only, starting after `)` and ending at the close of `integer`
580
- (0, chai_config_spec_1.expect)(changes[0].range).to.eql(util_1.util.createRange(1, 26, 1, 37));
581
- });
582
- it('offers fix-all for multiple subs with return types', () => {
583
- const file = program.setFile('source/main.brs', `
584
- sub test1() as integer
585
- return
586
- end sub
587
- sub test2() as string
588
- return
589
- end sub
590
- `);
591
- // ret|urn (first violation)
592
- testGetCodeActions(file, util_1.util.createRange(2, 24, 2, 24), [
593
- `Fix all: Remove return type from sub declarations`,
594
- `Remove return type from sub declaration`
595
- ]);
596
- });
597
- it('offers fix-all for multiple functions with missing return types', () => {
598
- const file = program.setFile('source/main.brs', `
599
- function test1()
600
- return
601
- end function
602
- function test2()
603
- return
604
- end function
605
- `);
606
- // ret|urn (first violation)
607
- testGetCodeActions(file, util_1.util.createRange(2, 24, 2, 24), [
608
- `Add void return type to function declaration`,
609
- `Convert function to sub`,
610
- `Fix all: Add void return type to function declarations`
611
- ]);
612
- });
613
- it('does not offer fix-all when only one non-void-return violation exists', () => {
614
- const file = program.setFile('source/main.brs', `
615
- sub test1() as integer
616
- return
617
- end sub
618
- `);
619
- // ret|urn
620
- testGetCodeActions(file, util_1.util.createRange(2, 24, 2, 24), [`Remove return type from sub declaration`]);
621
- });
622
- it('deduplicates fix-all changes when one function has multiple bare returns', () => {
623
- const file = program.setFile('source/main.brs', `
624
- sub test1() as integer
625
- return
626
- return
627
- end sub
628
- sub test2() as string
629
- return
630
- end sub
631
- `);
632
- program.validate();
633
- const actions = program.getCodeActions(file.srcPath, util_1.util.createRange(2, 24, 2, 24));
634
- const fixAll = actions.find(a => a.title === 'Fix all: Remove return type from sub declarations');
635
- // Two unique functions → two changes (not three)
636
- (0, chai_config_spec_1.expect)(Object.values(fixAll.edit.changes)[0]).to.have.lengthOf(2);
637
- });
638
- });
639
- describe('referencedFileDoesNotExist', () => {
640
- it('offers to remove the script import line', () => {
641
- const file = program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
642
- <?xml version="1.0" encoding="utf-8" ?>
643
- <component name="comp1" extends="Scene">
644
- <script type="text/brightscript" uri="pkg:/source/missing.brs" />
645
- </component>
646
- `);
647
- // uri="pkg:/source/missing.brs" is on line 2
648
- testGetCodeActions(file, util_1.util.createRange(2, 50, 2, 50), ['Remove script import']);
649
- });
650
- it('deletes the entire script tag line', () => {
651
- const file = program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
652
- <?xml version="1.0" encoding="utf-8" ?>
653
- <component name="comp1" extends="Scene">
654
- <script type="text/brightscript" uri="pkg:/source/missing.brs" />
655
- </component>
656
- `);
657
- program.validate();
658
- (0, testHelpers_spec_1.expectCodeActions)(() => {
659
- program.getCodeActions(file.srcPath, util_1.util.createRange(2, 50, 2, 50));
660
- }, [{
661
- title: 'Remove script import',
662
- kind: 'quickfix',
663
- changes: [{
664
- type: 'delete',
665
- filePath: (0, util_1.standardizePath) `${testHelpers_spec_2.rootDir}/components/comp1.xml`,
666
- range: util_1.util.createRange(2, 0, 3, 0)
667
- }]
668
- }]);
669
- });
670
- it('offers fix-all when multiple missing imports exist', () => {
671
- const file = program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
672
- <?xml version="1.0" encoding="utf-8" ?>
673
- <component name="comp1" extends="Scene">
674
- <script type="text/brightscript" uri="pkg:/source/missing1.brs" />
675
- <script type="text/brightscript" uri="pkg:/source/missing2.brs" />
676
- </component>
677
- `);
678
- testGetCodeActions(file, util_1.util.createRange(2, 50, 2, 50), [
679
- 'Fix all: Remove script imports',
680
- 'Remove script import'
681
- ]);
682
- });
683
- });
684
- describe('unnecessaryScriptImportInChildFromParent', () => {
685
- it('offers to remove the redundant script import', () => {
686
- program.setFile('components/parent.xml', (0, testHelpers_spec_1.trim) `
687
- <?xml version="1.0" encoding="utf-8" ?>
688
- <component name="ParentScene" extends="Scene">
689
- <script type="text/brightscript" uri="pkg:/source/lib.brs" />
690
- </component>
691
- `);
692
- program.setFile('source/lib.brs', '');
693
- const file = program.setFile('components/child.xml', (0, testHelpers_spec_1.trim) `
694
- <?xml version="1.0" encoding="utf-8" ?>
695
- <component name="ChildScene" extends="ParentScene">
696
- <script type="text/brightscript" uri="pkg:/source/lib.brs" />
697
- </component>
698
- `);
699
- // uri on line 2 of child.xml
700
- testGetCodeActions(file, util_1.util.createRange(2, 50, 2, 50), ['Remove redundant script import']);
701
- });
702
- it('offers fix-all when multiple redundant imports exist', () => {
703
- program.setFile('components/parent.xml', (0, testHelpers_spec_1.trim) `
704
- <?xml version="1.0" encoding="utf-8" ?>
705
- <component name="ParentScene" extends="Scene">
706
- <script type="text/brightscript" uri="pkg:/source/lib1.brs" />
707
- <script type="text/brightscript" uri="pkg:/source/lib2.brs" />
708
- </component>
709
- `);
710
- program.setFile('source/lib1.brs', '');
711
- program.setFile('source/lib2.brs', '');
712
- const file = program.setFile('components/child.xml', (0, testHelpers_spec_1.trim) `
713
- <?xml version="1.0" encoding="utf-8" ?>
714
- <component name="ChildScene" extends="ParentScene">
715
- <script type="text/brightscript" uri="pkg:/source/lib1.brs" />
716
- <script type="text/brightscript" uri="pkg:/source/lib2.brs" />
717
- </component>
718
- `);
719
- testGetCodeActions(file, util_1.util.createRange(2, 50, 2, 50), [
720
- 'Fix all: Remove redundant script imports',
721
- 'Remove redundant script import'
722
- ]);
723
- });
724
- });
725
- describe('unnecessaryCodebehindScriptImport', () => {
726
- it('offers to remove the unnecessary codebehind import', () => {
727
- const file = program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
728
- <?xml version="1.0" encoding="utf-8" ?>
729
- <component name="comp1" extends="Scene">
730
- <script type="text/brightscript" uri="pkg:/components/comp1.brs" />
731
- </component>
732
- `);
733
- program.setFile('components/comp1.brs', '');
734
- // uri on line 2
735
- testGetCodeActions(file, util_1.util.createRange(2, 50, 2, 50), ['Remove unnecessary codebehind import']);
736
- });
737
- });
738
- describe('scriptImportCaseMismatch', () => {
739
- it('offers to fix the casing of the script import path', () => {
740
- const file = program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
741
- <?xml version="1.0" encoding="utf-8" ?>
742
- <component name="comp1" extends="Scene">
743
- <script type="text/brightscript" uri="pkg:/SOURCE/lib.brs" />
744
- </component>
745
- `);
746
- program.setFile('source/lib.brs', '');
747
- testGetCodeActions(file, util_1.util.createRange(2, 50, 2, 50), ['Fix script import path casing']);
748
- });
749
- it('replaces the URI value with the correctly-cased path', () => {
750
- const file = program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
751
- <?xml version="1.0" encoding="utf-8" ?>
752
- <component name="comp1" extends="Scene">
753
- <script type="text/brightscript" uri="pkg:/SOURCE/lib.brs" />
754
- </component>
755
- `);
756
- program.setFile('source/lib.brs', '');
757
- program.validate();
758
- const actions = program.getCodeActions(file.srcPath, util_1.util.createRange(2, 50, 2, 50));
759
- const fix = actions.find(a => a.title === 'Fix script import path casing');
760
- const changes = Object.values(fix.edit.changes)[0];
761
- (0, chai_config_spec_1.expect)(changes[0].newText).to.equal('pkg:/source/lib.brs');
762
- });
763
- it('offers fix-all when multiple case-mismatched imports exist', () => {
764
- const file = program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
765
- <?xml version="1.0" encoding="utf-8" ?>
766
- <component name="comp1" extends="Scene">
767
- <script type="text/brightscript" uri="pkg:/SOURCE/lib1.brs" />
768
- <script type="text/brightscript" uri="pkg:/SOURCE/lib2.brs" />
769
- </component>
770
- `);
771
- program.setFile('source/lib1.brs', '');
772
- program.setFile('source/lib2.brs', '');
773
- testGetCodeActions(file, util_1.util.createRange(2, 50, 2, 50), [
774
- 'Fix all: Fix script import path casing',
775
- 'Fix script import path casing'
776
- ]);
777
- });
778
- it('offers to fix the casing of a relative script import path', () => {
779
- const file = program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
780
- <?xml version="1.0" encoding="utf-8" ?>
781
- <component name="comp1" extends="Scene">
782
- <script type="text/brightscript" uri="LIB.brs" />
783
- </component>
784
- `);
785
- program.setFile('components/lib.brs', '');
786
- testGetCodeActions(file, util_1.util.createRange(2, 45, 2, 45), ['Fix script import path casing']);
787
- });
788
- it('replaces a relative URI with the correctly-cased relative path', () => {
789
- const file = program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
790
- <?xml version="1.0" encoding="utf-8" ?>
791
- <component name="comp1" extends="Scene">
792
- <script type="text/brightscript" uri="LIB.brs" />
793
- </component>
794
- `);
795
- program.setFile('components/lib.brs', '');
796
- program.validate();
797
- const actions = program.getCodeActions(file.srcPath, util_1.util.createRange(2, 45, 2, 45));
798
- const fix = actions.find(a => a.title === 'Fix script import path casing');
799
- const changes = Object.values(fix.edit.changes)[0];
800
- (0, chai_config_spec_1.expect)(changes[0].newText).to.equal('lib.brs');
801
- });
802
- it('replaces a cross-directory relative URI with the correctly-cased relative path', () => {
803
- const file = program.setFile('components/sub/comp1.xml', (0, testHelpers_spec_1.trim) `
804
- <?xml version="1.0" encoding="utf-8" ?>
805
- <component name="comp1" extends="Scene">
806
- <script type="text/brightscript" uri="../utils/HELPER.brs" />
807
- </component>
808
- `);
809
- program.setFile('components/utils/helper.brs', '');
810
- program.validate();
811
- const actions = program.getCodeActions(file.srcPath, util_1.util.createRange(2, 50, 2, 50));
812
- const fix = actions.find(a => a.title === 'Fix script import path casing');
813
- const changes = Object.values(fix.edit.changes)[0];
814
- (0, chai_config_spec_1.expect)(changes[0].newText).to.equal('../utils/helper.brs');
815
- });
816
- });
817
- describe('missingOverrideKeyword', () => {
818
- it('offers to add the override keyword', () => {
819
- program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `<component name="comp1" extends="Scene"></component>`);
820
- const file = program.setFile('components/comp1.bs', `
821
- class Animal
822
- function speak()
823
- end function
824
- end class
825
- class Dog extends Animal
826
- function speak()
827
- end function
828
- end class
829
- `);
830
- // "function speak()" in Dog — diagnostic starts at the function keyword on line 6
831
- testGetCodeActions(file, util_1.util.createRange(6, 20, 6, 20), [`Add missing 'override' keyword`]);
832
- });
833
- it('inserts override before the function keyword', () => {
834
- program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `<component name="comp1" extends="Scene"></component>`);
835
- const file = program.setFile('components/comp1.bs', `
836
- class Animal
837
- function speak()
838
- end function
839
- end class
840
- class Dog extends Animal
841
- function speak()
842
- end function
843
- end class
844
- `);
845
- program.validate();
846
- const actions = program.getCodeActions(file.srcPath, util_1.util.createRange(6, 20, 6, 20));
847
- const fix = actions.find(a => a.title === `Add missing 'override' keyword`);
848
- const changes = Object.values(fix.edit.changes)[0];
849
- (0, chai_config_spec_1.expect)(changes[0].newText).to.equal('override ');
850
- });
851
- it('offers fix-all when multiple methods are missing override', () => {
852
- program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `<component name="comp1" extends="Scene"></component>`);
853
- const file = program.setFile('components/comp1.bs', `
854
- class Animal
855
- function speak()
856
- end function
857
- function move()
858
- end function
859
- end class
860
- class Dog extends Animal
861
- function speak()
862
- end function
863
- function move()
864
- end function
865
- end class
866
- `);
867
- testGetCodeActions(file, util_1.util.createRange(8, 20, 8, 20), [
868
- `Add missing 'override' keyword`,
869
- `Fix all: Add missing 'override' keywords`
870
- ]);
871
- });
872
- });
873
- describe('cannotUseOverrideKeywordOnConstructorFunction', () => {
874
- it('offers to remove override from constructor', () => {
875
- const file = program.setFile('source/main.bs', `
876
- class Dog
877
- override function new()
878
- end function
879
- end class
880
- `);
881
- // "override" is on line 2
882
- testGetCodeActions(file, util_1.util.createRange(2, 20, 2, 20), [`Remove 'override' from constructor`]);
883
- });
884
- it('deletes the override keyword and trailing space', () => {
885
- const file = program.setFile('source/main.bs', `
886
- class Dog
887
- override function new()
888
- end function
889
- end class
890
- `);
891
- program.validate();
892
- const actions = program.getCodeActions(file.srcPath, util_1.util.createRange(2, 20, 2, 20));
893
- const fix = actions.find(a => a.title === `Remove 'override' from constructor`);
894
- const changes = Object.values(fix.edit.changes)[0];
895
- // range covers "override " (8 chars + 1 space)
896
- (0, chai_config_spec_1.expect)(changes[0].range.start.character).to.equal(changes[0].range.end.character - 9);
897
- });
898
- });
899
- describe('mismatched loop terminator', () => {
900
- it('offers a single quick fix for `while ... next`', () => {
901
- const file = program.setFile('source/main.bs', `
902
- sub a()
903
- while n <= 3
904
- n = n + 1
905
- next
906
- end sub
907
- `);
908
- // cursor on the bogus `next` (line 4)
909
- testGetCodeActions(file, util_1.util.createRange(4, 20, 4, 20), [`Convert 'next' to 'end while'`]);
910
- });
911
- it('replaces only the bogus `next` token, preserving indentation', () => {
912
- const file = program.setFile('source/main.bs', `
913
- sub a()
914
- while n <= 3
915
- n = n + 1
916
- next
917
- end sub
918
- `);
919
- program.validate();
920
- const actions = program.getCodeActions(file.srcPath, util_1.util.createRange(4, 20, 4, 20));
921
- const fix = actions.find(a => a.title === `Convert 'next' to 'end while'`);
922
- const changes = Object.values(fix.edit.changes)[0];
923
- (0, chai_config_spec_1.expect)(changes).to.be.lengthOf(1);
924
- (0, chai_config_spec_1.expect)(changes[0].newText).to.equal('end while');
925
- //the replace range is exactly the 4-character `next` token
926
- (0, chai_config_spec_1.expect)(changes[0].range.end.character - changes[0].range.start.character).to.equal(4);
927
- });
928
- it('marks the `end while` quick fix as preferred for `while ... next`', () => {
929
- const file = program.setFile('source/main.bs', `
930
- sub a()
931
- while n <= 3
932
- n = n + 1
933
- next
934
- end sub
935
- `);
936
- program.validate();
937
- const actions = program.getCodeActions(file.srcPath, util_1.util.createRange(4, 20, 4, 20));
938
- const fix = actions.find(a => a.title === `Convert 'next' to 'end while'`);
939
- (0, chai_config_spec_1.expect)(fix.isPreferred).to.equal(true);
940
- });
941
- it('offers a fix-all for multiple `while ... next` instances in the same file', () => {
942
- const file = program.setFile('source/main.bs', `
943
- sub a()
944
- while x
945
- x = false
946
- next
947
- while y
948
- y = false
949
- next
950
- end sub
951
- `);
952
- //cursor on the first bogus `next`
953
- testGetCodeActions(file, util_1.util.createRange(4, 20, 4, 20), [
954
- `Convert 'next' to 'end while'`,
955
- `Fix all: Convert 'next' to 'end while'`
956
- ]);
957
- });
958
- it('offers two quick fixes (end for preferred, next) for `for ... end while`', () => {
959
- const file = program.setFile('source/main.bs', `
960
- sub a()
961
- for i = 0 to 3
962
- print i
963
- end while
964
- end sub
965
- `);
966
- testGetCodeActions(file, util_1.util.createRange(4, 20, 4, 20), [
967
- `Convert 'end while' to 'end for'`,
968
- `Convert 'end while' to 'next'`
969
- ]);
970
- });
971
- it('marks the `end for` quick fix as preferred and `next` as non-preferred', () => {
972
- const file = program.setFile('source/main.bs', `
973
- sub a()
974
- for i = 0 to 3
975
- print i
976
- end while
977
- end sub
978
- `);
979
- program.validate();
980
- const actions = program.getCodeActions(file.srcPath, util_1.util.createRange(4, 20, 4, 20));
981
- const endForFix = actions.find(a => a.title === `Convert 'end while' to 'end for'`);
982
- const nextFix = actions.find(a => a.title === `Convert 'end while' to 'next'`);
983
- (0, chai_config_spec_1.expect)(endForFix.isPreferred).to.equal(true);
984
- (0, chai_config_spec_1.expect)(nextFix.isPreferred).to.not.equal(true);
985
- });
986
- it('offers two quick fixes for `for each ... end while`', () => {
987
- const file = program.setFile('source/main.bs', `
988
- sub a()
989
- for each x in arr
990
- print x
991
- end while
992
- end sub
993
- `);
994
- testGetCodeActions(file, util_1.util.createRange(4, 20, 4, 20), [
995
- `Convert 'end while' to 'end for'`,
996
- `Convert 'end while' to 'next'`
997
- ]);
998
- });
999
- it('offers fix-all variants for both end for and next when there are multiple `for ... end while` instances', () => {
1000
- const file = program.setFile('source/main.bs', `
1001
- sub a()
1002
- for i = 0 to 3
1003
- print i
1004
- end while
1005
- for j = 0 to 3
1006
- print j
1007
- end while
1008
- end sub
1009
- `);
1010
- //cursor on the first bogus `end while`
1011
- testGetCodeActions(file, util_1.util.createRange(4, 20, 4, 20), [
1012
- `Convert 'end while' to 'end for'`,
1013
- `Convert 'end while' to 'next'`,
1014
- `Fix all: Convert 'end while' to 'end for'`,
1015
- `Fix all: Convert 'end while' to 'next'`
1016
- ]);
1017
- });
1018
- it('does not offer the quick fix for a valid `for ... next`', () => {
1019
- const file = program.setFile('source/main.bs', `
1020
- sub a()
1021
- for i = 0 to 3
1022
- print i
1023
- next
1024
- end sub
1025
- `);
1026
- //cursor on the valid `next`
1027
- testGetCodeActions(file, util_1.util.createRange(4, 20, 4, 20), []);
1028
- });
1029
- });
1030
- describe('disable diagnostic actions', () => {
1031
- const findLineAction = (actions, code) => actions.find(a => a.title.startsWith(`Disable ${code} for this line`));
1032
- const findFileAction = (actions, code) => actions.find(a => a.title.startsWith(`Disable ${code} for this file`));
1033
- it('emits "Disable for this line" and "Disable for this file" actions for any diagnostic with a code', () => {
1034
- const file = program.setFile('source/main.bs', `
1035
- sub init()
1036
- doSomething()
1037
- end sub
1038
- `);
1039
- program.validate();
1040
- const actions = program.getCodeActions(file.srcPath, util_1.util.createRange(2, 22, 2, 22));
1041
- //the diagnostic for an undefined function — code is `cannotFindFunction` (1140)
1042
- (0, chai_config_spec_1.expect)(findLineAction(actions, 1140), 'expected a "Disable 1140 for this line: ..." action').to.exist;
1043
- (0, chai_config_spec_1.expect)(findFileAction(actions, 1140), 'expected a "Disable 1140 for this file: ..." action').to.exist;
1044
- });
1045
- it('includes the diagnostic message in the action title', () => {
1046
- const file = program.setFile('source/main.bs', `
1047
- sub init()
1048
- doSomething()
1049
- end sub
1050
- `);
1051
- program.validate();
1052
- const actions = program.getCodeActions(file.srcPath, util_1.util.createRange(2, 22, 2, 22));
1053
- const action = findLineAction(actions, 1140);
1054
- (0, chai_config_spec_1.expect)(action.title).to.match(/^Disable 1140 for this line: .+/);
1055
- //the message portion is the diagnostic's message, so it should mention the missing function name
1056
- (0, chai_config_spec_1.expect)(action.title).to.include('doSomething');
1057
- });
1058
- it('inserts a bs:disable-next-line directive above the diagnostic, preserving indent', () => {
1059
- const file = program.setFile('source/main.bs', `
1060
- sub init()
1061
- doSomething()
1062
- end sub
1063
- `);
1064
- program.validate();
1065
- const action = findLineAction(program.getCodeActions(file.srcPath, util_1.util.createRange(2, 22, 2, 22)), 1140);
1066
- (0, chai_config_spec_1.expect)(action).to.exist;
1067
- const edits = Object.values(action.edit.changes)[0];
1068
- (0, chai_config_spec_1.expect)(edits).to.have.lengthOf(1);
1069
- //" doSomething()" — 20 spaces of indent on line 2
1070
- (0, chai_config_spec_1.expect)(edits[0].newText).to.equal(` ' bs:disable-next-line: 1140\n`);
1071
- (0, chai_config_spec_1.expect)(edits[0].range).to.eql(util_1.util.createRange(2, 0, 2, 0));
1072
- });
1073
- it('inserts a bs:disable directive at line 0 in a brs/bs file', () => {
1074
- const file = program.setFile('source/main.bs', `
1075
- sub init()
1076
- doSomething()
1077
- end sub
1078
- `);
1079
- program.validate();
1080
- const action = findFileAction(program.getCodeActions(file.srcPath, util_1.util.createRange(2, 22, 2, 22)), 1140);
1081
- (0, chai_config_spec_1.expect)(action).to.exist;
1082
- const edits = Object.values(action.edit.changes)[0];
1083
- (0, chai_config_spec_1.expect)(edits[0].newText).to.equal(`' bs:disable: 1140\n`);
1084
- (0, chai_config_spec_1.expect)(edits[0].range).to.eql(util_1.util.createRange(0, 0, 0, 0));
1085
- });
1086
- it('inserts an XML-style bs:disable directive after the XML declaration', () => {
1087
- const file = program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
1088
- <?xml version="1.0" encoding="utf-8" ?>
1089
- <component name="comp1">
1090
- </component>
1091
- `);
1092
- program.validate();
1093
- const action = program.getCodeActions(file.srcPath, util_1.util.createRange(1, 5, 1, 5))
1094
- .find(a => /^Disable .+ for this file/.test(a.title));
1095
- (0, chai_config_spec_1.expect)(action).to.exist;
1096
- const edits = Object.values(action.edit.changes)[0];
1097
- //inserted right after `?>` on line 0 with a leading newline so the directive sits on its own line
1098
- (0, chai_config_spec_1.expect)(edits[0].newText.startsWith('\n<!-- bs:disable: ')).to.be.true;
1099
- (0, chai_config_spec_1.expect)(edits[0].newText.endsWith(' -->')).to.be.true;
1100
- (0, chai_config_spec_1.expect)(edits[0].range.start.line).to.equal(0);
1101
- });
1102
- it('inserts an XML-style bs:disable directive at line 0 when the <?xml ?> declaration is missing', () => {
1103
- //Roku permits XML component files without the optional `<?xml ?>` declaration
1104
- const file = program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
1105
- <component name="comp1">
1106
- </component>
1107
- `);
1108
- program.validate();
1109
- const action = program.getCodeActions(file.srcPath, util_1.util.createRange(0, 5, 0, 5))
1110
- .find(a => /^Disable .+ for this file/.test(a.title));
1111
- (0, chai_config_spec_1.expect)(action).to.exist;
1112
- const edits = Object.values(action.edit.changes)[0];
1113
- //no declaration to anchor to, so insert at the very top with a trailing newline
1114
- (0, chai_config_spec_1.expect)(edits[0].newText.startsWith('<!-- bs:disable: ')).to.be.true;
1115
- (0, chai_config_spec_1.expect)(edits[0].newText.endsWith(' -->\n')).to.be.true;
1116
- (0, chai_config_spec_1.expect)(edits[0].range).to.eql(util_1.util.createRange(0, 0, 0, 0));
1117
- });
1118
- it('does not emit disable actions for diagnostics without a code', () => {
1119
- const file = program.setFile('source/main.bs', `
1120
- sub init()
1121
- end sub
1122
- `);
1123
- program.validate();
1124
- //inject a diagnostic with no code into the event
1125
- const range = util_1.util.createRange(1, 16, 1, 16);
1126
- const event = {
1127
- program: program,
1128
- file: file,
1129
- range: range,
1130
- scopes: program.getScopesForFile(file),
1131
- diagnostics: [{ code: undefined, message: 'no code', range: range, file: file }],
1132
- codeActions: []
1133
- };
1134
- new CodeActionsProcessor_1.CodeActionsProcessor(event).process();
1135
- (0, chai_config_spec_1.expect)(event.codeActions.filter(a => /^Disable .+ for this/.test(a.title))).to.be.empty;
1136
- });
1137
- it('extends an existing bs:disable-next-line directive instead of inserting a new one', () => {
1138
- const file = program.setFile('source/main.bs', `
1139
- sub init()
1140
- ' bs:disable-next-line: 9999
1141
- doSomething()
1142
- end sub
1143
- `);
1144
- program.validate();
1145
- //the diagnostic is on line 3 (the doSomething call). The existing directive sits on line 2.
1146
- const action = findLineAction(program.getCodeActions(file.srcPath, util_1.util.createRange(3, 22, 3, 22)), 1140);
1147
- (0, chai_config_spec_1.expect)(action).to.exist;
1148
- const edits = Object.values(action.edit.changes)[0];
1149
- (0, chai_config_spec_1.expect)(edits).to.have.lengthOf(1);
1150
- //replaces the existing comment with a merged version
1151
- (0, chai_config_spec_1.expect)(edits[0].newText).to.equal(`' bs:disable-next-line: 9999 1140`);
1152
- });
1153
- it('extends an existing trailing bs:disable-line directive', () => {
1154
- const file = program.setFile('source/main.bs', `
1155
- sub init()
1156
- doSomething() ' bs:disable-line: 9999
1157
- end sub
1158
- `);
1159
- program.validate();
1160
- const action = findLineAction(program.getCodeActions(file.srcPath, util_1.util.createRange(2, 22, 2, 22)), 1140);
1161
- (0, chai_config_spec_1.expect)(action).to.exist;
1162
- const edits = Object.values(action.edit.changes)[0];
1163
- (0, chai_config_spec_1.expect)(edits[0].newText).to.equal(`' bs:disable-line: 9999 1140`);
1164
- });
1165
- it('extends an existing header-level bs:disable directive instead of inserting a new one', () => {
1166
- const file = program.setFile('source/main.bs', `' bs:disable: 9999
1167
- sub init()
1168
- doSomething()
1169
- end sub
1170
- `);
1171
- program.validate();
1172
- const action = findFileAction(program.getCodeActions(file.srcPath, util_1.util.createRange(2, 22, 2, 22)), 1140);
1173
- (0, chai_config_spec_1.expect)(action).to.exist;
1174
- const edits = Object.values(action.edit.changes)[0];
1175
- (0, chai_config_spec_1.expect)(edits[0].newText).to.equal(`' bs:disable: 9999 1140`);
1176
- });
1177
- it('extends an existing XML header-level bs:disable directive', () => {
1178
- const file = program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
1179
- <?xml version="1.0" encoding="utf-8" ?>
1180
- <!-- bs:disable: 9999 -->
1181
- <component name="comp1">
1182
- </component>
1183
- `);
1184
- program.validate();
1185
- const action = program.getCodeActions(file.srcPath, util_1.util.createRange(2, 5, 2, 5))
1186
- .find(a => /^Disable .+ for this file/.test(a.title));
1187
- (0, chai_config_spec_1.expect)(action).to.exist;
1188
- const edits = Object.values(action.edit.changes)[0];
1189
- //the new code is appended to the existing space-separated list
1190
- (0, chai_config_spec_1.expect)(/^<!-- bs:disable: 9999 \d+ -->$/.test(edits[0].newText)).to.be.true;
1191
- });
1192
- it('does not duplicate the code when it is already in an existing directive', () => {
1193
- const file = program.setFile('source/main.bs', `
1194
- sub init()
1195
- ' bs:disable-next-line: 9001
1196
- print "hello"
1197
- end sub
1198
- `);
1199
- program.validate();
1200
- //inject a synthetic diagnostic so we can exercise the no-op path with a code that's already listed in the existing directive
1201
- const range = util_1.util.createRange(3, 22, 3, 22);
1202
- const event = {
1203
- program: program,
1204
- file: file,
1205
- range: range,
1206
- scopes: program.getScopesForFile(file),
1207
- diagnostics: [{ code: 9001, message: 'fake diagnostic', range: range, file: file }],
1208
- codeActions: []
1209
- };
1210
- new CodeActionsProcessor_1.CodeActionsProcessor(event).process();
1211
- //the line action should be skipped (already in directive); the file action should still be available
1212
- (0, chai_config_spec_1.expect)(findLineAction(event.codeActions, 9001)).to.be.undefined;
1213
- (0, chai_config_spec_1.expect)(findFileAction(event.codeActions, 9001)).to.exist;
1214
- });
1215
- it('skips the line action when an existing directive suppresses all codes', () => {
1216
- const file = program.setFile('source/main.bs', `
1217
- sub init()
1218
- ' bs:disable-next-line
1219
- print "hello"
1220
- end sub
1221
- `);
1222
- program.validate();
1223
- const range = util_1.util.createRange(3, 22, 3, 22);
1224
- const event = {
1225
- program: program,
1226
- file: file,
1227
- range: range,
1228
- scopes: program.getScopesForFile(file),
1229
- diagnostics: [{ code: 9001, message: 'fake diagnostic', range: range, file: file }],
1230
- codeActions: []
1231
- };
1232
- new CodeActionsProcessor_1.CodeActionsProcessor(event).process();
1233
- (0, chai_config_spec_1.expect)(findLineAction(event.codeActions, 9001)).to.be.undefined;
1234
- });
1235
- });
1236
- });
1237
- //# sourceMappingURL=CodeActionsProcessor.spec.js.map