Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into lsp-refactor
  • Loading branch information
TwitchBronBron committed Oct 11, 2024
2 parents b065e57 + 024e9a4 commit 9407565
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 5 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ A superset of Roku's BrightScript language. Compiles to standard BrightScript.

The BrighterScript language provides new features and syntax enhancements to Roku's BrightScript language. Because the language is a superset of BrightScript, the parser and associated tools (VSCode integration, cli, etc...) work with standard BrightScript (.brs) files. This means you will get benefits (as described in the following section) from using the BrighterScript compiler, whether your project contains BrighterScript (.bs) files or not. The BrighterScript language transpiles to standard BrightScript, so your code is fully compatible with all roku devices.

## Help!

> [!IMPORTANT]
> We are currently seeking testers for two major rewrites:
- Language Server Protocol (LSP) Rewrite: We’ve been hard at work revamping our LSP to improve stability, performance, and add new features. We would love your feedback as you put it through its paces. ([Join the LSP discussion](https://github.com/rokucommunity/brighterscript/discussions/1322))

- Version 1 (v1) Rewrite: This is a complete overhaul of the core of our project. Your input is crucial in helping us identify bugs and further refine the release. ([Join the v1 discussion](https://github.com/rokucommunity/brighterscript/discussions/1321))

If you're interested in helping, please visit the GitHub discussion links above for more information and instructions on how to get involved.

## Features
BrighterScript adds several new features to the BrightScript language such as namespaces, classes, import statements, and more. Take a look at the language specification docs for more information.

Expand Down
5 changes: 5 additions & 0 deletions src/ProgramBuilder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ describe('ProgramBuilder', () => {
});

describe('run', () => {
it('does not crash when options is undefined', async () => {
sinon.stub(builder as any, 'runOnce').callsFake(() => { });
await builder.run(undefined as any);
});

it('uses default options when the config file fails to parse', async () => {
//supress the console log statements for the bsconfig parse errors
sinon.stub(console, 'log').returns(undefined);
Expand Down
8 changes: 5 additions & 3 deletions src/ProgramBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ export class ProgramBuilder {
}

public async run(options: BsConfig & { skipInitialValidation?: boolean }) {
this.logger.logLevel = options.logLevel;
if (options?.logLevel) {
this.logger.logLevel = options.logLevel;
}

if (this.isRunning) {
throw new Error('Server is already running');
Expand Down Expand Up @@ -154,12 +156,12 @@ export class ProgramBuilder {
if (this.options.watch) {
this.logger.log('Starting compilation in watch mode...');
await this.runOnce({
skipValidation: options.skipInitialValidation
skipValidation: options?.skipInitialValidation
});
this.enableWatchMode();
} else {
await this.runOnce({
skipValidation: options.skipInitialValidation
skipValidation: options?.skipInitialValidation
});
}
}
Expand Down
32 changes: 32 additions & 0 deletions src/files/BrsFile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2650,6 +2650,38 @@ describe('BrsFile', () => {
`);
});

it('transpiles namespace calls from within an array', () => {
testTranspile(`
namespace Vertibrates.Birds
function GetAllBirds()
return [
GetDuck(),
GetGoose()
]
end function
function GetDuck()
end function
function GetGoose()
end function
end namespace
`, `
function Vertibrates_Birds_GetAllBirds()
return [
Vertibrates_Birds_GetDuck()
Vertibrates_Birds_GetGoose()
]
end function
function Vertibrates_Birds_GetDuck()
end function
function Vertibrates_Birds_GetGoose()
end function
`, undefined, 'components/NobodyImportsMe.bs', false);
});

it('properly transpiles inferred namespace function for assignment', () => {
testTranspile(`
namespace NameA.NameB
Expand Down
12 changes: 10 additions & 2 deletions src/files/BrsFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CancellationTokenSource } from 'vscode-languageserver';
import { CompletionItemKind, TextEdit } from 'vscode-languageserver';
import chalk from 'chalk';
import * as path from 'path';
import type { Scope } from '../Scope';
import { Scope } from '../Scope';
import { DiagnosticCodeMap, diagnosticCodes, DiagnosticMessages } from '../DiagnosticMessages';
import { FunctionScope } from '../FunctionScope';
import type { Callable, CallableArg, CallableParam, CommentFlag, FunctionCall, BsDiagnostic, FileReference, FileLink, BscFile } from '../interfaces';
Expand Down Expand Up @@ -1241,7 +1241,15 @@ export class BrsFile {
let lowerCalleeName = callee?.name?.text?.toLowerCase();
if (lowerCalleeName) {
let scope = this.program.getFirstScopeForFile(this);
let namespace = scope?.namespaceLookup.get(namespaceName.toLowerCase());

//if this file does not belong to any scopes, make a temporary one to answer the question
if (!scope) {
scope = new Scope(`temporary-for-${this.pkgPath}`, this.program);
scope.getAllFiles = () => [this];
scope.getOwnFiles = scope.getAllFiles;
}

let namespace = scope.namespaceLookup.get(namespaceName.toLowerCase());
if (namespace?.functionStatements[lowerCalleeName]) {
return true;
}
Expand Down

0 comments on commit 9407565

Please sign in to comment.