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

c/cpp: Use compile_commands if present to determine compiler args #78

Closed

Conversation

@d-karl
Copy link

@d-karl d-karl commented Feb 12, 2020

The old behavior without a compile_commands.json present in the working
dir was kept available. If this file is present, the new mechanism
will use the actual compiler flags as specified by the build system to
parse the actual file the user is working in and retrieve info about the
token under the user's cursor.

Prelude

Thank you for helping out DoGe!

By contributing to DoGe you agree to the following statements (Replace [ ] with [x] with those you agree with):

Why this PR?

In environments where the compiler generates a compile commands database (compile_commands.json). The clang toolchain can use this database to parse files in the exact way the compiler would. This enables reliable identification of the token type for which the user has requested documentation to be generated and associated tokens, such as parameters.
This PR is probably par from perfect, but it improves upon the existing mechanism if a compile commands database is present. The old mechanism for parsing has been preserved.

It should be noted that:

  • It is assumed the compile_commands.json file is in the current working dir, as that should commonly be the project root and I didn't feel like searching for it, as that requires quite a bit of heuristics.
  • The available token types are limited from DoGe's side.
  • The current way of triggering the generator is suboptimal, since it is triggered 3 times, when one pass would be sufficient for the clang-based indexer. This makes documentation generation far slower than it would need to be, resulting in a noticable delay.
  • Since header files have no entry inside the compile commands db, clang uses an internal heuristic to guess the correct flags for these files. This can very seldomly lead to incorrect results.
The old behavior without a compile_commands.json present in the working
dir was kept available. If a this file is present, the new mechanism
will use the actual compiler flags as specified by the build system to
parse the actual file the user is working in and retrieve info about the
token under the user's cursor.
@d-karl
Copy link
Author

@d-karl d-karl commented Feb 12, 2020

I just realized that I committed under the wrong author name. I will fix this soon, please hold off on merging for now.

output['name'] = node.spelling
output['returnType'] = node.result_type.spelling
output['parameters'] = []
output["name"] = node.spelling

This comment has been minimized.

@kkoomen

kkoomen Feb 14, 2020
Owner

Use single-quotes to match the project's standards.

"""
Check the actual cpp file with the compile arguments retrieved from compile_commands.json.
:param filename: file to check

This comment has been minimized.

@kkoomen

kkoomen Feb 14, 2020
Owner

Capitalize the first letter of a description and add a period to the end of a description. The same goes for other comments.

@kkoomen
Copy link
Owner

@kkoomen kkoomen commented Feb 14, 2020

I just realized that I committed under the wrong author name. I will fix this soon, please hold off on merging for now.

sure


Thanks for your time for doing this. I really appreciate it. I haven't reviewed your code yet functionality-based, but it looks good enough. I'm not an experienced C dev, so any help I get is appreciated.

It is assumed the compile_commands.json file is in the current working dir, as that should commonly be the project root and I didn't feel like searching for it, as that requires quite a bit of heuristics.

It is preferred that we look from the cwd up until root (/) for a compile_commands.json file, since it's a small thing.

The current way of triggering the generator is suboptimal, since it is triggered 3 times, when one pass would be sufficient for the clang-based indexer. This makes documentation generation far slower than it would need to be, resulting in a noticable delay.

This is true, since DoGe defines multiple patterns in the ftplugin/c.vim. Could you implement it in a way that the database compilations are cached, unless all of the patterns in ftplugin/c.vim failed or there is 1 pattern that matches?

Detecting the last pattern requires a bit more work and I'll help you with it once we confirmed the caching strategy is an option.

@kkoomen
Copy link
Owner

@kkoomen kkoomen commented Oct 8, 2020

Closing due to new rewrite where clang is no longer needed, see #101.

@kkoomen kkoomen closed this Oct 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.