Created
December 10, 2025 03:38
-
-
Save iccir/a7d73a7da5044ee4c49c708dcad8b3a6 to your computer and use it in GitHub Desktop.
Sublime Text command to debug blank/wrong file icons
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Given a file extension, displays information about the assigned file icon | |
| # | |
| # Usage: | |
| # | |
| # 1) Open a window in Sublime Text | |
| # 2) View -> Show Console | |
| # 3) Type in the following (with your extension instead of "h"): | |
| # window.run_command("debug_file_icon, { "extension": "h" }) | |
| # | |
| from __future__ import annotations | |
| import sublime | |
| import sublime_plugin | |
| import plistlib | |
| def get_icon_for_syntax(syntax: sublime.Syntax) -> str: | |
| window = sublime.active_window() | |
| tmp_view = window.new_file(flags=sublime.NewFileFlags.TRANSIENT) | |
| tmp_view.set_scratch(True) | |
| tmp_view.assign_syntax(syntax) | |
| icon = tmp_view.meta_info("icon", 0) | |
| tmp_view.close() | |
| return icon | |
| class DebugFileIcon(sublime_plugin.WindowCommand): | |
| def run(self, extension: str): | |
| syntax = sublime.find_syntax_for_file(f"foo.{extension}") | |
| used_icon = get_icon_for_syntax(syntax) | |
| scope = syntax.scope | |
| print("") | |
| print(f"File extension '{extension}' resolved to scope '{scope}'") | |
| print(f"Scope '{scope}' resolved to icon name '{used_icon}'") | |
| print() | |
| print("Scanning .tmPreferences files for icon settings...") | |
| print() | |
| matches = [ ] | |
| for tm_preference in sublime.find_resources("*.tmPreferences"): | |
| contents = sublime.load_binary_resource(tm_preference) | |
| plist = plistlib.loads(contents) | |
| if settings := plist.get("settings"): | |
| icon = settings.get("icon") | |
| selector = plist.get("scope") | |
| if icon and selector and icon == used_icon: | |
| score = sublime.score_selector(syntax.scope, selector) | |
| if score > 0: | |
| matches.append( ( tm_preference, score, selector, icon ) ) | |
| for match in matches: | |
| print(f" File: '{match[0]}'") | |
| print(f" Score: '{match[1]}'") | |
| print(f"Selector: '{match[2]}'") | |
| print(f" Icon: '{match[3]}'") | |
| print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment