From 905e5a6f7b672c4676ca39b76ef9676fdb5ccc6c Mon Sep 17 00:00:00 2001 From: Mark Pearce Date: Sat, 22 Jul 2023 10:07:49 -0300 Subject: [PATCH] Fixed lint errors and added hover test --- src/Scope.ts | 2 +- src/bscPlugin/hover/HoverProcessor.spec.ts | 21 +++++++++++++++++++++ src/bscPlugin/hover/HoverProcessor.ts | 2 +- src/bscPlugin/validation/ScopeValidator.ts | 2 +- src/files/BrsFile.ts | 2 +- src/parser/Expression.ts | 2 +- 6 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/Scope.ts b/src/Scope.ts index 54565b819..3b8449d56 100644 --- a/src/Scope.ts +++ b/src/Scope.ts @@ -18,7 +18,7 @@ import { URI } from 'vscode-uri'; import { LogLevel } from './Logger'; import type { BrsFile } from './files/BrsFile'; import type { DependencyGraph, DependencyChangedEvent } from './DependencyGraph'; -import { isBrsFile, isMethodStatement, isClassStatement, isConstStatement, isEnumStatement, isFunctionStatement, isFunctionType, isXmlFile, isEnumMemberStatement, isNamespaceStatement, isNamespaceType, isReferenceType, isTypedFunctionType } from './astUtils/reflection'; +import { isBrsFile, isMethodStatement, isClassStatement, isConstStatement, isEnumStatement, isFunctionStatement, isXmlFile, isEnumMemberStatement, isNamespaceStatement, isNamespaceType, isReferenceType, isTypedFunctionType } from './astUtils/reflection'; import { SymbolTable, SymbolTypeFlag } from './SymbolTable'; import type { Statement } from './parser/AstNode'; import type { BscType } from './types/BscType'; diff --git a/src/bscPlugin/hover/HoverProcessor.spec.ts b/src/bscPlugin/hover/HoverProcessor.spec.ts index b0913df1c..0d93d8066 100644 --- a/src/bscPlugin/hover/HoverProcessor.spec.ts +++ b/src/bscPlugin/hover/HoverProcessor.spec.ts @@ -355,5 +355,26 @@ describe('HoverProcessor', () => { // TODO: Add comments for class methods/properties expect(hover?.contents).to.eql([`${fence('function MyKlass.getName() as string')}`]); }); + + it('finds functions as params', () => { + program.setFile('source/main.brs', ` + function getStrLength(name as string) as integer + return len(name) + end function + + sub tryManyParams(someFunc as function) + print someFunc(1, 2, "hello", "world") + end sub + + sub test() + tryManyParams(getStrLength) + end sub + `); + program.validate(); + // print some|Func(1, 2, "hello", "world") + let hover = program.getHover('source/main.brs', util.createPosition(6, 31))[0]; + expect(hover?.range).to.eql(util.createRange(6, 26, 6, 34)); + expect(hover?.contents).to.eql([fence('someFunc as function')]); + }); }); }); diff --git a/src/bscPlugin/hover/HoverProcessor.ts b/src/bscPlugin/hover/HoverProcessor.ts index b7f7d115a..e43b2a8ed 100644 --- a/src/bscPlugin/hover/HoverProcessor.ts +++ b/src/bscPlugin/hover/HoverProcessor.ts @@ -1,5 +1,5 @@ import { SourceNode } from 'source-map'; -import { isBrsFile, isClassType, isFunctionType, isInterfaceType, isNewExpression, isTypeExpression, isTypedFunctionType, isXmlFile } from '../../astUtils/reflection'; +import { isBrsFile, isClassType, isInterfaceType, isNewExpression, isTypeExpression, isTypedFunctionType, isXmlFile } from '../../astUtils/reflection'; import type { BrsFile } from '../../files/BrsFile'; import type { XmlFile } from '../../files/XmlFile'; import type { Hover, ProvideHoverEvent, TypeChainEntry } from '../../interfaces'; diff --git a/src/bscPlugin/validation/ScopeValidator.ts b/src/bscPlugin/validation/ScopeValidator.ts index 3f637ce91..bc543ad68 100644 --- a/src/bscPlugin/validation/ScopeValidator.ts +++ b/src/bscPlugin/validation/ScopeValidator.ts @@ -1,5 +1,5 @@ import { URI } from 'vscode-uri'; -import { isBinaryExpression, isBrsFile, isFunctionType, isLiteralExpression, isNamespaceStatement, isTypeExpression, isTypedFunctionType, isXmlScope } from '../../astUtils/reflection'; +import { isBinaryExpression, isBrsFile, isLiteralExpression, isNamespaceStatement, isTypeExpression, isTypedFunctionType, isXmlScope } from '../../astUtils/reflection'; import { Cache } from '../../Cache'; import { DiagnosticMessages } from '../../DiagnosticMessages'; import type { BrsFile } from '../../files/BrsFile'; diff --git a/src/files/BrsFile.ts b/src/files/BrsFile.ts index e42aaeb14..31c4dd8db 100644 --- a/src/files/BrsFile.ts +++ b/src/files/BrsFile.ts @@ -22,7 +22,7 @@ import { BrsTranspileState } from '../parser/BrsTranspileState'; import { Preprocessor } from '../preprocessor/Preprocessor'; import { LogLevel } from '../Logger'; import { serializeError } from 'serialize-error'; -import { isMethodStatement, isClassStatement, isDottedGetExpression, isFunctionStatement, isFunctionType, isLiteralExpression, isNamespaceStatement, isStringType, isVariableExpression, isXmlFile, isImportStatement, isFieldStatement, isEnumStatement, isConstStatement, isFunctionExpression, isCallableType } from '../astUtils/reflection'; +import { isMethodStatement, isClassStatement, isDottedGetExpression, isFunctionStatement, isLiteralExpression, isNamespaceStatement, isStringType, isVariableExpression, isXmlFile, isImportStatement, isFieldStatement, isEnumStatement, isConstStatement, isFunctionExpression, isCallableType } from '../astUtils/reflection'; import { createVisitor, WalkMode } from '../astUtils/visitors'; import type { DependencyGraph } from '../DependencyGraph'; import { CommentFlagProcessor } from '../CommentFlagProcessor'; diff --git a/src/parser/Expression.ts b/src/parser/Expression.ts index 7a98677d7..d46bb8df3 100644 --- a/src/parser/Expression.ts +++ b/src/parser/Expression.ts @@ -10,7 +10,7 @@ import * as fileUrl from 'file-url'; import type { WalkOptions, WalkVisitor } from '../astUtils/visitors'; import { WalkMode } from '../astUtils/visitors'; import { walk, InternalWalkMode, walkArray } from '../astUtils/visitors'; -import { isAALiteralExpression, isArrayLiteralExpression, isCallExpression, isCallableType, isCallfuncExpression, isCommentStatement, isDottedGetExpression, isEscapedCharCodeLiteralExpression, isFunctionExpression, isFunctionStatement, isFunctionType, isIntegerType, isInterfaceMethodStatement, isLiteralBoolean, isLiteralExpression, isLiteralNumber, isLiteralString, isLongIntegerType, isMethodStatement, isNamespaceStatement, isNewExpression, isReferenceType, isStringType, isUnaryExpression } from '../astUtils/reflection'; +import { isAALiteralExpression, isArrayLiteralExpression, isCallExpression, isCallableType, isCallfuncExpression, isCommentStatement, isDottedGetExpression, isEscapedCharCodeLiteralExpression, isFunctionExpression, isFunctionStatement, isIntegerType, isInterfaceMethodStatement, isLiteralBoolean, isLiteralExpression, isLiteralNumber, isLiteralString, isLongIntegerType, isMethodStatement, isNamespaceStatement, isNewExpression, isReferenceType, isStringType, isUnaryExpression } from '../astUtils/reflection'; import type { GetTypeOptions, TranspileResult, TypedefProvider } from '../interfaces'; import { TypeChainEntry } from '../interfaces'; import type { BscType } from '../types/BscType';