@@ -50,57 +50,55 @@ While there are no restrictions on plugin names, it helps others to find your pl
5050
5151Full compiler lifecycle:
5252
53- - ` beforeProgramCreate `
54- - ` afterProgramCreate `
55- - ` afterScopeCreate ` ("source" scope)
53+ - ` beforeProvideProgram `
54+ - ` afterProvideProgram `
55+ - ` afterProvideScope ` ("source" scope)
5656 - For each physical file:
5757 - ` beforeProvideFile `
5858 - ` onProvideFile `
5959 - ` afterProvideFile `
60- - ` beforeFileParse ` (deprecated)
61- - ` afterFileParse ` (deprecated)
6260 - For each physical and virtual file
6361 - ` beforeAddFile `
6462 - ` afterAddFile `
65- - ` afterScopeCreate ` (component scope)
66- - ` beforeProgramValidate `
63+ - ` afterProvideScope ` (component scope)
64+ - ` beforeValidateProgram `
6765 - For each file:
68- - ` beforeFileValidate `
69- - ` onFileValidate `
70- - ` afterFileValidate `
66+ - ` beforeValidateFile `
67+ - ` validateFile `
68+ - ` afterValidateFile `
7169 - For each scope:
72- - ` beforeScopeValidate `
73- - ` onScopeValidate `
74- - ` afterScopeValidate `
75- - ` afterProgramValidate `
70+ - ` beforeValidateScope `
71+ - ` validateScope `
72+ - ` afterValidateScope `
73+ - ` afterValidateProgram `
7674- ` beforePrepublish `
7775- ` afterPrepublish `
78- - ` beforePublish `
79- - ` beforeProgramTranspile `
76+ - ` beforeSerializeProgram `
77+ - ` beforeBuildProgram `
8078 - For each file:
81- - ` beforeFileTranspile `
82- - ` afterFileTranspile `
83- - ` afterProgramTranspile `
84- - ` afterPublish `
85- - ` beforeProgramDispose `
79+ - ` beforePrepareFile `
80+ - ` afterPrepareFile `
81+ - ` afterBuildProgram `
82+ - ` afterSerializeProgram `
83+ - ` beforeRemoveProgram `
8684
8785### Language server
8886
8987Once the program has been validated, the language server runs a special loop - it never reaches the publishing steps.
9088
9189When a file is removed:
9290
93- - ` beforeFileDispose `
94- - ` beforeScopeDispose ` (component scope)
95- - ` afterScopeDispose ` (component scope)
96- - ` afterFileDispose `
91+ - ` beforeRemoveFile `
92+ - ` beforeRemoveScope ` (component scope)
93+ - ` afterRemoveScope ` (component scope)
94+ - ` afterRemoveFile `
9795
9896When a file is added:
9997
100- - ` beforeFileParse `
101- - ` afterFileParse `
102- - ` afterScopeCreate ` (component scope)
103- - ` afterFileValidate `
98+ - ` beforeProvideFile `
99+ - ` afterProvideFile `
100+ - ` afterProvideScope ` (component scope)
101+ - ` afterValidateFile `
104102
105103When any file is modified:
106104
@@ -109,18 +107,18 @@ When any file is modified:
109107
110108After file addition/removal (note: throttled/debounced):
111109
112- - ` beforeProgramValidate `
110+ - ` beforeValidateProgram `
113111- For each invalidated/not-yet-validated file
114- - ` beforeFileValidate `
115- - ` onFileValidate `
116- - ` afterFileValidate `
112+ - ` beforeValidateFile `
113+ - ` validateFile `
114+ - ` afterValidateFile `
117115- For each invalidated scope:
118- - ` beforeScopeValidate `
119- - ` afterScopeValidate `
120- - ` afterProgramValidate `
116+ - ` beforeValidateScope `
117+ - ` afterValidateScope `
118+ - ` afterValidateProgram `
121119
122120Code Actions
123- - ` onGetCodeActions `
121+ - ` provideCodeActions `
124122
125123Completions
126124 - ` beforeProvideCompletions `
@@ -133,7 +131,7 @@ Hovers
133131 - ` afterProvideHover `
134132
135133Semantic Tokens
136- - ` onGetSemanticTokens `
134+ - ` provideSemanticTokens `
137135
138136
139137## Compiler API
@@ -164,11 +162,11 @@ export interface CompilerPlugin {
164162 /**
165163 * Called before a new program is created
166164 */
167- beforeProgramCreate ? (event : BeforeProgramCreateEvent ): any ;
165+ beforeProvideProgram ? (event : BeforeProvideProgramEvent ): any ;
168166 /**
169167 * Called after a new program is created
170168 */
171- afterProgramCreate ? (event : AfterProgramCreateEvent ): any ;
169+ afterProvideProgram ? (event : AfterProvideProgramEvent ): any ;
172170
173171
174172 /**
@@ -188,20 +186,20 @@ export interface CompilerPlugin {
188186 /**
189187 * Called before the entire program is validated
190188 */
191- beforeProgramValidate ? (event : BeforeProgramValidateEvent ): any ;
189+ beforeValidateProgram ? (event : BeforeValidateProgramEvent ): any ;
192190 /**
193191 * Called before the entire program is validated
194192 */
195- onProgramValidate ? (event : OnProgramValidateEvent ): any ;
193+ validateProgram ? (event : ValidateProgramEvent ): any ;
196194 /**
197195 * Called after the program has been validated
198196 */
199- afterProgramValidate ? (event : AfterProgramValidateEvent ): any ;
197+ afterValidateProgram ? (event : AfterValidateProgramEvent ): any ;
200198
201199 /**
202200 * Called right before the program is disposed/destroyed
203201 */
204- beforeProgramDispose ? (event : BeforeProgramDisposeEvent ): any ;
202+ beforeRemoveProgram ? (event : BeforeRemoveProgramEvent ): any ;
205203
206204 /**
207205 * Emitted before the program starts collecting completions
@@ -233,13 +231,13 @@ export interface CompilerPlugin {
233231 /**
234232 * Called after a scope was created
235233 */
236- afterScopeCreate ? (event : AfterScopeCreateEvent ): any ;
234+ afterProvideScope ? (event : AfterProvideScopeEvent ): any ;
237235
238- beforeScopeDispose ? (event : BeforeScopeDisposeEvent ): any ;
239- onScopeDispose ? (event : OnScopeDisposeEvent ): any ;
240- afterScopeDispose ? (event : AfterScopeDisposeEvent ): any ;
236+ beforeRemoveScope ? (event : BeforeRemoveProgramEvent ): any ;
237+ removeScope ? (event : RemoveScopeEvent ): any ;
238+ afterRemoveScope ? (event : AfterRemoveScopeEvent ): any ;
241239
242- beforeScopeValidate ? (event : BeforeScopeValidateEvent ): any ;
240+ beforeValidateScope ? (event : BeforeValidateScopeEvent ): any ;
243241
244242 /**
245243 * Called before the `provideDefinition` hook
@@ -305,13 +303,13 @@ export interface CompilerPlugin {
305303 afterProvideWorkspaceSymbols? (event : AfterProvideWorkspaceSymbolsEvent ): any ;
306304
307305
308- onGetSemanticTokens ? : PluginHandler <OnGetSemanticTokensEvent >;
306+ provideSemanticTokens ? : PluginHandler <ProvideSemanticTokensEvent >;
309307 // scope events
310- onScopeValidate ? (event : OnScopeValidateEvent ): any ;
311- afterScopeValidate ? (event : BeforeScopeValidateEvent ): any ;
308+ validateScope ? (event : ValidateScopeEvent ): any ;
309+ afterValidateScope ? (event : BeforeValidateScopeEvent ): any ;
312310
313- onGetCodeActions ? (event : OnGetCodeActionsEvent ): any ;
314- onGetSemanticTokens ? (event : OnGetSemanticTokensEvent ): any ;
311+ provideCodeActions ? (event : ProvideCodeActionsEvent ): any ;
312+ provideSemanticTokens ? (event : ProvideSemanticTokensEvent ): any ;
315313
316314
317315 /**
@@ -333,35 +331,35 @@ export interface CompilerPlugin {
333331 * Called before a file is added to the program.
334332 * Includes physical files as well as any virtual files produced by `provideFile` events
335333 */
336- beforeFileAdd ? (event : BeforeFileAddEvent ): any ;
334+ beforeAddFile ? (event : BeforeAddFileEvent ): any ;
337335 /**
338336 * Called after a file has been added to the program.
339337 * Includes physical files as well as any virtual files produced by `provideFile` events
340338 */
341- afterFileAdd ? (event : AfterFileAddEvent ): any ;
339+ afterAddFile ? (event : AfterAddFileEvent ): any ;
342340
343341 /**
344342 * Called before a file is removed from the program. This includes physical and virtual files
345343 */
346- beforeFileRemove ? (event : BeforeFileRemoveEvent ): any ;
344+ beforeRemoveFile ? (event : BeforeRemoveFileEvent ): any ;
347345 /**
348346 * Called after a file has been removed from the program. This includes physical and virtual files
349347 */
350- afterFileRemove ? (event : AfterFileRemoveEvent ): any ;
348+ afterRemoveFile ? (event : AfterRemoveFileEvent ): any ;
351349
352350
353351 /**
354352 * Called before each file is validated
355353 */
356- beforeFileValidate ? (event : BeforeFileValidateEvent ): any ;
354+ beforeValidateFile ? (event : BeforeValidateFileEvent ): any ;
357355 /**
358356 * Called during the file validation process. If your plugin contributes file validations, this is a good place to contribute them.
359357 */
360- onFileValidate ? (event : OnFileValidateEvent ): any ;
358+ validateFile ? (event : ValidateFileEvent ): any ;
361359 /**
362360 * Called after each file is validated
363361 */
364- afterFileValidate ? (event : AfterFileValidateEvent ): any ;
362+ afterValidateFile ? (event : AfterValidateFileEvent ): any ;
365363
366364
367365 /**
@@ -395,7 +393,7 @@ export interface CompilerPlugin {
395393 /**
396394 * Emitted right at the start of the program turning all file objects into their final buffers
397395 */
398- onSerializeProgram ? (event : OnSerializeProgramEvent ): any ;
396+ serializeProgram ? (event : SerializeProgramEvent ): any ;
399397 /**
400398 * After the program turns all file objects into their final buffers
401399 */
@@ -542,8 +540,8 @@ npx tsc myPlugin.ts -m commonjs --sourceMap --watch
542540
543541Diagnostics must run every time it is relevant:
544542
545- - Files have one out-of-context validation step (` afterFileValidate ` ),
546- - Scopes are validated once all the the files have been collected (` before/afterScopeValidate ` ).
543+ - Files have one out-of-context validation step (` afterValidateFile ` ),
544+ - Scopes are validated once all the the files have been collected (` before/afterValidateScope ` ).
547545
548546Note: in a language-server context, Scope validation happens every time a file changes.
549547
@@ -558,7 +556,7 @@ export default function () {
558556 return {
559557 name: ' no-underscores' ,
560558 // post-parsing validation
561- afterFileValidate : (event : AfterFileValidateEvent ) => {
559+ afterValidateFile : (event : AfterValidateFileEvent ) => {
562560 if (isBrsFile (event .file )) {
563561 // clear existing diagnostics
564562 event .program .diagnosticManager .clearByContext ({file: file , tag: ' no-underscores-plugin' });
@@ -587,7 +585,7 @@ export default function () {
587585## Modifying code
588586Sometimes plugins will want to modify code before the project is transpiled. While you can technically edit the AST directly at any point in the file's lifecycle, this is not recommended as those changes will remain changed as long as that file exists in memory and could cause issues with file validation if the plugin is used in a language-server context (i.e. inside vscode).
589587
590- Instead, we provide an instace of an ` Editor ` class in the ` beforeFileTranspile ` event that allows you to modify AST before the file is transpiled, and then those modifications are undone ` afterFileTranspile ` .
588+ Instead, we provide an instace of an ` Editor ` class in the ` beforePrepareFile ` event that allows you to modify AST before the file is transpiled, and then those modifications are undone ` afterPrepareFile ` .
591589
592590For example, consider the following brightscript code:
593591` ` ` brightscript
@@ -606,7 +604,7 @@ export default function () {
606604 return {
607605 name: ' replacePlaceholders' ,
608606 // transform AST before transpilation
609- beforeFileTranspile : (event : BeforeFileTranspileEvent ) => {
607+ beforePrepareFile : (event : BeforeFileTranspileEvent ) => {
610608 if (isBrsFile (event .file )) {
611609 event .file .ast .walk (createVisitor ({
612610 LiteralExpression : (literal ) => {
@@ -670,14 +668,14 @@ export default function (): Plugin {
670668
671669## Modifying ` bsconfig .json ` via a plugin
672670
673- In some cases you may want to modify the project's configuration via a plugin, such as to change settings based on environment variables or to dynamically modify the project's ` files ` array. Plugins may do so in the ` beforeProgramCreate ` step. For example, here's a plugin which adds an additional file to the build:
671+ In some cases you may want to modify the project's configuration via a plugin, such as to change settings based on environment variables or to dynamically modify the project's ` files ` array. Plugins may do so in the ` beforeProvideProgram ` step. For example, here's a plugin which adds an additional file to the build:
674672` ` ` typescript
675673import { CompilerPlugin , ProgramBuilder } from ' brighterscript' ;
676674
677675export default function plugin() {
678676 return {
679677 name: ' addFilesDynamically' ,
680- beforeProgramCreate : (builder : ProgramBuilder ) => {
678+ beforeProvideProgram : (builder : ProgramBuilder ) => {
681679 if (! builder .options .files ) {
682680 builder .options .files = [];
683681 }
@@ -791,7 +789,7 @@ You can see examples of this in the previous code snippets above.
791789### Program changes
792790Historically, only ` .brs ` , ` .bs ` , and ` .xml ` files would be present in the ` Program ` . As a result of the File API being introduced, now all files included as a result of the bsconfig.json ` files ` array will be present in the program. Unhandled files will be loaded as generic ` AssetFile ` instances. This may impact plugins that aren't properly guarding against specific file types. Consider this plugin code:
793791` ` ` typescript
794- onFileValidate (event ){
792+ validateFile (event ){
795793 if (isXmlFile (event.file)) {
796794 // do XmlFile work
797795 } else {
0 commit comments