ycm-core / YouCompleteMe

A code-completion engine for Vim

Home Page:http://ycm-core.github.io/YouCompleteMe/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add option to disable syntax highlighting in method signature

GergelyKalmar opened this issue · comments

Issue Prelude

Please complete these steps and check these boxes (by putting an x inside
the brackets) before filing your issue:

  • I have read and understood YCM's [CONTRIBUTING][cont] document.
  • I have read and understood YCM's [CODE_OF_CONDUCT][code] document.
  • I have read and understood YCM's [README][readme], especially the
    [Frequently Asked Questions][faq] section.
  • I have searched YCM's issue tracker to find issues similar to the one I'm
    about to report and couldn't find an answer to my problem. ([Example Google
    search.][search])
  • If filing a bug report, I have included the output of vim --version.
  • If filing a bug report, I have included the output of :YcmDebugInfo.
  • If filing a bug report, I have attached the contents of the logfiles using
    the :YcmToggleLogs command.
  • If filing a bug report, I have included which OS (including specific OS
    version) I am using.
  • If filing a bug report, I have included a minimal test case that reproduces
    my issue, using vim -Nu /path/to/YCM/vimrc_ycm_minimal, including what I
    expected to happen and what actually happened.
  • If filing a installation failure report, I have included the entire output
    of install.py (or cmake/make/ninja) including its invocation
  • I understand this is an open-source project staffed by volunteers and
    that any help I receive is a selfless, heartfelt gift of their free time. I
    know I am not entitled to anything and will be polite and courteous.
  • I understand my issue may be closed if it becomes obvious I didn't
    actually perform all of these steps.

Thank you for adhering to this process! It ensures your issue is resolved
quickly and that neither your nor our time is needlessly wasted.

Issue Details

Provide a clear description of the problem, including the following key
questions:

  • What did you do?

Enabled the signature pop-up.

  • What did you expect to happen?

Getting a clearly readable pop-up with the function's signature.

  • What actually happened?

Parts of the pop-up were unreadable because the background color was the same as the foreground color (same issue as in #3926).

There seems to be two options to resolve this problem:

  1. Setting the pop-up background color to be a similar color to my actual (black) background. This would ensure that syntax-highlighted text stays readable, but has the downside that the pop-up is not contrasting anymore, not "popping" out from the background.
  2. Disabling the syntax highlighting inside the signature popup, so it uses the default popup background and foreground colors. This way it does not matter what colorscheme the user users, the signature remains perfectly readable. (The user can still re-configure the inversion if they want via the YCMInverse highlight group.)

Option 1 is not really desireable (but already possible), and option 2 does not seem to be possible at the moment (as far as I could tell).

Please can you provide steps to reproduce, as requested in the issue template and CONTRIBUTING.md ?

The reason I ask for this is that this is of course dependent on your colour scheme and may be dependent on your terminal setup. I have never had this problem personally, so it's important to root cause before "adding a spacebar heating option"

I agree that it might be somewhat difficult to reproduce, because it may also depend on the terminal scheme.

I'm using GNOME Terminal 3.36.2 with the Green on black scheme and the Tango palette. Colorscheme for vim is elflord. I'm also using https://github.com/vim-python/python-syntax with the following settings:

let g:python_highlight_builtins = 1
let g:python_highlight_builtin_funcs_kwarg = 0
let g:python_highlight_exceptions = 1
let g:python_highlight_string_formatting = 1
let g:python_highlight_string_format = 1
let g:python_highlight_string_templates = 1
let g:python_highlight_file_headers_as_comments = 1

To reproduce the issue create a Python file as follows:

def x(a: str, b: Optional[str] = None):
    pass

x(

Note that when you type x( and the signature pop-up appears, it looks like this:

image

Note that the "None" text is invisible because the highlight color for built-ins happens to be the same as the menu pop-up color. The word "def" and the white function name don't really contrast with the light pop-up background either. This issue can happen basically anytime, as the linked issue also shows.

Syntax highlighting in small text fragments like the method signature does not really help readability for me in general, so I think it is a reasonable ask to provide a way to disable it. It also resolves the issue mentioned in the linked issue.

Can you try this patch:

diff --git a/python/ycm/signature_help.py b/python/ycm/signature_help.py
index 35ced789..22ba1d5c 100644
--- a/python/ycm/signature_help.py
+++ b/python/ycm/signature_help.py
@@ -189,7 +189,11 @@ def UpdateSignatureHelp( state, signature_info ): # noqa
   if state.state == SignatureHelpState.ACTIVE:
     vim.eval( f'popup_show( { state.popup_win_id } )' )
 
-  syntax = utils.ToUnicode( vim.current.buffer.options[ 'syntax' ] )
+  if vim.vars.get( 'ycm_signature_help_disable_syntax', False ):
+    syntax = ''
+  else:
+    syntax = utils.ToUnicode( vim.current.buffer.options[ 'syntax' ] )
+
   active_signature = int( signature_info.get( 'activeSignature', 0 ) )
   vim.eval( f"win_execute( { state.popup_win_id }, "
             f"'set syntax={ syntax } cursorline | "

Then let g:ycm_signature_help_disable_syntax=1 ?

Yes, this worked perfectly! Thank you.

I also noticed something else: there seems to be a space between the brackets and the arguments in the method signature, that looks odd. Is that on purpose? I see that YCM also uses this style in its Python source, which might be due to historical reasons, however, these days it's not really standard (see https://peps.python.org/pep-0008/#whitespace-in-expressions-and-statements). I understand that this might affect the pop-up for other languages too, but nonetheless, the current format is quite rare in any language as far as I know.

Any chance to merge the patch, perhaps with fixing the spaces in brackets?

Awesome, thank you very much for the help with this one!