()
| 220 | |
| 221 | // TODO: very similar to ./utils.getCurrentWorkspaceFolder() |
| 222 | export function projectPath(): { path: string | undefined; } { |
| 223 | |
| 224 | if (typeof workspace.workspaceFolders !== 'undefined') { |
| 225 | // Is there a root folder open? |
| 226 | |
| 227 | if (workspace.workspaceFolders.length === 1) { |
| 228 | // In single root common case, this will always work. |
| 229 | return { |
| 230 | path: workspace.workspaceFolders[0].uri.path |
| 231 | }; |
| 232 | } else if (workspace.workspaceFolders.length > 1) { |
| 233 | // In less common multi-root folder case is a bit tricky. If the active |
| 234 | // text editor has scheme 'untitled:' (is unsaved), then |
| 235 | // workspace.getWorkspaceFolder() won't be able to find its Uri in any |
| 236 | // folder and will return undefined. |
| 237 | const currentDocument = getLastActiveTextEditor().document; |
| 238 | const currentDocFolder = workspace.getWorkspaceFolder(currentDocument.uri); |
| 239 | if (typeof currentDocFolder !== 'undefined') { |
| 240 | return { |
| 241 | path: currentDocFolder.uri.path |
| 242 | }; |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | // if we got to here either: |
| 248 | // - the workspaceFolders array was undefined (no folder open) |
| 249 | // - the activeText editor was an unsaved document, which has undefined workspace folder. |
| 250 | // return undefined and handle with a message in R. |
| 251 | return { |
| 252 | path: undefined |
| 253 | }; |
| 254 | } |
| 255 | |
| 256 | export async function documentNew(text: string, type: string, position: number[]): Promise<void> { |
| 257 | const currentProjectPath = projectPath().path; |
no test coverage detected