|
5 | 5 | import * as path from 'path'; |
6 | 6 | import { |
7 | 7 | TaskDefinition, Task, TaskGroup, ShellExecution, Uri, workspace, |
8 | | - TaskProvider, TaskScope, CustomExecution, ProcessExecution, TextEditor, Pseudoterminal, EventEmitter, Event, TerminalDimensions, window |
| 8 | + TaskProvider, TaskScope, CustomExecution, ProcessExecution, TextEditor, Pseudoterminal, EventEmitter, Event, TerminalDimensions, window, WorkspaceFolder |
9 | 9 | } from 'vscode'; |
10 | 10 | import * as os from 'os'; |
11 | 11 | import * as util from '../common'; |
@@ -181,13 +181,18 @@ export class CppBuildTaskProvider implements TaskProvider { |
181 | 181 | }; |
182 | 182 | } |
183 | 183 |
|
184 | | - const activeClient: Client = ext.getActiveClient(); |
185 | | - const uri: Uri | undefined = activeClient.RootUri; |
186 | | - if (!uri) { |
187 | | - throw new Error("No client URI found in getBuildTasks()"); |
188 | | - } |
189 | | - if (!workspace.getWorkspaceFolder(uri)) { |
190 | | - throw new Error("No target WorkspaceFolder found in getBuildTasks()"); |
| 184 | + const editor: TextEditor | undefined = window.activeTextEditor; |
| 185 | + const folder: WorkspaceFolder | undefined = editor ? workspace.getWorkspaceFolder(editor.document.uri) : undefined; |
| 186 | + // Check uri exists (single-mode files are ignored). |
| 187 | + if (folder) { |
| 188 | + const activeClient: Client = ext.getActiveClient(); |
| 189 | + const uri: Uri | undefined = activeClient.RootUri; |
| 190 | + if (!uri) { |
| 191 | + throw new Error("No client URI found in getBuildTasks()"); |
| 192 | + } |
| 193 | + if (!workspace.getWorkspaceFolder(uri)) { |
| 194 | + throw new Error("No target WorkspaceFolder found in getBuildTasks()"); |
| 195 | + } |
191 | 196 | } |
192 | 197 |
|
193 | 198 | const scope: TaskScope = TaskScope.Workspace; |
|
0 commit comments