def get_attribute_completion(self, context: XmlContext) -> CompletionList: """Gets a list of completion items with all the attributes that can be used in the current context node. Args: context (XmlContext): The XML context information at a specific document position. It should contain, at least, the current node. Returns: CompletionList: The completion item with the basic information about the attributes. """ if ( context.is_empty or context.is_content or context.is_attribute_value or context.is_closing_tag or not context.token.name ): return CompletionList(is_incomplete=False) result = [] if context.xsd_element: existing_attr_names = context.token.get_attribute_names() for attr_name in context.xsd_element.attributes: if attr_name in existing_attr_names: continue attr = context.xsd_element.attributes[attr_name] result.append(self._build_attribute_completion_item(attr, len(result))) return CompletionList(items=result, is_incomplete=False)
def complete(self): """Return CompletionList for given context.""" completion_item_list = [] if self.rs_object is not None: if self.completion_types.get(CompletionType.KEYWORD_COMPLETION, False): completion_item_list += self.complete_keyword() if self.completion_types.get(CompletionType.SEMANTIC_COMPLETION, False): completion_item_list += self.complete_semantic() if self.completion_types.get(CompletionType.HERITAGE_COMPLETION, False): completion_item_list += self.complete_heritage() if self.completion_types.get(CompletionType.IMPORT_COMPLETION, False): completion_item_list += self.complete_import() if self.completion_types.get(CompletionType.IMPORT_FROM_COMPLETION, False): completion_item_list += self.complete_import_from() if self.completion_types.get(CompletionType.BUILTINS_COMPLETION, False): completion_item_list += self.complete_semantic_builtins() # if CompletionType.DOT_COMPLETION in completion_types: # self.complete_dot() else: logging.error("Invalid context, can't complete.") return CompletionList(False, completion_item_list)
def get_attribute_value_completion(self, context: XmlContext) -> CompletionList: """Gets a list of possible values for a anumeration restricted attribute if exists. Args: context (XmlContext): The XML context at an attribute value position. Returns: CompletionList: The list of possible values of the attribute if it has an enumeration restriction. """ if context.attribute_name: attribute: Optional[XsdAttribute] = context.xsd_element.attributes.get(context.attribute_name) if attribute and attribute.enumeration: result = [CompletionItem(item, CompletionItemKind.Value) for item in attribute.enumeration] return CompletionList(items=result, is_incomplete=False) return CompletionList(False)
def completions(ls, params: CompletionParams = None): """Returns completion items.""" if not params: return CompletionList(False, []) parser = CompletionParser(params, ls) return parser.complete()
def completion(server: LanguageServer, params: CompletionParams) -> CompletionList: """Returns completion items""" jedi_script = jedi_utils.script(server.workspace, params.textDocument.uri) jedi_lines = jedi_utils.line_column(params.position) completions = jedi_script.complete(**jedi_lines) char = pygls_utils.char_before_cursor( document=server.workspace.get_document(params.textDocument.uri), position=params.position, ) return CompletionList( is_incomplete=False, items=[ CompletionItem( label=completion.name, kind=get_lsp_completion_type(completion.type), detail=completion.description, documentation=docstring_to_markup_content( completion.docstring()), sort_text=jedi_utils.complete_sort_name(completion), insert_text=pygls_utils.clean_completion_name( completion.name, char), ) for completion in completions ], )
def completion(server: JediLanguageServer, params: CompletionParams) -> CompletionList: """Returns completion items""" jedi_script = jedi_utils.script(server.workspace, params.textDocument.uri) jedi_lines = jedi_utils.line_column(params.position) completions = jedi_script.complete(**jedi_lines) char = pygls_utils.char_before_cursor( document=server.workspace.get_document(params.textDocument.uri), position=params.position, ) markup_preferred = ( server.initialize_params.initializationOptions_markupKindPreferred) markup_supported = ( server.initialize_params. capabilities_textDocument_completion_completionItem_documentationFormat ) markup_kind = (markup_preferred if markup_preferred in markup_supported else markup_supported[0]) return CompletionList( is_incomplete=False, items=[ CompletionItem( label=completion.name, kind=get_lsp_completion_type(completion.type), detail=completion.description, documentation=MarkupContent(kind=markup_kind, value=completion.docstring()), sort_text=jedi_utils.complete_sort_name(completion), insert_text=pygls_utils.clean_completion_name( completion.name, char), ) for completion in completions ], )
def completions(params: CompletionParams): """Returns completion items.""" return CompletionList(False, [ CompletionItem('hello'), CompletionItem('world'), CompletionItem('test_pygls') ])
def completions(params: CompletionParams): if (params.context.triggerKind == CompletionTriggerKind.TriggerCharacter): token = '' trigger = params.context.triggerCharacter else: word = self._cursor_word(params.textDocument.uri, params.position, False) token = '' if word is None else word[0] trigger = None items: List[CompletionItem] = [] if trigger is None: commands = self._api.search_command(token) items.extend( CompletionItem(x, CompletionItemKind.Function, documentation=self._api.get_command_doc(x)) for x in commands) if trigger is None or trigger == '{': variables = self._api.search_variable(token) items.extend( CompletionItem(x, CompletionItemKind.Variable, documentation=self._api.get_variable_doc(x)) for x in variables) if trigger is None: targets = self._api.search_target(token) items.extend( CompletionItem(x, CompletionItemKind.Class) for x in targets) if trigger == '(': func = self._cursor_function(params.textDocument.uri, params.position) if func is not None: func = func.lower() if func == 'include': modules = self._api.search_module(token, False) items.extend( CompletionItem(x, CompletionItemKind.Module, documentation=self._api. get_module_doc(x, False)) for x in modules) elif func == 'find_package': modules = self._api.search_module(token, True) items.extend( CompletionItem(x, CompletionItemKind.Module, documentation=self._api. get_module_doc(x, True)) for x in modules) return CompletionList(False, items)
def completions(params: CompletionParams): """Returns completion items.""" a = 1 b = 1 c = a+b return CompletionList(False, [ CompletionItem('hello',kind=2,data=1), CompletionItem('world',kind=2,data=2) ])
def completions(params: CompletionParams = None): """Returns completion items.""" return CompletionList(False, [ CompletionItem('"'), CompletionItem('['), CompletionItem(']'), CompletionItem('{'), CompletionItem('}') ])
def completions(params: CompletionParams = None): """Returns completion items.""" return CompletionList(False, [ CompletionItem('"'), CompletionItem('elephant'), CompletionItem('function'), CompletionItem('module'), CompletionItem('{'), CompletionItem('}') ])
def complete_code(ls, c: CompletionParams) -> CompletionList: # noqa doc = ls.workspace.get_document(c.textDocument.uri) completions = complete(doc.uri, doc.source, c.position.line, c.position.character) # noqa items = [ CompletionItem(x.name, jedi_to_lsp_kind(x.type), documentation=x.docstring()) # noqa for x in completions ] return CompletionList(False, items)
def completions(ls,params: CompletionParams = None): """Returns completion items.""" print("completions") ls.show_message_log('completions') global context global check print("check_contexts:{}".format(context)) #返回补全的内容 return CompletionList(False, [ CompletionItem(label='aicoder',detail="AICoder",documentation='aicoder'), CompletionItem(abel='test_AICoder',detail="AICoder",documentation='test_AICoder'), CompletionItem(label=context,detail="AICoder",documentation=context) ])
def on_completion(rst: RstLanguageServer, params: CompletionParams): """Suggest completions based on the current context.""" uri = params.textDocument.uri pos = params.position doc = rst.workspace.get_document(uri) line = get_line_til_position(doc, pos) items = [] for pattern, handlers in rst.completion_handlers.items(): match = pattern.match(line) if match: for handler in handlers: items += handler(match, doc, pos) return CompletionList(False, items)
def completion( server: JediLanguageServer, params: CompletionParams ) -> Optional[CompletionList]: """Returns completion items.""" document = server.workspace.get_document(params.textDocument.uri) jedi_script = jedi_utils.script(server.project, document) jedi_lines = jedi_utils.line_column(jedi_script, params.position) completions_jedi = jedi_script.complete(**jedi_lines) snippet_support = ( server.initialize_params.capabilities_textDocument_completion_completionItem_snippetSupport ) snippet_disable = ( server.initialize_params.initializationOptions_completion_disableSnippets ) resolve_eagerly = ( server.initialize_params.initializationOptions_completion_resolveEagerly ) markup_kind = choose_markup(server) is_import_context = jedi_utils.is_import( script_=jedi_script, line=jedi_lines["line"], column=jedi_lines["column"], ) enable_snippets = ( snippet_support and not snippet_disable and not is_import_context ) char_before_cursor = pygls_utils.char_before_cursor( document=server.workspace.get_document(params.textDocument.uri), position=params.position, ) jedi_utils.clear_completions_cache() completion_items = [ jedi_utils.lsp_completion_item( completion=completion, char_before_cursor=char_before_cursor, enable_snippets=enable_snippets, resolve_eagerly=resolve_eagerly, markup_kind=markup_kind, ) for completion in completions_jedi ] return ( CompletionList(is_incomplete=False, items=completion_items) if completion_items else None )
def get_completion_at_context( self, context: XmlContext, completion_context: CompletionContext, mode: CompletionMode = CompletionMode.AUTO ) -> CompletionList: triggerKind = completion_context.triggerKind if mode == CompletionMode.AUTO and triggerKind == CompletionTriggerKind.TriggerCharacter: if completion_context.triggerCharacter == "<": return self.get_node_completion(context) if completion_context.triggerCharacter == " ": return self.get_attribute_completion(context) elif triggerKind == CompletionTriggerKind.Invoked: if context.is_attribute_value: return self.get_attribute_value_completion(context) if context.is_tag and not context.is_closing_tag: if context.token.name: return self.get_attribute_completion(context) return self.get_node_completion(context) return CompletionList(items=[], is_incomplete=False)
def completions(params: CompletionParams): text_doc = server.workspace.get_document(params.textDocument.uri) antfile = get_antfile(text_doc) # TODO better isolation; no pygls stuff in antfile ant_completions = antfile.completions(sb_position(params.position)) # TODO move this function to utils def map_completion(ant_compl: AntCompletion): if ant_compl.kind == AntCompletionKind.TEXT: return CompletionItem(ant_compl.text, kind=CompletionItemKind.Text) elif ant_compl.kind == AntCompletionKind.RATE_LAW: return CompletionItem('(mass action) ' + ant_compl.text, kind=CompletionItemKind.Text, insert_text=ant_compl.text, insert_text_format=InsertTextFormat.Snippet) else: assert False, 'Not implemented' items = list(map(map_completion, ant_completions)) return CompletionList(False, items)
def completion(server: JediLanguageServer, params: CompletionParams) -> Optional[CompletionList]: """Returns completion items.""" document = server.workspace.get_document(params.textDocument.uri) jedi_script = jedi_utils.script(server.project, document) jedi_lines = jedi_utils.line_column(jedi_script, params.position) completions_jedi = jedi_script.complete(**jedi_lines) markup_preferred = ( server.initialize_params.initializationOptions_markupKindPreferred) markup_supported = ( server.initialize_params. capabilities_textDocument_completion_completionItem_documentationFormat ) markup_kind = (markup_preferred if markup_preferred in markup_supported else markup_supported[0]) snippet_support = ( server.initialize_params. capabilities_textDocument_completion_completionItem_snippetSupport) snippet_disable = (server.initialize_params. initializationOptions_completion_disableSnippets) is_import_context = jedi_utils.is_import( script_=jedi_script, line=jedi_lines["line"], column=jedi_lines["column"], ) enable_snippets = (snippet_support and not snippet_disable and not is_import_context) char_before_cursor = pygls_utils.char_before_cursor( document=server.workspace.get_document(params.textDocument.uri), position=params.position, ) completion_items = [ jedi_utils.lsp_completion_item( name=completion, char_before_cursor=char_before_cursor, enable_snippets=enable_snippets, markup_kind=markup_kind, ) for completion in completions_jedi ] return (CompletionList(is_incomplete=False, items=completion_items) if completion_items else None)
def get_node_completion(self, context: XmlContext) -> CompletionList: """Gets a list of completion items with all the available child tags that can be placed in the current context node. Args: context (XmlContext): The XML context information at a specific document position. It should contain, at least, the current node. Returns: CompletionList: A list of completion items with the child nodes that can be placed under the current node. """ result = [] if context.is_empty or context.is_root: result.append(self._build_node_completion_item(context.xsd_element)) elif context.xsd_element: for child in context.xsd_element.children: if not context.has_reached_max_occurs(child): result.append(self._build_node_completion_item(child, len(result))) result.append(self._build_node_completion_item(self.xsd_tree.expand_element, len(result))) return CompletionList(items=result, is_incomplete=False)
def completions(ls: LarkLanguageServer, params: CompletionParams = None): """Returns completion items.""" ls.show_message_log('completion called @ {}'.format(params.position)) items: t.List[CompletionItem] = [] return CompletionList(False, items)
def _complete(english_server, params): results = ["what", "no"] return CompletionList(False, [CompletionItem(i) for i in results])
def completions(params: CompletionParams): if ( hasattr(params, "context") and params.context.triggerKind == CompletionTriggerKind.TriggerCharacter ): token = "" trigger = params.context.triggerCharacter else: line = self._cursor_line(params.textDocument.uri, params.position) idx = params.position.character - 1 if 0 <= idx < len(line) and line[idx] in trigger_characters: token = "" trigger = line[idx] else: word = self._cursor_word( params.textDocument.uri, params.position, False ) token = "" if word is None else word[0] trigger = None items: List[CompletionItem] = [] if trigger is None: commands = self._api.search_command(token) items.extend( CompletionItem( x, CompletionItemKind.Function, documentation=self._api.get_command_doc(x), insert_text=x, ) for x in commands ) if trigger is None or trigger == "{": variables = self._api.search_variable(token) items.extend( CompletionItem( x, CompletionItemKind.Variable, documentation=self._api.get_variable_doc(x), insert_text=x, ) for x in variables ) if trigger is None: targets = self._api.search_target(token) items.extend( CompletionItem(x, CompletionItemKind.Class, insert_text=x) for x in targets ) if trigger == "(": func = self._cursor_function(params.textDocument.uri, params.position) if func is not None: func = func.lower() if func == "include": modules = self._api.search_module(token, False) items.extend( CompletionItem( x, CompletionItemKind.Module, documentation=self._api.get_module_doc(x, False), insert_text=x, ) for x in modules ) elif func == "find_package": modules = self._api.search_module(token, True) items.extend( CompletionItem( x, CompletionItemKind.Module, documentation=self._api.get_module_doc(x, True), insert_text=x, ) for x in modules ) return CompletionList(False, items)
def completions(ls, params: CompletionParams = None): print('start') ls.show_message('Validating ' + str(params.position.character)) if params.position.character < 3: print('end') return document = ls.workspace.get_document(params.textDocument.uri) lines = document.lines line = lines[params.position.line] idx = line.rfind('[ch', 0, params.position.character) #print(line) if idx == -1: print('end') return next_char = '' if params.position.character + 1 < len(line): next_char = line[params.position.character + 1] if next_char != ']': next_char = ']' else: next_char = '' in_list = False list_head = line[:idx] line = line[idx:params.position.character] list_bullet = list_head.replace(' ', '') list_stories = [] first_list_head = list_head insert_epic_after = -1 if list_bullet in ['*', '-']: in_list = True def extract_id(search_line: str): line = search_line[1:] # trim the bullet if not line.startswith('[ch'): return None line = line[3:] # Skip `[ch` idx = line.find(']') if idx == -1: return None line = line[:idx] try: return int(line) except: return None first_line = params.position.line search_line = lines[first_line].replace(' ', '') while first_line > 0 and search_line.startswith(list_bullet): first_line -= 1 search_line = lines[first_line].replace(' ', '') story_id = extract_id(search_line) if story_id != None: list_stories.append(story_id) first_line += 1 first_list_head = lines[first_line] idx = first_list_head.find('[') first_list_head = first_list_head[:idx] insert_epic_after = first_line last_line = params.position.line search_line = lines[last_line].replace(' ', '') while last_line + 1 < len(lines) and search_line.replace( ' ', '').startswith(list_bullet): last_line += 1 search_line = lines[last_line].replace(' ', '') story_id = extract_id(search_line) if story_id != None: list_stories.append(story_id) if line.find(']') != -1: print('end') return line = line[3:] print(line) items = [] prec = math.ceil(math.log10(max_story_position)) sort_str = '{}:0{}d{}'.format('{', prec, '}') ordering = 0 prefix = '{}'.format(line) try: id = int(line) except: prefix = '' comp_items = [] for item in all_stories: story = item['story'] if prefix != '': if not str(story['id']).startswith(prefix): continue tag = 'ch{}'.format(story["id"]) label = tag detail = tag + ': ' if item['is_namesake']: detail += 'Epic: ' detail += story["name"] cap = 94 sort_text = '' def sort_conf(is_higher_prio): if is_higher_prio: return '(' return '[' sort_text += sort_conf(item['main_workflow']) sort_text += sort_conf(item['in_progress']) sort_text += sort_conf(item['is_mine']) sort_text += sort_str.format(story['position']) insert_text = tag + next_char epic_insert = [] kind = 'enumMember' if in_list: insert_text += ' ' if item['is_namesake']: insert_text += 'Epic: ' kind = 'enum' insert_text += story['name'] + '\n' + list_head if story['epic_id'] is not None and not item['is_namesake']: namesake = epic_by_id[story['epic_id']]['namesake'] if namesake is not None and namesake['id'] not in list_stories: pos = Position(insert_epic_after, 0) epic_text = '{}[ch{}] Epic: {}\n'.format( first_list_head, namesake['id'], namesake['name']) epic_insert = [TextEdit(Range(pos, pos), epic_text)] if len(detail) > cap: detail = detail[:cap - 3] + '...' comp_items.append( CompletionItem(label=detail, sort_text=sort_text, insert_text=insert_text, additional_text_edits=epic_insert, kind=kind)) print('end') return CompletionList(False, comp_items)