Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

showcmd option triggers error in directory completion when directory contains file with certain non-ascii characters #2088

Closed
mcaceresb opened this issue Mar 30, 2016 · 5 comments · Fixed by ycm-core/ycmd#455

Comments

@mcaceresb
Copy link

I have the following vimrc

filetype off
set nocompatible
set runtimepath+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'gmarik/Vundle.vim'
Plugin 'Valloric/YouCompleteMe',    {'name' : 'YouCompleteMe'}
call vundle#end()
filetype plugin indent on
syntax enable

set showcmd

let g:ycm_complete_in_strings = 1
let g:ycm_collect_identifiers_from_comments_and_strings = 1
let g:ycm_autoclose_preview_window_after_completion = 1
let g:ycm_filetype_blacklist = {}
let g:ycm_server_keep_logfiles = 1
let g:ycm_server_log_level = 'debug'

I have a directory with a wile named "⌘ rest of file name" and the following text file

This directory contains ./

When I type anything after ./, I get the following

UnicodeEncodeError: 'ascii' codec can't encode character u'\u2318' in position 0: ordinal not in range(128)

If I do :set noshowcmd then I can type normally (though completion for the directory does not work; of course completion still works elsewhere). Ideally completion would work but it would ignore the problematic file name. Second best would be no error message. I also have no idea why this is related to the showcmd option. My system info and vim version:

$ uname -srvmo
Linux 4.4.5-1-ARCH #1 SMP PREEMPT Thu Mar 10 07:38:19 CET 2016 x86_64 GNU/Linux

$ vim --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Mar 23 2016 11:41:09)
Included patches: 1-1639
Compiled by Arch Linux
Huge version with GTK2 GUI.  Features included (+) or not (-):
+acl             +farsi           +mouse_netterm   +tag_binary
+arabic          +file_in_path    +mouse_sgr       +tag_old_static
+autocmd         +find_in_path    -mouse_sysmouse  -tag_any_white
+balloon_eval    +float           +mouse_urxvt     +tcl/dyn
+browse          +folding         +mouse_xterm     +terminfo
++builtin_terms  -footer          +multi_byte      +termresponse
+byte_offset     +fork()          +multi_lang      +textobjects
+channel         +gettext         -mzscheme        +timers
+cindent         -hangul_input    +netbeans_intg   +title
+clientserver    +iconv           +packages        +toolbar
+clipboard       +insert_expand   +path_extra      +user_commands
+cmdline_compl   +job             +perl/dyn        +vertsplit
+cmdline_hist    +jumplist        +persistent_undo +virtualedit
+cmdline_info    +keymap          +postscript      +visual
+comments        +langmap         +printer         +visualextra
+conceal         +libcall         +profile         +viminfo
+cryptv          +linebreak       +python/dyn      +vreplace
+cscope          +lispindent      +python3/dyn     +wildignore
+cursorbind      +listcmds        +quickfix        +wildmenu
+cursorshape     +localmap        +reltime         +windows
+dialog_con_gui  +lua/dyn         +rightleft       +writebackup
+diff            +menu            +ruby/dyn        +X11
+digraphs        +mksession       +scrollbind      -xfontset
+dnd             +modify_fname    +signs           +xim
-ebcdic          +mouse           +smartindent     +xsmp_interact
+emacs_tags      +mouseshape      +startuptime     +xterm_clipboard
+eval            +mouse_dec       +statusline      -xterm_save
+ex_extra        +mouse_gpm       -sun_workshop    -xpm
+extra_search    -mouse_jsbterm   +syntax          
   system vimrc file: "/etc/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "/etc/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
    system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK  -pthread -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/libdrm -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng16 -I/usr/include/pango-1.0 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/harfbuzz -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -D_FORTIFY_SOURCE=2  -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1      
Linking: gcc   -L. -Wl,-O1,--sort-common,--as-needed,-z,relro -fstack-protector -rdynamic -Wl,-export-dynamic -Wl,-E -Wl,-rpath,/usr/lib/perl5/core_perl/CORE  -Wl,-O1,--sort-common,--as-needed,-z,relro -L/usr/local/lib -Wl,--as-needed -o vim   -lgtk-x11-2.0 -lgdk-x11-2.0 -lpangocairo-1.0 -latk-1.0 -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lpangoft2-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lfontconfig -lfreetype -lSM -lICE -lXt -lX11 -lXdmcp -lSM -lICE  -lm -lncurses -lelf -lnsl    -lacl -lattr -lgpm -ldl   -Wl,-E -Wl,-rpath,/usr/lib/perl5/core_perl/CORE -Wl,-O1,--sort-common,--as-needed,-z,relro -fstack-protector-strong -L/usr/local/lib  -L/usr/lib/perl5/core_perl/CORE -lperl -lpthread -lnsl -ldl -lm -lcrypt -lutil -lc   -L/usr/lib -ltclstub8.6 -ldl -lz -lpthread -lieee -lm 

The following was output by :YcmToggleLogs stderr

2016-03-30 00:53:28,257 - DEBUG - No global extra conf, not calling method YcmCorePreload
2016-03-30 00:53:28,664 - INFO - Received event notification
2016-03-30 00:53:28,665 - DEBUG - Event name: BufferVisit
2016-03-30 00:53:28,665 - ERROR - No semantic completer exists for filetypes: ['text']
Traceback (most recent call last):
  File "/home/mauricio/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../ycmd/server_state.py", line 94, in FiletypeCompletionAvailable
    self.GetFiletypeCompleter( filetypes )
  File "/home/mauricio/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../ycmd/server_state.py", line 89, in GetFiletypeCompleter
    current_filetypes ) )
ValueError: No semantic completer exists for filetypes: ['text']
2016-03-30 00:53:28,667 - INFO - Received event notification
2016-03-30 00:53:28,668 - DEBUG - Event name: FileReadyToParse
2016-03-30 00:53:28,668 - INFO - Adding buffer identifiers for file: /home/mauricio/Downloads/tmp.txt
2016-03-30 00:53:28,669 - ERROR - No semantic completer exists for filetypes: ['text']
Traceback (most recent call last):
  File "/home/mauricio/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../ycmd/server_state.py", line 94, in FiletypeCompletionAvailable
    self.GetFiletypeCompleter( filetypes )
  File "/home/mauricio/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../ycmd/server_state.py", line 89, in GetFiletypeCompleter
    current_filetypes ) )
ValueError: No semantic completer exists for filetypes: ['text']
2016-03-30 00:53:28,933 - INFO - Received health request
2016-03-30 00:53:28,936 - INFO - Received filetype completion available request
2016-03-30 00:53:28,936 - ERROR - No semantic completer exists for filetypes: ['text']
Traceback (most recent call last):
  File "/home/mauricio/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../ycmd/server_state.py", line 94, in FiletypeCompletionAvailable
    self.GetFiletypeCompleter( filetypes )
  File "/home/mauricio/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../ycmd/server_state.py", line 89, in GetFiletypeCompleter
    current_filetypes ) )
ValueError: No semantic completer exists for filetypes: ['text']
2016-03-30 00:53:29,731 - INFO - Received completion request
2016-03-30 00:53:29,732 - ERROR - No semantic completer exists for filetypes: ['text']
Traceback (most recent call last):
  File "/home/mauricio/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../ycmd/server_state.py", line 94, in FiletypeCompletionAvailable
    self.GetFiletypeCompleter( filetypes )
  File "/home/mauricio/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../ycmd/server_state.py", line 89, in GetFiletypeCompleter
    current_filetypes ) )
ValueError: No semantic completer exists for filetypes: ['text']
2016-03-30 00:53:29,732 - DEBUG - Using filetype completion: False
Traceback (most recent call last):
  File "/home/mauricio/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/bottle/bottle.py", line 861, in _handle
    return route.call(**args)
  File "/home/mauricio/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/bottle/bottle.py", line 1734, in wrapper
    rv = callback(*a, **ka)
  File "/home/mauricio/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../ycmd/watchdog_plugin.py", line 106, in wrapper
    return callback( *args, **kwargs )
  File "/home/mauricio/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../ycmd/hmac_plugin.py", line 72, in wrapper
    body = callback( *args, **kwargs )
  File "/home/mauricio/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../ycmd/handlers.py", line 129, in GetCompletions
    .ComputeCandidates( request_data ) )
  File "/home/mauricio/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../ycmd/completers/general/general_completer_store.py", line 89, in ComputeCandidates
    candidates += completer.ComputeCandidates( request_data )
  File "/home/mauricio/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../ycmd/completers/completer.py", line 172, in ComputeCandidates
    request_data[ 'query' ] )
  File "/home/mauricio/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../ycmd/completers/completer.py", line 245, in FilterAndSortCandidates
    return self.FilterAndSortCandidatesInner( candidates, sort_property, query )
  File "/home/mauricio/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../ycmd/completers/completer.py", line 250, in FilterAndSortCandidatesInner
    candidates, sort_property, query )
  File "/home/mauricio/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../ycmd/completers/completer_utils.py", line 160, in FilterAndSortCandidatesWrap
    ToCppStringCompatible( query ) )
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2318' in position 0: ordinal not in range(128)
2016-03-30 00:53:30,118 - INFO - Received event notification
2016-03-30 00:53:30,118 - DEBUG - Event name: FileReadyToParse
2016-03-30 00:53:30,118 - INFO - Adding buffer identifiers for file: /home/mauricio/Downloads/tmp.txt
2016-03-30 00:53:30,119 - ERROR - No semantic completer exists for filetypes: ['text']
Traceback (most recent call last):
  File "/home/mauricio/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../ycmd/server_state.py", line 94, in FiletypeCompletionAvailable
    self.GetFiletypeCompleter( filetypes )
  File "/home/mauricio/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../ycmd/server_state.py", line 89, in GetFiletypeCompleter
    current_filetypes ) )
ValueError: No semantic completer exists for filetypes: ['text']
2016-03-30 00:53:30,120 - INFO - Received event notification
2016-03-30 00:53:30,120 - DEBUG - Event name: InsertLeave
2016-03-30 00:53:30,120 - INFO - Adding ONE buffer identifier for file: /home/mauricio/Downloads/tmp.txt
2016-03-30 00:53:30,121 - ERROR - No semantic completer exists for filetypes: ['text']
Traceback (most recent call last):
  File "/home/mauricio/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../ycmd/server_state.py", line 94, in FiletypeCompletionAvailable
    self.GetFiletypeCompleter( filetypes )
  File "/home/mauricio/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../ycmd/server_state.py", line 89, in GetFiletypeCompleter
    current_filetypes ) )
ValueError: No semantic completer exists for filetypes: ['text']
2016-03-30 00:53:32,432 - INFO - Received debug info request
2016-03-30 00:53:32,433 - DEBUG - Exception in debug info request: Traceback (most recent call last):
  File "/home/mauricio/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../ycmd/handlers.py", line 228, in DebugInfo
    _GetCompleterForRequestData( request_data ).DebugInfo( request_data) )
  File "/home/mauricio/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../ycmd/handlers.py", line 265, in _GetCompleterForRequestData
    return _server_state.GetFiletypeCompleter( request_data[ 'filetypes' ] )
  File "/home/mauricio/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../ycmd/server_state.py", line 89, in GetFiletypeCompleter
    current_filetypes ) )
ValueError: No semantic completer exists for filetypes: ['text']

The following files were pointed to me by :YcmDebugInfo

Printing YouCompleteMe debug information...
-- Server has Clang support compiled in: True
-- Clang version: clang version 3.7.0 (tags/RELEASE_370/final)
-- Server running at: http://127.0.0.1:40572
-- Server process ID: 11459
-- Server logfiles
--   /tmp/ycm_temp/server_40572_stderr.log
--   /tmp/ycm_temp/server_40572_stdout.log

stdout was blank. stderr is above. Cheers!

@puremourning
Copy link
Member

We are working on a fix for this.

@puremourning
Copy link
Member

@mcaceresb It would be real;ly useful if you could checkout my YouCompleteMe and ycmd branches which I hope resolve this (and a number of other) unicode issues:

Feedback on whether or not it resolves your particular issue will speed up getting it PR'd :)

Thanks!

@mcaceresb
Copy link
Author

@puremourning This appears to fix it. The behavior now is that it lists the file with no errors raised (though it drops it after I type anything else, but I expected that). Thanks!

@puremourning
Copy link
Member

Excellent :)

@Valloric
Copy link
Member

Valloric commented Apr 7, 2016

@puremourning's all like:

:D

homu added a commit to ycm-core/ycmd that referenced this issue Apr 24, 2016
[READY] Fix issues with multi-byte characters

## Summary

This change introduces more general support for non-ASCII characters in buffers handled by YCMD.

In ycmd's public API, all offsets are byte offsets into the UTF-8 encoded buffers. We also assume (because, we have no other choice) that files stored on disk are also UTF-8 encoded. Internally, almost all of ycmd's functionality operates on unicode strings (python 2 `unicode()` and python 3 `str()` objects, transparently via `future`). Many of the downstream completion engines expect unicode code points as the offsets in their APIs. One special case is the `ycm_core` library (identifier completer and clang completer), which requires instances of the _native_ `str` type. All strings used within the c++ using `boost::python` require passing through `ToCppStringCompatible`

Previously, we were largely just assuming that `code point == byte offset` - i.e. all buffers contained only ASCII characters. This worked up to a point, but more by luck than judgement in a number of places.

## References

In combination with a YCM change and PR #453, I hope this:

- fixes #109
- fixes ycm-core/YouCompleteMe#2096
- fixes ycm-core/YouCompleteMe#2088
- fixes ycm-core/YouCompleteMe#2069
- fixes ycm-core/YouCompleteMe#2066
- fixes ycm-core/YouCompleteMe#1378

## Overview of changes

The changes fall into the following areas:

- Providing access to and conversion to/from code points and byte offsets (`request_wrap.py`)
- Changing certain algorithms/features to work entirely in codepoint space when they are trying to operate on logical 'characters' within the buffer (see known issues for why this isn't perfect, but probably most of the way there)
- Changing the completers to convert between the external (on both sides) and internal representations by using the shortcuts provided in `request_wrap.py`
- Adding tests for each of the completers for both completions and subcommands

## Completer-specific notes

Pretty much all of the completers I tested required some changes:
- clang uses utf-8 and byte offsets, but had some bugs with the `GetDoc` parsing stuff
- OmniSharp speaks codepoint offsets
- Tern speaks codepoint offsets
- JediHTTP speaks codepoint offsets
- tsserver speaks codepoint offsets
- gocode speaks byte offsets
- racer i did not test

## Further work / Known issues

- we act blissfully ignorant of the case where a unicode character consumes multiple code points (such as where there is a modifier after the code point)
- when typing a unicode character, we still get an exception from `bitset` (see #453 for that fix)
- the filtering and sorting system is 100% designed for ASCII only, and it is not in the scope of this PR to change that. Currently after any filtering operation, words containing non-ASCII characters are excluded.
- I did not get round to testing rust using racer
- there are further changes required to YouCompleteMe client (a further PR is coming for that)

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/ycmd/455)
<!-- Reviewable:end -->
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants