Skip to content

Commit

Permalink
Safer completion handling for callfuncs.
Browse files Browse the repository at this point in the history
Fixes #352
  • Loading branch information
TwitchBronBron committed Mar 13, 2021
1 parent 471884d commit 0764306
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/Program.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1826,6 +1826,21 @@ describe('Program', () => {
}
});

it('does not crash on callfunc operator', () => {
//there needs to be at least one xml component WITHOUT an interface
program.addOrReplaceFile<XmlFile>('components/MyNode.xml', trim`<?xml version="1.0" encoding="utf-8" ?>
<component name="Component1" extends="Scene">
<script type="text/brightscript" uri="pkg:/components/MyNode.bs" />
</component>
`);
const file = program.addOrReplaceFile('source/main.bs', `
sub main()
someFunc()@.
end sub
`);
program.getCompletions(file.pathAbsolute, util.createPosition(2, 32));
});

it('gets signature help for constructor with no args', () => {
program.addOrReplaceFile('source/main.bs', `
function main()
Expand Down
3 changes: 2 additions & 1 deletion src/Program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,8 @@ export class Program {
let funcNames = new Set<string>();
let currentScope = scope;
while (isXmlScope(currentScope)) {
for (let name of currentScope.xmlFile.ast.component.api.functions.map((f) => f.name)) {
const functionNames = currentScope.xmlFile.ast.component.api?.functions.map((f) => f.name) ?? [];
for (let name of functionNames) {
if (!filterName || name === filterName) {
funcNames.add(name);
}
Expand Down

0 comments on commit 0764306

Please sign in to comment.