{"record":{"id":"6fa2fc5bfd74c3e5","repo":"neoclide/coc.nvim","slug":"required-root-pattern-not-resolved","errorCode":null,"errorMessage":"Required root pattern not resolved.","messagePattern":"Required root pattern not resolved\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/core/documents.ts","lineNumber":200,"sourceCode":"\n  public detach(): void {\n    this._attached = false\n    for (let bufnr of this.buffers.keys()) {\n      this.onBufUnload(bufnr)\n    }\n  }\n\n  public resolveRoot(rootPatterns: string[], requireRootPattern = false): string | undefined {\n    let doc = this.getDocument(this.bufnr)\n    let resolved: string | undefined\n    if (doc && doc.schema == 'file') {\n      let dir = path.dirname(URI.parse(doc.uri).fsPath)\n      resolved = resolveRoot(dir, rootPatterns, this.cwd)\n    } else {\n      resolved = resolveRoot(this.cwd, rootPatterns)\n    }\n    if (requireRootPattern && !resolved) {\n      throw new Error(`Required root pattern not resolved.`)\n    }\n    return resolved\n  }\n\n  public get textDocuments(): LinesTextDocument[] {\n    let docs: LinesTextDocument[] = []\n    for (let b of this.buffers.values()) {\n      if (b.attached) docs.push(b.textDocument)\n    }\n    return docs\n  }\n\n  public getDocument(uri: number | string, caseInsensitive = platform.isWindows || platform.isMacintosh): Document | null | undefined {\n    if (typeof uri === 'number') {\n      return this.buffers.get(uri)\n    }\n    let u = URI.parse(uri)\n    uri = u.toString()","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/neoclide/coc.nvim/blob/50e974d9692461a69147d5cab146a8d3e439abe4/src/core/documents.ts#L182-L218","documentation":"For language servers that declare a required root pattern (requireRootPattern), coc must locate a workspace root by matching rootPatterns (e.g. package.json, .git) starting from the document's directory. If no pattern is found anywhere up the tree, resolveRoot throws because the server cannot be started without a valid workspace root.","triggerScenarios":"Opening a file covered by a language server whose configuration sets requireRootPattern:true while the file lives outside any directory containing the configured rootPatterns.","commonSituations":"Opening a stray .ts file in a temp dir with tsserver configured with required roots; single-file editing outside a project; wrong rootPatterns configured for the language server.","solutions":["Open the file inside a project containing a root pattern (e.g. .git, package.json)","Add/relax rootPatterns in coc settings for that language server, or unset requireRootPattern","Use :CocOpenLog / workspace.rootPatterns to debug which patterns are searched","Create a minimal root marker (e.g. empty .git or the configured pattern file) in the directory"],"exampleFix":"// before (coc-settings.json)\n\"tsserver\": { \"requireRootPattern\": true }\n// after\n\"tsserver\": { \"requireRootPattern\": false, \"rootPatterns\": [\"tsconfig.json\", \".git\"] }","handlingStrategy":"fallback","validationCode":"// before opening the file, confirm a root pattern exists\nconst fs = require('fs'); const path = require('path')\nlet dir = path.dirname(file)\nwhile (true) {\n  if (['.git','package.json','tsconfig.json'].some(p => fs.existsSync(path.join(dir, p)))) break\n  const parent = path.dirname(dir); if (parent === dir) { notify('no workspace root found'); break }\n  dir = parent\n}","typeGuard":null,"tryCatchPattern":"try {\n  await workspace.openTextDocument(uri)\n} catch (e) {\n  if (String(e.message).includes('root pattern')) notify('Open this file inside a project folder')\n  else throw e\n}","preventionTips":["Set sensible rootPatterns for each language server in coc-settings.json","Avoid requireRootPattern:true unless the server truly needs a project root","Keep project marker files (.git, package.json) present in your workspaces","Use workspace.folder/workspace.root to confirm detection before opening files"],"tags":["workspace","language-server","configuration"],"backgroundTag":"workspace-root-not-found","analyzedSha":"50e974d9692461a69147d5cab146a8d3e439abe4","analyzedAt":"2026-08-31T11:17:23.966Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}