From 4463d5a39a2fc5af4f7cde8146b46e63c5f8022f Mon Sep 17 00:00:00 2001 From: bsmith Date: Thu, 18 May 2017 15:22:15 +0200 Subject: [PATCH 1/6] add autocomplete for reqs in open tabs --- Snippets/Requirement-Block.sublime-snippet | 5 +-- Syntaxes/Asciidoctor.YAML-tmLanguage | 7 ++--- Syntaxes/Asciidoctor.tmLanguage | 13 ++------ completions.py | 36 ++++++++++++---------- 4 files changed, 29 insertions(+), 32 deletions(-) diff --git a/Snippets/Requirement-Block.sublime-snippet b/Snippets/Requirement-Block.sublime-snippet index ed3d27c..94e54ed 100644 --- a/Snippets/Requirement-Block.sublime-snippet +++ b/Snippets/Requirement-Block.sublime-snippet @@ -2,9 +2,10 @@ Requirement Block diff --git a/Syntaxes/Asciidoctor.YAML-tmLanguage b/Syntaxes/Asciidoctor.YAML-tmLanguage index cc5efa3..6afb0f6 100644 --- a/Syntaxes/Asciidoctor.YAML-tmLanguage +++ b/Syntaxes/Asciidoctor.YAML-tmLanguage @@ -859,15 +859,14 @@ repository: block_title: comment: | - Title of a block. + Title of a block. Exludes custom block titles for better + scoping / preventing overlap. Examples: .My title Lorem ipsum dolor. name: markup.heading.block.asciidoc - match: ^(\.)\w.*$\n? - captures: - '1': {name: punctuation.definition.blockheading.asciidoc} + match: (\.)\w.*\n(?!\[(req|def|math)) block_id: comment: | diff --git a/Syntaxes/Asciidoctor.tmLanguage b/Syntaxes/Asciidoctor.tmLanguage index c357d25..634cc46 100644 --- a/Syntaxes/Asciidoctor.tmLanguage +++ b/Syntaxes/Asciidoctor.tmLanguage @@ -731,23 +731,16 @@ Examples: block_title - captures - - 1 - - name - punctuation.definition.blockheading.asciidoc - - comment - Title of a block. + Title of a block. Exludes custom block titles for better +scoping / preventing overlap. Examples: .My title Lorem ipsum dolor. match - ^(\.)\w.*$\n? + (\.)\w.*\n(?!\[(req|def|math)) name markup.heading.block.asciidoc diff --git a/completions.py b/completions.py index d5cfdd0..30fd215 100644 --- a/completions.py +++ b/completions.py @@ -3,6 +3,7 @@ from sublime import Region from sublime_plugin import EventListener +MAX_VIEWS = 20 # String that must be found in the syntax setting of the current view # to active this plugin. SYNTAX = 'Asciidoc' @@ -83,19 +84,24 @@ class AsciidocCrossReferenceCompletions(EventListener): def on_query_completions(self, view, prefix, locations): """ Called by SublimeText when auto-complete pop-up box appears. """ - - if SYNTAX not in view.settings().get('syntax'): - return None - if not all(self.should_trigger(view, loc) for loc in locations): - return None - - anchors = zip(find_by_scope(view, ANCHOR_SCOPE), repeat('anchor')) - titles = zip(find_by_scope(view, SEC_TITLE_SCOPE), repeat('title')) - # Refactor needed... - reqs = list(find_by_scope(view, REQ_ID_SCOPE)) - prefixed_reqs = zip(('Req-' + r for r in reqs), repeat('reqs')) - - return sorted(filter_completions(prefix, anchors, titles, prefixed_reqs), + + reqs_all = [] + # Search in all open tabs + other_views = [v for v in sublime.active_window().views() if v.id != view.id] + views = [view] + other_views + # Limit tabs + views = views[0:MAX_VIEWS] + for i in views: + # For each open tab, search by + reqs = list(find_by_scope(i, REQ_ID_SCOPE)) + # Add the Req- prefix + reqs_by_view = zip(('Req-' + r for r in reqs), repeat(' requirements')) + reqs_all.extend(reqs_by_view) + + titles = zip(find_by_scope(view, SEC_TITLE_SCOPE), repeat(' title')) + anchors = zip(find_by_scope(view, ANCHOR_SCOPE), repeat(' anchors')) + + return sorted(filter_completions(prefix, anchors, titles, reqs_all), key=lambda t: t[0].lower()) def should_trigger(self, view, point): @@ -103,14 +109,13 @@ def should_trigger(self, view, point): return (view.match_selector(point, XREF_SCOPE) or view.match_selector(point, ADOC_SCOPE) and lsubstr(view, point, 2) == '<<') - def filter_completions(prefix, *data): """ Filter completions that starts with the given prefix and format them for the completions list. Arguments: prefix (str): - *data: An iterable with tuples of a trigger (content) and a hint (text + *data: An iterable with Tuples of a trigger (content) and a hint (text showed on the right side of the trigger). """ return (("%s\t%s" % (content, hint), content) @@ -121,7 +126,6 @@ def cursors_line_num(view): """ Return list of 0-based line numbers of the cursor(s). """ return [view.rowcol(region.b)[0] for region in view.sel()] - def find_by_scope(view, selector): """ Find all substrings in the file matching the given scope selector. """ return map(view.substr, view.find_by_selector(selector)) From e9da17cfad700048c590e5e451b950521cd1c7e4 Mon Sep 17 00:00:00 2001 From: bsmith Date: Thu, 18 May 2017 15:29:09 +0200 Subject: [PATCH 2/6] fix whitespace --- .sublime-build | 4 ++-- completions.py | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.sublime-build b/.sublime-build index 5311f8f..96fe4c4 100644 --- a/.sublime-build +++ b/.sublime-build @@ -1,4 +1,4 @@ { - "working_dir": "${project_path}", - "cmd": ["ruby", "requirements.rb"] + "working_dir": "${packages}/asciispec-sublime/script", + "cmd": ["./test"] } \ No newline at end of file diff --git a/completions.py b/completions.py index 30fd215..06c29e2 100644 --- a/completions.py +++ b/completions.py @@ -84,7 +84,6 @@ class AsciidocCrossReferenceCompletions(EventListener): def on_query_completions(self, view, prefix, locations): """ Called by SublimeText when auto-complete pop-up box appears. """ - reqs_all = [] # Search in all open tabs other_views = [v for v in sublime.active_window().views() if v.id != view.id] @@ -100,15 +99,17 @@ def on_query_completions(self, view, prefix, locations): titles = zip(find_by_scope(view, SEC_TITLE_SCOPE), repeat(' title')) anchors = zip(find_by_scope(view, ANCHOR_SCOPE), repeat(' anchors')) - + return sorted(filter_completions(prefix, anchors, titles, reqs_all), key=lambda t: t[0].lower()) def should_trigger(self, view, point): """ Return True if completions should be triggered at the given point. """ + return (view.match_selector(point, XREF_SCOPE) or view.match_selector(point, ADOC_SCOPE) and lsubstr(view, point, 2) == '<<') + def filter_completions(prefix, *data): """ Filter completions that starts with the given prefix and format them for the completions list. @@ -126,6 +127,7 @@ def cursors_line_num(view): """ Return list of 0-based line numbers of the cursor(s). """ return [view.rowcol(region.b)[0] for region in view.sel()] + def find_by_scope(view, selector): """ Find all substrings in the file matching the given scope selector. """ return map(view.substr, view.find_by_selector(selector)) From 15f00bf8c3a57b6010c9de07c16bac7f26b94219 Mon Sep 17 00:00:00 2001 From: bsmith Date: Thu, 18 May 2017 15:32:57 +0200 Subject: [PATCH 3/6] minor edit --- .sublime-build | 2 +- completions.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.sublime-build b/.sublime-build index 96fe4c4..19ac62b 100644 --- a/.sublime-build +++ b/.sublime-build @@ -1,4 +1,4 @@ { "working_dir": "${packages}/asciispec-sublime/script", "cmd": ["./test"] -} \ No newline at end of file +} diff --git a/completions.py b/completions.py index 06c29e2..34da224 100644 --- a/completions.py +++ b/completions.py @@ -94,11 +94,11 @@ def on_query_completions(self, view, prefix, locations): # For each open tab, search by reqs = list(find_by_scope(i, REQ_ID_SCOPE)) # Add the Req- prefix - reqs_by_view = zip(('Req-' + r for r in reqs), repeat(' requirements')) + reqs_by_view = zip(('Req-' + r for r in reqs), repeat(' requirement')) reqs_all.extend(reqs_by_view) titles = zip(find_by_scope(view, SEC_TITLE_SCOPE), repeat(' title')) - anchors = zip(find_by_scope(view, ANCHOR_SCOPE), repeat(' anchors')) + anchors = zip(find_by_scope(view, ANCHOR_SCOPE), repeat(' anchor')) return sorted(filter_completions(prefix, anchors, titles, reqs_all), key=lambda t: t[0].lower()) From 246b43b99626b9eab4fbc5187aed184adc426eca Mon Sep 17 00:00:00 2001 From: bsmith Date: Fri, 19 May 2017 14:57:24 +0200 Subject: [PATCH 4/6] revert title pattern matching --- Syntaxes/Asciidoctor.YAML-tmLanguage | 2 +- Syntaxes/Asciidoctor.tmLanguage | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Syntaxes/Asciidoctor.YAML-tmLanguage b/Syntaxes/Asciidoctor.YAML-tmLanguage index 6afb0f6..a47ff2b 100644 --- a/Syntaxes/Asciidoctor.YAML-tmLanguage +++ b/Syntaxes/Asciidoctor.YAML-tmLanguage @@ -866,7 +866,7 @@ repository: .My title Lorem ipsum dolor. name: markup.heading.block.asciidoc - match: (\.)\w.*\n(?!\[(req|def|math)) + match: ^(\.)\w.*$\n? block_id: comment: | diff --git a/Syntaxes/Asciidoctor.tmLanguage b/Syntaxes/Asciidoctor.tmLanguage index 634cc46..30ba986 100644 --- a/Syntaxes/Asciidoctor.tmLanguage +++ b/Syntaxes/Asciidoctor.tmLanguage @@ -740,7 +740,7 @@ Examples: Lorem ipsum dolor. match - (\.)\w.*\n(?!\[(req|def|math)) + ^(\.)\w.*$\n? name markup.heading.block.asciidoc From d181bc04019488e3930f1dfa3d1881166c215807 Mon Sep 17 00:00:00 2001 From: bsmith Date: Wed, 31 May 2017 16:13:30 +0200 Subject: [PATCH 5/6] add build script --- .sublime-build | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.sublime-build b/.sublime-build index 19ac62b..5d0670d 100644 --- a/.sublime-build +++ b/.sublime-build @@ -1,4 +1,6 @@ { - "working_dir": "${packages}/asciispec-sublime/script", - "cmd": ["./test"] + "working_dir": "${project_path}", + "shell": true, + "shell_cmd": "./build.sh -h", } + From cdd86929facd62ae45ad6083f5a40ab960e56ee8 Mon Sep 17 00:00:00 2001 From: Brian Thomas Smith Date: Thu, 1 Jun 2017 23:35:49 +0200 Subject: [PATCH 6/6] Revert "Add docs build script" --- .sublime-build | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.sublime-build b/.sublime-build index 5d0670d..19ac62b 100644 --- a/.sublime-build +++ b/.sublime-build @@ -1,6 +1,4 @@ { - "working_dir": "${project_path}", - "shell": true, - "shell_cmd": "./build.sh -h", + "working_dir": "${packages}/asciispec-sublime/script", + "cmd": ["./test"] } -