Skip to content

Commit

Permalink
Merge pull request #39 from husanjun/master
Browse files Browse the repository at this point in the history
Add support project setting
  • Loading branch information
adael authored Oct 18, 2021
2 parents 882d151 + 76f0d44 commit 800af03
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions SublimePhpCsFixer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ def load_settings():
return sublime.load_settings("SublimePhpCsFixer.sublime-settings")


def load_project_settings():
return sublime.active_window().active_view().settings().get('SublimePhpCsFixer')


def setting_enabled(name):
return load_settings().get(name)

Expand Down Expand Up @@ -129,15 +133,22 @@ def debug(self, msg):


class FormatterSettings:
def __init__(self, settings):
def __init__(self, settings, project_settings):
self.settings = settings
self.project_settings = project_settings
self.variables = self.get_active_window_variables()

def has(self, key):
return self.settings.has(key) or self.project_settings.get(key)

def get(self, key):
value = self.project_settings.get(key)
if value:
return value
return self.settings.get(key)

def get_expanded(self, key):
return self.expand(self.settings.get(key))
return self.expand(self.get(key))

def expand(self, value):
return sublime.expand_variables(value, self.variables)
Expand Down Expand Up @@ -304,7 +315,7 @@ class SublimePhpCsFixCommand(sublime_plugin.TextCommand):

def __init__(self, view):
sublime_plugin.TextCommand.__init__(self, view)
self.settings = load_settings()
self.settings = FormatterSettings(load_settings(), load_project_settings())
self.logger = Logger(self.settings)

def is_enabled(self):
Expand All @@ -324,8 +335,7 @@ def format(self, edit):
self.logger.console("Done. No contents")
return

formatter = ViewFormatter(
FormatterSettings(self.settings), self.logger)
formatter = ViewFormatter(self.settings, self.logger)
new_contents = formatter.format(contents)

if new_contents and new_contents != contents:
Expand Down

0 comments on commit 800af03

Please sign in to comment.