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

Method open

src/integrations/editor/DiffViewProvider.ts:93–247  ·  view source on GitHub ↗
(relPath: string)

Source from the content-addressed store, hash-verified

91 }
92
93 async open(relPath: string): Promise<void> {
94 this.relPath = relPath
95 const fileExists = this.editType === "modify"
96 const absolutePath = path.resolve(this.cwd, relPath)
97 this.isEditing = true
98
99 // Capture the current scroll position before we close the tab so we can
100 // restore it after saving/reverting.
101 const existingEditor = vscode.window.visibleTextEditors.find(
102 (e) => e.document.uri.scheme === "file" && arePathsEqual(e.document.uri.fsPath, absolutePath),
103 )
104 this.preEditScrollLine = existingEditor?.visibleRanges?.[0]?.start.line
105
106 // If the file is already open, ensure it's not dirty before getting its
107 // contents.
108 if (fileExists) {
109 const existingDocument = vscode.workspace.textDocuments.find(
110 (doc) => doc.uri.scheme === "file" && arePathsEqual(doc.uri.fsPath, absolutePath),
111 )
112
113 if (existingDocument && existingDocument.isDirty) {
114 await existingDocument.save()
115 }
116 }
117
118 // Get diagnostics before editing the file, we'll compare to diagnostics
119 // after editing to see if cline needs to fix anything.
120 this.preDiagnostics = vscode.languages.getDiagnostics()
121
122 if (fileExists) {
123 this.originalContent = await fs.readFile(absolutePath, "utf-8")
124 } else {
125 this.originalContent = ""
126 }
127
128 // For new files, create any necessary directories and keep track of new
129 // directories to delete if the user denies the operation.
130 this.createdDirs = await createDirectoriesForFile(absolutePath)
131
132 // Make sure the file exists before we open it.
133 if (!fileExists) {
134 await fs.writeFile(absolutePath, "")
135 }
136
137 // If the file was already open, close it (must happen after showing the
138 // diff view since if it's the only tab the column will close).
139 this.documentWasOpen = false
140 this.documentWasPinned = false
141
142 // Close the tab if it's open (it's already saved above).
143 const tabs = vscode.window.tabGroups.all
144 .map((tg) => tg.tabs)
145 .flat()
146 .filter(
147 (tab) =>
148 tab.input instanceof vscode.TabInputText &&
149 tab.input.uri.scheme === "file" &&
150 arePathsEqual(tab.input.uri.fsPath, absolutePath),

Callers 12

readArtifactMethod · 0.80
searchInArtifactMethod · 0.80
executeMethod · 0.80
executeMethod · 0.80
executeMethod · 0.80
handleAddFileMethod · 0.80
handleUpdateFileMethod · 0.80
executeMethod · 0.80
handlePartialMethod · 0.80
executeMethod · 0.80
openWithScrollListenerFunction · 0.80

Calls 12

openDiffEditorMethod · 0.95
arePathsEqualFunction · 0.90
createDirectoriesForFileFunction · 0.90
writeFileMethod · 0.80
addLinesMethod · 0.80
saveMethod · 0.65
closeMethod · 0.65
errorMethod · 0.65
readFileMethod · 0.45

Tested by 1

openWithScrollListenerFunction · 0.64