UNPKG

maestro-roku-bsc-plugin

Version:

Visual studio plugin for maestro brightscript development

351 lines 24.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.functionNotImported = exports.wrongMethodArgs = exports.unknownClassField = exports.unknownClassMethod = exports.unknownType = exports.addXmlBindingCantParseFunctionCall = exports.IOCClassWrongArgs = exports.IOCClassNotInScope = exports.addIOCWrongArgs = exports.addIOCNoTypeSupplied = exports.addClassFieldsNotFoundOnSetOrGet = exports.addXMLTagErrorCouldNotParseBindingBadPart = exports.addNodeClassCallbackWrongParams = exports.addNodeClassCallbackNotDefined = exports.addNodeClassCallbackNotFound = exports.addNodeClassFieldNoFieldType = exports.addXmlBindingVMFieldRequired = exports.addNodeClassWrongNewSignature = exports.addNodeClassNeedsClassDeclaration = exports.addNodeClassBadDeclaration = exports.addNodeClassDuplicateName = exports.addNodeClassNoExtendNodeFound = exports.addNodeClassNoExecuteMethod = exports.addBuildTimeErrorImportNoImports = exports.addXmlBindingUsingFunctionAsField = exports.addXmlBindingVMFunctionWrongArgCount = exports.addXmlBindingVMFunctionNotFound = exports.addXmlBindingVMFieldNotFound = exports.addXmlBindingVMClassNotFound = exports.addXmlBindingNoVMClassDefined = exports.addCorruptVMType = exports.addXmlBindingDuplicateField = exports.addXmlBindingDuplicateTag = exports.addFileErrorCouldNotParseXML = exports.addFileErrorCouldNotSave = exports.addXMLTagErrorCouldNotParseIsFiringOnceForField = exports.addXMLTagErrorCouldNotParseeagerForField = exports.addXMLTagErrorCouldMissingEndBrackets = exports.addXMLTagErrorCouldNotParseBindingTransformFunctionForField = exports.addXMLTagErrorCouldNotParseBindingModeDetailsForField = exports.addXMLTagErrorCouldNotParseBindingDetailsForField = exports.addXMLTagErrorCouldNotParseBinding = exports.addXMLTagErrorCorruptXMLElement = exports.addProjectFileMapErrorDuplicateXMLComp = exports.addBuildTimeErrorImportMissingPkg = exports.addBuildTimeErrorImportMissingKey = exports.addXmlBindingErrorValidatingBindings = exports.addXmlBindingParentHasDuplicateField = exports.addXmlBindingCouldNotParseXML = exports.addXmlBindingNoCodeBehind = void 0; exports.observeFunctionNameWrongArgs = exports.observeFunctionNameNotFound = exports.observeRequiresFirstArgumentIsNotM = exports.addTooManyPublicParams = exports.observeRequiresFirstArgumentIsField = exports.noCallsInAsXXXAllowed = exports.noPathForInject = exports.noPathForIOCSync = exports.unknownSuperClass = exports.addNodeClassUnknownClassType = exports.namespaceNotImported = exports.wrongConstructorArgs = exports.unknownConstructorMethod = void 0; const brighterscript_1 = require("brighterscript"); function addErrorDiagnostic(file, code, message, startLine = 0, startCol = 0, endLine = -1, endCol = 99999) { endLine = endLine === -1 ? startLine : endLine; // eslint-disable-next-line @typescript-eslint/no-unsafe-argument let targetFile = (0, brighterscript_1.isBrsFile)(file) || (0, brighterscript_1.isXmlFile)(file) ? file : file.bscFile; // eslint-disable-next-line @typescript-eslint/no-unsafe-argument targetFile.diagnostics.push(createDiagnostic(targetFile, code, message, startLine, startCol, endLine, endCol, brighterscript_1.DiagnosticSeverity.Error)); } function addErrorDiagnosticForBinding(file, code, message, binding) { file.bscFile.diagnostics.push(createDiagnostic(file.bscFile, code, message, binding.range.start.line, binding.range.start.character, binding.range.end.line, binding.range.end.character, brighterscript_1.DiagnosticSeverity.Error)); } function createDiagnostic(bscFile, code, message, startLine = 0, startCol = 99999, endLine = 0, endCol = 99999, severity = brighterscript_1.DiagnosticSeverity.Error) { endLine = endLine < startLine ? startLine : endLine; const diagnostic = { code: `MSTO${code}`, message: message, range: brighterscript_1.Range.create(startLine, startCol, endLine, endCol), file: bscFile, severity: severity }; return diagnostic; } /** * Public methods */ function addXmlBindingNoCodeBehind(file) { addErrorDiagnostic(file, 6900, 'This XML file has bindings; but there is no code behind file!'); } exports.addXmlBindingNoCodeBehind = addXmlBindingNoCodeBehind; function addXmlBindingCouldNotParseXML(file, message) { addErrorDiagnostic(file, 6903, 'Could not parse xml in file: ' + message); } exports.addXmlBindingCouldNotParseXML = addXmlBindingCouldNotParseXML; function addXmlBindingParentHasDuplicateField(file, id, line = 0, col = 0) { addErrorDiagnostic(file, 6904, 'a parent of this xml file contains duplicate field id: ' + id, line, col); } exports.addXmlBindingParentHasDuplicateField = addXmlBindingParentHasDuplicateField; function addXmlBindingErrorValidatingBindings(file, message) { addErrorDiagnostic(file, 6905, 'Error while validating bindings' + message, 0, 0); } exports.addXmlBindingErrorValidatingBindings = addXmlBindingErrorValidatingBindings; function addBuildTimeErrorImportMissingKey(file, buildKey, line = 0, col = 0) { file.addDiagnostics([createDiagnostic(file, 1006, `xml file imports a build time import key that was not defined in your config:file that cannot be found ${buildKey}`, line, col, line, col, brighterscript_1.DiagnosticSeverity.Warning)]); } exports.addBuildTimeErrorImportMissingKey = addBuildTimeErrorImportMissingKey; function addBuildTimeErrorImportMissingPkg(file, pkg, buildKey, line = 0, col = 0) { file.addDiagnostics([createDiagnostic(file, 1007, `xml file imports a build time import '${buildKey}', which contains a pkg of a file that cannot be found '${pkg}'`, line, col)]); } exports.addBuildTimeErrorImportMissingPkg = addBuildTimeErrorImportMissingPkg; function addProjectFileMapErrorDuplicateXMLComp(file, duplicatePath) { addErrorDiagnostic(file, 1008, `Found duplicate named xml component ${file.componentName}. The name is already used by ${duplicatePath}`, 0, 0); } exports.addProjectFileMapErrorDuplicateXMLComp = addProjectFileMapErrorDuplicateXMLComp; function addXMLTagErrorCorruptXMLElement(file, tagText) { addErrorDiagnostic(file, 1009, `Received corrupt XMLElement`, 0, 0); } exports.addXMLTagErrorCorruptXMLElement = addXMLTagErrorCorruptXMLElement; function addXMLTagErrorCouldNotParseBinding(file, tagText, message, range) { addErrorDiagnostic(file, 1010, `Could not parse binding: ${message}`, range.start.line, range.start.character); } exports.addXMLTagErrorCouldNotParseBinding = addXMLTagErrorCouldNotParseBinding; function addXMLTagErrorCouldNotParseBindingDetailsForField(file, partText, tagText, range) { addErrorDiagnostic(file, 1011, `Could not parse binding details`, range.start.line, range.start.character); } exports.addXMLTagErrorCouldNotParseBindingDetailsForField = addXMLTagErrorCouldNotParseBindingDetailsForField; function addXMLTagErrorCouldNotParseBindingModeDetailsForField(file, partText, tagText, line, range) { addErrorDiagnostic(file, 1012, `Could not parse binding mode`, range.start.line, range.start.character); } exports.addXMLTagErrorCouldNotParseBindingModeDetailsForField = addXMLTagErrorCouldNotParseBindingModeDetailsForField; function addXMLTagErrorCouldNotParseBindingTransformFunctionForField(file, partText, tagText, range) { addErrorDiagnostic(file, 1013, `Could not parse transformFunction"`, range.start.line, range.start.character); } exports.addXMLTagErrorCouldNotParseBindingTransformFunctionForField = addXMLTagErrorCouldNotParseBindingTransformFunctionForField; function addXMLTagErrorCouldMissingEndBrackets(file, tagText, range) { addErrorDiagnostic(file, 1013, `Binding could not be parsed: Missing matching end brackets.`, range.start.line, range.start.character); } exports.addXMLTagErrorCouldMissingEndBrackets = addXMLTagErrorCouldMissingEndBrackets; function addXMLTagErrorCouldNotParseeagerForField(file, partText, tagText, range) { addErrorDiagnostic(file, 1014, `Could not parse eager for field`, range.start.line, range.start.character); } exports.addXMLTagErrorCouldNotParseeagerForField = addXMLTagErrorCouldNotParseeagerForField; function addXMLTagErrorCouldNotParseIsFiringOnceForField(file, partText, binding) { addErrorDiagnosticForBinding(file, 1015, `Could not parse binding setting "${partText}" - valid settings are 'once', 'eager', 'lazy' and 'transform'`, binding); } exports.addXMLTagErrorCouldNotParseIsFiringOnceForField = addXMLTagErrorCouldNotParseIsFiringOnceForField; function addFileErrorCouldNotSave(file) { addErrorDiagnostic(file, 1016, `could not save file at path ${file.fullPath} - does the path exist?`); } exports.addFileErrorCouldNotSave = addFileErrorCouldNotSave; function addFileErrorCouldNotParseXML(file, message) { addErrorDiagnostic(file, 1017, 'Could not parse xml in file: ' + message); } exports.addFileErrorCouldNotParseXML = addFileErrorCouldNotParseXML; function addXmlBindingDuplicateTag(file, field, line, col = 9999) { addErrorDiagnostic(file, 1018, `Could not parse binding the id is already used in another xml element: ${field}`, line, col); } exports.addXmlBindingDuplicateTag = addXmlBindingDuplicateTag; function addXmlBindingDuplicateField(file, field, line, col = 9999) { addErrorDiagnostic(file, 1019, `Could not parse binding id is already used in another interface field: ${field}`, line, col); } exports.addXmlBindingDuplicateField = addXmlBindingDuplicateField; function addCorruptVMType(file, line, col = 9999) { addErrorDiagnostic(file, 1020, `Could not pass vm field`, line, col); } exports.addCorruptVMType = addCorruptVMType; function addXmlBindingNoVMClassDefined(file) { addErrorDiagnostic(file, 1021, `The vm attribute was not set. Please add the 'vm' attribute to your component. e.g. '<Component name='MyScreen' extends 'BaseScreen' vm='fully.namespaced.className'/>" so that maestro can give you accurate binding validations.`); } exports.addXmlBindingNoVMClassDefined = addXmlBindingNoVMClassDefined; function addXmlBindingVMClassNotFound(file) { addErrorDiagnostic(file, 1022, `The VMClass specified "${file.vmClassName}" was not found.`, file.componentTag.range.start.line, file.componentTag.range.start.character); } exports.addXmlBindingVMClassNotFound = addXmlBindingVMClassNotFound; function addXmlBindingVMFieldNotFound(file, binding) { addErrorDiagnosticForBinding(file, 1023, `The bound field "${binding.observerField}" was not found in class "${file.vmClassName}".`, binding); } exports.addXmlBindingVMFieldNotFound = addXmlBindingVMFieldNotFound; function addXmlBindingVMFunctionNotFound(file, binding) { addErrorDiagnosticForBinding(file, 1024, `Function "${binding.observerField}" was not found in class "${file.vmClassName}".`, binding); } exports.addXmlBindingVMFunctionNotFound = addXmlBindingVMFunctionNotFound; function addXmlBindingVMFunctionWrongArgCount(file, binding, minArgs, maxArgs, actualParams) { let expectedText = minArgs !== maxArgs ? `${minArgs} - ${maxArgs}` : `${minArgs}`; addErrorDiagnosticForBinding(file, 1025, `Binding invokes "${binding.observerField}" with ${actualParams} params when ${expectedText} params was expected`, binding); } exports.addXmlBindingVMFunctionWrongArgCount = addXmlBindingVMFunctionWrongArgCount; function addXmlBindingUsingFunctionAsField(file, binding) { addErrorDiagnosticForBinding(file, 1026, `Binding "${binding.observerField}" is configured as a field binding; but points to a function. Either use a field as the target of this binding, or indicate the function call signature: e.g. (), (value), (node), or (value, node)`, binding); } exports.addXmlBindingUsingFunctionAsField = addXmlBindingUsingFunctionAsField; function addBuildTimeErrorImportNoImports(file, buildKey, line = 0, col = 0) { file.addDiagnostics([createDiagnostic(file, 1027, `This file imports a build time import key that is defined in bsConfig; but does not include any imports: ${buildKey}`, line, col, line, 99999, brighterscript_1.DiagnosticSeverity.Warning)]); } exports.addBuildTimeErrorImportNoImports = addBuildTimeErrorImportNoImports; function addNodeClassNoExecuteMethod(file, line = 0, col = 0) { file.addDiagnostics([createDiagnostic(file, 1028, `Node classes must declare a function name execute(args as assoccarray), which returns dynamic`, line, col)]); } exports.addNodeClassNoExecuteMethod = addNodeClassNoExecuteMethod; function addNodeClassNoExtendNodeFound(file, name, extendsName, line = 0, col = 0) { file.addDiagnostics([createDiagnostic(file, 1029, `Node class "${name}" extends component ${extendsName}, which cannot be found in scope. You must extend a valid SG Node, or Custom node`, line, col)]); } exports.addNodeClassNoExtendNodeFound = addNodeClassNoExtendNodeFound; function addNodeClassDuplicateName(file, name, line = 0, col = 0) { file.addDiagnostics([createDiagnostic(file, 1030, `Node class name "${name}" is already used`, line, col)]); } exports.addNodeClassDuplicateName = addNodeClassDuplicateName; function addNodeClassBadDeclaration(file, text, line = 0, col = 0) { file.addDiagnostics([createDiagnostic(file, 1031, `Could not interpret node class annotation "${text}". Should be "'@node|@task ([name],[baseCompName])`, line, col)]); } exports.addNodeClassBadDeclaration = addNodeClassBadDeclaration; function addNodeClassNeedsClassDeclaration(file, line = 0, col = 0) { file.addDiagnostics([createDiagnostic(file, 1032, `Node class annotation must immediately precede the target class; but no class statement was found`, line, col)]); } exports.addNodeClassNeedsClassDeclaration = addNodeClassNeedsClassDeclaration; function addNodeClassWrongNewSignature(file, line = 0, col = 0) { file.addDiagnostics([createDiagnostic(file, 1033, `Node classes constructors must take 0 arguments`, line, col)]); } exports.addNodeClassWrongNewSignature = addNodeClassWrongNewSignature; function addXmlBindingVMFieldRequired(file, binding) { addErrorDiagnosticForBinding(file, 1034, `Field bindings are only available for vm fields. Cannot bind to vm function "${binding.observerField}" in class "${file.vmClassName}".`, binding); } exports.addXmlBindingVMFieldRequired = addXmlBindingVMFieldRequired; function addNodeClassFieldNoFieldType(file, name, line = 0, col = 0) { file.addDiagnostics([createDiagnostic(file, 1035, `Node class field "${name}" type cannot be ascertained. Set a reasonable default value, or add an as clause. For a default node type, use as 'mc.Node' `, line, col)]); } exports.addNodeClassFieldNoFieldType = addNodeClassFieldNoFieldType; function addNodeClassCallbackNotFound(file, name, callbackName, className, line = 0, col = 0) { file.addDiagnostics([createDiagnostic(file, 1036, `Node class field "${name}" specifies observer function ${callbackName} which is not found in class ${className}`, line, col)]); } exports.addNodeClassCallbackNotFound = addNodeClassCallbackNotFound; function addNodeClassCallbackNotDefined(file, name, line = 0, col = 0) { file.addDiagnostics([createDiagnostic(file, 1037, `Node class field "${name}" does not specify the observer function name. Syntax is 'observe("CALLBACK_NAME")`, line, col)]); } exports.addNodeClassCallbackNotDefined = addNodeClassCallbackNotDefined; function addNodeClassCallbackWrongParams(file, name, callbackName, className, line = 0, col = 0) { file.addDiagnostics([createDiagnostic(file, 1038, `Node class field "${name}" specifies observer function ${callbackName}, in class ${className}, which must have zero, or one param (which is the value of the updated field, if specified)`, line, col)]); } exports.addNodeClassCallbackWrongParams = addNodeClassCallbackWrongParams; function addXMLTagErrorCouldNotParseBindingBadPart(file, partText, range) { addErrorDiagnostic(file, 1039, `Could not parse unknown binding part "${partText}"`, range.start.line, range.start.character); } exports.addXMLTagErrorCouldNotParseBindingBadPart = addXMLTagErrorCouldNotParseBindingBadPart; function addClassFieldsNotFoundOnSetOrGet(file, text, className, range) { addErrorDiagnostic(file, 1040, `class field: "${text}" was not found on ${className} or it's parent classes`, range.start.line, range.start.character); } exports.addClassFieldsNotFoundOnSetOrGet = addClassFieldsNotFoundOnSetOrGet; function addIOCNoTypeSupplied(file, text, className, range) { addErrorDiagnostic(file, 1041, `Cannot inject: ${className}.${text}. Wrong arguments valid arts are: (type, optional subPath)`, range.start.line, range.start.character); } exports.addIOCNoTypeSupplied = addIOCNoTypeSupplied; function addIOCWrongArgs(file, text, className, range) { addErrorDiagnostic(file, 1042, `Inject annotation on ${className}.${text} must supply one argument`, range.start.line, range.start.character); } exports.addIOCWrongArgs = addIOCWrongArgs; function IOCClassNotInScope(file, wrongclass, text, className, range) { addErrorDiagnostic(file, 1043, `cannot inject ${wrongclass} into field ${className}.${text}. It is not in scope`, range.start.line, range.start.character); } exports.IOCClassNotInScope = IOCClassNotInScope; function IOCClassWrongArgs(file, wrongclass, text, className, range) { addErrorDiagnostic(file, 1044, `Cannot inject ${wrongclass} into field ${className}.${text}. Constructor arg mistmatch.`, range.start.line, range.start.character); } exports.IOCClassWrongArgs = IOCClassWrongArgs; function addXmlBindingCantParseFunctionCall(file, tagText, range) { addErrorDiagnostic(file, 1045, `Binding observer ${tagText} is configured as a function binding; but with an incorrect signature. Either use a field as the target of this binding, or indicate the function call signature: e.g. (), (value), (node), or (value, node).`, range.start.line, range.start.character); } exports.addXmlBindingCantParseFunctionCall = addXmlBindingCantParseFunctionCall; function unknownType(name, scopeName) { return { message: `Cannot find namespaced function or class with name '${name}' when this file is included in scope '${scopeName}'`, code: `MSTO${1046}`, severity: brighterscript_1.DiagnosticSeverity.Error }; } exports.unknownType = unknownType; function unknownClassMethod(name, scopeName) { return { message: `Cannot find class method with name '${name}' when this file is included in scope '${scopeName}'`, code: `MSTO${1047}`, severity: brighterscript_1.DiagnosticSeverity.Error }; } exports.unknownClassMethod = unknownClassMethod; function unknownClassField(name, scopeName) { return { message: `Cannot find class field with name '${name}' when this file is included in scope '${scopeName}'`, code: `MSTO${1048}`, severity: brighterscript_1.DiagnosticSeverity.Error }; } exports.unknownClassField = unknownClassField; function wrongMethodArgs(name, numArgs, minArgs, maxArgs) { return { message: maxArgs ? `Invoking '${name}' with wrong number of args. Received ${numArgs} instead of expected ${minArgs} to ${maxArgs}'` : `Invoking '${name}' with wrong number of args. Received ${numArgs} instead of expected ${minArgs}'`, code: `MSTO${1049}`, severity: brighterscript_1.DiagnosticSeverity.Error }; } exports.wrongMethodArgs = wrongMethodArgs; function functionNotImported(name) { return { message: `Method '${name}' is not in scope on any of the imported files. did you forget to import it?'`, code: `MSTO${1050}`, severity: brighterscript_1.DiagnosticSeverity.Error }; } exports.functionNotImported = functionNotImported; function unknownConstructorMethod(name, scopeName) { return { message: `Cannot find class with name '${name}' when this file is included in scope '${scopeName}'`, code: `MSTO${1051}`, severity: brighterscript_1.DiagnosticSeverity.Error }; } exports.unknownConstructorMethod = unknownConstructorMethod; function wrongConstructorArgs(name, numArgs, minArgs, maxArgs) { return { message: maxArgs ? `Instantiating class '${name}' with wrong number of args. Received ${numArgs} instead of expected ${minArgs} to ${maxArgs}'` : `Instantiating class '${name}' with wrong number of args. Received ${numArgs} instead of expected ${minArgs}'`, code: `MSTO${1052}`, severity: brighterscript_1.DiagnosticSeverity.Error }; } exports.wrongConstructorArgs = wrongConstructorArgs; function namespaceNotImported(name) { return { message: `Namespace method '${name}' is not in scope on any of the imported files. Did you forget to import it?'`, code: `MSTO${1053}`, severity: brighterscript_1.DiagnosticSeverity.Error }; } exports.namespaceNotImported = namespaceNotImported; function addNodeClassUnknownClassType(file, name, fieldName, className, line = 0, col = 0) { file.addDiagnostics([createDiagnostic(file, 1054, `Node class field "${name}" is of unknown type ${fieldName}, in class ${className}`, line, col)]); } exports.addNodeClassUnknownClassType = addNodeClassUnknownClassType; function unknownSuperClass(name) { return { message: `Extended class '${name}' cannot be found. Did you gorget to import it?'`, code: `MSTO${1055}`, severity: brighterscript_1.DiagnosticSeverity.Error }; } exports.unknownSuperClass = unknownSuperClass; function noPathForIOCSync() { return { message: `@sync tag requires that the injected field is private and is injecting a sub-value, from a node e.g @inject("user", "name"), @inject("user", "profile.name") - in the latter case, the observer will fire when profile.name changes.'`, code: `MSTO${1056}`, severity: brighterscript_1.DiagnosticSeverity.Error }; } exports.noPathForIOCSync = noPathForIOCSync; function noPathForInject() { return { message: `@inject tag requires 1 or 2 arguments to indicate what to inject. e.g @inject("user", "name"), @inject("user", "profile.name") '`, code: `MSTO${1057}`, severity: brighterscript_1.DiagnosticSeverity.Error }; } exports.noPathForInject = noPathForInject; function noCallsInAsXXXAllowed(functionName) { return { message: `Cannot call function inside an as expression. Function called: "${functionName}"`, code: `MSTO${1058}`, severity: brighterscript_1.DiagnosticSeverity.Error }; } exports.noCallsInAsXXXAllowed = noCallsInAsXXXAllowed; function observeRequiresFirstArgumentIsField() { return { message: `m.observe requires the first argument end with a field, such as 'node.field'`, code: `MSTO${1059}`, severity: brighterscript_1.DiagnosticSeverity.Error }; } exports.observeRequiresFirstArgumentIsField = observeRequiresFirstArgumentIsField; function addTooManyPublicParams(file, name, className, line = 0, col = 0) { file.addDiagnostics([createDiagnostic(file, 1060, `Node class public method "${name}", in class ${className}, has too many paramters. Public methods (which become callfunc methods), will crash a roku device when they have more than 5 params`, line, col)]); } exports.addTooManyPublicParams = addTooManyPublicParams; function observeRequiresFirstArgumentIsNotM() { return { message: `m.observe cannot observe m, did you accidentally try to observe 'm.node', instead of 'm.node.field'?`, code: `MSTO${1061}`, severity: brighterscript_1.DiagnosticSeverity.Error }; } exports.observeRequiresFirstArgumentIsNotM = observeRequiresFirstArgumentIsNotM; function observeFunctionNameNotFound(funcName, fieldName) { return { message: `m.observe with unknown function ${funcName}, when observing field: ${fieldName}`, code: `MSTO${1062}`, severity: brighterscript_1.DiagnosticSeverity.Error }; } exports.observeFunctionNameNotFound = observeFunctionNameNotFound; function observeFunctionNameWrongArgs(funcName, nodeName, fieldName, sendMode, expectedArgs, actualArgs) { return { message: `m.observe function ${funcName} should have ${expectedArgs} args when observing ${nodeName}.${fieldName}, with sendMode ${sendMode}. Function expects ${actualArgs} args`, code: `MSTO${1063}`, severity: brighterscript_1.DiagnosticSeverity.Error }; } exports.observeFunctionNameWrongArgs = observeFunctionNameWrongArgs; //# sourceMappingURL=Diagnostics.js.map