MCPcopy Create free account
hub / github.com/anomalyco/opencode / getActiveFile

Function getActiveFile

sdks/vscode/src/extension.ts:103–136  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

101 }
102
103 function getActiveFile() {
104 const activeEditor = vscode.window.activeTextEditor
105 if (!activeEditor) {
106 return
107 }
108
109 const document = activeEditor.document
110 const workspaceFolder = vscode.workspace.getWorkspaceFolder(document.uri)
111 if (!workspaceFolder) {
112 return
113 }
114
115 // Get the relative path from workspace root
116 const relativePath = vscode.workspace.asRelativePath(document.uri)
117 let filepathWithAt = `@${relativePath}`
118
119 // Check if there's a selection and add line numbers
120 const selection = activeEditor.selection
121 if (!selection.isEmpty) {
122 // Convert to 1-based line numbers
123 const startLine = selection.start.line + 1
124 const endLine = selection.end.line + 1
125
126 if (startLine === endLine) {
127 // Single line selection
128 filepathWithAt += `#L${startLine}`
129 } else {
130 // Multi-line selection
131 filepathWithAt += `#L${startLine}-${endLine}`
132 }
133 }
134
135 return filepathWithAt
136 }
137}

Callers 2

activateFunction · 0.85
openTerminalFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected