Skip to content

Commit 6c9b0f3

Browse files
docs: Document project root requirement + troubleshooting (#418)
The project root part is important, so let's emphasize that and document common troubleshooting steps if precise code intel doesn't show up.
1 parent 2e4f203 commit 6c9b0f3

File tree

2 files changed

+122
-1
lines changed

2 files changed

+122
-1
lines changed

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ from the project root like so:
7979
scip-clang --compdb-path=path/to/compile_commands.json
8080
```
8181

82+
> **WARNING:** You must invoke scip-clang from the project root,
83+
> not from a subdirectory, even when you only want to index a subdirectory.
84+
> If you only want to index a subdirectory, filter out unnecessary
85+
> entries in the compilation database.
86+
8287
If you see any errors, see the
8388
[Troubleshooting](#troubleshooting) section.
8489

@@ -165,9 +170,15 @@ For example:
165170
```bash
166171
# Using jq (https://github.com/stedolan/jq)
167172
jq '.[0:5]' build/compile_commands.json > build/small_compdb.json
173+
# Invoke scip-clang from the project root
168174
scip-clang --compdb-path=build/small_compdb.json --show-compiler-diagnostics
169175
```
170176

177+
> **WARNING:** You must invoke scip-clang from the project root,
178+
> not from a subdirectory, even when you only want to index a subdirectory.
179+
> If you only want to index a subdirectory, filter out unnecessary
180+
> entries in the compilation database.
181+
171182
If there are errors about missing system or SDK headers,
172183
install the relevant system dependencies.
173184

docs/Troubleshooting.md

+111-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,116 @@ The most common problems are timeouts, crashes,
99
and lack of sufficient space for [IPC][] (in Docker),
1010
which are discussed below.
1111

12+
## Missing code intel
13+
14+
In certain cases, precise code intel may be entirely missing despite
15+
creating and uploading an index successfully.
16+
There are two common failure modes for this.
17+
18+
### Possibility 1: Missing documents in SCIP index
19+
20+
A SCIP index stores documents containing definition and reference
21+
information for each file on disk.
22+
23+
[SCIP CLI]: https://github.com/sourcegraph/scip/releases
24+
25+
You can inspect the documents using the [SCIP CLI][]:
26+
27+
```bash
28+
scip print --json index.scip | jq .documents
29+
```
30+
31+
If this prints a non-empty array, see the [troubleshooting steps for possibility 2](#possibility-2-incorrect-document-paths-in-scip-index).
32+
33+
If this prints `null` or an empty array, it's likely
34+
that the indexer was invoked from a directory other than the project root.
35+
You can double-check this using:
36+
37+
```bash
38+
scip print --json index.scip | jq .metadata.projectRoot
39+
```
40+
41+
If this points to a subdirectory and not the project root,
42+
then the scip-clang invocation was incorrect.
43+
44+
Here is an example of a common project structure:
45+
46+
```
47+
/home/me/myproject
48+
+--- .git/
49+
+--- README.md
50+
+--- src/
51+
| |
52+
| +--- A.cc
53+
| +--- subdir/
54+
| +--- B.cc
55+
+--- build/ (.gitignored directory)
56+
```
57+
58+
In this case, `scip-clang` **must** be invoked from `/home/me/myproject`,
59+
regardless of the contents of the compilation database file (`compile_commands.json`).
60+
61+
If you want to only index a subset of files (say under `src/subdir`),
62+
then reduce the size of the compilation database by selecting only specific files.
63+
64+
For example, if the compilation database looks like the following:
65+
66+
```json
67+
[
68+
{
69+
"directory": "/home/me/myproject/build",
70+
"file": "/home/me/myproject/src/A.cc",
71+
"command": "some stuff here"
72+
},
73+
{
74+
"directory": "/home/me/myproject/build",
75+
"file": "/home/me/myproject/src/subdir/B.cc",
76+
"command": "some stuff here"
77+
}
78+
]
79+
```
80+
81+
And if you only want to index the files inside `src/subdir`, then run:
82+
83+
```bash
84+
cat compile_commands.json | jq '.[] | select(.file | contains("src/subdir/"))' > minimal.json
85+
scip-clang --compdb-path=minimal.json <other args>
86+
```
87+
88+
### Possibility 2: Incorrect document paths in SCIP index
89+
90+
If the output of the following command using the [SCIP CLI][]
91+
92+
```bash
93+
scip print --json index.scip | jq .documents
94+
```
95+
96+
is a non-empty array, and you're still not seeing precise code intel
97+
in the Sourcegraph UI, it's possible the document paths stored in the index
98+
do not match the actual paths on disk.
99+
100+
Double-check that the various `relativePath` keys in the `documents`
101+
array correspond to actual files on disk relative to the `projectRoot` path.
102+
103+
- If the `relativePath` values are incorrect, then double-check if there
104+
are any symlinks present in the project layout which may potentially
105+
be causing incorrect path determination.
106+
- If the `relativePath` values are correct, but you still don't see any
107+
precise code intel for that file, check that `occurrences` arrays for
108+
various documents are non-empty.
109+
- If the `occurrences` arrays are empty, then report it as an
110+
indexer bug.
111+
- If the `occurrences` arrays are non-empty, then you can double-check
112+
the precise code intel using the debug view in the Sourcegraph UI.
113+
114+
Click on the 🧠 icon near the top-right of the file contents view
115+
for the commit for which the index was uploaded,
116+
and click on 'Display debug information'.
117+
![Debug information for a SCIP index](https://github.com/sourcegraph/scip-clang/assets/93103176/58becf36-5524-40f6-87b9-a72bc00b1e04).
118+
119+
Then try hovering over entities which have `^^^` markers below them;
120+
you should see precise code intel.
121+
12122
## Timeouts
13123

14124
scip-clang sets a timeout for indexing an individual translation unit,
@@ -78,4 +188,4 @@ There are 3 possible fixes for this:
78188
3. Reducing the number of workers:
79189
scip-clang will automatically use fewer workers if possible,
80190
but will print a warning when it does so.
81-
This warning can be suppressed by explicitly passing `--jobs N`.
191+
This warning can be suppressed by explicitly passing `--jobs N`.

0 commit comments

Comments
 (0)