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

Method getFilePath

src/integrations/editor/EditorUtils.ts:106–127  ·  view source on GitHub ↗

* Retrieves the file path of a given text document. * Utilizes an internal cache to avoid redundant computations. * If the document belongs to a workspace, attempts to compute a relative path; otherwise, returns the absolute fsPath. * * @param document - The text document for which to retrie

(document: vscode.TextDocument)

Source from the content-addressed store, hash-verified

104 * @returns The file path as a string.
105 */
106 static getFilePath(document: vscode.TextDocument): string {
107 let filePath = this.filePathCache.get(document)
108 if (filePath) {
109 return filePath
110 }
111
112 try {
113 const workspaceFolder = vscode.workspace.getWorkspaceFolder(document.uri)
114 if (!workspaceFolder) {
115 filePath = document.uri.fsPath
116 } else {
117 const relativePath = path.relative(workspaceFolder.uri.fsPath, document.uri.fsPath)
118 filePath = !relativePath || relativePath.startsWith("..") ? document.uri.fsPath : relativePath
119 }
120
121 this.filePathCache.set(document, filePath)
122 return filePath
123 } catch (error) {
124 console.error("Error getting file path:", error)
125 return document.uri.fsPath
126 }
127 }
128
129 /**
130 * Converts a VSCode Diagnostic object to a local DiagnosticData instance.

Callers 3

getEditorContextMethod · 0.95
provideCodeActionsMethod · 0.80

Calls 3

getMethod · 0.65
setMethod · 0.65
errorMethod · 0.65

Tested by

no test coverage detected