-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathLinuxMain.ts
49 lines (44 loc) · 1.51 KB
/
LinuxMain.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//===----------------------------------------------------------------------===//
//
// This source file is part of the VS Code Swift open source project
//
// Copyright (c) 2024 Apple Inc. and the VS Code Swift project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of VS Code Swift project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
import * as vscode from "vscode";
import { pathExists } from "./utilities/filesystem";
/**
* Cache the existence of `Tests/LinuxMain.swift`.
*/
export class LinuxMain {
private fileWatcher: vscode.FileSystemWatcher;
constructor(
folder: vscode.Uri,
public exists: boolean
) {
this.fileWatcher = vscode.workspace.createFileSystemWatcher(
new vscode.RelativePattern(folder, "Tests/LinuxMain.swift"),
false,
true
);
this.fileWatcher.onDidCreate(() => (this.exists = true));
this.fileWatcher.onDidDelete(() => (this.exists = false));
}
static async create(folder: vscode.Uri): Promise<LinuxMain> {
const hasLinuxMain = await pathExists(folder.fsPath, "Tests", "LinuxMain.swift");
return new LinuxMain(folder, hasLinuxMain);
}
/**
* Disposes the {@link vscode.FileSystemWatcher file system watcher} when
* the extension deactivates.
*/
dispose() {
this.fileWatcher?.dispose();
}
}