How to use the jsonc-parser.parse function in jsonc-parser

To help you get started, we’ve selected a few jsonc-parser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DonJayamanne / pythonVSCode / src / client / testing / common / debugLauncher.ts View on Github external
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 {
github imodeljs / imodeljs / tools / certa / src / CertaConfig.ts View on Github external
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));
  }
}
github wpilibsuite / vscode-wpilib / vscode / vscode-wpilib / src / cpp / cppgradleproperties.ts View on Github external
// 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) => {
github wpilibsuite / vscode-wpilib / vscode-wpilib / src / cppprovider / apiprovider.ts View on Github external
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;
    }
github wpilibsuite / vscode-wpilib / vscode / vscode-wpilib-cpp / src / cpp_gradle_properties.ts View on Github external
// 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);
    });
  }
github microsoft / vscode-cpptools / Extension / src / LanguageServer / colorization.ts View on Github external
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
github wpilibsuite / vscode-wpilib / vscode-wpilib-core / src / riolog / rioconnector.ts View on Github external
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();
github wpilibsuite / vscode-wpilib / vscode-wpilib / src / preferences.ts View on Github external
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;
  }
github eclipse-theia / theia / packages / plugin-ext / src / hosted / node / scanners / scanner-theia.ts View on Github external
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 {