Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python from completion not being erased and filled with spaces #51

Open
evandrocoan opened this issue Feb 14, 2018 · 0 comments
Open

Python from completion not being erased and filled with spaces #51

evandrocoan opened this issue Feb 14, 2018 · 0 comments
Labels

Comments

@evandrocoan
Copy link
Contributor

evandrocoan commented Feb 14, 2018

back2

"""
# from sub

"""

Console with debug:

FFP  search s F:/SublimeText/Data ['py'] False
FFP  2 completions found
FFP  CurrentState Abort -- view already updated
FFP  SelectedTrigger {'auto': True, 'extensions': ['py'], 'replace_on_insert': [['^\\/', ''], ['\\/', '.'], ['^(.*)\\.py$', 'FuzzyFilePath.\\1']], 'prefix': ['from'], 'scope': '\\.python', 'relative': False}
FFP  search sub F:/SublimeText/Data ['py'] False
FFP  2 completions found
FFP  post cleanup path:' sub

"" ' ~~> ' sub

"" '
FFP  CurrentState Abort -- view already updated
FFP  CurrentState Abort -- view already updated
FFP  CurrentState Abort -- view already updated

This only happens when the commit_completion is triggered by an indirection like this:

class OverwriteCommitCompletionCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        window = self.view.window()
        window.run_command( "commit_completion" )

On autocompletion event, I call the command overwrite_commit_completion which just calls the commit_completion. This should be the same cause of the problem: #49 (FFP post cleanup path:' merge set ' ~~> ' merge set ')

Comment out this line on this package, fixes the problem:

self.on_post_insert_completion(view, command_name)

When the commit_completion command is not redirected, this is the console output from my debugging:

start tracking: ``
start tracking: ``
finish tracking
expression: `{'error': None, 'tagName': None, 'valid_needle': True, 'is_valid': True, 'region': (5110, 5117), 'style': None, 'prefix': 'from', 'needle': 'sublime', 'word': 'sublime'}`
expression['needle']: `sublime`
diff['start']:        ``
result 1: `sublime`
result 2: `sublime`
base_directory: `False`
replace_on_insert: `[['^\\/', ''], ['\\/', '.'], ['^(.*)\\.py$', 'FuzzyFilePath.\\1']]`
post_remove: ``, arguments: `{'b': 5117, 'string': 'sublime', 'a': 5110, 'move_cursor': True}`
end

When there is the mentioned redirection, this is the console output:

start tracking: ``
start tracking: ``
finish tracking
expression: `{'error': <_sre.SRE_Match object at 0x04E15480>, 'tagName': None, 'valid_needle': False, 'is_valid': False, 'region': (5110, 5117), 'style': None, 'prefix': 'from', 'needle': 'sub\n\n\n"', 'word': 'sub\n\n\n"'}`
expression['needle']: `sub


"`
diff['start']:        ``
result 1: `sub


"`
result 2: `sub


"`
base_directory: `False`
replace_on_insert: `[['^\\/', ''], ['\\/', '.'], ['^(.*)\\.py$', 'FuzzyFilePath.\\1']]`
post_remove: ``, arguments: `{'b': 5117, 'string': 'sub\n\n\n"', 'a': 5110, 'move_cursor': True}`
end

Now I added more debugging power:

This is without the indirection:

position: `5113`
word_region: `(5110, 5113)`
line_region: `(5103, 5113)`
pre_region:  `(5103, 5110)`
post_region: `(5113, 5113)`
line: `# from sub`
word: `sub`
pre:  `# from `
post: ``
error: `None`
needle_region: `(5110, 5113)`
pre_quotes 1: `None`
pre_quotes 2: `<_sre.SRE_Match object at 0x03A9A650>`
needle:        `sub`
separator:     ` `
pre_match:     ``
needle_region: `(5110, 5113)`
pre_quotes 3:  `<_sre.SRE_Match object at 0x03A9A650>`
post_quotes:   `<_sre.SRE_Match object at 0x08B92DA0>`
needle:        `sub`
needle_region: `(5110, 5113)`
valid:         `True`
prefix_line:   `# from`
prefix_region: `(5103, 5109)`
prefix 1: `<_sre.SRE_Match object at 0x053BB760>`
prefix 2: `<_sre.SRE_Match object at 0x053BB760>`
prefix 3: `from`
tag 1: `None`
tag 2: `None`
propertyName 1: `None`
propertyName 2: `None`
valid: `True`
valid_needle: `True`
results: `{'error': None, 'tagName': None, 'valid_needle': True, 'is_valid': True, 'region': (5110, 5113), 'style': None, 'prefix': 'from', 'needle': 'sub', 'word': 'sub'}`
start tracking: ``
position: `5113`
word_region: `(5110, 5113)`
line_region: `(5103, 5113)`
pre_region:  `(5103, 5110)`
post_region: `(5113, 5113)`
line: `# from sub`
word: `sub`
pre:  `# from `
post: ``
error: `None`
needle_region: `(5110, 5113)`
pre_quotes 1: `None`
pre_quotes 2: `<_sre.SRE_Match object at 0x03A9A458>`
needle:        `sub`
separator:     ` `
pre_match:     ``
needle_region: `(5110, 5113)`
pre_quotes 3:  `<_sre.SRE_Match object at 0x03A9A458>`
post_quotes:   `<_sre.SRE_Match object at 0x053BB760>`
needle:        `sub`
needle_region: `(5110, 5113)`
valid:         `True`
prefix_line:   `# from`
prefix_region: `(5103, 5109)`
prefix 1: `<_sre.SRE_Match object at 0x053BB720>`
prefix 2: `<_sre.SRE_Match object at 0x053BB720>`
prefix 3: `from`
tag 1: `None`
tag 2: `None`
propertyName 1: `None`
propertyName 2: `None`
valid: `True`
valid_needle: `True`
results: `{'error': None, 'tagName': None, 'valid_needle': True, 'is_valid': True, 'region': (5110, 5113), 'style': None, 'prefix': 'from', 'needle': 'sub', 'word': 'sub'}`
position: `5113`
word_region: `(5110, 5113)`
line_region: `(5103, 5113)`
pre_region:  `(5103, 5110)`
post_region: `(5113, 5113)`
line: `# from sub`
word: `sub`
pre:  `# from `
post: ``
error: `None`
needle_region: `(5110, 5113)`
pre_quotes 1: `None`
pre_quotes 2: `<_sre.SRE_Match object at 0x03940F98>`
needle:        `sub`
separator:     ` `
pre_match:     ``
needle_region: `(5110, 5113)`
pre_quotes 3:  `<_sre.SRE_Match object at 0x03940F98>`
post_quotes:   `<_sre.SRE_Match object at 0x08B92DA0>`
needle:        `sub`
needle_region: `(5110, 5113)`
valid:         `True`
prefix_line:   `# from`
prefix_region: `(5103, 5109)`
prefix 1: `<_sre.SRE_Match object at 0x053BB760>`
prefix 2: `<_sre.SRE_Match object at 0x053BB760>`
prefix 3: `from`
tag 1: `None`
tag 2: `None`
propertyName 1: `None`
propertyName 2: `None`
valid: `True`
valid_needle: `True`
results: `{'error': None, 'tagName': None, 'valid_needle': True, 'is_valid': True, 'region': (5110, 5113), 'style': None, 'prefix': 'from', 'needle': 'sub', 'word': 'sub'}`
start tracking: ``
finish tracking
position: `5117`
word_region: `(5110, 5117)`
line_region: `(5103, 5117)`
pre_region:  `(5103, 5110)`
post_region: `(5117, 5117)`
line: `# from sublime`
word: `sublime`
pre:  `# from `
post: ``
error: `None`
needle_region: `(5110, 5117)`
pre_quotes 1: `None`
pre_quotes 2: `<_sre.SRE_Match object at 0x03A9A458>`
needle:        `sublime`
separator:     ` `
pre_match:     ``
needle_region: `(5110, 5117)`
pre_quotes 3:  `<_sre.SRE_Match object at 0x03A9A458>`
post_quotes:   `<_sre.SRE_Match object at 0x08B92DA0>`
needle:        `sublime`
needle_region: `(5110, 5117)`
valid:         `True`
prefix_line:   `# from`
prefix_region: `(5103, 5109)`
prefix 1: `<_sre.SRE_Match object at 0x053BB760>`
prefix 2: `<_sre.SRE_Match object at 0x053BB760>`
prefix 3: `from`
tag 1: `None`
tag 2: `None`
propertyName 1: `None`
propertyName 2: `None`
valid: `True`
valid_needle: `True`
results: `{'error': None, 'tagName': None, 'valid_needle': True, 'is_valid': True, 'region': (5110, 5117), 'style': None, 'prefix': 'from', 'needle': 'sublime', 'word': 'sublime'}`
end

This is with the indirection:

position: `5113`
word_region: `(5110, 5113)`
line_region: `(5103, 5113)`
pre_region:  `(5103, 5110)`
post_region: `(5113, 5113)`
line: `# from sub`
word: `sub`
pre:  `# from `
post: ``
error: `None`
needle_region: `(5110, 5113)`
pre_quotes 1: `None`
pre_quotes 2: `<_sre.SRE_Match object at 0x062F64A0>`
needle:        `sub`
separator:     ` `
pre_match:     ``
needle_region: `(5110, 5113)`
pre_quotes 3:  `<_sre.SRE_Match object at 0x062F64A0>`
post_quotes:   `<_sre.SRE_Match object at 0x052A7460>`
needle:        `sub`
needle_region: `(5110, 5113)`
valid:         `True`
prefix_line:   `# from`
prefix_region: `(5103, 5109)`
prefix 1: `<_sre.SRE_Match object at 0x08B92CE0>`
prefix 2: `<_sre.SRE_Match object at 0x08B92CE0>`
prefix 3: `from`
tag 1: `None`
tag 2: `None`
propertyName 1: `None`
propertyName 2: `None`
valid: `True`
valid_needle: `True`
results: `{'error': None, 'tagName': None, 'valid_needle': True, 'is_valid': True, 'region': (5110, 5113), 'style': None, 'prefix': 'from', 'needle': 'sub', 'word': 'sub'}`
start tracking: ``
position: `5113`
word_region: `(5110, 5113)`
line_region: `(5103, 5113)`
pre_region:  `(5103, 5110)`
post_region: `(5113, 5113)`
line: `# from sub`
word: `sub`
pre:  `# from `
post: ``
error: `None`
needle_region: `(5110, 5113)`
pre_quotes 1: `None`
pre_quotes 2: `<_sre.SRE_Match object at 0x04E18A40>`
needle:        `sub`
separator:     ` `
pre_match:     ``
needle_region: `(5110, 5113)`
pre_quotes 3:  `<_sre.SRE_Match object at 0x04E18A40>`
post_quotes:   `<_sre.SRE_Match object at 0x08B92CE0>`
needle:        `sub`
needle_region: `(5110, 5113)`
valid:         `True`
prefix_line:   `# from`
prefix_region: `(5103, 5109)`
prefix 1: `<_sre.SRE_Match object at 0x08B926A0>`
prefix 2: `<_sre.SRE_Match object at 0x08B926A0>`
prefix 3: `from`
tag 1: `None`
tag 2: `None`
propertyName 1: `None`
propertyName 2: `None`
valid: `True`
valid_needle: `True`
results: `{'error': None, 'tagName': None, 'valid_needle': True, 'is_valid': True, 'region': (5110, 5113), 'style': None, 'prefix': 'from', 'needle': 'sub', 'word': 'sub'}`
position: `5113`
word_region: `(5110, 5113)`
line_region: `(5103, 5113)`
pre_region:  `(5103, 5110)`
post_region: `(5113, 5113)`
line: `# from sub`
word: `sub`
pre:  `# from `
post: ``
error: `None`
needle_region: `(5110, 5113)`
pre_quotes 1: `None`
pre_quotes 2: `<_sre.SRE_Match object at 0x06555F98>`
needle:        `sub`
separator:     ` `
pre_match:     ``
needle_region: `(5110, 5113)`
pre_quotes 3:  `<_sre.SRE_Match object at 0x06555F98>`
post_quotes:   `<_sre.SRE_Match object at 0x052A7460>`
needle:        `sub`
needle_region: `(5110, 5113)`
valid:         `True`
prefix_line:   `# from`
prefix_region: `(5103, 5109)`
prefix 1: `<_sre.SRE_Match object at 0x08B92CE0>`
prefix 2: `<_sre.SRE_Match object at 0x08B92CE0>`
prefix 3: `from`
tag 1: `None`
tag 2: `None`
propertyName 1: `None`
propertyName 2: `None`
valid: `True`
valid_needle: `True`
results: `{'error': None, 'tagName': None, 'valid_needle': True, 'is_valid': True, 'region': (5110, 5113), 'style': None, 'prefix': 'from', 'needle': 'sub', 'word': 'sub'}`
start tracking: ``
finish tracking
position: `5117`
word_region: `(5110, 5117)`
line_region: `(5103, 5117)`
pre_region:  `(5103, 5110)`
post_region: `(5117, 5117)`
line: `# from sub


"`
word: `sub


"`
pre:  `# from `
post: ``
error: `<_sre.SRE_Match object at 0x05D276B0>`
needle_region: `(5110, 5117)`
pre_quotes 1: `None`
pre_quotes 2: `<_sre.SRE_Match object at 0x04E18A40>`
needle:        `sub


"`
separator:     ` `
pre_match:     ``
needle_region: `(5110, 5117)`
pre_quotes 3:  `<_sre.SRE_Match object at 0x04E18A40>`
post_quotes:   `<_sre.SRE_Match object at 0x052A7460>`
needle:        `sub


"`
needle_region: `(5110, 5117)`
valid:         `True`
prefix_line:   `# from`
prefix_region: `(5103, 5109)`
prefix 1: `<_sre.SRE_Match object at 0x08B92CE0>`
prefix 2: `<_sre.SRE_Match object at 0x08B92CE0>`
prefix 3: `from`
tag 1: `None`
tag 2: `None`
propertyName 1: `None`
propertyName 2: `None`
valid: `False`
valid_needle: `False`
results: `{'error': <_sre.SRE_Match object at 0x05D276B0>, 'tagName': None, 'valid_needle': False, 'is_valid': False, 'region': (5110, 5117), 'style': None, 'prefix': 'from', 'needle': 'sub\n\n\n"', 'word': 'sub\n\n\n"'}`
end


Patched function:

File: Data/Packages/FuzzyFilePath/expression.py
 16: def get_context(view):
 17:    error = False
 18:    valid = True
 19:    valid_needle = True
 20:    position = Selection.get_position(view)
 21: 
 22:    print("position: `%s`" % position)
 23: 
 24:    # regions
 25:    word_region = view.word(position)
 26:    line_region = view.line(position)
 27:    pre_region = sublime.Region(line_region.a, word_region.a)
 28:    post_region = sublime.Region(word_region.b, line_region.b)
 29: 
 30:    print("word_region: `%s`" % word_region)
 31:    print("line_region: `%s`" % line_region)
 32:    print("pre_region:  `%s`" % pre_region)
 33:    print("post_region: `%s`" % post_region)
 34: 
 35:    # text
 36:    line = view.substr(line_region)
 37:    word = view.substr(word_region)
 38:    pre = view.substr(pre_region)
 39:    post = view.substr(post_region)
 40: 
 41:    print("line: `%s`" % line)
 42:    print("word: `%s`" % word)
 43:    print("pre:  `%s`" % pre)
 44:    print("post: `%s`" % post)
 45: 
 46:    error = re.search("[" + NEEDLE_INVALID_CHARACTERS + "]", word)
 47:    needle_region = view.word(position)
 48: 
 49:    print("error: `%s`" % error)
 50:    print("needle_region: `%s`" % needle_region)
 51: 
 52:    # grab everything in 'separators'
 53:    needle = ""
 54:    separator = False
 55:    pre_match = ""
 56:    # search for a separator before current word, i.e. <">path/to/<position>
 57:    pre_quotes = re.search("(["+NEEDLE_SEPARATOR_BEFORE+"])([^"+NEEDLE_SEPARATOR+"]*)$", pre)
 58: 
 59:    print("pre_quotes 1: `%s`" % pre_quotes)
 60: 
 61:    if pre_quotes:
 62:        needle += pre_quotes.group(2) + word
 63:        separator = pre_quotes.group(1)
 64:        pre_match = pre_quotes.group(2)
 65:        needle_region.a -= len(pre_quotes.group(2))
 66:    else:
 67:        # use whitespace as separator
 68:        pre_quotes = re.search("(\s)([^"+NEEDLE_SEPARATOR+"\s]*)$", pre)
 69:        print("pre_quotes 2: `%s`" % pre_quotes)
 70: 
 71:        if pre_quotes:
 72:            needle = pre_quotes.group(2) + word
 73:            separator = pre_quotes.group(1)
 74:            pre_match = pre_quotes.group(2)
 75:            needle_region.a -= len(pre_quotes.group(2))
 76: 
 77:    print("needle:        `%s`" % needle)
 78:    print("separator:     `%s`" % separator)
 79:    print("pre_match:     `%s`" % pre_match)
 80:    print("needle_region: `%s`" % needle_region)
 81: 
 82:    if pre_quotes:
 83:        post_quotes = re.search("^(["+NEEDLE_SEPARATOR_AFTER+"]*)", post)
 84:        if post_quotes:
 85:            needle += post_quotes.group(1)
 86:            needle_region.b += len(post_quotes.group(1))
 87:        else:
 88:            logger.verbose(ID, "no post quotes found => invalid")
 89:            valid = False
 90:    elif not re.search("["+NEEDLE_INVALID_CHARACTERS+"]", needle):
 91:        needle = pre + word
 92:        needle_region.a = pre_region.a
 93:    else:
 94:        needle = word
 95: 
 96:    print("pre_quotes 3:  `%s`" % pre_quotes)
 97:    print("post_quotes:   `%s`" % post_quotes)
 98:    print("needle:        `%s`" % needle)
 99:    print("needle_region: `%s`" % needle_region)
100:    print("valid:         `%s`" % valid)
101: 
102:    # grab prefix
103:    prefix_region = sublime.Region(line_region.a, pre_region.b - len(pre_match) - 1)
104:    prefix_line = view.substr(prefix_region)
105:    # # print("prefix line", prefix_line)
106: 
107:    print("prefix_line:   `%s`" % prefix_line)
108:    print("prefix_region: `%s`" % prefix_region)
109: 
110:    #define? (["...", "..."]) -> before?
111:    # before: ABC =:([
112:    prefix = re.search("\s*(["+NEEDLE_CHARACTERS+"]+)["+DELIMITER+"]*$", prefix_line)
113: 
114:    print("prefix 1: `%s`" % prefix)
115: 
116:    if prefix is None:
117:        # validate array, like define(["...", ".CURSOR."])
118:        prefix = re.search("^\s*(["+NEEDLE_CHARACTERS+"]+)["+DELIMITER+"]+", prefix_line)
119: 
120:    print("prefix 2: `%s`" % prefix)
121: 
122:    if prefix:
123:        # print("prefix:", prefix.group(1))
124:        prefix = prefix.group(1)
125: 
126:    print("prefix 3: `%s`" % prefix)
127: 
128:    tag = re.search("<\s*(["+NEEDLE_CHARACTERS+"]*)\s*[^>]*$", prefix_line)
129:    print("tag 1: `%s`" % tag)
130: 
131:    if tag:
132:        tag = tag.group(1)
133:        # print("tag:", tag)
134: 
135:    propertyName = re.search("[\s\"\'']*(["+NEEDLE_CHARACTERS+"]*)[\s\"\']*\:[^\:]*$", prefix_line)
136: 
137:    print("tag 2: `%s`" % tag)
138:    print("propertyName 1: `%s`" % propertyName)
139: 
140:    if propertyName:
141:        propertyName = propertyName.group(1)
142:        # print("style:", style)
143: 
144:    print("propertyName 2: `%s`" % propertyName)
145: 
146:    if separator is False:
147:        logger.verbose(ID, "separator undefined => invalid", needle)
148:        valid_needle = False
149:        valid = False
150:    elif re.search("["+NEEDLE_INVALID_CHARACTERS+"]", needle):
151:        logger.verbose(ID, "invalid characters in needle => invalid", needle)
152:        valid_needle = False
153:        valid = False
154:    elif prefix is None and separator.strip() == "":
155:        logger.verbose(ID, "prefix undefined => invalid", needle)
156:        valid = False
157: 
158:    print("valid: `%s`" % valid)
159:    print("valid_needle: `%s`" % valid_needle)
160: 
161:    results = {
162:        "is_valid": valid,
163:        "valid_needle": valid_needle,
164:        "needle": needle,
165:        "prefix": prefix,
166:        "tagName": tag,
167:        "style": propertyName,
168:        "region": needle_region,
169:        "word": word,
170:        # really do not use any of this
171:        "error": error
172:    }
173: 
174:    print("results: `%s`" % results)
175:    return results


Comparing both full debugging outputs we see that the only difference is the line contents. The start and end points are correct on both cases, but while using the completion indirection by a window command, the view.substr does not return the inserted text, but the old contents on the position before the completion take place.

evandrocoan added a commit to evandrocoan/OverrideCommitCompletion that referenced this issue Feb 14, 2018
commit completion does not work with from sublime_plu
@sagold sagold added the bug label Feb 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants