vscode 源码学到的技巧

技巧列表

    • 将json格式中的非json替换

将json格式中的非json替换

		// First group matches a double quoted string
		// Second group matches a single quoted string
		// Third group matches a multi line comment
		// Forth group matches a single line comment
		// Fifth group matches a trailing comma
		const regexp = /("[^"\\]*(?:\\.[^"\\]*)*")|('[^'\\]*(?:\\.[^'\\]*)*')|(\/\*[^\/\*]*(?:(?:\*|\/)[^\/\*]*)*?\*\/)|(\/{2,}.*?(?:(?:\r?\n)|$))|(,\s*[}\]])/g;
		/**
		 *
		 * @param {string} content
		 * @returns {string}
		 */
		function stripComments(content) {
			return content.replace(regexp, function (match, _m1, _m2, m3, m4, m5) {
				// Only one of m1, m2, m3, m4, m5 matches
				if (m3) {
					// A block comment. Replace with nothing
					return '';
				} else if (m4) {
					// Since m4 is a single line comment is is at least of length 2 (e.g. //)
					// If it ends in \r?\n then keep it.
					const length = m4.length;
					if (m4[length - 1] === '\n') {
						return m4[length - 2] === '\r' ? '\r\n' : '\n';
					}
					else {
						return '';
					}
				} else if (m5) {
					// Remove the trailing comma
					return match.substring(1);
				} else {
					// We match a string
					return match;
				}
			});
		}

例子:
启动argv.json文件

// This configuration file allows you to pass permanent command line arguments to VS Code.
// Only a subset of arguments is currently supported to reduce the likelihood of breaking
// the installation.
//
// PLEASE DO NOT CHANGE WITHOUT UNDERSTANDING THE IMPACT
//
// NOTE: Changing this file requires a restart of VS Code.
{
	// Use software rendering instead of hardware accelerated rendering.
	// This can help in cases where you see rendering issues in VS Code.
	// "disable-hardware-acceleration": true,

	// Allows to disable crash reporting.
	// Should restart the app if the value is changed.
	"enable-crash-reporter": true,

	// Unique id used for correlating crash reports sent from this instance.
	// Do not edit this value.
	"crash-reporter-id": "7d869ddc-01cd-4184-a9bb-029e673556b1"
}

替换后








{






        "enable-crash-reporter": true,



        "crash-reporter-id": "7d869ddc-01cd-4184-a9bb-029e673556b1"       
}

你可能感兴趣的:(vscode,前端,javascript)