<div dir="ltr">Add an entry to compile_commands.json:<div>{</div><div>  "file": ".../libraries/chain/include/eosio/chain/types.hpp",</div><div>  "directory": ".../build/libraries/chain",</div><div>  "command": "/usr/bin/clang++-4.0 ... -c .../libraries/chain/include/eosio/chain/types.hpp"</div><div>}</div><div><br></div><div>where the ... path is adjusted for your system, and the command is taken from the entry from some other relevant file (e.g. abi_serializer.cpp)</div><div><br></div><div>You'll also need to prevent your build system from overwriting this change.</div><div><br></div><div>---</div><div><br></div><div>Another thought on a proper fix: we know that types.hpp is a good match for resource_limits.hpp in the same directory, which in turn is a good match for resource_limits.cpp. This transitive connection might be a useful signal. Unfortunately we don't know that resource_limits.hpp exists when loading the interpolating CDB. Maybe listing the parent directory of types.hpp is viable though.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Apr 3, 2019 at 4:30 AM yus <<a href="mailto:suyu.nu@gmail.com">suyu.nu@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>Many thanks for your analysis and suggestion. </div><div>For you suggestion, I know what to do but don't know how to do.</div><div><br></div><div>Can you give some details about the option 1:</div><div>- adding an explicit compile command for types.hpp, and avoid overwriting it,<br></div><div>How to do it.</div><div><br></div><div>Thanks.</div><div><br></div><div>Brs,</div><div>Su Yu</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Sam McCall <<a href="mailto:sammccall@google.com" target="_blank">sammccall@google.com</a>> 于2019年4月3日周三 上午12:24写道:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Indeed, the heuristics are valuing base filenames over directory structure match in this case:</div><div dir="ltr"><br></div><div dir="ltr">sed -i s%/root/workspace/eos4%$PWD%g compile_commands.json<br></div><div dir="ltr">mkdir -p libraries/chain/include/eosio/chain<br></div><div dir="ltr">touch libraries/chain/include/eosio/chain/{types,resource_limits,zzz}.hpp<br></div><div dir="ltr"><br></div><div dir="ltr">clang-check -debug-only=interpolate libraries/chain/include/eosio/chain/types.hpp<br></div><div dir="ltr">interpolate: chose .../libraries/wasm-jit/Source/IR/<b>Types</b>.cpp as proxy for .../libraries/chain/include/eosio/chain/<b>types</b>.hpp preferring c++ score=2<br></div><div>(this is a bad result: prefer e.g. .../libraries/chain/abi_serializer.cpp)</div><div dir="ltr"><br></div><div dir="ltr">clang-check -debug-only=interpolate libraries/chain/include/eosio/chain/resource_limits.hpp<br></div><div dir="ltr">interpolate: chose .../libraries/<b>chain</b>/<b>resource_limits</b>.cpp as proxy for .../libraries/chain/include/eosio/<b>chain</b>/<b>resource_limits</b>.hpp preferring c++ score=3<br></div><div>(this is a good result)</div><div dir="ltr"><br></div><div><div>clang-check -debug-only=interpolate libraries/chain/include/eosio/chain/zzz.hpp</div><div>interpolate: chose .../libraries/<b>chain</b>/abi_serializer.cpp as proxy for .../libraries/chain/include/eosio/<b>chain</b>/zzz.hpp preferring c++ score=1</div></div><div>(this is a good result)</div><div><br></div><div>--- details ---</div><div><br></div><div>Points are awarded to entries in compile_commands:</div><div> - 2 points for filename match without extension (1 for prefix match)</div><div> - up to 3 points for directory structure match (1 for each of last 2 segments, 1 for the rest)</div><div><br></div><div>For files in this directory, the relevant directory structure parts are .../libraries/chain/include eosio chain.</div><div>So:</div><div>  - anything under ".../libraries/chain/include" would get 1 point (there are no cpp files there)</div><div>  - anything with "eosio" in the last 4 directory segments gets 1 point (no matches)</div><div>  - anything with "chain" in the last 4 directory segments gets 1 point (<b>1 point for sources in "chain" subproject</b>)</div><div>With this directory structure, we do manage to pair headers/sources in the same project, but we only give a 1 point bonus for doing so, and so the 2 point bonus for matching basename can take precedence.</div><div><br></div><div>--- how to fix in clang ---</div><div><br></div><div>We only need to tweak the scores here by one point: a tie will be broken in favor of the longest prefix match, which would be when sources are in the same subproject with this directory structure.</div><div><br></div><div>One option is to make the name match worth less: 0.5/1 rather than 1/2 points, though I do worry this will break some cases in the other direction.</div><div><br></div><div>Another option is to recognize this directory structure match as particularly good, and boost it more - 1 seems relatively low for e.g. .../chain/abi_serializer.cpp matching .../chain/types.hpp where it's the immediate parent directories that match.</div><div>This would be somewhat involved: the index data structure doesn't currently capture where the word "chain" appeared within the cpp filename.</div><div><br></div><div>I'll look into this...</div><div><br></div><div>--- how to work around ---</div><div><br></div><div>The only thing I can suggest is to change your compilation database, either:</div><div> - adding an explicit compile command for types.hpp, and avoid overwriting it, or</div><div> - only generate the CDB for a smaller subset of the project that avoids Types.cpp</div></div></div></div></div></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Apr 1, 2019 at 6:37 PM Sam McCall <<a href="mailto:sammccall@google.com" target="_blank">sammccall@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Apologies, missed the attachment in the original email. Will look in the morning!</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Apr 1, 2019 at 2:17 PM Sam McCall <<a href="mailto:sammccall@google.com" target="_blank">sammccall@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi! Sorry the heuristics aren't working here.<div>The most likely thing is the bare name "types" is matching some *.cpp file from a base library, and we're weighing that too heavily and the directory not heavily enough. This is probably due to heuristics tuned for the LLVM project itself, which has few dependencies and parallel source/include trees.</div><div>Can you attach compile_commands.json please?</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Apr 1, 2019 at 11:24 AM Ilya Biryukov <<a href="mailto:ibiryukov@google.com" target="_blank">ibiryukov@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">I don't think there's any simple solution to this. You could try patching your 'compile_commands.json' to add the header files in there, but CMake won't do this automatically for you.<div>I believe the following project on GitHub tries to do something similar, but I haven't tried it myself: <a href="https://github.com/Sarcasm/compdb" target="_blank">https://github.com/Sarcasm/compdb</a></div><div><br></div><div><br></div><div><a class="gmail_plusreply" id="gmail-m_-5863788009347099937gmail-m_-2061787975550133650gmail-m_-8307880841716528283gmail-m_-8221677862545125505gmail-m_-4235615652641857154plusReplyChip-2" href="mailto:sammccall@google.com" target="_blank">+Sam McCall</a>, now that you're back from leave, any ideas for improving the heuristics to find proper matching .cpp files in more cases?</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Apr 1, 2019 at 11:11 AM yus <<a href="mailto:suyu.nu@gmail.com" target="_blank">suyu.nu@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Excuse me, is there any solution for my problem?<div>Thanks</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">yus <<a href="mailto:suyu.nu@gmail.com" target="_blank">suyu.nu@gmail.com</a>> 于2019年3月23日周六 上午9:40写道:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">HI,<div><br></div><div>Got it.</div><div>So my problem has no relationship with front-end vim-YoucompleteMe</div><div>I just need to wait for your solution or workaround.</div><div><br></div><div>Thanks for your help.</div><div><br></div><div>Brs,</div><div>Su Yu</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Ilya Biryukov <<a href="mailto:ibiryukov@google.com" target="_blank">ibiryukov@google.com</a>> 于2019年3月22日周五 下午8:43写道:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Mar 22, 2019 at 12:41 PM yus <<a href="mailto:suyu.nu@gmail.com" target="_blank">suyu.nu@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>By the way,</div><div>If a header has no source file (*.cpp), how it been handled.</div></div></blockquote><div>In that case we would fallback to something like `clang -xc++ test.hpp`.</div><div>But that almost never happens, our heuristics will always try to pick some cpp file first.<br></div><div>E.g. in the extreme case when compile_commands.json has just a single file, we will take the compile command from that file for <b>all</b> headers we encounter.</div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><br></div><div>Brs,</div><div>Su Yu</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">yus <<a href="mailto:suyu.nu@gmail.com" target="_blank">suyu.nu@gmail.com</a>> 于2019年3月22日周五 下午7:37写道:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hi,</div><div><br></div><div dir="ltr">Many thanks for your prompt answer.<div>It's an open source project.</div><div>But it's a little difficult to build. It has many dependency</div><div>Hope it can help.<br></div><div><a href="https://github.com/EOSIO/eos" target="_blank">https://github.com/EOSIO/eos</a><br></div><div><br></div><div>Thanks.</div><div><br></div><div>Brs,</div><div>Su Yu</div><div><br></div><div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Ilya Biryukov <<a href="mailto:ibiryukov@google.com" target="_blank">ibiryukov@google.com</a>> 于2019年3月22日周五 下午5:18写道:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi Su,<div><br></div><div>Since compile_commands.json only contains compile commands for .cpp files, we use a heuristics-based approach to infer compile commands for headers.</div><div>More precisely, based on the path to the header file we try to guess the best .cpp file for a header (e.g. an implementation file) and pick the compile command from it.</div><div><br></div><div>In your case, we fail to guess a good compile command. I don't know of a good workaround, unfortunately.</div><div><a class="gmail_plusreply" id="gmail-m_-5863788009347099937gmail-m_-2061787975550133650gmail-m_-8307880841716528283gmail-m_-8221677862545125505gmail-m_-4235615652641857154gmail-m_2069525623820267518m_-449997816327468673gmail-m_-4300355639342071512gmail-m_7433235076812451419gmail-m_3408066171976145221gmail-m_3456006460747175476gmail-m_-5674883773920619418plusReplyChip-0" href="mailto:sammccall@google.com" target="_blank">+Sam McCall</a> is the author of this approach, he might have ideas on how to fix this.</div><div><br></div><div>Is the project you're working on open-source? If so, could you provide a link to the source code? If not, compilation database should also be enough to reproduce.</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Mar 21, 2019 at 10:41 PM yus via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hi,<div>I encounter an error in clangd</div><div><br></div><div><div><div>I[12:49:12.197] Updating file /root/workspace/eos4/libraries/chain/include/eosio/chain/types.hpp with command<b><font color="#cc0000"> [/root/workspace/eos4/build/libraries/wasm-jit/Source/IR] </font></b>/usr/bin/clang++-4.0 -D ENABLE_SIMD_PROTOTYPE=0 -D ENABLE_THREADING_PROTOTYPE=0 -D IR_API=DLL_EXPORT -D PRETEND_32BIT_ADDRESS_SPACE=0 -D WAVM_METRICS_OUTPUT=0 -I /root/workspace/eos4/libraries/wasm-jit/Include -I /root/workspace/eos4/libraries/wasm-jit/Include/IR -Wall -Wno-invalid-partial-specialization -O3 -D NDEBUG -c -std=gnu++14 /root/workspace/eos4/libraries/chain/include/eosio/chain/types.hpp -resource-dir=/root/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clang/lib/clang/7.0.0</div><div>V[12:49:12.199] Preamble for file /root/workspace/eos4/libraries/chain/include/eosio/chain/types.hpp cannot be reused. Attempting to rebuild it.</div><div>V[12:49:12.238] Built preamble of size 213512 for file /root/workspace/eos4/libraries/chain/include/eosio/chain/types.hpp</div><div>I[12:49:12.242] Dropped diagnostic outside main file: : too many errors emitted, stopping now</div></div></div><div><br></div><div>some other file in same folder update correctly</div><div><br></div><div><div>I[12:49:03.898] Updating file /root/workspace/eos4/libraries/chain/include/eosio/chain/resource_limits.hpp with command <font color="#cc0000"><b>[/root/workspace/eos4/build/libraries/chain] </b></font>/usr/bin/clang++-4.0 -I /root/workspace/eos4/libraries/chain/include -I /root/workspace/eos4/build/libraries/chain/include -I /root/workspace/eos4/libraries/chain/../wasm-jit/Include -I /root/workspace/eos4/libraries/chain/../../externals/binaryen/src -I /root/workspace/eos4/libraries/utilities/include -I /root/workspace/eos4/libraries/utilities/../wasm-jit/Include -I /root/workspace/eos4/libraries/fc/include -I /root/opt/boost/include -I /usr/local/include -I /root/workspace/eos4/libraries/fc/vendor/websocketpp -I /root/workspace/eos4/libraries/chainbase/include -I /root/workspace/eos4/libraries/wasm-jit/Source/Runtime/../../../chain/include -I /root/workspace/eos4/libraries/softfloat/source/include -I /root/workspace/eos4/libraries/softfloat/source/8086-SSE -I /root/workspace/eos4/libraries/softfloat/build/Linux-x86_64-GCC -I /root/workspace/eos4/libraries/builtins -I /root/workspace/eos4/libraries/builtins../softfloat/source/include -Wall -Wno-invalid-partial-specialization -O3 -D NDEBUG -c -std=gnu++14 /root/workspace/eos4/libraries/chain/include/eosio/chain/resource_limits.hpp -resource-dir=/root/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clang/lib/clang/7.0.0</div><div>V[12:49:03.901] Preamble for file /root/workspace/eos4/libraries/chain/include/eosio/chain/resource_limits.hpp cannot be reused. Attempting to rebuild it.</div><div>V[12:49:10.676] <<< {"id":"3","jsonrpc":"2.0","method":"textDocument/definition","params":{"position":{"character":51,"line":53},"textDocument":{"uri":"file:///root/workspace/eos4/libraries/chain/include/eosio/chain/resource_limits.hpp"}}}</div></div><div><br></div><div>I don't know why, and what's the difference. why the flags are different.</div><div>How to fix the problem</div><div><br></div><div><div>root@39470746ee31:~/workspace/eos4# /usr/bin/clang++-4.0 -D ENABLE_SIMD_PROTOTYPE=0 -D ENABLE_THREADING_PROTOTYPE=0 -D IR_API=DLL_EXPORT -D PRETEND_32BIT_ADDRESS_SPACE=0 -D WAVM_METRICS_OUTPUT=0 -I /root/workspace/eos4/libraries/wasm-jit/Include -I /root/workspace/eos4/libraries/wasm-jit/Include/IR -Wall -Wno-invalid-partial-specialization -O3 -D NDEBUG -c -std=gnu++14 /root/workspace/eos4/libraries/chain/include/eosio/chain/types.hpp -resource-dir=/root/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clang/lib/clang/7.0.0</div><div>/root/workspace/eos4/libraries/chain/include/eosio/chain/types.hpp:6:10: fatal error: 'eosio/chain/name.hpp' file not found</div><div>#include <eosio/chain/name.hpp></div><div>         ^~~~~~~~~~~~~~~~~~~~~~</div><div>1 error generated.</div></div><div><br></div><div>attach the error and compilation database</div><div><br></div><div>Thanks.</div><div><br></div><div>Brs</div><div>Su Yu</div><div><br></div></div></div></div></div></div>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail-m_-5863788009347099937gmail-m_-2061787975550133650gmail-m_-8307880841716528283gmail-m_-8221677862545125505gmail-m_-4235615652641857154gmail-m_2069525623820267518m_-449997816327468673gmail-m_-4300355639342071512gmail-m_7433235076812451419gmail-m_3408066171976145221gmail-m_3456006460747175476gmail-m_-5674883773920619418gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>Regards,</div><div>Ilya Biryukov</div></div></div></div></div>
</blockquote></div>
</blockquote></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail-m_-5863788009347099937gmail-m_-2061787975550133650gmail-m_-8307880841716528283gmail-m_-8221677862545125505gmail-m_-4235615652641857154gmail-m_2069525623820267518m_-449997816327468673gmail-m_-4300355639342071512gmail-m_7433235076812451419gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>Regards,</div><div>Ilya Biryukov</div></div></div></div></div></div>
</blockquote></div>
</blockquote></div></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail-m_-5863788009347099937gmail-m_-2061787975550133650gmail-m_-8307880841716528283gmail-m_-8221677862545125505gmail-m_-4235615652641857154gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>Regards,</div><div>Ilya Biryukov</div></div></div></div></div>
</blockquote></div>
</blockquote></div>
</blockquote></div>
</blockquote></div>
</blockquote></div>