MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / showTextDocument

Method showTextDocument

packages/vscode-shim/src/api/WindowAPI.ts:151–204  ·  view source on GitHub ↗
(
		documentOrUri: TextDocument | Uri,
		columnOrOptions?: ViewColumn | TextDocumentShowOptions,
		_preserveFocus?: boolean,
	)

Source from the content-addressed store, hash-verified

149 }
150
151 async showTextDocument(
152 documentOrUri: TextDocument | Uri,
153 columnOrOptions?: ViewColumn | TextDocumentShowOptions,
154 _preserveFocus?: boolean,
155 ): Promise<TextEditor> {
156 // Mock implementation for CLI
157 // In a real VSCode environment, this would open the document in an editor
158 const uri = documentOrUri instanceof Uri ? documentOrUri : documentOrUri.uri
159 logs.debug(`showTextDocument called for: ${uri?.toString() || "unknown"}`, "VSCode.Window")
160
161 // Create a placeholder editor first so it's in visibleTextEditors when onDidOpenTextDocument fires
162 const placeholderEditor: TextEditor = {
163 document: { uri } as TextDocument,
164 selection: new Selection(new Position(0, 0), new Position(0, 0)),
165 selections: [new Selection(new Position(0, 0), new Position(0, 0))],
166 visibleRanges: [new Range(new Position(0, 0), new Position(0, 0))],
167 options: {},
168 viewColumn: typeof columnOrOptions === "number" ? columnOrOptions : ViewColumn.One,
169 edit: () => Promise.resolve(true),
170 insertSnippet: () => Promise.resolve(true),
171 setDecorations: () => {},
172 revealRange: () => {},
173 show: () => {},
174 hide: () => {},
175 }
176
177 // Add placeholder to visible editors BEFORE opening document
178 this.visibleTextEditors.push(placeholderEditor)
179 logs.debug(
180 `Placeholder editor added to visibleTextEditors, total: ${this.visibleTextEditors.length}`,
181 "VSCode.Window",
182 )
183
184 // If we have a URI, open the document (this will fire onDidOpenTextDocument)
185 let document: TextDocument | Uri = documentOrUri
186 if (documentOrUri instanceof Uri && this._workspace) {
187 logs.debug("Opening document via workspace.openTextDocument", "VSCode.Window")
188 document = await this._workspace.openTextDocument(uri)
189 logs.debug("Document opened successfully", "VSCode.Window")
190
191 // Update the placeholder editor with the real document
192 placeholderEditor.document = document
193 }
194
195 // Fire events immediately using setImmediate
196 setImmediate(() => {
197 logs.debug("Firing onDidChangeVisibleTextEditors event", "VSCode.Window")
198 this._onDidChangeVisibleTextEditors.fire(this.visibleTextEditors)
199 logs.debug("onDidChangeVisibleTextEditors event fired", "VSCode.Window")
200 })
201
202 logs.debug("Returning editor from showTextDocument", "VSCode.Window")
203 return placeholderEditor
204 }
205
206 registerWebviewViewProvider(
207 viewId: string,

Callers 11

WindowAPI.test.tsFile · 0.80
webviewMessageHandlerFunction · 0.80
generateErrorDiagnosticsFunction · 0.80
restorePreviewTabsMethod · 0.80
openDiffEditorMethod · 0.80
saveDirectlyMethod · 0.80
downloadTaskFunction · 0.80
openFileFunction · 0.80

Calls 4

openTextDocumentMethod · 0.80
fireMethod · 0.80
debugMethod · 0.65
toStringMethod · 0.65

Tested by

no test coverage detected