Closed wkirby closed 1 year ago
Thanks for the commit.
I haven't tested your patch yet; just looking at the code. It appears that JsPrettier only works with saved/existing files, while Formatter handles both saved files and unsaved buffers/view. This is where we encounter a problem at the first line of the logic:
active_view_parents = make_parent_directories(os.path.dirname(self.view.file_name()), limit=500)
We will get error here for dirty file, that has neither a filename nor a parent directory on the disk.
It is ok for existing files with this patch.
@wkirby
branch master
should fix the issue, both for saved and unsaved file.
In your User Settings you should add a default valid executable_path
for the case that local exec not found.
closed as fixed.
@bitst0rm thanks! Appreciate your feedback and integration.
It's very common to have multiple JS/TS projects, each with a different version of prettier installed. In these cases, it's not particularly useful to have
prettier
installed globally, and there's no oneexecutable_path
that can be set to resolve the correctprettier
executable for each project.This adapts some code from https://github.com/jonlabelle/SublimeJsPrettier to recursively search for a local install of prettier only if there is no global
prettier
executable andexecutable_path
is not set.This search is naive, in that it takes the currently open view, and looks in each directory for known
node_modules
paths for prettier until it finds one or reaches theos
root directory.