MCPcopy Create free account
hub / github.com/coderoad/coderoad-vscode / openFiles

Function openFiles

src/services/hooks/utils/openFiles.ts:5–23  ·  view source on GitHub ↗
(files: string[] = [])

Source from the content-addressed store, hash-verified

3import logger from '../../logger'
4
5const openFiles = async (files: string[] = []): Promise<void> => {
6 if (!files.length) {
7 return
8 }
9 for (const filePath of files) {
10 try {
11 const workspaceFolders: readonly vscode.WorkspaceFolder[] | undefined = vscode.workspace.workspaceFolders
12 if (!workspaceFolders || !workspaceFolders.length) {
13 throw new Error('No workspace directory. Open a workspace directory and try again')
14 }
15 const wr: string = workspaceFolders[0].uri.path
16 const absoluteFilePath = join(wr, filePath)
17 const doc = await vscode.workspace.openTextDocument(absoluteFilePath)
18 await vscode.window.showTextDocument(doc, vscode.ViewColumn.One)
19 } catch (error: any) {
20 logger(`Failed to open file ${filePath}: ${error.message}`)
21 }
22 }
23}
24
25export default openFiles

Callers 2

onSetupEnterFunction · 0.85
onSolutionEnterFunction · 0.85

Calls 1

loggerFunction · 0.50

Tested by

no test coverage detected