def on_query_completions(self, prefix, locations): view = self.view if view.syntax().name != 'Nextflow': return if len(locations) > 1: return point = locations[0] if not view.score_selector( point, 'source.nextflow meta.definition.process.nextflow'): return if not view.substr(view.line(point)).strip().startswith('label'): return folders = view.window().folders() if not folders: return root_dir = Path(folders[0]) labels = [] for path in root_dir.rglob('**/*.config'): labels += get_config_labels(path) if not labels: return flags = sublime.INHIBIT_REORDER | sublime.INHIBIT_WORD_COMPLETIONS completions = sublime.CompletionList(completions=[ sublime.CompletionItem(trigger=f"'{label_name}'", annotation=f'{config_name}: {label_name}', details='|'.join( f'<code>{x.replace(" ", "")}</code>' for x in text.split('\n'))) for config_name, label_name, text in labels ], flags=flags) return completions
def on_query_completions(self, view: sublime.View, prefix: Any, locations: Any) -> Optional[Iterable[Any]]: if not all([ is_python_code(view), is_identifier(view, locations[0]), DOCUMENT_COMPLETION, ]): return None try: param = CompletionParam(view) except ValueError: view.run_command("hide_auto_complete") return None if self.completion and self._prev_param: if (self._prev_param.location == param.location and self._prev_param.source == param.source): return sublime.CompletionList(self.completion, sublime.INHIBIT_WORD_COMPLETIONS) thread = Thread(target=self.document_completion, args=(view, param)) thread.start() view.run_command("hide_auto_complete") return None
def on_query_completions(self, view, prefix, locations): if view.syntax().name != 'Nextflow': return if len(locations) > 1: return point = locations[0] if not view.score_selector(point-1, 'source.nextflow punctuation.params.dot'): return folders = view.window().folders() if not folders: return root_dir = Path(folders[0]) nf_config_path = root_dir / 'nextflow.config' if not nf_config_path.exists(): print(f'Cannot get params completions. "{nf_config_path}" does not exist!') return None with open(nf_config_path) as f: nf_config = f.read() params_values = params_list(nf_config) if params_values: flags = sublime.INHIBIT_REORDER | sublime.INHIBIT_WORD_COMPLETIONS completions = sublime.CompletionList( completions=[ sublime.CompletionItem( trigger=x, annotation=f'default: {y}', details=f'<i>nextflow.config</i>: <code>params.<b>{x}</b> = {y}</code>' ) for x,y in params_values ], flags=flags ) return completions
def on_query_completions(self, prefix, locations): if int(sublime.version()) >= 4050: point = locations[0] - 1 if self.view.match_selector( point, "meta.symbol - meta.function.parameters"): session = get_session_by_owner(self.view.window(), "plugin") if session and session.supports("completions"): scope = selectors.expand_by_selector( self.view, point, "meta.symbol") if scope: prefix = self.view.substr(scope) completion_list = sublime.CompletionList() ns = namespace.find_declaration(self.view) op = {"op": "completions", "prefix": prefix} if ns: op["ns"] = ns session.send( op, handler=lambda response: self.handle_completions( completion_list, response), ) return completion_list
def on_query_completions(self, view, prefix, locations) -> Any: window = view.window() if not window: return autocomplete = Autocomplete.for_window(window) if not autocomplete or not autocomplete.enabled: return from .debugger import Debugger debugger = Debugger.get(view.window()) if not debugger or not debugger.sessions.has_active: return completions = sublime.CompletionList() text = view.substr(sublime.Region(0, view.size())) row, col = view.rowcol(locations[0]) @core.schedule async def fetch(): items = [] for completion in await debugger.sessions.active.completions( text, col + 1): items.append( [completion.label, completion.text or completion.label]) completions.set_completions(items) core.run(fetch()) return completions
def on_query_completions(self, view: sublime.View, prefix: str, locations: list[int]) -> Any: if not view.settings().get('debugger.autocomplete'): return window = view.window() if not window: return from .debugger import Debugger debugger = Debugger.get(window) if not debugger or not debugger.is_active: return completions = sublime.CompletionList() text = view.substr(sublime.Region(0, view.size())) row, col = view.rowcol(locations[0]) @core.schedule async def fetch(): items: list[sublime.CompletionItem] = [] for completion in await debugger.active.completions(text, col + 1): item = sublime.CompletionItem( completion.sortText or completion.label, annotation=completion.label, completion=completion.text or completion.label, completion_format=sublime.COMPLETION_FORMAT_TEXT, kind=sublime.KIND_AMBIGUOUS) items.append(item) completions.set_completions(items) core.run(fetch()) return completions
def on_query_completions(self, view, prefix, locations): settings = sublime.load_settings('CSS.sublime-settings') if settings.get('disable_default_completions'): return None selector = settings.get('default_completions_selector', '') if isinstance(selector, list): selector = ''.join(selector) pt = locations[0] if not match_selector(view, pt, selector): return None if match_selector( view, pt, "meta.property-value.css meta.function-call.arguments"): items = self.complete_function_argument(view, prefix, pt) elif match_selector(view, pt, "meta.property-value.css"): items = self.complete_property_value(view, prefix, pt) elif match_selector(view, pt, "meta.property-list.css, meta.property-name.css"): items = self.complete_property_name(view, prefix, pt) else: # TODO: provide selectors, at-rules items = None if items: return sublime.CompletionList(items, sublime.INHIBIT_WORD_COMPLETIONS) return None
def get_entity_completions(): """ Generate a completion list for HTML entities. """ return sublime.CompletionList([ sublime.CompletionItem( trigger='#00;', completion='#${1:00};', completion_format=sublime.COMPLETION_FORMAT_SNIPPET, kind=KIND_ENTITY_SNIPPET, details='Base-10 Unicode character', ), sublime.CompletionItem( trigger='#x0000;', completion='#x${1:0000};', completion_format=sublime.COMPLETION_FORMAT_SNIPPET, kind=KIND_ENTITY_SNIPPET, details='Base-16 Unicode character', ), *(sublime.CompletionItem( trigger=entity, annotation=printed, completion=entity, completion_format=sublime.COMPLETION_FORMAT_TEXT, kind=KIND_ENTITY_MARKUP, details=f'Renders as <code>{printed}</code>', ) for entity, printed in html.entities.html5.items() if entity.endswith(';')) ], sublime.INHIBIT_WORD_COMPLETIONS)
def on_query_completions(self, view, prefix, locations): if view.syntax().name != 'Nextflow': return if len(locations) > 1: return point = locations[0] if not view.score_selector( point, 'source.nextflow meta.definition.process.nextflow meta.definition.conda-directive.nextflow string' ): return pkgs = get_cached_pkgs_list() if pkgs: print(f'Retrieved {len(pkgs)} Conda packages from cache') else: print('Running nextflow_conda_packages_info_fetch command') view.run_command('nextflow_conda_packages_info_fetch') return pkgs = pkgs[::-1] flags = sublime.INHIBIT_REORDER | sublime.INHIBIT_WORD_COMPLETIONS completions = sublime.CompletionList(completions=[ sublime.CompletionItem( trigger=f'{name}={version}={build}' if channel.startswith('pkgs/') else f'{channel}::{name}={version}={build}', annotation=f'{channel}::{name}={version}={build}', ) for name, version, build, channel in pkgs ], flags=flags) return completions
def on_query_completions(self, view, prefix, locations): if sublime.load_settings('CSS.sublime-settings').get('disable_default_completions'): return None pt = locations[0] if not match_selector(view, pt, self.selector_scope): return None if not self.props: self.props = parse_css_data() self.re_name = re.compile(r"([a-zA-Z-]+)\s*:[^:;{}]*$") self.re_value = re.compile(r"^(?:\s*(:)|([ \t]*))([^:]*)([;}])") self.re_trigger = re.compile(r"\$(?:\d+|\{\d+\:([^}]+)\})") if match_selector(view, pt, "meta.property-value.css meta.function-call"): items = self.complete_function_argument(view, prefix, pt) elif match_selector(view, pt, "meta.property-value.css"): items = self.complete_property_value(view, prefix, pt) else: items = self.complete_property_name(view, prefix, pt) if items: return sublime.CompletionList(items, sublime.INHIBIT_WORD_COMPLETIONS) return None
def on_query_completions(self, view, prefix, locations): is_scss = view.match_selector(locations[0], "source.scss") if is_scss and sublime.load_settings('SCSS.sublime-settings').get('disable_default_completions'): return None elif sublime.load_settings('Sass.sublime-settings').get('disable_default_completions'): return None pt = locations[0] # completions only inside sass/scss files if not match_selector(view, pt, 'source.sass, source.scss'): return None if not match_selector(view, pt, ''): return None if match_selector(view, pt, "meta.property-value.css meta.function-call.arguments"): items = self.complete_function_argument(view, prefix, pt) elif match_selector(view, pt, "meta.property-value.css"): items = self.complete_property_value(view, prefix, pt, is_scss) else: items = self.complete_property_name(view, prefix, pt, is_scss) if items: return sublime.CompletionList(items, sublime.INHIBIT_WORD_COMPLETIONS) return None
def normalize_completion(symbols): return sublime.CompletionList( (sublime.CompletionItem(trigger=s[0], completion=s[1], annotation=s[1], kind=sublime.KIND_AMBIGUOUS) for s in symbols), flags=sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS)
def attribute_completions(self, view, pt, prefix): SEARCH_LIMIT = 500 search_start = max(0, pt - SEARCH_LIMIT - len(prefix)) line = view.substr(sublime.Region(search_start, pt + SEARCH_LIMIT)) line_head = line[0:pt - search_start] line_tail = line[pt - search_start:] # find the tag from end of line_head i = len(line_head) - 1 tag = None space_index = len(line_head) while i >= 0: c = line_head[i] if c == '<': # found the open tag tag = line_head[i + 1:space_index] break elif c == ' ': space_index = i i -= 1 # check that this tag looks valid if not tag or not tag.isalnum(): return None # determines whether we need to close the tag # default to closing the tag suffix = '>' for c in line_tail: if c == '>': # found end tag suffix = '' break elif c == '<': # found another open tag, need to close this one break if suffix == '' and line_tail[0] not in ' >': # add a space if not there suffix = ' ' # ensure the user can always tab to the end of the completion suffix += '$0' # got the tag, now find all attributes that match return sublime.CompletionList([ sublime.CompletionItem( trigger=attr, completion=f'{attr}{suffix}' if attr in boolean_attributes else f'{attr}="$1"{suffix}', completion_format=sublime.COMPLETION_FORMAT_SNIPPET, kind=KIND_ATTRIBUTE_SNIPPET) for attr in self.tag_attributes.get(tag, []) ], sublime.INHIBIT_WORD_COMPLETIONS)
def expand_tag_attributes(self, view, locations): """ The method responds to on_query_completions, but conceptually it's expanding expressions, rather than completing words. It expands these simple expressions: tag.class -> <tag class="class"></tag> tag#id -> <tag id="id"></tag> """ # Get the contents of each line, from the beginning of the line to # each point lines = [ view.substr(sublime.Region(view.line(pt).a, pt)) for pt in locations ] # Reverse the contents of each line, to simulate having the regex # match backwards lines = [line[::-1] for line in lines] # Check the first location looks like an expression pattern = re.compile(r"([-\w]+)([.#])(\w+)") expr = match(pattern, lines[0]) if not expr: return None # Ensure that all other lines have identical expressions for line in lines[1:]: ex = match(pattern, line) if ex != expr: return None # Return the completions arg, op, tag = pattern.match(expr).groups() arg = arg[::-1] tag = tag[::-1] expr = expr[::-1] attr = 'class' if op == '.' else 'id' snippet = f'<{tag} {attr}=\"{arg}\">' if tag in void_elements else f'<{tag} {attr}=\"{arg}\">$0</{tag}>' return sublime.CompletionList([ sublime.CompletionItem( trigger=expr, completion=snippet, completion_format=sublime.COMPLETION_FORMAT_SNIPPET, kind=KIND_TAG_MARKUP, details=f'Expands to <code>{html.escape(snippet)}</code>') ], sublime.INHIBIT_WORD_COMPLETIONS)
def tag_name_completions(self): """ Create a completion list with all known tag names. It uses the keys of `self.tag_attributes` dictionary as it contains all known/supported tag names and is available/cached anyway. """ return sublime.CompletionList([ sublime.CompletionItem( trigger=tag, completion_format=sublime.COMPLETION_FORMAT_TEXT, kind=KIND_TAG_MARKUP, details=f'Expands to <code>{html.escape(tag)}</code>') for tag in self.tag_attributes ], sublime.INHIBIT_WORD_COMPLETIONS)
def __init__(self): sublime_plugin.EventListener.__init__(self) cls = self.__class__ self.loveCompletions = sublime.CompletionList() self.kinds = { 'function': sublime.KIND_FUNCTION, 'type': sublime.KIND_TYPE, 'module': sublime.KIND_NAMESPACE, 'variable': sublime.KIND_VARIABLE } # Load JSON script_dir = os.path.dirname(os.path.realpath(__file__)) json_path = os.path.join(script_dir, 'love_api.json') with open(json_path) as api_json: cls.api = json.load(api_json)
def on_query_completions(self, view, prefix, locations): window = view.window() folders = window.folders() file_name = view.file_name() prefix = prefix.lower() root_dir = find_root_dir_for_file(folders, file_name) debug("prefix:", prefix) debug("file name:", file_name) debug("folders:", folders) debug("root dir:", root_dir) debug("Python version:", platform.python_version()) debug("debug?", settings("debug")) debug("rubocop command:", settings("rubocop_command")) debug("bundler command:", settings("bundler_command")) sel = view.sel()[0] line = view.substr(view.full_line(sel)) cursor = sel.begin() (row_number, col_number) = view.rowcol(cursor) cache = self.get_cache(root_dir) cops = cache["cops"] completions = [] completions += self.completions_for_ruby(cops, view, locations, folders, root_dir, row_number, col_number, line) completions += self.completions_for_yaml(cops, view, locations, folders, root_dir, row_number, col_number, line) if is_sublime_3(): completions = sorted(completions, key=lambda item: item[0]) return (completions, sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS) else: completions = sorted(completions, key=lambda item: item.trigger) return sublime.CompletionList( completions, sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS)
def on_query_completions( self, prefix: str, locations: List[int]) -> Optional[sublime.CompletionList]: def resolve(clist: sublime.CompletionList, items: List[sublime.CompletionItem], flags: int = 0) -> None: # Resolve on the main thread to prevent any sort of data race for _set_target (see sublime_plugin.py). sublime.set_timeout(lambda: clist.set_completions(items, flags)) clist = sublime.CompletionList() sublime.set_timeout_async(lambda: self._on_query_completions_async( partial(resolve, clist), locations[0])) # https://github.com/sublimehq/sublime_text/issues/4999 # Returning a CompletionList() on on_query_completions always do INHIBIT_WORD_COMPLETIONS prefs = userprefs() flags = 0 if prefs.inhibit_snippet_completions: flags |= sublime.INHIBIT_EXPLICIT_COMPLETIONS if prefs.inhibit_word_completions: flags |= sublime.INHIBIT_WORD_COMPLETIONS sublime.set_timeout(lambda: clist.set_completions([], flags)) return clist
def on_query_completions(self, view, prefix, locations): self._state["location"] = locations[0] self._state["prefix"] = prefix before, region_includes_beginning = get_before(view, AUTOCOMPLETE_CHAR_LIMIT) after, region_includes_end = get_after(view, AUTOCOMPLETE_CHAR_LIMIT) response = autocomplete( before, after, view.file_name(), region_includes_beginning, region_includes_end, ) self._state["completions"] = response["results"] completions = [ sublime.CompletionItem( r.get("new_prefix"), annotation="tabnine", completion="{}$0{}".format( escape_tab_stop_sign(r.get("new_prefix")), r.get("new_suffix", "") ), completion_format=sublime.COMPLETION_FORMAT_SNIPPET, kind=( sublime.KIND_ID_COLOR_PURPLISH, ATTRIBUTION_ELEMENT, r.get("detail", ""), ), ) for r in self._state["completions"] ] return sublime.CompletionList( completions=completions, flags=sublime.DYNAMIC_COMPLETIONS | sublime.INHIBIT_REORDER, )
def on_query_completions(self, prefix, locations): view = self.view if view.syntax().name != 'Nextflow': return if len(locations) > 1: return point = locations[0] if not view.score_selector(point - 1, 'source.nextflow meta.definition.workflow.nextflow punctuation.accessor.dot.process-out.nextflow'): return out_word_region = view.word(point - 2) if view.substr(out_word_region) != 'out': return proc_name_region = view.word(out_word_region.a - 1) proc_name = view.substr(proc_name_region) if not proc_name: return folders = view.window().folders() if not folders: return root_dir = Path(folders[0]) emits = [] for path in root_dir.rglob('**/*.nf'): emits += get_output_channel_emits(path, proc_name) if not emits: return flags = sublime.INHIBIT_REORDER | sublime.INHIBIT_WORD_COMPLETIONS completions = sublime.CompletionList( completions=[ sublime.CompletionItem( trigger=emit, annotation=chan, ) for emit, chan in emits ], flags=flags ) return completions
def get_tag_completions(inside_tag=True): """ Generate a default completion list for HTML """ normal_tags = ('abbr', 'acronym', 'address', 'applet', 'article', 'aside', 'audio', 'b', 'basefont', 'bdi', 'bdo', 'big', 'blockquote', 'body', 'button', 'center', 'canvas', 'caption', 'cdata', 'cite', 'colgroup', 'code', 'content', 'data', 'datalist', 'dialog', 'dir', 'div', 'dd', 'del', 'details', 'dfn', 'dl', 'dt', 'element', 'em', 'embed', 'fieldset', 'figure', 'figcaption', 'font', 'footer', 'form', 'frame', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'i', 'ins', 'isindex', 'kbd', 'keygen', 'li', 'label', 'legend', 'main', 'map', 'mark', 'meter', 'nav', 'noframes', 'noscript', 'object', 'ol', 'optgroup', 'option', 'output', 'p', 'picture', 'pre', 'q', 'rb', 'rp', 'rt', 'rtc', 'ruby', 's', 'samp', 'section', 'select', 'shadow', 'small', 'span', 'strong', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'title', 'tr', 'tt', 'u', 'ul', 'var', 'video') snippet_tags = (('a', 'a href=\"$1\">$0</a>'), ('area', 'area shape=\"$1\" coords=\"$2\" href=\"$3\">'), ('audio', 'audio src=\"$1\">$0</audio>'), ('base', 'base href=\"$1\">'), ('br', 'br>'), ('col', 'col>'), ('hr', 'hr>'), ('iframe', 'iframe src=\"$1\">$0</iframe>'), ('input', 'input type=\"$1\" name=\"$2\">'), ('img', 'img src=\"$1\">'), ('link', 'link rel=\"stylesheet\" type=\"text/css\" href=\"$1\">'), ('meta', 'meta ${1:charset=\"utf-8\"}>'), ('param', 'param name=\"$1\" value=\"$2\">'), ('progress', 'progress value=\"$1\" max=\"$2\">'), ('script', 'script${2: type=\"${1:text/javascript}\"}>$0</script>'), ('slot', 'slot name=name=\"$1\">$0</slot>'), ('source', 'source src=\"$1\" type=\"$2\">'), ('style', 'style type=\"${1:text/css}\">$0</style>'), ('track', 'track kind=\"$1\" src=\"$2\">'), ('wbr', 'wbr>'), ('video', 'video src=\"$1\">$0</video>')) tag_begin = '' if inside_tag else '<' return sublime.CompletionList([ *(sublime.CompletionItem( trigger=tag, completion=f'{tag_begin}{tag}>$0</{tag}>', completion_format=sublime.COMPLETION_FORMAT_SNIPPET, kind=KIND_TAG_MARKUP, details=f'Expands to <code><{tag}>$0</{tag}></code>') for tag in normal_tags), *(sublime.CompletionItem( trigger=tag, completion=f'{tag_begin}{completion}', completion_format=sublime.COMPLETION_FORMAT_SNIPPET, kind=KIND_TAG_MARKUP, details=f'Expands to <code><{html.escape(completion)}</code>') for tag, completion in snippet_tags) ], sublime.INHIBIT_WORD_COMPLETIONS)
) def on_query_completions(self, prefix, locations): point = locations[0] - 1 if settings().get("auto_complete") and self.view.match_selector( point, "source.clojure & (meta.symbol - meta.function.parameters) | (constant.other.keyword - punctuation.definition.keyword)", ) and (dialect := dialects.for_point( self.view, point)) and (client := state.client( self.view.window(), dialect)): if scope := selectors.expand_by_selector( self.view, point, "meta.symbol | constant.other.keyword"): prefix = self.view.substr(scope) completion_list = sublime.CompletionList() client.backchannel.send( { "op": edn.Keyword("completions"), "prefix": prefix, "ns": namespace.name(self.view) }, handler=lambda response: (completion_list.set_completions( map(self.completion_item, response.get(edn.Keyword("completions"), []))))) return completion_list def lookup(view, form, handler):
def on_query_completions(self, prefix, locations): global last_view_id global cached_symbols global cached_references completions = sublime.CompletionList() # views is an array of view-s not including self.view views = self.sort_views_by_relevance() symbols = [] current_view_symbols = find_symbols(self.view) if last_view_id != self.view.id(): cached_symbols = find_symbols(self.view, views) symbols.extend(current_view_symbols) symbols.extend(cached_symbols) self.items = [] # easy way to filter out hash completions unique_symbols = [] for symbol_location in symbols: _file_name, base_file_name, _region, symbol, symbol_type = symbol_location completion_item = sublime.CompletionItem( symbol, annotation=base_file_name, completion=symbol, kind=(sublime.KIND_ID_AMBIGUOUS, symbol_type, '') ) if symbol not in unique_symbols: unique_symbols.append(symbol) self.items.append(completion_item) references = [] current_view_references = find_references(self.view) if last_view_id != self.view.id(): cached_references = find_references(self.view, views) references.extend(current_view_references) references.extend(cached_references) for symbol_location in references: _file_name, base_file_name, _region, symbol, symbol_type = symbol_location completion_item = sublime.CompletionItem( symbol, annotation=base_file_name, completion=symbol, kind=(sublime.KIND_ID_AMBIGUOUS, symbol_type, '') ) if symbol not in unique_symbols: unique_symbols.append(symbol) self.items.append(completion_item) completions.set_completions(self.items) last_view_id = self.view.id() return completions
def __init__(self, view, points): self.view = view self.points = points self.completions = sublime.CompletionList()