EasyClangComplete icon indicating copy to clipboard operation
EasyClangComplete copied to clipboard

Feature request: Environment variable for using source file's current folder in `common_flags`

Open LantosIstvan opened this issue 9 years ago • 7 comments

We have these options to define include dirs in the plugin settings:

  // Every path variable in settings can contain wildcards (without the ""):
  //  - "$project_base_path"  <-- replaced by the full path to the project to
  //                              which the currently opened view belongs.
  //  - "$project_name"       <-- replaced by the name of the current project.
  //  - "$clang_version"      <-- replaced by the numeric version of used clang.
  //  - "~"                   <-- replaced by the path to user home directory.
  //
  //  In addition to these, you can use your environment variables:
  //  - OSX and Linux:  $variable_name or ${variable_name}
  //  - Windows:        $variable_name or ${variable_name} or %variable_name%

  // Specify common flags that will be passed to clang for EVERY build.
  "common_flags" : [
    // some example includes
    "-I/usr/include",
    "-I$project_base_path/src",
    // this is needed to include the correct headers for clang
    "-I/usr/lib/clang/$clang_version/include"
  ],

If you use Sublime that your Opened Project folder (D:\www) is where all of your dev projects stored (i.e. lots of subfolders where your real projects reside, for example: D:\www\cpp\asio, D:\www\node\koa, D:\www\html\personal-portfolio, etc.), so these environment variables:

    "-I$project_base_path/src",
    "-I$project_base_path/include",
    "-I%cd%/include",

Simply not giving you the desired paths. Also, the windows environment variable like %cd% simply didn't included in the verbose output that I included below (probably this also can be MSYS2 issue, because clang insalled in that, not native MSVC version). $project_base_path is just a confusing name, because you expect to get your current folder where your source .cpp files resides for linting, but instead you got:

DEBUG:EasyClangComplete.plugin.settings.settings_storage: populated '-I$project_base_path/src' to '-ID:\www/src'
DEBUG:EasyClangComplete.plugin.settings.settings_storage: populated '-I$project_base_path/include' to '-ID:\www/include'
DEBUG:EasyClangComplete.plugin.settings.settings_storage: populated '-I/usr/lib/clang/$clang_version/include' to '-I/usr/lib/clang/3.9.1/include'

But what should I want to have, if you open a .cpp file at D:\www\cpp\asio\src\main.cpp location, these lines should be:

DEBUG:EasyClangComplete.plugin.settings.settings_storage: populated '-I$current_path/include' to '-ID:\www\cpp\asio\src\include'

Something like $current_path would be nice to have, if the Windows environment variables doesn't work thanks to MSYS2, Cygwin, compatibility issues. I think it's not impossible because these lines already giving the desired paths:

DEBUG:EasyClangComplete.plugin.tools: searching 'CMakeLists.txt' from 'D:\www\cpp\asio\src' to 'D:\\www'
DEBUG:EasyClangComplete.plugin.tools: searching 'compile_commands.json' from 'D:\www\cpp\asio\src' to 'D:\\www'
DEBUG:EasyClangComplete.plugin.tools: searching '.clang_complete' from 'D:\www\cpp\asio\src' to 'D:\\www'

For many starters like me who learning C++, dealing with Cmake is just utterly confusing, that's why would be much simpler to have an option like $current_path in EasyClangComplete.

LantosIstvan avatar Jan 31 '17 14:01 LantosIstvan

The following environment flags also not work:

    "-I$pwd/include",
    "-I$(pwd)/include",

Strange enough, this one works:

    "-I~/include",

common_flags like this:

  "common_flags" : [
    // some example includes
    "-I/usr/include",
    "-I$project_base_path/src",
    "-I$project_base_path/include",
    "-I$project_name/include",
    "-I$pwd/include",
    "-I$(pwd)/include",
    "-I%cd%/include",
    "-I~/include",
    // this is needed to include the correct headers for clang
    "-I/usr/lib/clang/$clang_version/include"
  ],

Only resulting:

DEBUG:EasyClangComplete.plugin.settings.settings_storage: populating common_flags with current variables.
DEBUG:EasyClangComplete.plugin.settings.settings_storage: populated '-I$project_base_path/src' to '-ID:\www/src'
DEBUG:EasyClangComplete.plugin.settings.settings_storage: populated '-I$project_base_path/include' to '-ID:\www/include'
DEBUG:EasyClangComplete.plugin.settings.settings_storage: populated '-I$project_name/include' to '-Iwww/include'
DEBUG:EasyClangComplete.plugin.settings.settings_storage: populated '-I~/include' to '-IC:\Users\User/include'
DEBUG:EasyClangComplete.plugin.settings.settings_storage: populated '-I/usr/lib/clang/$clang_version/include' to '-I/usr/lib/clang/3.9.1/include'
DEBUG:EasyClangComplete.plugin.settings.settings_manager: settings initialized for view: 32

LantosIstvan avatar Jan 31 '17 15:01 LantosIstvan

Have you tried using .clang_complete file? I am not sure what your problem exactly is but you could do something like this: D:\www\P1\ .clang_complete D:\www\P2\ .clang_complete D:\www\P3\ .clang_complete

Then when working on file in P1 you would use includes from P1\ .clang_complete etc.

simia avatar Jan 31 '17 16:01 simia

I take a look at .clang_complete file.

I'm including a picture from ST3 how I organize all of my development projects. The top www folder is at D:\www, which in my case is not considered a project, instead open up everything with one shot:

scr

LantosIstvan avatar Jan 31 '17 16:01 LantosIstvan

Confirming that .clang_complete file works great.

LantosIstvan avatar Jan 31 '17 16:01 LantosIstvan

@DJviolin @simia Would you mind sharing how you managed to get the package working with .clang_complete on Windows ? I'm still not getting the desired result. 🤔

sus007 avatar Mar 05 '18 13:03 sus007

Sorry, I completely abandoned ST3 in favour of Visual Studio Code a year ago. I don't have a working setup now or a backup.

LantosIstvan avatar Mar 05 '18 14:03 LantosIstvan

Wow, I did the opposite. 😁 I left VSCode in favor of Sublime Text since VSCode consumed way too much memory for me. I hope @simia still uses Sublime.

sus007 avatar Mar 05 '18 14:03 sus007