diff --git a/src/bscPlugin/inlayHints/InlayHintProcessor.ts b/src/bscPlugin/inlayHints/InlayHintProcessor.ts index c558a31c3..2b4ac7e93 100644 --- a/src/bscPlugin/inlayHints/InlayHintProcessor.ts +++ b/src/bscPlugin/inlayHints/InlayHintProcessor.ts @@ -37,13 +37,15 @@ export class InlayHintProcessor { file.ast.walk(createVisitor({ CallExpression: (call) => { - if (!util.getLocation(call)?.range || !util.rangesIntersectOrTouch(util.getLocation(call).range, range)) { + const callRange = util.getLocation(call)?.range; + if (!callRange || !util.rangesIntersectOrTouch(callRange, range)) { return; } this.emitParameterNameHints(file, call); }, CallfuncExpression: (call) => { - if (!util.getLocation(call)?.range || !util.rangesIntersectOrTouch(util.getLocation(call).range, range)) { + const callRange = util.getLocation(call)?.range; + if (!callRange || !util.rangesIntersectOrTouch(callRange, range)) { return; } this.emitParameterNameHintsForCallfunc(file, call); diff --git a/src/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.ts b/src/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.ts index 20fc25864..78f025916 100644 --- a/src/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.ts +++ b/src/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.ts @@ -100,8 +100,9 @@ export class BrsFileSemanticTokensProcessor { private addToken(locatable: Locatable, type: SemanticTokenTypes, modifiers: SemanticTokenModifiers[] = []) { //only keep a single token per range. Last-in wins - this.result.set(util.rangeToString(util.getLocation(locatable).range), { - range: util.getLocation(locatable).range, + const range = util.getLocation(locatable).range; + this.result.set(util.rangeToString(range), { + range: range, tokenType: type, tokenModifiers: modifiers }); diff --git a/src/files/BrsFile.ts b/src/files/BrsFile.ts index e2163f80d..29aa54deb 100644 --- a/src/files/BrsFile.ts +++ b/src/files/BrsFile.ts @@ -600,9 +600,10 @@ export class BrsFile implements BscFile { //add every parameter for (let param of func.parameters) { + const nameRange = util.getLocation(param.tokens.name)?.range; scope.variableDeclarations.push({ - nameRange: util.getLocation(param.tokens.name)?.range, - lineIndex: util.getLocation(param.tokens.name)?.range?.start.line, + nameRange: nameRange, + lineIndex: nameRange?.start.line, name: param.tokens.name.text, getType: () => { return param.getType({ flags: SymbolTypeFlag.typetime }); @@ -613,18 +614,20 @@ export class BrsFile implements BscFile { //add all of ForEachStatement loop varibales func.body?.walk(createVisitor({ ForEachStatement: (stmt) => { + const nameRange = util.getLocation(stmt.tokens.item)?.range; scope.variableDeclarations.push({ - nameRange: util.getLocation(stmt.tokens.item)?.range, - lineIndex: util.getLocation(stmt.tokens.item)?.range?.start.line, + nameRange: nameRange, + lineIndex: nameRange?.start.line, name: stmt.tokens.item.text, getType: () => stmt.getType({ flags: SymbolTypeFlag.runtime }) }); }, LabelStatement: (stmt) => { const { name: identifier } = stmt.tokens; + const nameRange = util.getLocation(identifier)?.range; scope.labelStatements.push({ - nameRange: util.getLocation(identifier)?.range, - lineIndex: util.getLocation(identifier)?.range?.start.line, + nameRange: nameRange, + lineIndex: nameRange?.start.line, name: identifier.text }); } @@ -651,9 +654,10 @@ export class BrsFile implements BscFile { //skip variable declarations that are outside of any scope if (scope) { const variableName = statement.tokens.name; + const nameRange = util.getLocation(variableName)?.range; scope.variableDeclarations.push({ - nameRange: util.getLocation(variableName)?.range, - lineIndex: util.getLocation(variableName)?.range?.start.line, + nameRange: nameRange, + lineIndex: nameRange?.start.line, name: variableName.text, getType: () => { return statement.getType({ flags: SymbolTypeFlag.runtime }); @@ -746,9 +750,10 @@ export class BrsFile implements BscFile { return this.cache.getOrAdd(`namespaceStatementForPosition-${position.line}:${position.character}`, () => { let mostSpecificNamespace: NamespaceStatement; for (const statement of this._cachedLookups.namespaceStatements) { - if (util.rangeContains(util.getLocation(statement)?.range, position)) { + const statementRange = util.getLocation(statement)?.range; + if (util.rangeContains(statementRange, position)) { if (mostSpecificNamespace) { - if (util.isRangeInRange(util.getLocation(statement)?.range, util.getLocation(mostSpecificNamespace)?.range)) { + if (util.isRangeInRange(statementRange, util.getLocation(mostSpecificNamespace)?.range)) { mostSpecificNamespace = statement; } } else { diff --git a/src/parser/BrightScriptDocParser.ts b/src/parser/BrightScriptDocParser.ts index 49aefe062..f323ce648 100644 --- a/src/parser/BrightScriptDocParser.ts +++ b/src/parser/BrightScriptDocParser.ts @@ -99,7 +99,8 @@ export class BrightScriptDocParser { } public getTypeLocationFromToken(token: Token): Location { - if (!util.getLocation(token)) { + const location = util.getLocation(token); + if (!location) { return undefined; } const startCurly = token.text.indexOf('{'); @@ -107,16 +108,17 @@ export class BrightScriptDocParser { if (startCurly === -1 || endCurly === -1 || endCurly <= startCurly) { return undefined; } + const start = location.range.start; return { - uri: util.getLocation(token).uri, + uri: location.uri, range: { start: { - line: util.getLocation(token).range.start.line, - character: util.getLocation(token).range.start.character + startCurly + 1 + line: start.line, + character: start.character + startCurly + 1 }, end: { - line: util.getLocation(token).range.start.line, - character: util.getLocation(token).range.start.character + endCurly + line: start.line, + character: start.character + endCurly } } };