export async function updateExtensionsPath()

in src/emmetHelper.ts [920:1007]


export async function updateExtensionsPath(emmetExtensionsPathSetting: string[], fs: FileService, workspaceFolderPaths?: URI[], homeDir?: URI): Promise<void> {
	resetSettingsFromFile();

	if (!emmetExtensionsPathSetting.length) {
		return;
	}

	// Extract URIs from the given setting
	const emmetExtensionsPathUri: URI[] = [];
	for (let emmetExtensionsPath of emmetExtensionsPathSetting) {
		if (emmetExtensionsPath) {
			emmetExtensionsPath = emmetExtensionsPath.trim();
		}

		if (emmetExtensionsPath.length && emmetExtensionsPath[0] === '~') {
			if (homeDir) {
				emmetExtensionsPathUri.push(joinPath(homeDir, emmetExtensionsPath.substr(1)));
			}
		} else if (!isAbsolutePath(emmetExtensionsPath)) {
			if (workspaceFolderPaths) {
				// Try pushing the path for each workspace root
				for (const workspacePath of workspaceFolderPaths) {
					emmetExtensionsPathUri.push(joinPath(workspacePath, emmetExtensionsPath));
				}
			}
		} else {
			emmetExtensionsPathUri.push(URI.file(emmetExtensionsPath));
		}
	}

	// For each URI, grab the files
	for (const uri of emmetExtensionsPathUri) {
		try {
			if ((await fs.stat(uri)).type !== FileType.Directory) {
				// Invalid directory, or path is not a directory
				continue;
			}
		} catch (e) {
			// stat threw an error
			continue;
		}

		const snippetsPath = joinPath(uri, 'snippets.json');
		const profilesPath = joinPath(uri, 'syntaxProfiles.json');
		let decoder: TextDecoder | undefined;
		if (typeof (globalThis as any).TextDecoder === 'function') {
			decoder = new (globalThis as any).TextDecoder() as TextDecoder;
		} else {
			decoder = new TextDecoder();
		}

		// the only errors we want to throw here are JSON parse errors
		let snippetsDataStr = "";
		try {
			const snippetsData = await fs.readFile(snippetsPath);
			snippetsDataStr = decoder.decode(snippetsData);
		} catch (e) {
		}
		if (snippetsDataStr.length) {
			try {
				const snippetsJson = tryParseFile(snippetsPath, snippetsDataStr);
				if (snippetsJson['variables']) {
					updateVariables(snippetsJson['variables']);
				}
				updateSnippets(snippetsJson);
			} catch (e) {
				resetSettingsFromFile();
				throw e;
			}
		}

		let profilesDataStr = "";
		try {
			const profilesData = await fs.readFile(profilesPath);
			profilesDataStr = decoder.decode(profilesData);
		} catch (e) {
		}
		if (profilesDataStr.length) {
			try {
				const profilesJson = tryParseFile(profilesPath, profilesDataStr);
				updateProfiles(profilesJson);
			} catch (e) {
				resetSettingsFromFile();
				throw e;
			}
		}
	}
}