void () { if (!grammarToExtensions.isEmpty()) return; File packageJson = new File(bundleFile, "package.json"); try { Object json = JsonPlistReader.createJsonReader().readValue(new FileReader(packageJson, StandardCharsets.UTF_8), Object.class); if (json instanceof Map) { Object contributes = ((Map<?, ?>)json).get("contributes"); if (contributes instanceof Map) { Object languages = ((Map<?, ?>)contributes).get("languages"); Object grammars = ((Map<?, ?>)contributes).get("grammars"); Object snippets = ((Map<?, ?>)contributes).get("snippets"); if (languages instanceof ArrayList && grammars instanceof ArrayList) { Map<String, Collection<String>> idToExtension = new HashMap<>(); Map<String, String> idToConfig = new HashMap<>(); for (Object language : (ArrayList)languages) { if (language instanceof Map) { Object id = ((Map<?, ?>)language).get("id"); if (id instanceof String) { Object extensions = ((Map<?, ?>)language).get("extensions"); if (extensions instanceof ArrayList) { //noinspection unchecked Stream<String> stream = ((ArrayList)extensions).stream().map(ext -> Strings.trimStart((String)ext, ".")); idToExtension.computeIfAbsent((String)id, (key) -> new HashSet<>()).addAll(stream.toList()); } Object filenames = ((Map<?, ?>)language).get("filenames"); if (filenames instanceof ArrayList) { //noinspection unchecked idToExtension.computeIfAbsent((String)id, (key) -> new HashSet<>()).addAll((ArrayList)filenames); } Object configuration = ((Map<?, ?>)language).get("configuration"); if (configuration instanceof String) { idToConfig.put((String)id, FileUtilRt.toSystemIndependentName((String)configuration)); } } } } if (snippets instanceof ArrayList) { for (Object snippet : (ArrayList)snippets) { if (snippet instanceof Map) { Object path = ((Map<?, ?>)snippet).get("path"); if (path instanceof String) { snippetPaths.add((String)path); } } } } Map<String, Collection<String>> grammarExtensions = new LinkedHashMap<>(); Map<String, Collection<String>> scopeConfig = new HashMap<>(); for (Object grammar : (ArrayList)grammars) { if (grammar instanceof Map) { Object path = ((Map<?, ?>)grammar).get("path"); Object language = ((Map<?, ?>)grammar).get("language"); Collection<String> extensions = idToExtension.getOrDefault(language, emptyList()); if (path instanceof String) { grammarExtensions.put((String)path, extensions); } Object scopeName = ((Map<?, ?>)grammar).get("scopeName"); String config = idToConfig.get(language); if (scopeName instanceof String && config != null) { scopeConfig.computeIfAbsent(config, (key) -> new ArrayList<>()).add((String)scopeName); } Object embedded = ((Map<?, ?>)grammar).get("embeddedLanguages"); if (embedded instanceof Map) { for (Object embeddedScope : ((Map)embedded).keySet()) { Object embeddedLanguage = ((Map<?, ?>)embedded).get(embeddedScope); if (embeddedScope instanceof String && embeddedLanguage instanceof String) { String embeddedConfig = idToConfig.get(embeddedLanguage); if (embeddedConfig != null) { scopeConfig.computeIfAbsent(embeddedConfig, (key) -> new ArrayList<>()).add((String)embeddedScope); } } } } } } grammarToExtensions.putAll(grammarExtensions); configToScopes.putAll(scopeConfig); } } } } catch (Exception ignored) {} }