Skip to content

Commit 5e648aa

Browse files
committed
Merge branch 'v1' into intersection_type
2 parents 492e7ad + 3a7dcf6 commit 5e648aa

28 files changed

+539
-321
lines changed

docs/plugins.md

Lines changed: 68 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -50,57 +50,55 @@ While there are no restrictions on plugin names, it helps others to find your pl
5050

5151
Full 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

8987
Once the program has been validated, the language server runs a special loop - it never reaches the publishing steps.
9088

9189
When 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

9896
When 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

105103
When any file is modified:
106104

@@ -109,18 +107,18 @@ When any file is modified:
109107

110108
After 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

122120
Code Actions
123-
- `onGetCodeActions`
121+
- `provideCodeActions`
124122

125123
Completions
126124
- `beforeProvideCompletions`
@@ -133,7 +131,7 @@ Hovers
133131
- `afterProvideHover`
134132

135133
Semantic 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

543541
Diagnostics 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

548546
Note: 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
588586
Sometimes 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
592590
For 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
675673
import { CompilerPlugin, ProgramBuilder } from 'brighterscript';
676674

677675
export 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
792790
Historically, 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 {

src/BsConfig.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ export interface BsConfig {
6262
*/
6363
outDir?: string;
6464

65+
/**
66+
* @deprecated use `outDir` instead
67+
*/
68+
stagingDir?: string;
69+
70+
/**
71+
* @deprecated use `outDir` instead
72+
*/
73+
stagingFolderPath?: string;
74+
6575
/**
6676
* A list of error codes the compiler should NOT emit, even if encountered.
6777
*/
@@ -187,7 +197,9 @@ type OptionalBsConfigFields =
187197
| 'require'
188198
| 'outDir'
189199
| 'diagnosticLevel'
190-
| 'rootDir';
200+
| 'rootDir'
201+
| 'stagingDir'
202+
| 'stagingFolderPath';
191203

192204
export type FinalizedBsConfig =
193205
Omit<Required<BsConfig>, OptionalBsConfigFields>

src/LanguageServer.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,7 +1723,7 @@ describe('LanguageServer', () => {
17231723
expect(result['pathAbsolute']).to.eql(result.srcPath);
17241724
});
17251725

1726-
it('calls beforeProgramTranspile and afterProgramTranspile plugin events', async () => {
1726+
it('calls beforeBuildProgram and afterBuildProgram plugin events', async () => {
17271727
fsExtra.outputFileSync(s`${rootDir}/source/main.bs`, `
17281728
sub main()
17291729
print \`hello world\`
@@ -1736,7 +1736,7 @@ describe('LanguageServer', () => {
17361736
//make a plugin that changes string text
17371737
(server['projectManager'].projects[0] as Project)['builder'].program.plugins.add({
17381738
name: 'test-plugin',
1739-
beforeProgramTranspile: (event) => {
1739+
beforeBuildProgram: (event) => {
17401740
const { program, editor } = event;
17411741
const file = program.getFile('source/main.bs');
17421742
if (isBrsFile(file)) {
@@ -1751,7 +1751,7 @@ describe('LanguageServer', () => {
17511751
});
17521752
}
17531753
},
1754-
afterProgramTranspile: afterSpy
1754+
afterBuildProgram: afterSpy
17551755
});
17561756

17571757
const result = (await server.onExecuteCommand({

0 commit comments

Comments
 (0)