microsoft/typescript-go · error · Error

Unexpected number of arguments.

Error message

Unexpected number of arguments.

What it means

Thrown by the internal command typescript.native-preview.codeLens.showLocations when invoked with an argument count other than 3. The command is registered solely so the tsgo language server can trigger VS Code's reference UI from a code lens; the server invokes it with exactly (DocumentUri, Position, Location[]). Any other arity means it was invoked manually, programmatically with wrong arguments, or by a server/extension version skew.

Source

Thrown at _extension/src/commands.ts:78

    else {
        await jsTsConfig.update("experimental.useTsgo", enable, vscode.ConfigurationTarget.Global);
    }

    return restartExtHostOnChangeIfNeeded();
}

export async function updateWorkspaceUseTsgoSetting(enable: boolean): Promise<void> {
    await vscode.workspace.getConfiguration("js/ts").update("experimental.useTsgo", enable, vscode.ConfigurationTarget.Workspace);
    return restartExtHostOnChangeIfNeeded();
}

export const codeLensShowLocationsCommandName = "typescript.native-preview.codeLens.showLocations";
export function registerCodeLensShowLocationsCommand(): vscode.Disposable {
    return vscode.commands.registerCommand(codeLensShowLocationsCommandName, showCodeLensLocations);

    function showCodeLensLocations(...args: unknown[]): void {
        if (args.length !== 3) {
            throw new Error(vscode.l10n.t("Unexpected number of arguments."));
        }

        const lspUri = args[0] as DocumentUri;
        const lspPosition = args[1] as Position;
        const lspLocations = args[2] as Location[];

        const editorUri = vscode.Uri.parse(lspUri);
        const editorPosition = new vscode.Position(lspPosition.line, lspPosition.character);
        const editorLocations = lspLocations.map(loc =>
            new vscode.Location(
                vscode.Uri.parse(loc.uri),
                new vscode.Range(
                    new vscode.Position(loc.range.start.line, loc.range.start.character),
                    new vscode.Position(loc.range.end.line, loc.range.end.character),
                ),
            )
        );

View on GitHub (pinned to 1bcfa18d79)

Solutions

  1. Do not run this internal command manually; trigger the code lens from the editor instead
  2. If invoking programmatically, pass exactly 3 args: uri string, {line,character} position, and an array of LSP Location objects
  3. Align extension and server versions: restart the server / reinstall so the code lens command payload matches (typescript.native-preview.restart)
  4. If it fires from normal code-lens usage, report it - the extension and tsgo binary are out of sync

Example fix

// before
await vscode.commands.executeCommand(codeLensShowLocationsCommandName); // 0 args -> throws

// after
await vscode.commands.executeCommand(
    codeLensShowLocationsCommandName,
    document.uri.toString(),
    { line: 0, character: 0 },
    [{ uri: document.uri.toString(), range: { start: { line: 0, character: 0 }, end: { line: 0, character: 5 } } }],
);
Defensive patterns

Strategy: validation

Validate before calling

// Validate the exact payload shape before executing the internal command
function isCodeLensArgs(args: unknown[]): args is [string, { line: number; character: number }, Array<{ uri: string; range: unknown }>] {
    return args.length === 3
        && typeof args[0] === 'string'
        && typeof (args[1] as any)?.line === 'number'
        && Array.isArray(args[2]);
}
if (!isCodeLensArgs(args)) throw new Error('codeLens.showLocations expects (uri, position, locations)');
await vscode.commands.executeCommand(codeLensShowLocationsCommandName, ...args);

Type guard

const isCodeLensArgs = (a: unknown[]): a is [string, { line: number; character: number }, { uri: string; range: { start: unknown; end: unknown } }[]] =>
    a.length === 3 && typeof a[0] === 'string' && !!a[1] && typeof (a[1] as any).line === 'number' && Array.isArray(a[2]);

Try / catch

try {
    showCodeLensLocations(...args);
} catch (e) {
    if (e instanceof Error && e.message.includes('Unexpected number of arguments')) {
        // internal command invoked with a wrong payload: log and ignore rather than surface to users
        console.error('codeLens.showLocations invoked with', args);
    } else throw e;
}

Prevention

When it happens

Trigger: Executing the command by name from the command palette or executeCommand with zero arguments; a test invoking it without the (uri, position, locations) triple; an extension/server version mismatch where the server sends a different command payload shape.

Common situations: Users discovering the internal command in the palette and running it bare; extension developers replaying code-lens commands in tests; a stale tsgo binary from a mismatched workspace tsdk emitting arguments the newer extension does not expect.

Related errors


AI-assisted analysis of microsoft/typescript-go@1bcfa18d79 (2026-08-16). Data as JSON: /api/errors/22588ca6fadb3713. Report an issue: GitHub.