{"record":{"id":"3939fca39ea4bc0f","repo":"neoclide/coc.nvim","slug":"tokenmodifier-is-not-in-the-provided-legend","errorCode":null,"errorMessage":"`tokenModifier` is not in the provided legend","messagePattern":"`tokenModifier` is not in the provided legend","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/model/semanticTokensBuilder.ts","lineNumber":95,"sourceCode":"  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\n  private _pushEncoded(line: number, char: number, length: number, tokenType: number, tokenModifiers: number): void {\n    if (this._dataIsSortedAndDeltaEncoded && (line < this._prevLine || (line === this._prevLine && char < this._prevChar))) {\n      // push calls were ordered and are no longer ordered\n      this._dataIsSortedAndDeltaEncoded = false\n\n      // Remove delta encoding from data\n      const tokenCount = (this._data.length / 5) | 0\n      let prevLine = 0\n      let prevChar = 0\n      for (let i = 0; i < tokenCount; i++) {","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/neoclide/coc.nvim/blob/50e974d9692461a69147d5cab146a8d3e439abe4/src/model/semanticTokensBuilder.ts#L77-L113","documentation":"Each string token modifier must exist in the legend's tokenModifiers array so it can be converted to a bitmask. If any modifier string in the modifiers array is unknown to the legend, the builder throws this error.","triggerScenarios":"Calling push(range, 'keyword', ['static']) where 'static' is not in the tokenModifiers array given to the constructor; a server emitting a modifier absent from the client-built legend.","commonSituations":"Client legend built from an older spec while the server added new modifiers (e.g. 'defaultLibrary'); typos in modifier names; forgetting modifiers entirely in the legend object.","solutions":["Include all server-declared modifiers in the tokenModifiers legend array","Filter unknown modifiers before pushing: modifiers.filter(m => legend.tokenModifiers.includes(m))","Sync the legend from the server's SemanticTokensLegend rather than hand-writing it"],"exampleFix":"// before\nbuilder.push(range, 'function', ['static']) // 'static' not in legend\n// after\nconst known = ['static'].filter(m => legend.tokenModifiers.includes(m))\nbuilder.push(range, 'function', known)","handlingStrategy":"validation","validationCode":"const safeModifiers = modifiers.filter(m => legend.tokenModifiers.includes(m))","typeGuard":"function areKnownModifiers(ms: string[], legend: SemanticTokensLegend): boolean {\n  return ms.every(m => legend.tokenModifiers.includes(m))\n}","tryCatchPattern":"try {\n  builder.push(range, tokenType, modifiers)\n} catch (e) {\n  if (e.message.includes('tokenModifier` is not in the provided legend')) {\n    console.warn('Unknown token modifiers dropped', modifiers)\n  }\n}","preventionTips":["Keep the client legend in sync with the server's SemanticTokensLegend","Filter unknown modifiers instead of passing them raw","Log unknown modifiers once to detect legend drift early"],"tags":["semantic-tokens","legend","api-misuse"],"backgroundTag":"token-modifier-not-in-legend","analyzedSha":"50e974d9692461a69147d5cab146a8d3e439abe4","analyzedAt":"2026-08-31T11:17:23.966Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}