Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
).then((env) => {
if (env === undefined || env.label === '') {
return;
}
try {
// Modify JSON document & Write changes
settings.newContents = jsonc.applyEdits(
settings.contents,
jsonc.modify(
settings.contents,
['env'],
env.label,
{
formattingOptions: {
tabSize: 4
}
}
)
);
// Write back to the file
fs.writeFileSync(
this.paths.getNormalPath(settings.uri),
var edit = jsonc.modify(jsonText, [snippet.name],
{
prefix: snippet.prefix,
body: snippet.body,
description: snippet.description
},
{
formattingOptions: { // based on default vscode snippet format
tabSize: 2,
insertSpaces: false,
eol: ''
}
});
var fileContent = jsonc.applyEdits(jsonText, edit);
fs.writeFile(snippetFile, fileContent, () => { });
vscode.window.showInformationMessage("Snippet " + snippet.name + " added to " + snippet.language + " snippets");
});
}
private async modifyConfiguration(target: ConfigurationTarget, key: string, value?: any): Promise {
let { nvim, workspace } = this
let file = workspace.getConfigFile(target)
if (!file) return
let formattingOptions: FormattingOptions = { tabSize: 2, insertSpaces: true }
let content = fs.readFileSync(file, 'utf8')
value = value == null ? undefined : value
let edits = modify(content, [key], value, { formattingOptions })
content = applyEdits(content, edits)
fs.writeFileSync(file, content, 'utf8')
let doc = workspace.getDocument(URI.file(file).toString())
if (doc) nvim.command('checktime', true)
return
}
const allowedTypesSet = new Set(allowedTypes)
if (node && !allowedTypesSet.has(node.type)) {
throw new TemplatesConfigFieldTypeError({
message: 'Invalid configuration',
jsonPath: jsonPath,
actualType: node.type,
expectedTypes: allowedTypes
})
}
if (!node || node.type === 'null') {
const edits = jsonParser.modify(this.json, jsonPath, value, this.modificationOptions)
if (edits.length > 0) {
this.json = jsonParser.applyEdits(this.json, edits)
this.isDirty = true
}
}
}
private persistSetup(config: contexts.OAuth2 | contexts.OAuth1 | contexts.ApiKey | contexts.Basic) {
const setupRc = this.locator.localConfigPath
if (!fs.existsSync(setupRc)) {
fs.writeFileSync(setupRc, '{}', { encoding: 'utf8' })
}
const rawSetup = fs.readFileSync(setupRc, { encoding: 'utf8' })
const updates = modify(rawSetup, ['setup', 'auth'], config, {
formattingOptions: {
insertSpaces: true,
tabSize: 2,
eol: '\n'
}
})
const newSetupRc = applyEdits(rawSetup, updates)
this.debug('Writing setup config\n%j', { config, setupRc: newSetupRc })
fs.writeFileSync(setupRc, newSetupRc, { encoding: 'utf8' })
this.success(`Auth credentials have been saved to ${this.locator.toRelative(setupRc)}`)
}