{"record":{"id":"2495e377b5b6dd28","repo":"neoclide/coc.nvim","slug":"illegal-argument","errorCode":null,"errorMessage":"Illegal argument","messagePattern":"Illegal argument","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/model/semanticTokensBuilder.ts","lineNumber":74,"sourceCode":"   * Add another token. Use only when providing a legend.\n   * @param range The range of the token. Must be single-line.\n   * @param tokenType The token type.\n   * @param tokenModifiers The token modifiers.\n   */\n  public push(range: Range, tokenType: string, tokenModifiers?: string[]): void\n  public push(arg0: any, arg1: any, arg2: any, arg3?: any, arg4?: any): void {\n    if (typeof arg0 === 'number' && typeof arg1 === 'number' && typeof arg2 === 'number' && typeof arg3 === 'number' && (typeof arg4 === 'number' || typeof arg4 === 'undefined')) {\n      if (typeof arg4 === 'undefined') {\n        arg4 = 0\n      }\n      // 1st overload\n      return this._pushEncoded(arg0, arg1, arg2, arg3, arg4)\n    }\n    if (Range.is(arg0) && typeof arg1 === 'string' && isStrArrayOrUndefined(arg2)) {\n      // 2nd overload\n      return this._push(arg0, arg1, arg2)\n    }\n    throw new Error('Illegal argument')\n  }\n\n  private _push(range: Range, tokenType: string, tokenModifiers?: string[]): void {\n    if (!this._hasLegend) {\n      throw new Error('Legend must be provided in constructor')\n    }\n    if (range.start.line !== range.end.line) {\n      throw new Error('`range` cannot span multiple lines')\n    }\n    if (!this._tokenTypeStrToInt.has(tokenType)) {\n      throw new Error('`tokenType` is not in the provided legend')\n    }\n    const line = range.start.line\n    const char = range.start.character\n    const length = range.end.character - range.start.character\n    const nTokenType = this._tokenTypeStrToInt.get(tokenType)!\n    let nTokenModifiers = 0\n    if (tokenModifiers) {","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/neoclide/coc.nvim/blob/50e974d9692461a69147d5cab146a8d3e439abe4/src/model/semanticTokensBuilder.ts#L56-L92","documentation":"SemanticTokensBuilder.push() supports only two documented overloads: (deltaLine, deltaStart, length, tokenType, tokenModifiers) with numeric tokenType, or (range, tokenType, tokenModifiers) with a Range and string tokenType. If the arguments match neither overload signature, the builder throws 'Illegal argument'.","triggerScenarios":"Calling push with e.g. a numeric tokenType plus a Range, a string tokenType with numeric deltas, wrong argument counts (fewer than 3 or more than 5 args), or a non-string tokenType with a Range (typeof arg1 === 'string' fails).","commonSituations":"Mixing up the two overload styles during refactors; passing a LSP semantic token type index where a string is expected; migrating from vscode-languageserver builder API with different argument order.","solutions":["Use one overload consistently: push(line, startChar, length, tokenTypeIndex, modifiersBitmask) or push(range, 'keyword', ['readonly'])","Ensure the tokenType is a number when using the encoded overload and a string when using the Range overload","Check argument count: encoded overload needs exactly 5 args, Range overload needs 2-3","Add a unit test covering each push overload used in your provider"],"exampleFix":"// before\nbuilder.push(range, tokenTypeIndex) // mixed overload\n// after\nbuilder.push(range, legend.tokenTypes[tokenTypeIndex], []) // Range + string tokenType","handlingStrategy":"validation","validationCode":"function isValidPushArgs(...args: any[]): boolean {\n  if (args.length === 5 && typeof args[3] === 'number') return true\n  if (Range.is(args[0]) && typeof args[1] === 'string' && (args.length === 2 || Array.isArray(args[2]))) return true\n  return false\n}","typeGuard":"function isRangeOverload(a: any): a is [Range, string, string[]?] {\n  return Range.is(a[0]) && typeof a[1] === 'string' && (a[2] === undefined || Array.isArray(a[2]))\n}","tryCatchPattern":"try {\n  builder.push(range, tokenType, modifiers)\n} catch (e) {\n  if (e.message === 'Illegal argument') {\n    console.error('push called with mismatched overload arguments', arguments)\n  }\n}","preventionTips":["Pick one overload style per builder and stick to it","Type the wrapper function's parameters strictly to catch mistakes at compile time","Add unit tests for each overload you use"],"tags":["typescript","api-misuse","semantic-tokens"],"backgroundTag":"illegal-argument-overload","analyzedSha":"50e974d9692461a69147d5cab146a8d3e439abe4","analyzedAt":"2026-08-31T11:17:23.966Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}