Skip to content

Commit 89cdae0

Browse files
avoid throwing error for single-file mode task configuration (#6828)
* change master to main * ignore single-mode files error * linter error
1 parent f73a5d1 commit 89cdae0

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

Extension/src/LanguageServer/cppBuildTaskProvider.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import * as path from 'path';
66
import {
77
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
99
} from 'vscode';
1010
import * as os from 'os';
1111
import * as util from '../common';
@@ -181,13 +181,18 @@ export class CppBuildTaskProvider implements TaskProvider {
181181
};
182182
}
183183

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+
}
191196
}
192197

193198
const scope: TaskScope = TaskScope.Workspace;

0 commit comments

Comments
 (0)