{"record":{"id":"2bbcd7c091df4f33","repo":"AykutSarac/jsoncrack.com","slug":"please-select-some-text-first","errorCode":null,"errorMessage":"Please select some text first!","messagePattern":"Please select some text first!","errorType":"console","errorClass":null,"httpStatus":null,"severity":"info","filePath":"apps/vscode/ext-src/extension.ts","lineNumber":31,"sourceCode":"  context.subscriptions.push(\n    vscode.commands.registerCommand(\"jsoncrack-vscode.start\", () =>\n      createWebviewForActiveEditor(context)\n    ),\n    vscode.commands.registerCommand(\"jsoncrack-vscode.start.specific\", (content?: string) =>\n      createWebviewForContent(context, content)\n    ),\n    vscode.commands.registerCommand(\"jsoncrack-vscode.start.selected\", () =>\n      createWebviewForSelectedText(context)\n    )\n  );\n}\n\n// create webview for selected text\nasync function createWebviewForSelectedText(context: vscode.ExtensionContext) {\n  const editor = vscode.window.activeTextEditor;\n\n  if (editor && editor.selection.isEmpty) {\n    vscode.window.showInformationMessage(\"Please select some text first!\");\n    return;\n  }\n\n  const selectedText = editor?.document.getText(editor.selection);\n\n  // Create the webview panel and send the selected JSON content\n  const panel = createWebviewPanel(context, getPanelTitle(editor?.document));\n  panel.webview.postMessage({\n    json: selectedText,\n  });\n\n  const onReceiveMessage = panel.webview.onDidReceiveMessage(e => {\n    if (e === \"ready\") {\n      panel.webview.postMessage({\n        json: selectedText,\n      });\n    }\n  });","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/AykutSarac/jsoncrack.com/blob/3c9af69e23c635356293b6b28cf4cd0af10d1059/apps/vscode/ext-src/extension.ts#L13-L49","documentation":"When the VS Code command jsoncrack-vscode.start.selected runs, it checks editor.selection.isEmpty; if nothing is selected it shows this informational message and returns early. This is a deliberate input guard, not an exception — the command requires a text selection to populate the webview.","triggerScenarios":"Invoking the 'Open Selected' command via palette or keybinding with the cursor at a single position (no range selected); running the command in an editor with no active text; empty new untitled file.","commonSituations":"User expects the command to auto-select the whole document; command bound to a key hit accidentally; empty file.","solutions":["Select text (or Select All) first, then re-run the command.","If whole-document behavior is desired, fall back to editor.document.getText() when the selection is empty (as the start command does).","Point the user toward the non-selected command via the message.","Rebind the keybinding if it is triggered accidentally."],"exampleFix":"// before\nif (editor && editor.selection.isEmpty) {\n  vscode.window.showInformationMessage(\"Please select some text first!\");\n  return;\n}\nconst selectedText = editor?.document.getText(editor.selection);\n\n// after\nlet selectedText: string | undefined;\nif (!editor || editor.selection.isEmpty) {\n  selectedText = editor?.document.getText();\n  if (!selectedText) {\n    vscode.window.showInformationMessage(\"Please select some text first!\");\n    return;\n  }\n} else {\n  selectedText = editor.document.getText(editor.selection);\n}","handlingStrategy":"validation","validationCode":"function hasSelection(editor?: vscode.TextEditor): editor is vscode.TextEditor {\n  return !!editor && !editor.selection.isEmpty;\n}","typeGuard":"function hasSelection(editor?: vscode.TextEditor): editor is vscode.TextEditor {\n  return !!editor && !editor.selection.isEmpty;\n}","tryCatchPattern":null,"preventionTips":["If whole-document behavior is acceptable, fall back to document.getText() when the selection is empty.","Bind the 'selected' command to a distinct keybinding from the 'start' command so users pick the right one.","Surface a hint pointing to the non-selected command when the guard triggers."],"tags":["vscode","command","validation","ui-text"],"backgroundTag":null,"analyzedSha":"3c9af69e23c635356293b6b28cf4cd0af10d1059","analyzedAt":"2026-08-12T19:00:27.891Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}