niosus / EasyClangComplete

:boom: Robust C/C++ code completion for Sublime Text 3/4

Home Page:https://niosus.github.io/EasyClangComplete/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature request: support Meson as good as CMake

detly opened this issue · comments

(I am happy to do a PR for this, but I wanted to gauge interest first.)

I'm working on a project that uses Meson. Meson generates Ninja, so at the moment I can get ECC integration just by pointing ecc_flags_sources at my build directory.

But it strikes me that Meson is quite a lot like CMake from ECC's point of view: it runs out-of-tree, so you could just run it in a temporary directory and crib the necessary info like you do with CMake. Then tweaking ECC settings, remembering to run it, etc. becomes a non-issue.

Is this something you'd be interested in? I couldn't promise to be around to maintain it, so it might well increase the amount of stuff you have to maintain, a downside I certainly recognise. OTOH I'd be using it regularly for the foreseeable future.

@detly I think overall I am not against it. If it can work similarly to cmake, then sure, we can just add it. If it ever breaks and you're not there for reference, I could always ask people interested in this to find out what breaks and review a PR from them.

So sure, if you feel that it will make your life easier - go for it. But you will have to educate me a bit about Meson in the PR 😉

I would be happy to help in that process, I am wanting to switch from cmake to meson but I have a really hard time without proper completion.

@InfRandomness Yeah, I got derailed from this. But FYI, you can still have completion, you just need to manually run one command.

What you need is a compile_commands.json file (see here). Meson generates this routinely.

Steps are:

  1. Pick a consistent location for your Meson output eg. $project_base_path/build.
  2. In a console, go to your project directory and run meson build.
  3. Double check that build/compile_commands.json exists.
  4. In your project settings, add:
{
    "settings":
    {
        "ecc_flags_sources":
        [
            {
                "file": "compile_commands.json",
                "search_in": "$project_base_path/build",
            }
        ],
        "ecc_use_libclang": true,
    }
}

You can add any other settings you need too.

You should get completion from ECC at this point.

Oh, that's great, thanks ! :D
I will eventually try to think about a way to add solid support for meson to ECC.

@detly I have did that, and have added include/ as my include directory in meson, but it seems as if ECC does not take that into account because it does not provide completion over my headers in include/
Here is my meson config :

project('SporkGit', 'cpp',
  version : '0.1',
  default_options : ['warning_level=3', 'cpp_std=c++2a'])

inc = include_directories('include')

executable('SporkGit',
           'src/Main.cxx',
           'src/Repository.cxx',
           include_directories: inc,
           install : true)

Do you happen to know how I could make this work?

Funnily enough I don't actually use the include_directories() command - all my includes are either relative from the project root or system includes. I dimly remember that what you're seeing is a problem with compile_commands.json configuration - that it does not store include directories in an easy-to-parse way, just source files and build flags. It's the build flags that contain the include info.

However, ECC still works for me, because it's getting the header path from the source files itself (or rather, LLVM is). Since they're relative to the project root, it works all the same. In your case, if there's a manageable number of include directories, you could add them to your settings. For example:

{
	"settings":
	{
		"ecc_common_flags":
		[
                        "-I$project_base_path/include",
			"-I/usr/include",
			"-I/usr/lib/clang/$clang_version/include"
		],
        }
}

Alright, I will do that instead. Thanks!

This doesn't seem to work.
I have

{
    "settings":
    {
        "ecc_flags_sources":
        [
            {
                "file": "compile_commands.json",
                "search_in": "$project_base_path/builddir",
            }
        ],

        "ecc_common_flags":
        [
            "-I$project_base_path/include"
        ],
        
        "ecc_use_libclang": true,
    }
}

in my .sublime-project file, ECC still does not find my header file.
Can this be caused by the fact my header file extension is .hxx instead of .h?

Sorry guys, I only now read this thread. @InfRandomness does the solution provided by @detly in #713 (comment) work for you? If not then it would be interesting to see what doesn't work there as at that point it is just about reading that compilation database.

Other than that this all comes down to just calling a single command just like we do with cmake. The only compilation is that meson compile will actually compile the whole project which is probably not desirable. So the question is - is there a way to not build all the files but generate a compilation command with meson/ninja? If not, then the only way is to build code manually and reuse the compilation database generated as the restul. If there is a way for this - then we might be able to add this functionality to the plugin.

Sorry guys, I only now read this thread. @InfRandomness does the solution provided by @detly in #713 (comment) work for you? If not then it would be interesting to see what doesn't work there as at that point it is just about reading that compilation database.

It should work, but right now it isn't.
Here is the content of my compile_commands.json :

[
  {
    "directory": "/home/infrandomness/Documents/Dev/C++/SporkGIT/builddir",
    "command": "clang++ -ISporkGit.p -I. -I.. -I../include -fcolor-diagnostics -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wnon-virtual-dtor -Wextra -Wpedantic -std=c++2a -O0 -g -MD -MQ SporkGit.p/src_Main.cxx.o -MF SporkGit.p/src_Main.cxx.o.d -o SporkGit.p/src_Main.cxx.o -c ../src/Main.cxx",
    "file": "../src/Main.cxx",
    "output": "SporkGit.p/src_Main.cxx.o"
  },
  {
    "directory": "/home/infrandomness/Documents/Dev/C++/SporkGIT/builddir",
    "command": "clang++ -ISporkGit.p -I. -I.. -I../include -fcolor-diagnostics -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wnon-virtual-dtor -Wextra -Wpedantic -std=c++2a -O0 -g -MD -MQ SporkGit.p/src_Repository.cxx.o -MF SporkGit.p/src_Repository.cxx.o.d -o SporkGit.p/src_Repository.cxx.o -c ../src/Repository.cxx",
    "file": "../src/Repository.cxx",
    "output": "SporkGit.p/src_Repository.cxx.o"
  }
]

and here is the content of my .sublime-project

{
    "settings":
    {
        "ecc_flags_sources":
        [
            {
                "file": "compile_commands.json",
                "search_in": "$project_base_path/builddir",
            }
        ],
        
        "ecc_use_libclang": true,
    }
}

The problem is that ECC is failing to find the Repository.hxx file in the include/ directory from the project root