fix(r): bind roxygen @param tags to formals written in backticks

A formal written `data` in backticks never matched the tag @param data, so
its documented type was dropped. Look the tag up by the symbol.
This commit is contained in:
Mick Cooney 2026-10-16 17:11:11 +01:00
parent e57943e6f2
commit 6c487cffdb
2 changed files with 16 additions and 1 deletions

View file

@ -7,6 +7,7 @@ import type {
} from './types.js';
import type { SyntaxNode } from '../utils/ast-helpers.js';
import { getRClassNameArgument } from '../field-extractors/r.js';
import { rBareName } from '../languages/r/bare-name.js';
/**
* R type extractor — roxygen2 annotation parsing.
@ -205,7 +206,8 @@ const extractParameter: ParameterExtractor = (node: SyntaxNode, env: Map<string,
const rhs = assignment.childForFieldName('rhs');
if (rhs?.startIndex !== fn.startIndex || rhs.endIndex !== fn.endIndex) return;
const typeName = collectRoxygenParams(assignment).get(name.text);
// The tag names the symbol (`@param x`); a formal written `x` in backticks is the same one.
const typeName = collectRoxygenParams(assignment).get(rBareName(name.text));
if (typeName !== undefined) env.set(name.text, typeName);
};

View file

@ -75,6 +75,19 @@ AddOutlierStatuses <- function(data, outliers) {
expect(flatGet(typeEnv, 'outliers')).toBe('DataFrame');
});
it('binds a formal written in backticks to the type its @param tag gives the symbol', () => {
const tree = parse(`
DataFrame <- R6::R6Class("DataFrame", public = list(rows = function() 1))
#' @param data DataFrame
Summarise <- function(\`data\`) {
\`data\`$rows()
}
`);
const typeEnv = buildTypeEnv(tree, SupportedLanguages.R);
expect(flatGet(typeEnv, '`data`')).toBe('DataFrame');
});
it('binds nothing for a type the file does not define (primitive or capitalised)', () => {
const tree = parse(`
#' @param x numeric