ycm-core / YouCompleteMe

A code-completion engine for Vim
http://ycm-core.github.io/YouCompleteMe/
GNU General Public License v3.0
25.44k stars 2.81k forks source link

AttributeError: 'module' object has no attribute 'FlagsForFile' #2249

Closed aixiaoxiaoyu closed 8 years ago

aixiaoxiaoyu commented 8 years ago

Ubuntu 14.04(64bit) When I want to use the :YcmCompleter :YcmCompleter GoToDefinition command, the following occurs AttributeError: 'module' object has no attribute 'FlagsForFile' .(.c file)

Note:(./install.py --clang-completer) has been successfully installed

puremourning commented 8 years ago

Please see CONTRIBUTING.md.

In particular, please carefully read README.md sections on c-family semantic completions.

johannes87 commented 5 years ago

So the answer seems to be "you need to recompile YCM", which saddens me. Somehow, YCM goes broke sometimes and doesn't provide a proper user interface that tells the user what to do. Instead a cryptic debug-message is shown. End of rant ^^

bstaletic commented 5 years ago

@johannes87 Unless you faced a completely unrelated problem, the solution is to provide a valid extra conf file, which is described in detail in the README.

puremourning commented 5 years ago

In addition when recompilationnis required that’s exactly what the message says.

^^ end reasonable explanation.

asm-jaime commented 5 years ago

Here my .ycm_c-c++_conf.py:

import os
import ycm_core

flags = [
  '-Wall',
  '-Wextra',
  '-Werror',
  '-Wno-long-long',
  '-Wno-variadic-macros',
  '-fexceptions',
  '-ferror-limit=10000',
  '-DNDEBUG',
  '-std=c99',
  '-xc',
  '-isystem/usr/include/',
  ]

SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', ]

def FlagsForFile( filename, **kwargs ):
  return {
  'flags': flags,
  'do_cache': True
  }

Simple clang completion like struct/functions, works well for me. Bring this file to ~/.ycm_c-c++_conf.py or add this line: let g:ycm_global_ycm_extra_conf = "~/.ycm_c-c++_conf.py" to your .vimrc.

kamiradi commented 5 years ago

Wait, I'm confused, the README says that it calls a function called Settings in the .ycm_extra_conf.py file. Nowhere does it mention that it calls FlagsForFile. What is it exactly?

puremourning commented 5 years ago

FlagsForFile was superseded by Settings and we changed all the docs to talk about Settings. The reason for this change is that historically FlagsForFile was used only for c-family languages, but strictly returned more than just "flags". Now it is used for multiple languages and returns language-speicific settings. For example if the language is provided by LSP (such as java, rust, go, clangd, etc.) then the settings function returns the configuration options for the language server. If it is c++/etc., then it returns the flags for lib clang. I believe there are also python settings which control things like the python path and interpreter used by Jedi. Anyway this is all described in the ycmd README and summarised in the YCM readme.

The docs are the primary reference, and legacy/potentially misleading posts on the issue tracker are not going to remain current. If you feel the documentation is unclear, or lacking, feel free to head to Gitter and discuss or send a PR to correct or update it. Not reading it is not really an excuse.

kamiradi commented 5 years ago

Noob mistake, my bad. Thanks for the prompt reply.

felixcrazzolara commented 5 years ago

@puremourning I'd like to suggest that by default a warning is shown when starting vim, if a ycm_extra_conf.py file is loaded which has a FlagsForFile method, but no Settings method. This behaviour could then be disabled by setting a flag in your .vimrc. In my opinion it is very hard to use YouCompleteMe if you are relatively new to vim and don't have tons of time to debug your vim setup. For me it was very confusing why some .ycm_extra_conf.py files that are publicly available do not have a Settings method even though it is mentioned in the official documentation.

puremourning commented 5 years ago

FlagsForFile works fine. There’s no likelihood that will change. So warning is not necessary. We could however include an explanation of the historical interface in the docs. PRs are welcome 🙏

puremourning commented 5 years ago

Also how can we be held to ransom by ‘publicly available’ stuff that’s nothing to do with is? if you read the docs and still struggle we’re always willing to provide help and support. We can’t endorse any inaccurate or outdated third party advice or examples.