Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public async readAllDebugConfigs(workspaceFolder: WorkspaceFolder): Promise {
const filename = path.join(workspaceFolder.uri.fsPath, '.vscode', 'launch.json');
if (!(await this.fs.fileExists(filename))) {
return [];
}
try {
const text = await this.fs.readFile(filename);
const parsed = parse(text, [], { allowTrailingComma: true, disallowComments: false });
if (!parsed.version || !parsed.configurations || !Array.isArray(parsed.configurations)) {
throw Error('malformed launch.json');
}
// We do not bother ensuring each item is a DebugConfiguration...
return parsed.configurations;
} catch (exc) {
traceError('could not get debug config', exc);
const appShell = this.serviceContainer.get(IApplicationShell);
await appShell.showErrorMessage('Could not load unit test config from launch.json');
return [];
}
}
private resolveWorkspaceFolder(cwd: string): WorkspaceFolder {
export function fromConfigFile(filePath: string, overrides: PartialCertaConfig): CertaConfig {
const fileContents = fs.readFileSync(filePath);
const fileOpts = parse(fileContents.toString()); // Parsing with jsonc-parser lets us safely handle comments.
resolvePaths(path.dirname(filePath), fileOpts);
return fromObject(lodash.defaultsDeep(overrides, fileOpts));
}
}
// Check which properties changed, and fire new ones
let current: string | undefined;
try {
current = fs.readFileSync(file.fsPath, 'utf8');
} catch (error) {
}
if (current === undefined) {
this.lastConfig = defaultConfig;
this.libraryHeaderDirsChanged.fire([]);
this.localHeaderDirsChanged.fire([]);
this.propertiesChange.fire();
return;
}
const parsed: IEditorConfig = jsonc.parse(current);
this.checkForChanges(parsed);
});
vscode.workspace.findFiles(this.gradleJsonFileGlob, wp.uri.fsPath).then(async (f) => {
public async loadConfigs(): Promise {
this.toolchains = [];
let file = '';
try {
file = await readFileAsync(path.join(this.workspace.uri.fsPath, 'build', this.configFile), 'utf8');
} catch (err) {
this.statusBar.show();
this.binaryTypeStatusBar.show();
return false;
}
this.toolchains = jsonc.parse(file) as IToolChain[];
if (this.selectedName.Value === 'none') {
// Look for roborio release first
const c = this.toolchains[0];
let name = getToolchainName(c);
for (const t of this.toolchains) {
if (t.name === 'linuxathena' && t.buildType === 'release') {
name = getToolchainName(t);
break;
}
}
this.selectedName.Value = name;
this.statusBar.text = this.selectedName.Value;
}
// Check which properties changed, and fire new ones
let current: string | undefined;
try {
current = fs.readFileSync(file.fsPath, 'utf8');
} catch (error) {
}
if (current === undefined) {
this.lastConfig = defaultConfig;
this.libraryHeaderDirsChanged.fire([]);
this.localHeaderDirsChanged.fire([]);
this.propertiesChange.fire();
return;
}
const parsed: IEditorConfig = jsonc.parse(current);
this.checkForChanges(parsed);
});
}
public async loadTheme(themePath: string, defaultStyle: ThemeStyle): Promise {
let rules: TextMateRule[][] = [];
if (await util.checkFileExists(themePath)) {
let themeContentText: string = await util.readFileText(themePath);
let themeContent: any;
let textMateRules: TextMateRule[];
if (themePath.endsWith("tmTheme")) {
themeContent = plist.parse(themeContentText);
if (themeContent) {
textMateRules = themeContent.settings;
}
} else {
themeContent = jsonc.parse(themeContentText);
if (themeContent) {
textMateRules = themeContent.tokenColors;
if (themeContent.include) {
// parse included theme file
let includedThemePath: string = path.join(path.dirname(themePath), themeContent.include);
rules = await this.loadTheme(includedThemePath, defaultStyle);
}
if (themeContent.colors && themeContent.colors["editor.background"]) {
this.editorBackground = themeContent.colors["editor.background"];
}
}
}
if (textMateRules) {
// Convert comma delimited scopes into an array
ds.on('data', (data) => {
let parsed: IDriverStationData = jsonc.parse(data.toString());
if (parsed.robotIP === 0) {
ds.end();
ds.destroy();
ds.removeAllListeners();
reject();
return;
}
let ipAddr = '';
let ip = parsed.robotIP;
ipAddr += ((ip >> 24) & 0xff) + '.';
ipAddr += ((ip >> 16) & 0xff) + '.';
ipAddr += ((ip >> 8) & 0xff) + '.';
ipAddr += (ip & 0xff);
s.on('error', (_) => {
console.log('failed connection to ' + ip + ' at ' + port);
s.end();
private async updatePreferences() {
if (this.preferencesFile === undefined) {
this.preferencesJson = defaultPreferences;
return;
}
const results = await readFileAsync(this.preferencesFile.fsPath, 'utf8');
this.preferencesJson = jsonc.parse(results) as IPreferencesJson;
}
protected readJson(filePath: string): T | undefined {
const content = this.readFileSync(filePath);
return content ? jsoncparser.parse(content, undefined, { disallowComments: false }) : undefined;
}
protected readFileSync(filePath: string): string {