Skip to content

Commit

Permalink
move get_scopes to it's own module
Browse files Browse the repository at this point in the history
  • Loading branch information
keith-hall committed Mar 3, 2016
1 parent 86428d0 commit 58a41aa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
14 changes: 14 additions & 0 deletions sublime_helper.py
@@ -0,0 +1,14 @@
def get_scopes(view, start_at_position, stop_at_position):
"""Return the unique scopes in the view between start_at_position and stop_at_position, in the order in which they occur."""
current_scope = None
for pos in range(start_at_position, stop_at_position):
scope = view.scope_name(pos)
if current_scope is None:
current_scope = (scope, pos, pos)
elif current_scope[0] == scope: # if the current scope is exactly the same, extend it
current_scope = (current_scope[0], current_scope[1], pos)
else: # the previous scope is complete, register new one
yield current_scope
current_scope = (scope, pos, pos)
if current_scope is not None:
yield current_scope
17 changes: 1 addition & 16 deletions sublime_lxml.py
@@ -1,5 +1,6 @@
import sublime
from .lxml_parser import *
from .sublime_helper import get_scopes

# TODO: consider subclassing etree.ElementBase and adding as methods to that
def getNodeTagRegion(view, node, position_type):
Expand Down Expand Up @@ -148,22 +149,6 @@ def getElementXMLPreview(view, node, maxlen):
preview = view.substr(sublime.Region(open_pos.begin(), close_pos.end()))
return collapseWhitespace(preview, maxlen)

def get_scopes(view, start_at_position, stop_at_position):
scopes = []
current_scope = None
for pos in range(start_at_position, stop_at_position):
scope = view.scope_name(pos)
if current_scope is None:
current_scope = (scope, pos, pos)
elif current_scope[0] == scope: # if the current scope is exactly the same, extend it
current_scope = (current_scope[0], current_scope[1], pos)
else: # store the previous scope and register new one
scopes.append(current_scope)
current_scope = (scope, pos, pos)
if current_scope is not None:
scopes.append(current_scope)
return scopes

def parse_xpath_query_for_completions(view, completion_position):
"""Given a view with XPath syntax and a position where completions are desired, parse the xpath query and return the relevant sub queries."""

Expand Down

0 comments on commit 58a41aa

Please sign in to comment.