def _HasCompletionsThatCouldBeCompletedWithMoreText( completed_item, completions ): if not completed_item: return False completed_word = ToUnicode( completed_item[ 'word' ] ) if not completed_word: return False # Sometimes CompleteDone is called after the next character is inserted. # If so, use inserted character to filter possible completions further. text = vimsupport.TextBeforeCursor() reject_exact_match = True if text and text[ -1 ] != completed_word[ -1 ]: reject_exact_match = False completed_word += text[ -1 ] for index, completion in enumerate( completions ): word = ToUnicode( _ConvertCompletionDataToVimData( index, completion )[ 'word' ] ) if reject_exact_match and word == completed_word: continue if word.startswith( completed_word ): return True return False
def EchoTextVimWidth(text): vim_width = GetIntValue("&columns") truncated_text = ToUnicode(text)[: int(vim_width * 0.9)] truncated_text.replace("\n", " ") old_ruler = GetIntValue("&ruler") old_showcmd = GetIntValue("&showcmd") vim.command("set noruler noshowcmd") vim.command("redraw") EchoText(truncated_text, False) SetVariableValue("&ruler", old_ruler) SetVariableValue("&showcmd", old_showcmd)
def EchoTextVimWidth( text ): vim_width = GetIntValue( '&columns' ) truncated_text = ToUnicode( text )[ : int( vim_width * 0.9 ) ] truncated_text.replace( '\n', ' ' ) old_ruler = GetIntValue( '&ruler' ) old_showcmd = GetIntValue( '&showcmd' ) vim.command( 'set noruler noshowcmd' ) vim.command( 'redraw' ) EchoText( truncated_text, False ) SetVariableValue( '&ruler', old_ruler ) SetVariableValue( '&showcmd', old_showcmd )
def PostVimMessage( message, warning = True, truncate = False ): """Display a message on the Vim status line. By default, the message is highlighted and logged to Vim command-line history (see :h history). Unset the |warning| parameter to disable this behavior. Set the |truncate| parameter to avoid hit-enter prompts (see :h hit-enter) when the message is longer than the window width.""" echo_command = 'echom' if warning else 'echo' # Displaying a new message while previous ones are still on the status line # might lead to a hit-enter prompt or the message appearing without a # newline so we do a redraw first. vim.command( 'redraw' ) if warning: vim.command( 'echohl WarningMsg' ) message = ToUnicode( message ) if truncate: vim_width = GetIntValue( '&columns' ) message = message.replace( '\n', ' ' ) if len( message ) > vim_width: message = message[ : vim_width - 4 ] + '...' old_ruler = GetIntValue( '&ruler' ) old_showcmd = GetIntValue( '&showcmd' ) vim.command( 'set noruler noshowcmd' ) vim.command( "{0} '{1}'".format( echo_command, EscapeForVim( message ) ) ) SetVariableValue( '&ruler', old_ruler ) SetVariableValue( '&showcmd', old_showcmd ) else: for line in message.split( '\n' ): vim.command( "{0} '{1}'".format( echo_command, EscapeForVim( line ) ) ) if warning: vim.command( 'echohl None' )
def Parse(data): """Reads the raw language server message payload into a Python dictionary""" return json.loads(ToUnicode(data))
def SetHmacHeader(body, hmac_secret): value = b64encode( hmac_utils.CreateHmac(ToBytes(body), ToBytes(hmac_secret))) response.set_header(_HMAC_HEADER, ToUnicode(value))
def PostMultiLineNotice(message): vim.command("redraw | echohl WarningMsg | echo '{0}' | echohl None".format( EscapeForVim(ToUnicode(message))))
def PostVimMessage(message): vim.command( "redraw | echohl WarningMsg | echom '{0}' | echohl None".format( EscapeForVim(ToUnicode(message))))
def _PrepareTrigger(trigger): trigger = ToUnicode(trigger) if trigger.startswith(TRIGGER_REGEX_PREFIX): return re.compile(trigger[len(TRIGGER_REGEX_PREFIX):], re.UNICODE) return re.compile(re.escape(trigger), re.UNICODE)
def FiletypesForBuffer( buffer_object ): # NOTE: Getting &ft for other buffers only works when the buffer has been # visited by the user at least once, which is true for modified buffers return ToUnicode( GetBufferOption( buffer_object, 'ft' ) ).split( '.' )
def _GetRustSysroot(rustc_exec): return ToUnicode( utils.SafePopen([rustc_exec, '--print', 'sysroot'], stdin_windows=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0].rstrip())
def GetBufferFiletypes(bufnr): command = f'getbufvar({ bufnr }, "&ft")' filetypes = vim.eval(command) if not filetypes: filetypes = 'ycm_nofiletype' return ToUnicode(filetypes).split('.')
def CurrentFiletypes(): filetypes = vim.eval("&filetype") if not filetypes: filetypes = 'ycm_nofiletype' return ToUnicode(filetypes).split('.')
def UsingPreviewPopup(): return 'popup' in ToUnicode(vim.options['completeopt']).split(',')
def _FormatRawComment( comment ): """Strips leading indentation and comment markers from the comment string""" return textwrap.dedent( '\n'.join( [ re.sub( STRIP_TRAILING_COMMENT, '', re.sub( STRIP_LEADING_COMMENT, '', line ) ) for line in ToUnicode( comment ).splitlines() ] ) )
def _PrepareTrigger( trigger ): trigger = ToUnicode( trigger ) if trigger.startswith( TRIGGER_REGEX_PREFIX ): return re.compile( trigger[ len( TRIGGER_REGEX_PREFIX ) : ], re.UNICODE ) return re.compile( re.escape( trigger ), re.UNICODE )
def GetLines(self): """Returns the contents of the buffer as a list of unicode strings.""" return [ToUnicode(x) for x in self.contents]
def matcher(key): return (ToUnicode(completed_item.get(key, "")) == ToUnicode( item.get(key, "")))
def SetResponseHeader(name, value): name = ToCppStringCompatible(name) if PY2 else ToUnicode(name) value = ToCppStringCompatible(value) if PY2 else ToUnicode(value) bottle.response.set_header(name, value)