-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
181 additions
and
181 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[{ | ||
"caption": "SublimeBump", | ||
"caption": "Bump", | ||
"children": [ | ||
{ | ||
"caption": "Format to the latest version", | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
[ | ||
{ | ||
"caption": "Preferences: SublimeBump Settings", | ||
"caption": "Preferences: Bump Settings", | ||
"command": "edit_settings", | ||
"args": { | ||
"base_file": "${packages}/SublimeBump/SublimeBump.sublime-settings", | ||
"default": "${packages}/User/SublimeBump.sublime-settings" | ||
"base_file": "${packages}/Bump/Bump.sublime-settings", | ||
"default": "${packages}/User/Bump.sublime-settings" | ||
} | ||
}, | ||
{ | ||
"caption": "SublimeBump: Choose Distribution Mode", | ||
"caption": "Bump: Choose Distribution Mode", | ||
"command": "choose_distribution_mode" | ||
}, | ||
{ | ||
"caption": "SublimeBump: Format To The Latest Version", | ||
"caption": "Bump: Format To The Latest Version", | ||
"command": "bump_latest_version" | ||
}, | ||
{ | ||
"caption": "SublimeBump: Format To The Next Version", | ||
"caption": "Bump: Format To The Next Version", | ||
"command": "bump_next_version" | ||
} | ||
] |
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,121 +1,48 @@ | ||
import json | ||
import os | ||
import urllib | ||
from string import Template | ||
|
||
import sublime | ||
import sublime_plugin | ||
|
||
from . import defaults | ||
from . import settings as conf | ||
from . import parser | ||
from . import transfrom | ||
from . import cache | ||
from . import request | ||
from . import log | ||
from . import semver | ||
|
||
class Bump: | ||
def get_focused_view_id(self, view): | ||
active_view = view.window().active_view() | ||
|
||
for view in view.window().views(): | ||
if view == active_view: | ||
return view | ||
|
||
def file_supported(self, view): | ||
full_filename = view.file_name() | ||
if not full_filename: | ||
return False | ||
filename = os.path.split(full_filename)[1] | ||
return filename in conf.settings.get('supported_filenames', defaults.get_supported_filenames()) | ||
|
||
def from_cache_or_fetch(self, package, distribution_mode, vid, callback): | ||
cached = cache.get_by_package(package, distribution_mode, vid) | ||
if cached: | ||
callback(cached) | ||
return | ||
|
||
try: request.fetch_package_version(package, distribution_mode, callback) | ||
except urllib.error.URLError as e: | ||
if e.code == 404 and distribution_mode != 'latest': | ||
request.fetch_package_version(package, 'latest', callback) | ||
|
||
def run_bump_with_mode(self, view, edit, distribution_mode): | ||
if not self.file_supported(view): return | ||
|
||
region = parser.get_active_region(view) | ||
parent_key = parser.get_parent_key(view, region) | ||
target_fields = conf.settings.get('dependency_fields', defaults.get_dependency_fields()) | ||
|
||
# Prevent parsing values from other fields. | ||
if not parent_key or parent_key not in target_fields: | ||
return | ||
|
||
line_text = parser.get_text_from_line(view, region) | ||
if not line_text: return | ||
from . import request | ||
from . import cache | ||
from . import transfrom | ||
from . import commands | ||
from . import settings as conf | ||
from . import persist | ||
|
||
package, version = parser.get_current_package(line_text) | ||
vid = view.id() | ||
def plugin_loaded(): | ||
"""Entry point for SL plugins.""" | ||
conf.plugin_is_loaded = True | ||
conf.settings.load() | ||
log.printf('debug mode:', 'on' if conf.debug_mode() else 'off') | ||
|
||
def callback(version): | ||
transfrom.format_version_on_line(view, edit, region, version) | ||
plugin = Bump.shared_plugin() | ||
conf.settings.on_update_call(Bump.on_settings_updated) | ||
|
||
self.from_cache_or_fetch(package, distribution_mode, vid, callback) | ||
class Bump(sublime_plugin.EventListener): | ||
def __init__(self, *args, **kwargs): | ||
"""Initialize a new instance.""" | ||
super().__init__(*args, **kwargs) | ||
|
||
def log_version_for_view(self, view): | ||
if not self.file_supported(view): | ||
return | ||
self.__class__.shared_instance = self | ||
|
||
view = self.get_focused_view_id(view) | ||
@classmethod | ||
def shared_plugin(cls): | ||
"""Return the plugin instance.""" | ||
return cls.shared_instance | ||
|
||
if view is None: | ||
return | ||
@classmethod | ||
def on_settings_updated(cls, setting): | ||
persist.worker.log_version_for_active_view() | ||
|
||
vid = view.id() | ||
# Get active region | ||
region = parser.get_active_region(view) | ||
def on_selection_modified_async(self, view): | ||
self.display_version_for_line(view, tooltip=True) | ||
|
||
if region == None: | ||
def display_version_for_line(self, view, tooltip=False): | ||
if persist.worker.is_scratch(view): | ||
return | ||
|
||
# Get parent package key for active region. | ||
parent_key = parser.get_parent_key(view, region) | ||
target_fields = conf.settings.get('dependency_fields', defaults.get_dependency_fields()) | ||
|
||
# Prevent parsing values from other fields. | ||
if not parent_key or parent_key not in target_fields: | ||
return | ||
|
||
line_text = parser.get_text_from_line(view, region) | ||
|
||
if not line_text: | ||
return | ||
|
||
package, current_version = parser.get_current_package(line_text) | ||
|
||
distribution_mode = conf.settings.get('distribution_mode', defaults.get_distribution_mode()) | ||
def callback(version): | ||
cache.set_package(package, distribution_mode, vid, version) | ||
with_tooltip = conf.settings.get('tooltip', defaults.get_tooltip()) | ||
has_matched = semver.satisfies(version, current_version) | ||
log.log_version(view, package, version, has_matched, with_tooltip) | ||
self.from_cache_or_fetch(package, distribution_mode, vid, callback) | ||
|
||
|
||
def log_version_for_active_view(self): | ||
view = sublime.active_window().active_view() | ||
self.log_version_for_view(view) | ||
|
||
def is_scratch(self, view): | ||
if view.is_scratch() or view.is_read_only() or view.window() is None or view.settings().get("repl") is not None: | ||
return True | ||
elif ( | ||
view.file_name() and | ||
view.file_name().startswith(sublime.packages_path() + os.path.sep) and | ||
not os.path.exists(view.file_name()) | ||
): | ||
return True | ||
else: | ||
return False | ||
|
||
|
||
if 'plugin_is_loaded' not in globals(): | ||
worker = Bump() | ||
persist.worker.log_version_for_view(view) |
This file contains 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
Oops, something went wrong.