|
1 | 1 | 'use strict'; |
| 2 | +import * as fs from 'fs'; |
2 | 3 | import * as jsonc from 'jsonc-parser'; |
3 | 4 | import * as path from 'path'; |
4 | 5 | import * as vscode from 'vscode'; |
5 | 6 | import { IPreferences } from 'vscode-wpilibapi'; |
6 | 7 | import { localize as i18n } from './locale'; |
7 | 8 | import { IPreferencesJson } from './shared/preferencesjson'; |
8 | 9 | import { existsAsync, mkdirAsync, readFileAsync, writeFileAsync } from './utilities'; |
| 10 | +import { logger } from './logger'; |
9 | 11 |
|
10 | 12 | const defaultPreferences: IPreferencesJson = { |
11 | 13 | currentLanguage: 'none', |
@@ -85,6 +87,28 @@ export class Preferences implements IPreferences { |
85 | 87 | } |
86 | 88 |
|
87 | 89 | public getIsWPILibProject(): boolean { |
| 90 | + // If we already know, return it |
| 91 | + if (this.isWPILibProject) { |
| 92 | + return true; |
| 93 | + } |
| 94 | + |
| 95 | + // Synchronously check for the preferences file in the workspace root. |
| 96 | + // This is intentionally sync to avoid updating vscode-wpilibapi |
| 97 | + // This can happen if the file watcher missed an update. |
| 98 | + try { |
| 99 | + const configFilePath = Preferences.getPrefrencesFilePath(this.workspace.uri.fsPath); |
| 100 | + if (fs.existsSync(configFilePath)) { |
| 101 | + vscode.commands.executeCommand('setContext', 'isWPILibProject', true); |
| 102 | + this.isWPILibProject = true; |
| 103 | + this.preferencesFile = vscode.Uri.file(configFilePath); |
| 104 | + this.updatePreferences().catch((err) => { |
| 105 | + logger.error('Failed to update WPILib preferences', err); |
| 106 | + }); |
| 107 | + } |
| 108 | + } catch (err) { |
| 109 | + logger.error('Failed to update WPILib preferences', err); |
| 110 | + } |
| 111 | + |
88 | 112 | return this.isWPILibProject; |
89 | 113 | } |
90 | 114 |
|
|
0 commit comments