Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/bscPlugin/inlayHints/InlayHintProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
Expand Down
25 changes: 15 additions & 10 deletions src/files/BrsFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand All @@ -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
});
}
Expand All @@ -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 });
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 8 additions & 6 deletions src/parser/BrightScriptDocParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,24 +99,26 @@ 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('{');
const endCurly = token.text.indexOf('}');
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
}
}
};
Expand Down
Loading