vscode-impls.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. console.log("Loading stub impls...")
  2. const { createStub } = require("./stub-utils")
  3. // Import the base vscode object from stubs
  4. const vscode = require("./vscode-stubs.js")
  5. // Extend the existing window object from stubs rather than overwriting it
  6. vscode.window = {
  7. ...vscode.window, // Keep existing properties from stubs
  8. showInformationMessage: (...args) => {
  9. console.log("Stubbed showInformationMessage:", ...args)
  10. return Promise.resolve(undefined)
  11. },
  12. showWarningMessage: (...args) => {
  13. console.log("Stubbed showWarningMessage:", ...args)
  14. return Promise.resolve(undefined)
  15. },
  16. showErrorMessage: (...args) => {
  17. console.log("Stubbed showErrorMessage:", ...args)
  18. return Promise.resolve(undefined)
  19. },
  20. showInputBox: async (options) => {
  21. console.log("Stubbed showInputBox:", options)
  22. return ""
  23. },
  24. showOpenDialog: async (options) => {
  25. console.log("Stubbed showOpenDialog:", options)
  26. return []
  27. },
  28. showSaveDialog: async (options) => {
  29. console.log("Stubbed showSaveDialog:", options)
  30. return undefined
  31. },
  32. showTextDocument: async (...args) => {
  33. console.log("Stubbed showTextDocument:", ...args)
  34. return {}
  35. },
  36. createTerminal: (...args) => {
  37. // In standalone mode, terminals are managed directly by Task.terminalManager (StandaloneTerminalManager)
  38. // This stub is provided for compatibility but should not be called directly
  39. console.log("Stubbed createTerminal:", ...args)
  40. // Return a minimal stub terminal object
  41. const stubTerminal = {
  42. name: args[0]?.name || args[0] || "Terminal",
  43. processId: Promise.resolve(undefined),
  44. creationOptions: {},
  45. exitStatus: undefined,
  46. state: { isInteractedWith: false },
  47. sendText: (text) => console.log("Stubbed terminal.sendText:", text),
  48. show: () => console.log("Stubbed terminal.show"),
  49. hide: () => console.log("Stubbed terminal.hide"),
  50. dispose: () => console.log("Stubbed terminal.dispose"),
  51. }
  52. vscode.window.terminals.push(stubTerminal)
  53. return stubTerminal
  54. },
  55. activeTextEditor: undefined,
  56. visibleTextEditors: [],
  57. tabGroups: {
  58. all: [],
  59. close: async () => {},
  60. onDidChangeTabs: createStub("vscode.env.tabGroups.onDidChangeTabs"),
  61. activeTabGroup: { tabs: [] },
  62. },
  63. withProgress: async (_options, task) => {
  64. console.log("Stubbed withProgress")
  65. return task({ report: () => {} })
  66. },
  67. registerUriHandler: () => ({ dispose: () => {} }),
  68. registerWebviewViewProvider: () => ({ dispose: () => {} }),
  69. onDidChangeActiveTextEditor: () => ({ dispose: () => {} }),
  70. createTextEditorDecorationType: () => ({ dispose: () => {} }),
  71. createWebviewPanel: (..._args) => {
  72. throw new Error("WebviewPanel is not supported in standalone app.")
  73. },
  74. }
  75. vscode.env = {
  76. uriScheme: "vscode",
  77. appName: "Visual Studio Code",
  78. appRoot: "/tmp/vscode/appRoot",
  79. language: "en",
  80. machineId: "stub-machine-id",
  81. remoteName: undefined,
  82. sessionId: "stub-session-id",
  83. shell: "/bin/bash",
  84. clipboard: createStub("vscode.env.clipboard"),
  85. openExternal: createStub("vscode.env.openExternal"),
  86. getQueryParameter: createStub("vscode.env.getQueryParameter"),
  87. onDidChangeTelemetryEnabled: createStub("vscode.env.onDidChangeTelemetryEnabled"),
  88. isTelemetryEnabled: createStub("vscode.env.isTelemetryEnabled"),
  89. telemetryConfiguration: createStub("vscode.env.telemetryConfiguration"),
  90. onDidChangeTelemetryConfiguration: createStub("vscode.env.onDidChangeTelemetryConfiguration"),
  91. createTelemetryLogger: createStub("vscode.env.createTelemetryLogger"),
  92. }
  93. vscode.Uri = {
  94. parse: (uriString) => {
  95. const url = new URL(uriString)
  96. return {
  97. scheme: url.protocol.replace(":", ""),
  98. authority: url.hostname,
  99. path: url.pathname,
  100. query: url.search.slice(1),
  101. fragment: url.hash.slice(1),
  102. fsPath: `/tmp${url.pathname}`,
  103. toString: () => uriString,
  104. toJSON: () => uriString,
  105. with: (change) => {
  106. const newUrl = new URL(uriString)
  107. if (change.scheme) {
  108. newUrl.protocol = change.scheme + ":"
  109. }
  110. if (change.authority) {
  111. newUrl.hostname = change.authority
  112. }
  113. if (change.path) {
  114. newUrl.pathname = change.path
  115. }
  116. if (change.query) {
  117. newUrl.search = "?" + change.query
  118. }
  119. if (change.fragment) {
  120. newUrl.hash = "#" + change.fragment
  121. }
  122. return vscode.Uri.parse(newUrl.toString())
  123. },
  124. }
  125. },
  126. file: (path) => {
  127. return {
  128. scheme: "file",
  129. authority: "",
  130. path,
  131. fsPath: path,
  132. query: "",
  133. fragment: "",
  134. toString: () => `file://${path}`,
  135. toJSON: () => `file://${path}`,
  136. with: (change) => {
  137. const modified = Object.assign({}, vscode.Uri.file(path), change)
  138. return modified
  139. },
  140. }
  141. },
  142. joinPath: (...segments) => {
  143. const joined = segments.map((s) => (typeof s === "string" ? s : s.path)).join("/")
  144. return vscode.Uri.file("/" + joined.replace(/\/+/g, "/"))
  145. },
  146. }
  147. console.log("Finished loading stub impls...")