abingham / emacs-ycmd

Emacs client for ycmd, the code completion system.
MIT License
384 stars 46 forks source link

YCMD right complete candidates after 5 chars #483

Closed linuzlover closed 5 years ago

linuzlover commented 5 years ago

Hi,

I am using company-ycmd 20180520.1053 with ycmd server commit 522bf1c83e40978f36f5704bf31b70b2d835fa99. I noticed a strange behavior on completion when I try to complete a member function using just a few characters. In particular:

Emacs 26.1 (x86_64-pc-linux-gnu) of 2018-05-29 on lgw01-amd64-038
Company 0.9.6

company-backends: (company-ycmd company-bbdb company-eclim company-clang company-xcode company-cmake company-capf company-files
              (company-dabbrev-code company-gtags company-etags company-keywords)
              company-oddmuse company-dabbrev)

Used backend: company-ycmd
Major mode: c++-mode
Prefix: ("" . t)

Completions:
  #("char" 0 4 (params nil doc nil kind nil meta " char" return_type "")) ""
  #("const" 0 5 (params nil doc nil kind nil meta " const" return_type "")) ""
  #("double" 0 6 (params nil doc nil kind nil meta " double" return_type "")) ""
  #("enum" 0 4 (params nil doc nil kind nil meta " enum" return_type "")) ""
  #("extern" 0 6 (params nil doc nil kind nil meta " extern" return_type "")) ""
  #("float" 0 5 (params nil doc nil kind nil meta " float" return_type "")) ""
  #("inline" 0 6 (params nil doc nil kind nil meta " inline" return_type "")) ""
  #("int" 0 3 (params nil doc nil kind nil meta " int" return_type "")) ""
  #("obfuscated_EXPORTS" 0 20 (params nil doc nil kind "macro" meta " obfuscated_EXPORTS" return_type "")) " [macro]"
  #("linux" 0 5 (params nil doc nil kind "macro" meta " linux" return_type "")) " [macro]"
  #("long" 0 4 (params nil doc nil kind nil meta " long" return_type "")) ""
  #("restrict" 0 8 (params nil doc nil kind nil meta " restrict" return_type "")) ""
  #("short" 0 5 (params nil doc nil kind nil meta " short" return_type "")) ""
  #("signed" 0 6 (params nil doc nil kind nil meta " signed" return_type "")) ""
  #("static" 0 6 (params nil doc nil kind nil meta " static" return_type "")) ""
  #("struct" 0 6 (params nil doc nil kind nil meta " struct" return_type "")) ""
  #("typedef " 0 8 (params nil doc nil kind nil meta " typedef type name" return_type "")) ""
  #("typeof" 0 6 (params nil doc nil kind nil meta " typeof( type )" return_type "")) ""
  #("typeof " 0 7 (params nil doc nil kind nil meta " typeof expression" return_type "")) ""
  #("union" 0 5 (params nil doc nil kind nil meta " union" return_type "")) ""
  #("unix" 0 4 (params nil doc nil kind "macro" meta " unix" return_type "")) " [macro]"
  #("unsigned" 0 8 (params nil doc nil kind nil meta " unsigned" return_type "")) ""
  #("void" 0 4 (params nil doc nil kind nil meta " void" return_type "")) ""
  #("volatile" 0 8 (params nil doc nil kind nil meta " volatile" return_type "")) ""
  #("__amd64" 0 7 (params nil doc nil kind "macro" meta " __amd64" return_type "")) " [macro]"
  #("__amd64__" 0 9 (params nil doc nil kind "macro" meta " __amd64__" return_type "")) " [macro]"
  #("__auto_type" 0 11 (params nil doc nil kind nil meta " __auto_type" return_type "")) ""
  #("__building_module" 0 17 (params nil doc nil kind "macro" meta " __building_module" return_type "")) " [macro]"
  #("__clang_major__" 0 15 (params nil doc nil kind "macro" meta " __clang_major__" return_type "")) " [macro]"
  #("__clang_minor__" 0 15 (params nil doc nil kind "macro" meta " __clang_minor__" return_type "")) " [macro]"
  #("__clang_patchlevel__" 0 20 (params nil doc nil kind "macro" meta " __clang_patchlevel__" return_type "")) " [macro]"
  #("__clang_version__" 0 17 (params nil doc nil kind "macro" meta " __clang_version__" return_type "")) " [macro]"
  #("__clang__" 0 9 (params nil doc nil kind "macro" meta " __clang__" return_type "")) " [macro]"
  #("__gnu_linux__" 0 13 (params nil doc nil kind "macro" meta " __gnu_linux__" return_type "")) " [macro]"
  #("__has_attribute" 0 15 (params nil doc nil kind "macro" meta " __has_attribute" return_type "")) " [macro]"
  #("__has_builtin" 0 13 (params nil doc nil kind "macro" meta " __has_builtin" return_type "")) " [macro]"
  #("__has_c_attribute" 0 17 (params nil doc nil kind "macro" meta " __has_c_attribute" return_type "")) " [macro]"
  #("__has_declspec_attribute" 0 24 (params nil doc nil kind "macro" meta " __has_declspec_attribute" return_type "")) " [macro]"
  #("__has_extension" 0 15 (params nil doc nil kind "macro" meta " __has_extension" return_type "")) " [macro]"
  #("__has_feature" 0 13 (params nil doc nil kind "macro" meta " __has_feature" return_type "")) " [macro]"
  #("__has_include" 0 13 (params nil doc nil kind "macro" meta " __has_include" return_type "")) " [macro]"
  #("__has_include_next" 0 18 (params nil doc nil kind "macro" meta " __has_include_next" return_type "")) " [macro]"
  #("__has_warning" 0 13 (params nil doc nil kind "macro" meta " __has_warning" return_type "")) " [macro]"
  #("__is_identifier" 0 15 (params nil doc nil kind "macro" meta " __is_identifier" return_type "")) " [macro]"
  #("__is_target_arch" 0 16 (params nil doc nil kind "macro" meta " __is_target_arch" return_type "")) " [macro]"
  #("__is_target_environment" 0 23 (params nil doc nil kind "macro" meta " __is_target_environment" return_type "")) " [macro]"
  #("__is_target_os" 0 14 (params nil doc nil kind "macro" meta " __is_target_os" return_type "")) " [macro]"
  #("__is_target_vendor" 0 18 (params nil doc nil kind "macro" meta " __is_target_vendor" return_type "")) " [macro]"
  #("__k8" 0 4 (params nil doc nil kind "macro" meta " __k8" return_type "")) " [macro]"
  #("__k8__" 0 6 (params nil doc nil kind "macro" meta " __k8__" return_type "")) " [macro]"

However, if i try to complete after inserting exactly 5 chars, I get the right member functions:

Emacs 26.1 (x86_64-pc-linux-gnu) of 2018-05-29 on lgw01-amd64-038
Company 0.9.6

company-backends: (company-ycmd company-bbdb company-eclim company-clang company-xcode company-cmake company-capf company-files
              (company-dabbrev-code company-gtags company-etags company-keywords)
              company-oddmuse company-dabbrev)

Used backend: company-ycmd
Major mode: c++-mode
Prefix: (#("initi" 0 1
   (fontified t ws-butler-chg chg)
   1 2
   (fontified t ws-butler-chg chg)
   2 3
   (fontified t ws-butler-chg chg)
   3 4
   (fontified t ws-butler-chg chg)
   4 5
   (fontified t ws-butler-chg chg))
 . t)

Completions:
  #("initializeAndEnableTools" 0 24 (return_type "[ID]")) " -> [ID]"
  #("initialize" 0 10 (return_type "[ID]")) " -> [ID]"
  #("portHandleInitialize" 0 20 (return_type "[ID]")) " -> [ID]"

Is there any way to obtain the right candidates using less than 5 chars?

Thanks

AP

Edit:

I forgot to attach the init.el portion where company-ycmd is initialized:

(use-package yasnippet
  :ensure t
  :diminish yas-minor-mode
  :init (yas-global-mode t))

(require 'validate)

;; Code-comprehension server
(use-package ycmd
  :ensure t
  :init (add-hook 'c++-mode-hook #'ycmd-mode)
  :config
  (set-variable 'ycmd-server-command '("python3" "/home/attilio/Workspace/ycmd/ycmd"))
  )

(use-package company-ycmd
  :ensure t
  :init (company-ycmd-setup)
  )

(require 'ycmd-eldoc)
(add-hook 'ycmd-mode-hook 'ycmd-eldoc-setup)

(setq-local company-backends (remove 'company-semantic company-backends))

(define-key c-mode-map [(tab)] 'company-complete)
(define-key c++-mode-map [(tab)] 'company-complete)

It is based on https://onze.io/emacs/c++/2017/03/16/emacs-cpp.html

abingham commented 5 years ago

What kind of activity do you see in the *ycmd-server* buffer when you get completions on only a few characters? How does it differ (if at all) from when you're getting the expected results?

linuzlover commented 5 years ago

Here is the output in both cases.

First case (completion after "->" symbol)

2018-10-10 12:56:57,866 - DEBUG - No global extra conf, not calling method YcmCorePreload
serving on http://localhost:44079
2018-10-10 12:56:57,916 - INFO - Received event notification
2018-10-10 12:56:57,917 - DEBUG - Event name: BufferVisit
2018-10-10 12:56:57,956 - INFO - Received event notification
2018-10-10 12:56:57,956 - DEBUG - Event name: FileReadyToParse
2018-10-10 12:56:57,956 - INFO - Adding buffer identifiers for file: /home/attilio/projects/***/src/EnhancedTracker.cpp
Traceback (most recent call last):
  File "/home/attilio/Workspace/ycmd/third_party/bottle/bottle.py", line 862, in _handle
    return route.call(**args)
  File "/home/attilio/Workspace/ycmd/third_party/bottle/bottle.py", line 1740, in wrapper
    rv = callback(*a, **ka)
  File "/home/attilio/Workspace/ycmd/ycmd/../ycmd/watchdog_plugin.py", line 107, in wrapper
    return callback( *args, **kwargs )
  File "/home/attilio/Workspace/ycmd/ycmd/../ycmd/hmac_plugin.py", line 70, in wrapper
    body = callback( *args, **kwargs )
  File "/home/attilio/Workspace/ycmd/ycmd/../ycmd/handlers.py", line 70, in EventNotification
    event_handler )( request_data )
  File "/home/attilio/Workspace/ycmd/ycmd/../ycmd/completers/cpp/clang_completer.py", line 381, in OnFileReadyToParse
    flags, filename = self._FlagsForRequest( request_data )
  File "/home/attilio/Workspace/ycmd/ycmd/../ycmd/completers/cpp/clang_completer.py", line 480, in _FlagsForRequest
    return self._flags.FlagsForFile( filename, client_data = client_data )
  File "/home/attilio/Workspace/ycmd/ycmd/../ycmd/completers/cpp/flags.py", line 131, in FlagsForFile
    results = self._GetFlagsFromExtraConfOrDatabase( filename, client_data )
  File "/home/attilio/Workspace/ycmd/ycmd/../ycmd/completers/cpp/flags.py", line 170, in _GetFlagsFromExtraConfOrDatabase
    module = extra_conf_store.ModuleForSourceFile( filename )
  File "/home/attilio/Workspace/ycmd/ycmd/../ycmd/extra_conf_store.py", line 66, in ModuleForSourceFile
    return Load( ModuleFileForSourceFile( filename ) )
  File "/home/attilio/Workspace/ycmd/ycmd/../ycmd/extra_conf_store.py", line 77, in ModuleFileForSourceFile
    if Load( module_file ):
  File "/home/attilio/Workspace/ycmd/ycmd/../ycmd/extra_conf_store.py", line 163, in Load
    if not force and not _ShouldLoad( module_file, is_global ):
  File "/home/attilio/Workspace/ycmd/ycmd/../ycmd/extra_conf_store.py", line 146, in _ShouldLoad
    raise UnknownExtraConf( module_file )
ycmd.responses.UnknownExtraConf: Found /home/attilio/projects/***/.ycm_extra_conf.py. Load? 

(Question can be turned off with options, see YCM docs)
2018-10-10 12:57:03,806 - INFO - Received extra conf load request
2018-10-10 12:57:03,857 - INFO - Received event notification
2018-10-10 12:57:03,858 - DEBUG - Event name: FileReadyToParse
2018-10-10 12:57:03,858 - INFO - Adding buffer identifiers for file: /home/attilio/projects/***/src/EnhancedTracker.cpp
2018-10-10 12:57:08,113 - INFO - Received filetype completion available request
2018-10-10 12:57:08,180 - INFO - Received defined subcommands request
2018-10-10 12:57:08,218 - INFO - Received command request
2018-10-10 12:57:09,995 - INFO - Received command request
2018-10-10 12:57:15,818 - INFO - Received event notification
2018-10-10 12:57:15,819 - DEBUG - Event name: FileReadyToParse
2018-10-10 12:57:15,819 - INFO - Adding buffer identifiers for file: /home/attilio/projects/***/src/EnhancedTracker.cpp
2018-10-10 12:57:15,914 - INFO - Received event notification
2018-10-10 12:57:15,914 - DEBUG - Event name: FileReadyToParse
2018-10-10 12:57:15,915 - INFO - Adding buffer identifiers for file: /home/attilio/projects/***src/EnhancedTracker.cpp
2018-10-10 12:57:16,649 - INFO - Received command request
2018-10-10 12:57:19,419 - INFO - Received completion request
2018-10-10 12:57:19,420 - DEBUG - Using filetype completion: True
2018-10-10 12:57:24,660 - INFO - Received command request

Second case (right behavior), completion after ->check (method name is chechAllToolsVisible()

2018-10-10 12:56:57,866 - DEBUG - No global extra conf, not calling method YcmCorePreload
serving on http://localhost:44079
2018-10-10 12:56:57,916 - INFO - Received event notification
2018-10-10 12:56:57,917 - DEBUG - Event name: BufferVisit
2018-10-10 12:56:57,956 - INFO - Received event notification
2018-10-10 12:56:57,956 - DEBUG - Event name: FileReadyToParse
2018-10-10 12:56:57,956 - INFO - Adding buffer identifiers for file: /home/attilio/projects/***/src/EnhancedTracker.cpp
Traceback (most recent call last):
  File "/home/attilio/Workspace/ycmd/third_party/bottle/bottle.py", line 862, in _handle
    return route.call(**args)
  File "/home/attilio/Workspace/ycmd/third_party/bottle/bottle.py", line 1740, in wrapper
    rv = callback(*a, **ka)
  File "/home/attilio/Workspace/ycmd/ycmd/../ycmd/watchdog_plugin.py", line 107, in wrapper
    return callback( *args, **kwargs )
  File "/home/attilio/Workspace/ycmd/ycmd/../ycmd/hmac_plugin.py", line 70, in wrapper
    body = callback( *args, **kwargs )
  File "/home/attilio/Workspace/ycmd/ycmd/../ycmd/handlers.py", line 70, in EventNotification
    event_handler )( request_data )
  File "/home/attilio/Workspace/ycmd/ycmd/../ycmd/completers/cpp/clang_completer.py", line 381, in OnFileReadyToParse
    flags, filename = self._FlagsForRequest( request_data )
  File "/home/attilio/Workspace/ycmd/ycmd/../ycmd/completers/cpp/clang_completer.py", line 480, in _FlagsForRequest
    return self._flags.FlagsForFile( filename, client_data = client_data )
  File "/home/attilio/Workspace/ycmd/ycmd/../ycmd/completers/cpp/flags.py", line 131, in FlagsForFile
    results = self._GetFlagsFromExtraConfOrDatabase( filename, client_data )
  File "/home/attilio/Workspace/ycmd/ycmd/../ycmd/completers/cpp/flags.py", line 170, in _GetFlagsFromExtraConfOrDatabase
    module = extra_conf_store.ModuleForSourceFile( filename )
  File "/home/attilio/Workspace/ycmd/ycmd/../ycmd/extra_conf_store.py", line 66, in ModuleForSourceFile
    return Load( ModuleFileForSourceFile( filename ) )
  File "/home/attilio/Workspace/ycmd/ycmd/../ycmd/extra_conf_store.py", line 77, in ModuleFileForSourceFile
    if Load( module_file ):
  File "/home/attilio/Workspace/ycmd/ycmd/../ycmd/extra_conf_store.py", line 163, in Load
    if not force and not _ShouldLoad( module_file, is_global ):
  File "/home/attilio/Workspace/ycmd/ycmd/../ycmd/extra_conf_store.py", line 146, in _ShouldLoad
    raise UnknownExtraConf( module_file )
ycmd.responses.UnknownExtraConf: Found /home/attilio/projects/***/.ycm_extra_conf.py. Load? 

(Question can be turned off with options, see YCM docs)
2018-10-10 12:57:03,806 - INFO - Received extra conf load request
2018-10-10 12:57:03,857 - INFO - Received event notification
2018-10-10 12:57:03,858 - DEBUG - Event name: FileReadyToParse
2018-10-10 12:57:03,858 - INFO - Adding buffer identifiers for file: /home/attilio/projects/***/src/EnhancedTracker.cpp
2018-10-10 12:57:08,113 - INFO - Received filetype completion available request
2018-10-10 12:57:08,180 - INFO - Received defined subcommands request
2018-10-10 12:57:08,218 - INFO - Received command request
2018-10-10 12:57:09,995 - INFO - Received command request
2018-10-10 12:57:15,818 - INFO - Received event notification
2018-10-10 12:57:15,819 - DEBUG - Event name: FileReadyToParse
2018-10-10 12:57:15,819 - INFO - Adding buffer identifiers for file: /home/attilio/projects/***/src/EnhancedTracker.cpp
2018-10-10 12:57:15,914 - INFO - Received event notification
2018-10-10 12:57:15,914 - DEBUG - Event name: FileReadyToParse
2018-10-10 12:57:15,915 - INFO - Adding buffer identifiers for file: /home/attilio/projects/***/src/EnhancedTracker.cpp
2018-10-10 12:57:16,649 - INFO - Received command request
2018-10-10 12:57:19,419 - INFO - Received completion request
2018-10-10 12:57:19,420 - DEBUG - Using filetype completion: True
2018-10-10 12:57:24,660 - INFO - Received command request
2018-10-10 12:58:37,599 - INFO - Received command request
2018-10-10 12:58:38,452 - INFO - Received command request
2018-10-10 12:58:38,982 - INFO - Received command request
2018-10-10 12:58:40,609 - INFO - Received completion request
2018-10-10 12:58:40,610 - DEBUG - Using filetype completion: True
2018-10-10 12:58:40,627 - INFO - Received completion request
2018-10-10 12:58:40,628 - DEBUG - Using filetype completion: True
2018-10-10 12:58:40,672 - INFO - Received completion request
2018-10-10 12:58:40,672 - DEBUG - Using filetype completion: True
2018-10-10 12:58:40,685 - INFO - Received command request
2018-10-10 12:58:40,837 - INFO - Received completion request
2018-10-10 12:58:40,838 - DEBUG - Using filetype completion: True
2018-10-10 12:58:41,426 - INFO - Received completion request
2018-10-10 12:58:41,426 - DEBUG - Using filetype completion: True
2018-10-10 12:58:41,451 - INFO - Received command request
2018-10-10 12:58:44,309 - INFO - Received completion request
2018-10-10 12:58:44,310 - DEBUG - Using filetype completion: True

Do you need my init.el?

Thank you for your support

abingham commented 5 years ago

Do you need my init.el?

That might help, but it's hard to say. Could you post your .ycm_extra_conf.py as well?

My guess is that ycmd.el is behaving correctly and is just showing you what ycmd is returning. There's likely just some misconfiguration of ycmd.el, company, or ycmd itself which is leading the confusion.

linuzlover commented 5 years ago

Here is the .ycm_extra_conf.py created by YCM Generator:

# Generated by YCM Generator at 2018-10-08 10:49:59.226131

# This file is NOT licensed under the GPLv3, which is the license for the rest
# of YouCompleteMe.
#
# Here's the license text for this file:
#
# This is free and unencumbered software released into the public domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
# means.
#
# In jurisdictions that recognize copyright laws, the author or authors
# of this software dedicate any and all copyright interest in the
# software to the public domain. We make this dedication for the benefit
# of the public at large and to the detriment of our heirs and
# successors. We intend this dedication to be an overt act of
# relinquishment in perpetuity of all present and future rights to this
# software under copyright law.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
# For more information, please refer to <http://unlicense.org/>

import os
import ycm_core

flags = [
    '-x',
    'c',
    '-DCAPICOMMON_EXPORTS',
    '-DCMAKE',
    '-DHAVE_GETADDRINFO_A',
    '-DVERSION="1.5.0"',
    '-DWITH_BRIDGE',
    '-DWITH_BROKER',
    '-DWITH_EC',
    '-DWITH_MEMORY_TRACKING',
    '-DWITH_PERSISTENCE',
    '-DWITH_SOCKS',
    '-DWITH_SYS_TREE',
    '-DWITH_THREADING',
    '-DWITH_TLS',
    '-DWITH_TLS_PSK',
    '-DWITH_UUID',
    '-Dlibmosquitto_EXPORTS',
    '-I/home/attilio/projects/***/3pp/CAPIcommon/include',
    '-I/home/attilio/projects/***/3pp/CAPIcommon/src/include',
    '-I/home/attilio/projects/***/3pp/eigen-git-mirror',
    '-I/home/attilio/projects/***/3pp/mosquitto',
    '-I/home/attilio/projects/***/3pp/mosquitto/lib',
    '-I/home/attilio/projects/***/3pp/mosquitto/lib/cpp',
    '-I/home/attilio/projects/***/3pp/mosquitto/src',
    '-I/home/attilio/projects/***/include',
    '-Wall',
    '-Wextra',
]

# Set this to the absolute path to the folder (NOT the file!) containing the
# compile_commands.json file to use that instead of 'flags'. See here for
# more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html
#
# You can get CMake to generate this file for you by adding:
#   set( CMAKE_EXPORT_COMPILE_COMMANDS 1 )
# to your CMakeLists.txt file.
#
# Most projects will NOT need to set this to anything; you can just change the
# 'flags' list of compilation flags. Notice that YCM itself uses that approach.
compilation_database_folder = ''

if os.path.exists( compilation_database_folder ):
  database = ycm_core.CompilationDatabase( compilation_database_folder )
else:
  database = None

SOURCE_EXTENSIONS = [ '.C', '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ]

def DirectoryOfThisScript():
  return os.path.dirname( os.path.abspath( __file__ ) )

def MakeRelativePathsInFlagsAbsolute( flags, working_directory ):
  if not working_directory:
    return list( flags )
  new_flags = []
  make_next_absolute = False
  path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ]
  for flag in flags:
    new_flag = flag

    if make_next_absolute:
      make_next_absolute = False
      if not flag.startswith( '/' ):
        new_flag = os.path.join( working_directory, flag )

    for path_flag in path_flags:
      if flag == path_flag:
        make_next_absolute = True
        break

      if flag.startswith( path_flag ):
        path = flag[ len( path_flag ): ]
        new_flag = path_flag + os.path.join( working_directory, path )
        break

    if new_flag:
      new_flags.append( new_flag )
  return new_flags

def IsHeaderFile( filename ):
  extension = os.path.splitext( filename )[ 1 ]
  return extension in [ '.H', '.h', '.hxx', '.hpp', '.hh' ]

def GetCompilationInfoForFile( filename ):
  # The compilation_commands.json file generated by CMake does not have entries
  # for header files. So we do our best by asking the db for flags for a
  # corresponding source file, if any. If one exists, the flags for that file
  # should be good enough.
  if IsHeaderFile( filename ):
    basename = os.path.splitext( filename )[ 0 ]
    for extension in SOURCE_EXTENSIONS:
      replacement_file = basename + extension
      if os.path.exists( replacement_file ):
        compilation_info = database.GetCompilationInfoForFile(
          replacement_file )
        if compilation_info.compiler_flags_:
          return compilation_info
    return None
  return database.GetCompilationInfoForFile( filename )

def FlagsForFile( filename, **kwargs ):
  if database:
    # Bear in mind that compilation_info.compiler_flags_ does NOT return a
    # python list, but a "list-like" StringVec object
    compilation_info = GetCompilationInfoForFile( filename )
    if not compilation_info:
      return None

    final_flags = MakeRelativePathsInFlagsAbsolute(
      compilation_info.compiler_flags_,
      compilation_info.compiler_working_dir_ )

  else:
    relative_to = DirectoryOfThisScript()
    final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )

  return {
    'flags': final_flags,
    'do_cache': True
  }

Here, instead, you find my init.el. I apologize for its ugliness, it is just a draft :$

;;; package --- Summary:
;;; Commentary:
(require 'package)
;;; Code:
(add-to-list 'package-archives
             '("melpa" . "http://melpa.org/packages/") t)

(package-initialize)

(when (not package-archive-contents)
  (package-refresh-contents))

(unless (package-installed-p 'use-package)
  (package-install 'use-package))

(require 'use-package)
(setq use-package-always-ensure t)

(add-to-list 'load-path "~/.emacs.d/custom")

(require 'setup-general)
(if (version< emacs-version "24.4")
    (require 'setup-ivy-counsel)
  (require 'setup-helm)
  (require 'setup-helm-gtags))

(require 'setup-cedet)
(require 'setup-editing)

;;Activate minibuffer autoresize
(helm-autoresize-mode t)
;;Activate M-x substitute
(global-set-key (kbd "M-x") 'helm-M-x)
;;Activate man
(add-to-list 'helm-sources-using-default-as-input 'helm-source-man-pages)
;;Find occurrences in this file
(global-set-key (kbd "C-c h o") 'helm-occur)

                                        ; Snippets
(use-package yasnippet
  :ensure t
  :diminish yas-minor-mode
  :init (yas-global-mode t))

(require 'validate)

;; Code-comprehension server
(use-package ycmd
  :ensure t
  :init (add-hook 'c++-mode-hook #'ycmd-mode)
  :config
  (set-variable 'ycmd-server-command '("python3" "/home/attilio/Workspace/ycmd/ycmd"))
  )

(use-package company-ycmd
  :ensure t
  :init (company-ycmd-setup)
  )

(require 'ycmd-eldoc)
(add-hook 'ycmd-mode-hook 'ycmd-eldoc-setup)

(setq-local company-backends (remove 'company-semantic company-backends))

(define-key c-mode-map [(tab)] 'company-complete)
(define-key c++-mode-map [(tab)] 'company-complete)

;;Use Meta+arrow to switch windows
(windmove-default-keybindings 'meta)
;;Indent when a newline is pressed
(global-set-key (kbd "RET") 'newline-and-indent)  ; automatically indent when press RET
;; activate whitespace-mode to view all whitespace characters
(global-set-key (kbd "C-c w") 'whitespace-mode)
;; show unncessary whitespace that can mess up your diff
(add-hook 'prog-mode-hook (lambda () (interactive) (setq show-trailing-whitespace 1)))
;; use space to indent by default
(setq-default indent-tabs-mode nil)
;; set appearance of a tab that is represented by 4 spaces
(setq-default tab-width 4)
;; Package: smartparens
(require 'smartparens-config)
(show-smartparens-global-mode +1)
(smartparens-global-mode 1)
;; when you press RET, the curly braces automatically
;; add another newline
(sp-with-modes '(c-mode c++-mode)
  (sp-local-pair "{" nil :post-handlers '(("||\n[i]" "RET")))
  (sp-local-pair "/*" "*/" :post-handlers '((" | " "SPC")
                                            ("* ||\n[i]" "RET"))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; undo tree mode                                                         ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;turn on everywhere
(global-undo-tree-mode 1)
;; make ctrl-z undo
(global-set-key (kbd "C-z") 'undo)
;; make ctrl-Z redo
(defalias 'redo 'undo-tree-redo)
(global-set-key (kbd "C-S-z") 'redo)
;; function-args
;; (require 'function-args)
;; (fa-config-default)
;; (define-key c-mode-map  [(tab)] 'company-complete)
;; (define-key c++-mode-map  [(tab)] 'company-complete)

(setq c-default-style "ellemtel"
      c-basic-offset 4)
;;reformat buffer using F12
(defun indent-buffer ()
  (interactive)
  (save-excursion
    (indent-region (point-min) (point-max) nil)))
(global-set-key [f12] 'indent-buffer)

(require 'helm-flycheck) ;; Not necessary if using ELPA package
                                        ; Force flycheck to always use c++11 support. We use
;; the clang language backend so this is set to clang
(add-hook 'c++-mode-hook
          (lambda () (setq flycheck-clang-language-standard "c++11")))
;; Turn flycheck on everywhere
(global-flycheck-mode)

;; Package: yasnippet
;;(require 'yasnippet)
;;(yas-global-mode 1)
(add-to-list 'custom-theme-load-path "~/.emacs.d/themes/")
(load-theme 'gruvbox-dark-soft t)

(require 'highlight-doxygen)
(highlight-doxygen-global-mode 1)

(add-to-list 'load-path "~/.emacs.d/doxymacs/lisp/")
(load "doxymacs")
(require 'doxymacs)
(doxymacs-mode 1)

(require 'srefactor)
(define-key c-mode-map (kbd "M-RET") 'srefactor-refactor-at-point)
(define-key c++-mode-map (kbd "M-RET") 'srefactor-refactor-at-point)

(set-face-attribute 'default nil :family "Anonymous Pro" :height 180)
(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(package-selected-packages
   (quote
    (validate flycheck-ycmd company-ycmd highlight-doxygen srefactor gruvbox-theme distinguished-theme zenburn-theme nyan-mode zygospore yasnippet-snippets volatile-highlights use-package undo-tree smartparens iedit helm-swoop helm-projectile helm-gtags helm-flycheck dtrt-indent dracula-theme company-irony-c-headers company-irony company-c-headers comment-dwim-2 clean-aindent-mode anzu)))
 '(safe-local-variable-values
   (quote
    ((eval setq flycheck-clang-include-path
           (list
            (expand-file-name "/home/attilio/projects/***/include/.")
            (expand-file-name "/home/attilio/projects/***/3pp/CAPIcommon/include/.")
            (expand-file-name "/home/attilio/projects/***/3pp/mosquitto/lib/.")
            (expand-file-name "/home/attilio/projects/***/3pp/mosquitto/lib/cpp/.")
            (expand-file-name "/home/attilio/projects/***/3pp/eigen-git-mirror/.")))))))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )
(nyan-mode)

(provide 'init)
;;; init.el ends here

Again, thank you for your time.

AP

linuzlover commented 5 years ago

Do you need my init.el?

That might help, but it's hard to say. Could you post your .ycm_extra_conf.py as well?

My guess is that ycmd.el is behaving correctly and is just showing you what ycmd is returning. There's likely just some misconfiguration of ycmd.el, company, or ycmd itself which is leading the confusion.

@abingham Your comment inspired me and I modified the .ycm_extra_conf.py file adding the compilation_database_folder variable. Now, it behaves as expected. I will test it and I will close the issue.

TY!

AP

abingham commented 5 years ago

Excellent! I'm glad you got that sorted out.