From aee4d4f8c852570cf4ff6ebf047565da9d72b7f6 Mon Sep 17 00:00:00 2001 From: Kyle Bebak Date: Sun, 9 Jun 2019 11:05:21 -0500 Subject: [PATCH 1/5] without_duplicates O(n) instead of O(n^2) --- all_views_completions.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/all_views_completions.py b/all_views_completions.py index 57a9ad0..37c5722 100644 --- a/all_views_completions.py +++ b/all_views_completions.py @@ -62,19 +62,18 @@ def is_disabled_in(scope): return True return False + def filter_words(words): - words = words[0:MAX_WORDS_PER_VIEW] - return [w for w in words if MIN_WORD_SIZE <= len(w) <= MAX_WORD_SIZE] + return [w for w in words if MIN_WORD_SIZE <= len(w) <= MAX_WORD_SIZE][0:MAX_WORDS_PER_VIEW] -# keeps first instance of every word and retains the original order -# (n^2 but should not be a problem as len(words) <= MAX_VIEWS*MAX_WORDS_PER_VIEW) +# keeps first instance of every word and retains the original order, O(n) def without_duplicates(words): result = [] - used_words = [] + used_words = set() for w, v in words: if w not in used_words: - used_words.append(w) + used_words.add(w) result.append((w, v)) return result From 4d2e8aa36458088f1271a995470b391832c9b665 Mon Sep 17 00:00:00 2001 From: Kyle Bebak Date: Sun, 9 Jun 2019 11:05:46 -0500 Subject: [PATCH 2/5] Adds `abc` description for completions from current file --- all_views_completions.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/all_views_completions.py b/all_views_completions.py index 37c5722..1f5b861 100644 --- a/all_views_completions.py +++ b/all_views_completions.py @@ -20,12 +20,13 @@ def plugin_loaded(): global settings settings = sublime.load_settings('All Autocomplete.sublime-settings') + class AllAutocomplete(sublime_plugin.EventListener): def on_query_completions(self, view, prefix, locations): if is_disabled_in(view.scope_name(locations[0])): return [] - + words = [] # Limit number of views but always include the active view. This @@ -51,6 +52,8 @@ def on_query_completions(self, view, prefix, locations): contents = w.replace('$', '\\$') if v.id != view.id and v.file_name(): trigger += '\t(%s)' % basename(v.file_name()) + if v.id == view.id: + trigger += '\tabc' matches.append((trigger, contents)) return matches From 585b84b693b7eef8f57ed8331c0f012957cc6b4b Mon Sep 17 00:00:00 2001 From: Kyle Bebak Date: Sun, 9 Jun 2019 12:07:58 -0500 Subject: [PATCH 3/5] Can disable sourcing syntaxes for auto-completion --- README.md | 7 +++++-- all_views_completions.py | 13 ++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index c34a54c..7ab60ae 100644 --- a/README.md +++ b/README.md @@ -22,12 +22,15 @@ Settings You can disable the additional autocompletion provided by this package for specific source files and even select syntax within files. In the Sublime menu go to Preferences > Package Settings > All Autocomplete > Settings – User. -Example: the following Setting would disable All Autocomplete for CSS and JavaScript code: +Example: the following Setting would disable completions when you're editing CSS or JavaScript code, and would not source any completions from Markdown files: ``` "exclude_from_completion": [ "css", "js" +], +"exclude_sources": [ + "markdown" ] ``` @@ -53,4 +56,4 @@ as the name is changed. DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION -0. You just DO WHAT THE FUCK YOU WANT TO. \ No newline at end of file +0. You just DO WHAT THE FUCK YOU WANT TO. diff --git a/all_views_completions.py b/all_views_completions.py index 1f5b861..6c59dba 100644 --- a/all_views_completions.py +++ b/all_views_completions.py @@ -24,14 +24,18 @@ def plugin_loaded(): class AllAutocomplete(sublime_plugin.EventListener): def on_query_completions(self, view, prefix, locations): - if is_disabled_in(view.scope_name(locations[0])): + if is_excluded(view.scope_name(locations[0]), settings.get("exclude_from_completion", [])): return [] words = [] # Limit number of views but always include the active view. This # view goes first to prioritize matches close to cursor position. - other_views = [v for v in sublime.active_window().views() if v.id != view.id] + other_views = [ + v + for v in sublime.active_window().views() + if v.id != view.id and not is_excluded(v.scope_name(0), settings.get("exclude_sources", [])) + ] views = [view] + other_views views = views[0:MAX_VIEWS] @@ -58,10 +62,9 @@ def on_query_completions(self, view, prefix, locations): return matches -def is_disabled_in(scope): - excluded_scopes = settings.get("exclude_from_completion", []) +def is_excluded(scope, excluded_scopes): for excluded_scope in excluded_scopes: - if scope.find(excluded_scope) != -1: + if excluded_scope in scope: return True return False From e5397e7ebb8d74f4470ea1fa76c7f22e590e5bf2 Mon Sep 17 00:00:00 2001 From: Kyle Bebak Date: Sun, 9 Jun 2019 13:16:31 -0500 Subject: [PATCH 4/5] MIN_WORD_SIZE, MAX_WORD_SIZE configurable via settings --- all_views_completions.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/all_views_completions.py b/all_views_completions.py index 6c59dba..e9a0459 100644 --- a/all_views_completions.py +++ b/all_views_completions.py @@ -7,9 +7,6 @@ import time from os.path import basename -# limits to prevent bogging down the system -MIN_WORD_SIZE = 3 -MAX_WORD_SIZE = 50 MAX_VIEWS = 20 MAX_WORDS_PER_VIEW = 100 @@ -70,6 +67,8 @@ def is_excluded(scope, excluded_scopes): def filter_words(words): + MIN_WORD_SIZE = settings.get("min_word_size", 3) + MAX_WORD_SIZE = settings.get("max_word_size", 50) return [w for w in words if MIN_WORD_SIZE <= len(w) <= MAX_WORD_SIZE][0:MAX_WORDS_PER_VIEW] From 7c23ab1c3c4e7a7745e5fa58f33f27458335467a Mon Sep 17 00:00:00 2001 From: Kyle Bebak Date: Sun, 9 Jun 2019 13:19:24 -0500 Subject: [PATCH 5/5] Updates README --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7ab60ae..90b1cfb 100644 --- a/README.md +++ b/README.md @@ -24,14 +24,16 @@ You can disable the additional autocompletion provided by this package for speci Example: the following Setting would disable completions when you're editing CSS or JavaScript code, and would not source any completions from Markdown files: -``` +```json "exclude_from_completion": [ "css", "js" ], "exclude_sources": [ "markdown" -] +], +"min_word_size": 5, // don't show completions for words with fewer than this many chars +"max_word_size": 40 // don't show completions for words with more than this many chars ``` The names provided in this list are matched against the so-called "syntax scope" of the currently autocompleted input. For example, in a CSS file, when you start typing a new CSS class name, the syntax scope is "source.css meta.selector.css". The names you provide in the config above are partially matched against this scope. This means, you can completely disable All Autocomplete for all CSS code by specifying "css" – or you can disable it only for specific parts, for example, CSS selectors by specifying "selector.css". Or to disable completion in comments, include "comment" in the list.