{"record":{"id":"26217d9af8b179e9","repo":"microsoft/typescript-go","slug":"forrelease-requires-setprerelease-unless-nativepre","errorCode":null,"errorMessage":"forRelease requires setPrerelease unless nativePreviewReleaseVersion is hardcoded and VSIX production is disabled","messagePattern":"forRelease requires setPrerelease unless nativePreviewReleaseVersion is hardcoded and VSIX production is disabled","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"Herebyfile.mjs","lineNumber":99,"sourceCode":"\r\n// We can't use parseArgs' strict mode as it errors on hereby's --tasks flag.\r\n/**\r\n * @typedef {{ [K in keyof typeof rawOptions as {} extends Record<K, 1> ? never : K]: typeof rawOptions[K] }} Options\r\n */\r\nconst options = /** @type {Options} */ (rawOptions);\r\n\r\n// Native release branches can edit these constants to publish a fixed stable version.\r\n// Main publishes prerelease builds of the TypeScript package.\r\nconst nativePreviewReleaseProfile = /** @type {\"native-preview\" | \"typescript\"} */ (\"typescript\");\r\nconst nativePreviewReleaseVersion = /** @type {string | undefined} */ (undefined);\r\nconst produceNativePreviewVsix = /** @type {boolean} */ (false);\r\nconst produceTypeScriptNightlyVsix = /** @type {boolean} */ (true);\r\nconst usePublishedPlatformPackagesForVsix = /** @type {boolean} */ (false);\r\nconst produceAnyVsix = produceNativePreviewVsix || produceTypeScriptNightlyVsix;\r\nconst publishAsTypescript = nativePreviewReleaseProfile === \"typescript\";\r\n\r\nif (options.forRelease && !options.setPrerelease && (!nativePreviewReleaseVersion || produceAnyVsix)) {\r\n    throw new Error(\"forRelease requires setPrerelease unless nativePreviewReleaseVersion is hardcoded and VSIX production is disabled\");\r\n}\r\nif (usePublishedPlatformPackagesForVsix && !publishAsTypescript) {\r\n    throw new Error(\"usePublishedPlatformPackagesForVsix requires nativePreviewReleaseProfile to be 'typescript'\");\r\n}\r\n\r\nconst defaultGoBuildTags = [\r\n    ...(options.noembed ? [\"noembed\"] : []),\r\n];\r\n\r\n/**\r\n * @param  {...string} extra\r\n * @returns {string[]}\r\n */\r\nfunction goBuildTags(...extra) {\r\n    const tags = new Set(defaultGoBuildTags.concat(extra));\r\n    return tags.size ? [`-tags=${[...tags].join(\",\")}`] : [];\r\n}\r\n\r","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/microsoft/typescript-go/blob/1bcfa18d79a3be41772223d5c05dfe4480e614ff/Herebyfile.mjs#L81-L117","documentation":"Same nil-project condition as the plain lookup, but on the auto-import path: Session.GetLanguageServiceWithAutoImports clones the snapshot with cloneWithAutoImports for the URI, then calls GetDefaultProject on the clone. If the file belongs to no project, the freshly cloned snapshot is explicitly Deref'd (its initial ref of 1 is released to avoid a leak) and the error is returned. This is the entry point used for completions that need auto-import resolution, so it typically surfaces mid-completion-request.","triggerScenarios":"Triggering a completion (or other auto-import-enabled request) in a document that no project in the cloned snapshot contains: never opened via didOpen, excluded from every tsconfig, outside the workspace root, or a URI whose normalized path does not match the ProjectCollection keys. Because cloneWithAutoImports only enriches import resolution, it never creates a project for an unknown file — nil in implies nil out.","commonSituations":"Completing in a scratch/untitled buffer; completing in a file recently created on disk but not yet added to the project graph or reloaded after tsconfig edits; single-file sessions where no inferred project backs the file; VS Code multi-root workspaces where one root's tsconfig excludes the requested file.","solutions":["Ensure the document is part of a project before requesting completions: open it via didOpen and/or include it in tsconfig.json.","If the tsconfig was edited, wait for the configuration-change reload to be adopted (the clone is based on baseSnapshot; stale snapshots keep the old project set).","Guard callers: check snapshot.GetProjectsContainingFile(uri) (snapshot.go:86) and skip/degrade the auto-import path instead of failing the whole request.","Verify path/case normalization of the URI matches the host filesystem to avoid a false miss in GetDefaultProject."],"exampleFix":"// before\nls, err := session.GetLanguageServiceWithAutoImports(ctx, snapshot, uri)\nif err != nil { return err }\n\n// after: degrade gracefully for out-of-project files\nif len(snapshot.GetProjectsContainingFile(uri)) == 0 {\n\tls, err = session.GetLanguageService(ctx, uri) // or return empty completions\n\tif err != nil { return err }\n} else {\n\tls, err = session.GetLanguageServiceWithAutoImports(ctx, snapshot, uri)\n\tif err != nil { return err }\n}","handlingStrategy":"validation","validationCode":"// auto-import path only works for files already inside a project\nif len(baseSnapshot.GetProjectsContainingFile(uri)) == 0 {\n\t// skip auto-import enrichment; fall back to plain service or empty completions\n\treturn session.GetLanguageService(ctx, uri)\n}","typeGuard":"func canAutoImport(snap *project.Snapshot, uri lsproto.DocumentUri) bool {\n\treturn snap.GetDefaultProject(uri) != nil // clone preserves the project set\n}","tryCatchPattern":"ls, err := session.GetLanguageServiceWithAutoImports(ctx, snap, uri)\nif err != nil {\n\tif strings.Contains(err.Error(), \"no project found for URI\") {\n\t\t// completion can continue without auto-imports\n\t\treturn basicCompletions(ctx, uri)\n\t}\n\treturn nil, err\n}","preventionTips":["Ensure didOpen preceded the completion request.","After tsconfig edits, wait for the new snapshot to be adopted before requesting completions.","Treat out-of-project files as a normal completion edge case, not an error path."],"tags":["lsp","auto-imports","completion","project-resolution"],"backgroundTag":null,"analyzedSha":"1bcfa18d79a3be41772223d5c05dfe4480e614ff","analyzedAt":"2026-08-16T02:12:00.115Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}