{"record":{"id":"28b9061a669f1cd6","repo":"neoclide/coc.nvim","slug":"tokentype-is-not-in-the-provided-legend","errorCode":null,"errorMessage":"`tokenType` is not in the provided legend","messagePattern":"`tokenType` is not in the provided legend","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/model/semanticTokensBuilder.ts","lineNumber":85,"sourceCode":"      // 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) {\n      for (const tokenModifier of tokenModifiers) {\n        if (!this._tokenModifierStrToInt.has(tokenModifier)) {\n          throw new Error('`tokenModifier` is not in the provided legend')\n        }\n        const nTokenModifier = this._tokenModifierStrToInt.get(tokenModifier)!\n        nTokenModifiers |= (1 << nTokenModifier) >>> 0\n      }\n    }\n    this._pushEncoded(line, char, length, nTokenType, nTokenModifiers)\n  }\n","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/neoclide/coc.nvim/blob/50e974d9692461a69147d5cab146a8d3e439abe4/src/model/semanticTokensBuilder.ts#L67-L103","documentation":"When pushing a token with a string tokenType, the builder looks it up in the legend passed to the constructor. If the tokenType string is not present in the legend's tokenTypes array, it cannot be encoded and this error is thrown.","triggerScenarios":"Calling push(range, 'myTokenType', ...) where 'myTokenType' is not in the tokenTypes array supplied to new SemanticTokensBuilder({...}); typos or case mismatches between server legend and client legend.","commonSituations":"Server and client legends drift after adding a new token type on the server; hardcoding token type strings that differ from the server's SemanticTokensLegend; copy-pasting token names from another language's provider.","solutions":["Use the exact strings from the server's legend (fetch via the semanticTokensLegend registration)","Add the missing token type to the builder's legend constructor options","Guard with a check before pushing: if (!legend.tokenTypes.includes(type)) skip or log","Derive the client legend from the server registration instead of hardcoding"],"exampleFix":"// before\nconst builder = new SemanticTokensBuilder({ tokenTypes: ['keyword','string'], tokenModifiers: [] })\nbuilder.push(range, 'namespace') // throws\n// after\nconst builder = new SemanticTokensBuilder({ tokenTypes: ['keyword','string','namespace'], tokenModifiers: [] })","handlingStrategy":"validation","validationCode":"if (!legend.tokenTypes.includes(tokenType)) {\n  console.warn(`Skipping token with unknown type ${tokenType}`)\n  return\n}","typeGuard":"function isKnownTokenType(t: string, legend: SemanticTokensLegend): boolean {\n  return legend.tokenTypes.includes(t)\n}","tryCatchPattern":"try {\n  builder.push(range, tokenType, modifiers)\n} catch (e) {\n  if (e.message.includes('tokenType` is not in the provided legend')) {\n    console.warn(`Unknown token type: ${tokenType}`)\n  }\n}","preventionTips":["Build the legend from the server's registration, never hand-typed","Filter tokens against the legend before pushing","Re-sync the legend when the server updates its capability"],"tags":["semantic-tokens","legend","api-misuse"],"backgroundTag":"token-type-not-in-legend","analyzedSha":"50e974d9692461a69147d5cab146a8d3e439abe4","analyzedAt":"2026-08-31T11:17:23.966Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}