Files
github-merge-queue[bot] d1acc7fd75 deploy: 55825a4ee0
2026-04-11 14:49:38 +00:00

43 lines
9.8 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="`rust-project.json` file format."><title>project_model::project_json - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2"href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-77263533.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="project_model" data-themes="" data-resource-suffix="" data-rustdoc-version="1.94.1 (e408947bf 2026-03-25)" data-channel="1.94.1" data-search-js="search-9e2438ea.js" data-stringdex-js="stringdex-b897f86f.js" data-settings-js="settings-c38705f0.js" ><script src="../../static.files/storage-e2aeef58.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../static.files/main-7bab91a1.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-ffcac47a.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-eab170b8.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><rustdoc-topbar><h2><a href="#">Module project_json</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../project_model/index.html">project_<wbr>model</a><span class="version">0.0.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module project_<wbr>json</a></h2><h3><a href="#modules">Module Items</a></h3><ul class="block"><li><a href="#modules" title="Modules">Modules</a></li><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#enums" title="Enums">Enums</a></li><li><a href="#functions" title="Functions">Functions</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="../index.html">In crate project_<wbr>model</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../index.html">project_model</a></div><h1>Module <span>project_<wbr>json</span>&nbsp;<button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/project_model/project_json.rs.html#1-594">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p><code>rust-project.json</code> file format.</p>
<p>This format is spiritually a serialization of <code>base_db::CrateGraph</code>. The
idea here is that people who do not use Cargo, can instead teach their build
system to generate <code>rust-project.json</code> which can be ingested by
rust-analyzer.</p>
<p>This short file is a somewhat big conceptual piece of the architecture of
rust-analyzer, so its worth elaborating on the underlying ideas and
motivation.</p>
<p>For rust-analyzer to function, it needs some information about the project.
Specifically, it maintains an in-memory data structure which lists all the
crates (compilation units) and dependencies between them. This is necessary
a global singleton, as we do want, eg, find usages to always search across
the whole project, rather than just in the “current” crate.</p>
<p>Normally, we get this “crate graph” by calling <code>cargo metadata --message-format=json</code> for each cargo workspace and merging results. This
works for your typical cargo project, but breaks down for large folks who
have a monorepo with an infinite amount of Rust code which is built with bazel or
some such.</p>
<p>To support this use case, we need to make <em>something</em> configurable. To avoid
a <a href="https://lwn.net/Articles/336262/">midlayer mistake</a>, we allow configuring
the lowest possible layer. <code>ProjectJson</code> is essentially a hook to just set
that global singleton in-memory data structure. It is optimized for power,
not for convenience (youd be using cargo anyway if you wanted nice things,
right? :)</p>
<p><code>rust-project.json</code> also isnt necessary a file. Architecturally, we support
any convenient way to specify this data, which today is:</p>
<ul>
<li>file on disk</li>
<li>a field in the config (ie, you can send a JSON request with the contents
of <code>rust-project.json</code> to rust-analyzer, no need to write anything to disk)</li>
</ul>
<p>Another possible thing we dont do today, but which would be totally valid,
is to add an extension point to VS Code extension to register custom
project.</p>
<p>In general, it is assumed that if you are going to use <code>rust-project.json</code>,
youd write a fair bit of custom code gluing your build system to ra through
this JSON format. This logic can take form of a VS Code extension, or a
proxy process which injects data into “configure” LSP request, or maybe just
a simple build system rule to generate the file.</p>
<p>In particular, the logic for lazily loading parts of the monorepo as the
user explores them belongs to that extension (its totally valid to change
rust-project.json over time via configuration request!)</p>
</div></details><h2 id="modules" class="section-header">Modules<a href="#modules" class="anchor">§</a></h2><dl class="item-table"><dt><a class="mod" href="cfg_/index.html" title="mod project_model::project_json::cfg_">cfg_</a><span title="Restricted Visibility">&nbsp;🔒</span> </dt></dl><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><dl class="item-table"><dt><a class="struct" href="struct.Build.html" title="struct project_model::project_json::Build">Build</a></dt><dd>Additional, build-specific data about a crate.</dd><dt><a class="struct" href="struct.BuildData.html" title="struct project_model::project_json::BuildData">Build<wbr>Data</a><span title="Restricted Visibility">&nbsp;🔒</span> </dt><dt><a class="struct" href="struct.CfgList.html" title="struct project_model::project_json::CfgList">CfgList</a><span title="Restricted Visibility">&nbsp;🔒</span> </dt><dt><a class="struct" href="struct.Crate.html" title="struct project_model::project_json::Crate">Crate</a></dt><dd>A crate points to the root module of a crate and lists the dependencies of the crate. This is
useful in creating the crate graph.</dd><dt><a class="struct" href="struct.CrateArrayIdx.html" title="struct project_model::project_json::CrateArrayIdx">Crate<wbr>Array<wbr>Idx</a></dt><dd>Identifies a crate by position in the crates array.</dd><dt><a class="struct" href="struct.CrateData.html" title="struct project_model::project_json::CrateData">Crate<wbr>Data</a><span title="Restricted Visibility">&nbsp;🔒</span> </dt><dt><a class="struct" href="struct.CrateSource.html" title="struct project_model::project_json::CrateSource">Crate<wbr>Source</a><span title="Restricted Visibility">&nbsp;🔒</span> </dt><dt><a class="struct" href="struct.Dep.html" title="struct project_model::project_json::Dep">Dep</a><span title="Restricted Visibility">&nbsp;🔒</span> </dt><dt><a class="struct" href="struct.ProjectJson.html" title="struct project_model::project_json::ProjectJson">Project<wbr>Json</a></dt><dd>Roots and crates that compose this Rust project.</dd><dt><a class="struct" href="struct.ProjectJsonData.html" title="struct project_model::project_json::ProjectJsonData">Project<wbr>Json<wbr>Data</a></dt><dt><a class="struct" href="struct.Runnable.html" title="struct project_model::project_json::Runnable">Runnable</a></dt><dd>A template-like structure for describing runnables.</dd><dt><a class="struct" href="struct.RunnableData.html" title="struct project_model::project_json::RunnableData">Runnable<wbr>Data</a><span title="Restricted Visibility">&nbsp;🔒</span> </dt></dl><h2 id="enums" class="section-header">Enums<a href="#enums" class="anchor">§</a></h2><dl class="item-table"><dt><a class="enum" href="enum.EditionData.html" title="enum project_model::project_json::EditionData">Edition<wbr>Data</a><span title="Restricted Visibility">&nbsp;🔒</span> </dt><dt><a class="enum" href="enum.RunnableKind.html" title="enum project_model::project_json::RunnableKind">Runnable<wbr>Kind</a></dt><dd>The kind of runnable.</dd><dt><a class="enum" href="enum.RunnableKindData.html" title="enum project_model::project_json::RunnableKindData">Runnable<wbr>Kind<wbr>Data</a><span title="Restricted Visibility">&nbsp;🔒</span> </dt><dt><a class="enum" href="enum.TargetKindData.html" title="enum project_model::project_json::TargetKindData">Target<wbr>Kind<wbr>Data</a><span title="Restricted Visibility">&nbsp;🔒</span> </dt></dl><h2 id="functions" class="section-header">Functions<a href="#functions" class="anchor">§</a></h2><dl class="item-table"><dt><a class="fn" href="fn.deserialize_crate_name.html" title="fn project_model::project_json::deserialize_crate_name">deserialize_<wbr>crate_<wbr>name</a><span title="Restricted Visibility">&nbsp;🔒</span> </dt><dt><a class="fn" href="fn.serialize_crate_name.html" title="fn project_model::project_json::serialize_crate_name">serialize_<wbr>crate_<wbr>name</a><span title="Restricted Visibility">&nbsp;🔒</span> </dt></dl></section></div></main></body></html>