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

Trim redundant prefixes of syntax test suggestions. #340

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add option to trim redundant prefixes of syntax test suggestions.
  • Loading branch information
Thom1729 committed Mar 12, 2021
commit 4caed5b45ada0e73ba256178bcf87f00818e8936
4 changes: 4 additions & 0 deletions Package/PackageDev.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
// then suggest meta.example.markdown (true) vs meta.example (false).
"syntax_test.suggest_scope_suffix": true,

// Whether to trim leading scopes from suggestions
// that are already part of previous assertions.
"syntax_test.suggest_trimmed_prefix": false,


/// ADVANCED SETTINGS /////////////////////////////////////////////////////////////////////////

Expand Down
16 changes: 16 additions & 0 deletions plugins/syntaxtest_dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,22 @@ def run(self, edit, character='^'):
suggest_suffix = get_setting('syntax_test.suggest_scope_suffix', True)
scope = find_common_scopes(scopes, not suggest_suffix)

trim_prefix = get_setting('syntax_test.suggest_trimmed_prefix', False)
if trim_prefix:
above_scopes = [
self.view.substr(sublime.Region(
line.line_region.begin() + line.assertion_colrange[1],
line.line_region.end(),
)).strip()
for line in lines[1:]
if line.assertion_colrange[0] <= lines[0].assertion_colrange[0]
and line.assertion_colrange[1] >= lines[0].assertion_colrange[1]
]

for above_scope in reversed(above_scopes):
if scope.startswith(above_scope):
scope = scope[len(above_scope):].strip()

# delete the existing selection
if not view.sel()[0].empty():
view.erase(edit, view.sel()[0])
Expand Down