Add LSP config generation for C/C++ native code - #143
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
| [first | _rest] -> Path.basename(first) | ||
| end | ||
|
|
||
| binary in ~w[mkdir rm ar] || |
There was a problem hiding this comment.
This one will return false for /usr/bin/ar 🤔
There was a problem hiding this comment.
how so? ok, if it was actually /usr/bin/ar string, then sure, but https://github.com/membraneframework/bundlex/blob/work-on-lsp/lib/bundlex/toolchain/common/unix.ex#L76-L76 returns bare ar.
We could use String.ends_with?, but, since we are controlling emitted commands, and they are within the same repo, IMO it is fine. The comment could be less confusing.
There was a problem hiding this comment.
You are right, I skipped this Path.basename part
| defmodule Bundlex.LSP.Config do | ||
| @moduledoc """ | ||
| Generates LSP configuration files (compile_commands.json, compile_flags.txt) | ||
| for C/C++ code analysis tools like clangd. | ||
| """ | ||
|
|
||
| alias Bundlex.Output | ||
|
|
||
| @type compile_command :: %{ | ||
| required(:directory) => String.t(), | ||
| required(:command) => String.t(), | ||
| required(:file) => String.t(), | ||
| optional(:output) => String.t() | ||
| } | ||
|
|
||
| @doc """ | ||
| Generates LSP configuration files from a list of build commands. | ||
|
|
||
| ## Returns | ||
|
|
||
| `{:ok, [{:compile_commands_json, path} | {:compile_flags_txt, path}]}` | ||
| or `{:error, reason}` if all writes fail. | ||
| """ | ||
| @spec generate(commands :: [String.t()], project_dir :: String.t()) :: | ||
| {:ok, [{atom, String.t()}]} | {:error, String.t()} |
There was a problem hiding this comment.
I guess this module is not a part of public API, so it should have @moduledoc false and no function @doc
There was a problem hiding this comment.
You can add @moduledoc false and leave the current moduledoc content as a comment
Summary
--generate-lsp-configflag tomix compile.bundlexthat producescompile_commands.jsonandcompile_flags.txtfor clangd and other LSP toolsopt/symlinks for portabilitycompile_commands.jsonto the project root;compile_flags.txtis written to project root only (common flags intersection), avoiding pollution of VCS-tracked source directoriesjasonas a runtime dependency for JSON serializationNotes
compile_commands.jsonuses the actual compiler working directory (Path.dirname(source)) per entry so clangd resolves relative#includepaths correctlyskip_command?/1checks the basename of the first parsed token, so tools invoked via full path (e.g./usr/bin/ar) are correctly filtered outTest plan
mix compile.bundlex --generate-lsp-configin a project with C natives and verifycompile_commands.jsonandcompile_flags.txtare generated at the project rootcompile_flags.txtfiles are written inside source directories🤖 Generated with Claude Code