{"record":{"id":"ea78fc4f1173be3c","repo":"microsoft/vscode","slug":"please-open-a-text-editor-to-use-the-selection","errorCode":null,"errorMessage":"Please open a text editor to use the `#selection` variable.","messagePattern":"Please open a text editor to use the `#selection` variable\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"extensions/copilot/src/extension/conversation/vscode-node/remoteAgents.ts","lineNumber":646,"sourceCode":"\n\t\t// Check whether we can send file and selection data implicitly\n\t\tif (this.checkAuthorized(slug)) {\n\t\t\tconst { activeTextEditor } = this.tabsAndEditorsService;\n\t\t\tif (activeTextEditor && variables.find(v => v.id.startsWith('vscode.implicit'))) {\n\t\t\t\tawait addFileReference(activeTextEditor.document, undefined, true);\n\t\t\t\tawait addSelectionReference(activeTextEditor, undefined, undefined, true);\n\t\t\t\thasSentImplicitSelectionReference = true;\n\t\t\t}\n\t\t}\n\n\t\tfor (const variable of variables) {\n\t\t\tif (URI.isUri(variable.value)) {\n\t\t\t\tconst textDocument = await this.workspaceService.openTextDocument(variable.value);\n\t\t\t\tawait addFileReference(textDocument, variable.name);\n\t\t\t} else if (variable.name === 'selection') {\n\t\t\t\tconst { activeTextEditor } = this.tabsAndEditorsService;\n\t\t\t\tif (!activeTextEditor) {\n\t\t\t\t\tthrow new Error(l10n.t({ message: 'Please open a text editor to use the `#selection` variable.', comment: '{Locked=\\'`#selection`\\'}' }));\n\t\t\t\t}\n\t\t\t\tif (!hasSentImplicitSelectionReference) {\n\t\t\t\t\tawait addSelectionReference(activeTextEditor, variable.name, true);\n\t\t\t\t}\n\t\t\t} else if (variable.name === 'editor' && this.tabsAndEditorsService.activeTextEditor) {\n\t\t\t\tawait addFileReference(this.tabsAndEditorsService.activeTextEditor.document, variable.name);\n\t\t\t}\n\t\t}\n\n\t\t// Always send the open GitHub repositories\n\t\tif (!this.gitService.isInitialized) {\n\t\t\tawait this.gitService.initialize();\n\t\t}\n\t\tconst repositories = this.gitService.repositories;\n\t\tfor (const repository of repositories) {\n\t\t\tconst repoId = getGitHubRepoInfoFromContext(repository)?.id;\n\t\t\tif (!repoId) {\n\t\t\t\tcontinue; // Not a GitHub repository","sourceCodeStart":628,"sourceCodeEnd":664,"githubUrl":"https://github.com/microsoft/vscode/blob/a94b963a32aa9749d69504576791fa29700ae46d/extensions/copilot/src/extension/conversation/vscode-node/remoteAgents.ts#L628-L664","documentation":"Error \"Please open a text editor to use the `#selection` variable.\" thrown in microsoft/vscode.","triggerScenarios":"Thrown at extensions/copilot/src/extension/conversation/vscode-node/remoteAgents.ts:646 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"a94b963a32aa9749d69504576791fa29700ae46d","analyzedAt":"2026-08-12T01:08:56.794Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}