To anyone that might experience this same issue, the following are the solutions that worked for me.
First, make sure if the resource you’re trying to load do exists. As pointed by FichteFoll this can be done by running the code below to the console:
sublime.find_resources("data.json")
The returned list
must include the path to your resource file, in my case Packages/DeclareThatColor/libs/hexcode/data.json
.
Now into the solution.
If on the module level function call load_resource
inside plugin_loaded
:
def plugin_loaded():
sublime.load_resource("Packages/DeclareThatColor/libs/hexcode/data.json")
Otherwise, use a callback to load the JSON and pass that to set_timeout
function.
load_data_delay = 1000 # milliseconds
def _load_color_data():
sublime.load_resource("Packages/DeclareThatColor/libs/hexcode/data.json")
sublime.set_timeout(_load_color_data, load_data_delay)
For some reason, using ResourcePath
as suggested by ThomSmith gives me an ImportError: No module named 'sublime_lib'
error.