diff --git a/src/extension.ts b/src/extension.ts index 5ae0087..05217e2 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -140,15 +140,12 @@ function colorRuby(x: Parser.SyntaxNode, editor: vscode.TextEditor) { colors.push([x.children[3], 'entity.name.function']) } else if (variables.includes(x.type)) { colors.push([x, 'variable']) - } else if (x.type == 'call' && x.lastChild!.type == 'identifier') { - colors.push([x.lastChild!, 'entity.name.function']) - // Method parameters - } else if (x.type == 'identifier' && x.parent!.type == 'method_parameters') { - colors.push([x, 'variable.parameter']) - } else if (x.type == 'method_call' && x.firstChild!.type == 'identifier') { - colors.push([x.firstChild!, 'entity.name.function']) + } else if (x.type == 'call' && x.lastChild && x.lastChild.type == 'identifier') { + colors.push([x.lastChild, 'entity.name.function']) + } else if (x.type == 'method_call' && x.firstChild && x.firstChild.type == 'identifier') { + colors.push([x.firstChild, 'entity.name.function']) } else if (x.type == 'end') { - if (control.includes(x.parent!.type)) { + if (x.parent && control.includes(x.parent.type)) { colors.push([x, 'keyword.control']) } else { colors.push([x, 'keyword']) @@ -157,6 +154,9 @@ function colorRuby(x: Parser.SyntaxNode, editor: vscode.TextEditor) { colors.push([x, 'entity.name.type']) } else if (x.type == 'symbol') { colors.push([x, 'constant.language']) + // Method parameters + } else if (x.type == 'identifier' && x.parent && x.parent.type == 'method_parameters') { + colors.push([x, 'variable.parameter']) } for (const child of x.children) { scan(child)