update
This commit is contained in:
@@ -66,6 +66,20 @@ Optional, path to `prettierd` executable. If not specified, it will be searched
|
||||
"prettierd_path": null
|
||||
```
|
||||
|
||||
All these options can be configured globally in your user settings, or per project under the `"PrettierdFormat"` setting:
|
||||
|
||||
```json
|
||||
{
|
||||
"settings":
|
||||
{
|
||||
"PrettierdFormat":
|
||||
{
|
||||
"format_on_save": true
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br />
|
||||
|
||||
## Notes
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"name": "Prettierd Format", "version": "0.6.0", "sublime_text": ">=3092", "platforms": ["*"], "python_version": "3.3", "url": "https://packagecontrol.io/packages/Prettierd%20Format", "issues": "https://github.com/smastrom/sublime-prettierd-format/issues", "author": ["Simone Mastromattei"], "description": "Sublime Text plugin to format files faster using prettierd", "labels": ["prettier", "prettierd", "format"], "libraries": [], "install_time": 1725486374.408112, "release_time": "2024-04-18 02:07:04"}
|
||||
{"name": "Prettierd Format", "version": "0.7.0", "sublime_text": ">=3092", "platforms": ["*"], "python_version": "3.3", "url": "https://packagecontrol.io/packages/Prettierd%20Format", "issues": "https://github.com/smastrom/sublime-prettierd-format/issues", "author": ["Simone Mastromattei"], "description": "Sublime Text plugin to format files faster using prettierd", "labels": ["prettier", "prettierd", "format"], "libraries": [], "install_time": 1725486374.408112, "release_time": "2025-04-08 11:49:23", "upgrade_time": 1744137175.6824992}
|
||||
@@ -3,9 +3,7 @@ import sublime_plugin
|
||||
|
||||
from .prettierd_formatter import format_with_prettierd
|
||||
from .prettierd_extensions import valid_extensions
|
||||
|
||||
def get_settings():
|
||||
return sublime.load_settings("prettierd_format.sublime-settings")
|
||||
from .utils import get_setting
|
||||
|
||||
class PrettierdFormatCommand(sublime_plugin.TextCommand):
|
||||
def run(self, edit):
|
||||
@@ -17,8 +15,7 @@ class PrettierdFormatCommand(sublime_plugin.TextCommand):
|
||||
file_extension = file_path.split('.')[-1].lower()
|
||||
|
||||
# Fetch additional extensions from settings
|
||||
settings = get_settings()
|
||||
additional_extensions = settings.get("additional_extensions", [])
|
||||
additional_extensions = get_setting(self.view, "additional_extensions", [])
|
||||
all_extensions = valid_extensions + additional_extensions
|
||||
|
||||
if file_extension not in all_extensions:
|
||||
@@ -29,7 +26,7 @@ class PrettierdFormatCommand(sublime_plugin.TextCommand):
|
||||
|
||||
current_content = self.view.substr(sublime.Region(0, self.view.size()))
|
||||
file_path = self.view.file_name()
|
||||
formatted_code = format_with_prettierd(current_content, file_path)
|
||||
formatted_code = format_with_prettierd(self.view, current_content, file_path)
|
||||
|
||||
# print("Formatted Code:", formatted_code)
|
||||
|
||||
|
||||
@@ -8,5 +8,5 @@
|
||||
// Directories to disable formatting on save.
|
||||
"disabled_directories_on_save": ["*/node_modules/*"],
|
||||
// Path to prettierd binary, optional.
|
||||
"prettierd_path": null
|
||||
"prettierd_path": null,
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import subprocess
|
||||
import sublime
|
||||
import sublime_plugin
|
||||
import os
|
||||
@@ -6,15 +5,12 @@ import re
|
||||
|
||||
from .prettierd_formatter import format_with_prettierd
|
||||
from .prettierd_extensions import valid_extensions
|
||||
|
||||
def get_settings():
|
||||
return sublime.load_settings("prettierd_format.sublime-settings")
|
||||
from .utils import get_setting
|
||||
|
||||
class PrettierdFormatEventListener(sublime_plugin.EventListener):
|
||||
|
||||
def on_pre_save(self, view):
|
||||
settings = get_settings()
|
||||
format_on_save = settings.get("format_on_save", True)
|
||||
format_on_save = get_setting(view, "format_on_save", True)
|
||||
|
||||
if not format_on_save:
|
||||
return
|
||||
@@ -30,10 +26,10 @@ class PrettierdFormatEventListener(sublime_plugin.EventListener):
|
||||
|
||||
file_extension = file_path.split('.')[-1].lower()
|
||||
|
||||
disabled_extensions_on_save = settings.get("disabled_extensions_on_save", [])
|
||||
disabled_directories_on_save = settings.get("disabled_directories_on_save", [])
|
||||
disabled_extensions_on_save = get_setting(view, "disabled_extensions_on_save", [])
|
||||
disabled_directories_on_save = get_setting(view, "disabled_directories_on_save", [])
|
||||
|
||||
additional_extensions = settings.get("additional_extensions", [])
|
||||
additional_extensions = get_setting(view, "additional_extensions", [])
|
||||
|
||||
if file_extension in disabled_extensions_on_save:
|
||||
return
|
||||
@@ -54,7 +50,7 @@ class PrettierdFormatEventListener(sublime_plugin.EventListener):
|
||||
|
||||
if file_extension in all_extensions:
|
||||
current_content = view.substr(sublime.Region(0, view.size()))
|
||||
formatted_code = format_with_prettierd(current_content, file_path)
|
||||
formatted_code = format_with_prettierd(view, current_content, file_path)
|
||||
if formatted_code:
|
||||
view.run_command('replace_view_content', {'content': formatted_code})
|
||||
|
||||
|
||||
@@ -3,14 +3,14 @@ import shutil
|
||||
import subprocess
|
||||
import os
|
||||
|
||||
def get_prettierd_path():
|
||||
settings = sublime.load_settings("Prettierd.sublime-settings")
|
||||
|
||||
settings_path = settings.get("prettierd_path", "")
|
||||
from .utils import get_setting
|
||||
|
||||
def get_prettierd_path(view_or_window):
|
||||
settings_path = get_setting(view_or_window, "prettierd_path", "")
|
||||
if settings_path:
|
||||
return settings_path
|
||||
|
||||
# Default behavior when not specified
|
||||
# Default behavior when not specified
|
||||
default_path = shutil.which("prettierd")
|
||||
if default_path:
|
||||
return default_path
|
||||
@@ -18,8 +18,8 @@ def get_prettierd_path():
|
||||
sublime.error_message("prettierd executable not found.")
|
||||
return None
|
||||
|
||||
def format_with_prettierd(content, file_path):
|
||||
prettierd_path = get_prettierd_path()
|
||||
def format_with_prettierd(view_or_window, content, file_path):
|
||||
prettierd_path = get_prettierd_path(view_or_window)
|
||||
if not prettierd_path:
|
||||
message = "prettierd path not found."
|
||||
print(message)
|
||||
@@ -41,4 +41,4 @@ def format_with_prettierd(content, file_path):
|
||||
error_message = error.decode('utf-8') if error.decode('utf-8') else "Unknown error"
|
||||
print(error_message)
|
||||
sublime.error_message("Error formatting the file with prettierd: " + error_message)
|
||||
return None
|
||||
return None
|
||||
|
||||
9
Packages/Prettierd Format/utils.py
Normal file
9
Packages/Prettierd Format/utils.py
Normal file
@@ -0,0 +1,9 @@
|
||||
import sublime
|
||||
|
||||
def get_setting(view_or_window, setting_name, default_value):
|
||||
if view_or_window is not None:
|
||||
local_settings = view_or_window.settings().get("PrettierdFormat", {})
|
||||
if setting_name in local_settings:
|
||||
return local_settings[setting_name]
|
||||
|
||||
return sublime.load_settings("prettierd_format.sublime-settings").get(setting_name, default_value)
|
||||
Reference in New Issue
Block a user