{"record":{"id":"6e0cabaabfe96b6e","repo":"neoclide/coc.nvim","slug":"file-range-not-found-at-lnum-lnum","errorCode":null,"errorMessage":"File range not found at lnum: ${lnum}","messagePattern":"File range not found at lnum: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/handler/refactor/buffer.ts","lineNumber":140,"sourceCode":"\n  public get fileItems(): FileItem[] {\n    return this._fileItems\n  }\n\n  public getFileItem(uri: string): FileItem | undefined {\n    let filepath = URI.parse(uri).fsPath\n    return this._fileItems.find(o => sameFile(o.filepath, filepath))\n  }\n\n  public getFileRange(lnum: number): FileRange & { filepath: string } {\n    for (let item of this._fileItems) {\n      for (let r of item.ranges) {\n        if (r.lnum == lnum) {\n          return Object.assign(omit(r, ['highlights']), { filepath: item.filepath })\n        }\n      }\n    }\n    throw new Error(`File range not found at lnum: ${lnum}`)\n  }\n\n  public onChange(e: DidChangeTextDocumentParams): void {\n    if (this.changing) return\n    if (e.contentChanges.length === 0) {\n      this.highlightLineNr()\n      this.nvim.redrawVim()\n      return\n    }\n    let { nvim } = this\n    e = fixChangeParams(e)\n    let change = e.contentChanges[0]\n    let { original } = e\n    if (change.range.end.line > 2) {\n      nvim.call('setbufvar', [e.bufnr, '&modified', 1], true)\n    }\n    let { range, text } = change\n    let lineChange = lineCountChange(TextEdit.replace(range, text))","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/neoclide/coc.nvim/blob/50e974d9692461a69147d5cab146a8d3e439abe4/src/handler/refactor/buffer.ts#L122-L158","documentation":"RefactorBuffer.getFileRange looks up a FileRange by its line number in the refactor result buffer and throws when no registered range occupies that lnum. Callers (infos, r) rely on the cursor being inside a listed file entry; an arbitrary line yields no range.","triggerScenarios":"Calling `:CocCommand document.refactorSearch infos` or pressing the mapped key ('r' path) while the cursor sits on a line of the refactor panel that is not one of the recorded file-range lines (headers, separators, code lines not covered by ranges).","commonSituations":"Cursor on a file header or blank line instead of a result line; refactor panel was edited/reloaded so recorded lnums shifted; invoking the command from a window other than the refactor buffer.","solutions":["Move the cursor to a highlighted result line inside the refactor buffer before invoking the command.","Do not manually edit the refactor buffer; regenerate it with a fresh `:CocCommand document.refactorSearch`.","If ranges look stale (buffer edited after generation), close and redo the refactor search.","Check your mapping targets the correct command/window."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// check the cursor line is a recorded entry before invoking\nconst lnum = await vim.call('line', '.')\n// inspect the refactor buffer's highlighted entry lines\nif (!entryLnums.has(lnum)) return","typeGuard":null,"tryCatchPattern":"try {\n  const range = buffer.getFileRange(lnum)\n} catch (e) {\n  if (String(e?.message).startsWith('File range not found at lnum')) return\n  throw e\n}","preventionTips":["Only invoke refactor-search commands with the cursor on a result line","Never hand-edit the refactor buffer, which shifts recorded lnums","Regenerate the refactor search after any buffer edit"],"tags":["refactor","coc-nvim","cursor-position","line-range"],"backgroundTag":"cursor-line-not-a-search-result","analyzedSha":"50e974d9692461a69147d5cab146a8d3e439abe4","analyzedAt":"2026-08-31T11:17:23.966Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}