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

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

Closed
aixiaoxiaoyu opened this issue Jul 20, 2016 · 11 comments
Closed

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

aixiaoxiaoyu opened this issue Jul 20, 2016 · 11 comments

Comments

@aixiaoxiaoyu
Copy link

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
Copy link
Member

Please see CONTRIBUTING.md.

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

@johannes87
Copy link

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
Copy link
Collaborator

@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
Copy link
Member

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

^^ end reasonable explanation.

@asm-jaime
Copy link

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
Copy link

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
Copy link
Member

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
Copy link

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

@felixcrazzolara
Copy link

felixcrazzolara commented Sep 15, 2019

@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
Copy link
Member

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
Copy link
Member

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 9, 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

No branches or pull requests

7 participants