Skip to content

Commit 4d7b5c0

Browse files
committed
Doc updates: mention the LSP server
1 parent 745796f commit 4d7b5c0

7 files changed

Lines changed: 206 additions & 11 deletions

File tree

glean/lsp/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Glass, and currently provides the following LSP features:
1313
* Go to References
1414
* Type on Hover
1515
* Outline
16+
* Symbol Search
1617

1718
More features may be added in the future.
1819

glean/website/docs/building.md

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,31 @@ sidebar_label: Building Glean
55
---
66

77
import {OssOnly, FbInternalOnly} from 'internaldocs-fb-helpers';
8+
import {SrcFile,SrcFileLink} from '@site/utils';
89

910
## Introduction
1011

11-
Glean is written mainly in [Haskell](http://www.haskell.org/), and
12-
makes heavy use of
13-
[Thrift](https://github.com/facebookincubator/hsthrift) for data
14-
communication and serialization, so these are the main dependencies
15-
that are needed for building Glean.
12+
First we'll need to install some dependencies, and then we can build
13+
Glean. You can either build the latest stable release (easiest), or
14+
build the current code from the repository (harder), both methods are
15+
explained below.
1616

1717
## You will need
1818

1919
* Linux. The build is only tested on Linux so far; we hope to add
2020
support for other OSs in the future. We build on x86\_64 and arm64v8.
2121

22-
* [GHC](https://www.haskell.org/ghc/). To see which versions Glean is tested with, check the current [ci.yml](https://github.com/facebookincubator/Glean/blob/master/.github/workflows/ci.yml) script. We recommend installing GHC using [ghcup](https://www.haskell.org/ghcup/).
22+
* A working Haskell build environment including
23+
[GHC](https://www.haskell.org/ghc/) and Cabal. To see which versions
24+
Glean is tested with, check the current
25+
[ci.yml](https://github.com/facebookincubator/Glean/blob/master/.github/workflows/ci.yml)
26+
script.
2327

24-
* Cabal/cabal-install version 3.6 or later (older versions won't
25-
work). As for GHC, install these using ghcup.
28+
We recommend installing GHC and Cabal using [ghcup](https://www.haskell.org/ghcup/):
29+
30+
1. [Install ghcup](https://www.haskell.org/ghcup/)
31+
2. `ghcup install ghc 9.6.7`
32+
3. `ghcup install cabal`
2633

2734
Additional per-distribution setup follows.
2835

@@ -127,7 +134,7 @@ sudo dnf install \
127134

128135
## Build using Cabal
129136

130-
Glean can be built and installed entirely using `cabal`, with:
137+
To build and install the latest stable version of Glean:
131138

132139
```
133140
cabal install glean
@@ -143,7 +150,7 @@ The schema source files will be installed somewhere under
143150

144151
Installing with `cabal install` is sufficient if you want to:
145152

146-
* Just try it out
153+
* Just try it out, e.g. with the generic LSP server.
147154
* Index some source code in a supported language
148155
* Run queries against a DB, perhaps produced by someone else
149156
* Run a server (including Glass)
@@ -153,6 +160,13 @@ If you want to make changes to the schema or work on Glean itself then
153160
you will likely need to build from source: continue to the next
154161
section.
155162

163+
If you want to use the <SrcFileLink file="glean/lsp">generic LSP
164+
server</SrcFileLink>, build and install it with:
165+
166+
```
167+
cabal install glean-lsp
168+
```
169+
156170
## Building from the repository
157171

158172
Clone the repository:

glean/website/docs/docker.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
---
2+
id: docker
3+
title: Using the Docker image
4+
sidebar_label: Using the Docker image
5+
---
6+
7+
import {OssOnly, FbInternalOnly} from 'internaldocs-fb-helpers';
8+
import {SrcFile,SrcFileLink} from '@site/utils';
9+
10+
11+
:::warning
12+
13+
The Docker image is currently not working; however building Glean from
14+
scratch is now significantly easier than it was in the past, so we
15+
recommend just heading over to [Building Glean from
16+
Source](building.md).
17+
18+
:::
19+
20+
We provide a Docker image containing a pre-built set of Glean binaries
21+
that you can try out. These images are built automatically by a
22+
[Github Action](https://github.com/facebookincubator/Glean/blob/master/.github/workflows/glean-docker.yml).
23+
24+
Pull the latest demo Docker image (warning, this is around 7GB):
25+
26+
```
27+
docker pull ghcr.io/facebookincubator/glean/demo:latest
28+
```
29+
30+
Run it:
31+
32+
```
33+
docker run -it -p 8888:8888 ghcr.io/facebookincubator/glean/demo:latest
34+
```
35+
36+
:::info
37+
38+
What's in the image?
39+
40+
* A build of Glean, in `/glean-code`
41+
* The [flow](https://github.com/facebook/flow/) binary, in `/usr/local/bin/flow`
42+
* A checkout of [react](https://github.com/facebook/react/) in `/react-code`
43+
* A Glean database containing the Flow index of React in `/gleandb`
44+
45+
:::
46+
47+
Start the Glean [shell](shell.md):
48+
49+
```
50+
glean shell --db-root /glean-demo/db --schema /glean-demo/schema/source
51+
```
52+
53+
You should see:
54+
55+
```
56+
Glean Shell, built on <time>, from rev <unknown>
57+
type :help for help.
58+
>
59+
```
60+
61+
The demo image contains a pre-generated database containing the
62+
results of running the Flow indexer on the React repository:
63+
64+
```
65+
> :list
66+
react/0 (complete)
67+
Created: 2021-05-24T02:42:33Z (30 days, 9 hours ago)
68+
```
69+
70+
We can look at the contents:
71+
72+
```
73+
react> :db react
74+
using database react/0
75+
react> :stat
76+
flow.Declaration.3
77+
count: 26756
78+
size: 888756 (867.93 kB) 4.8248%
79+
...
80+
Total size: 17.57 MB
81+
```
82+
83+
## Running the server
84+
85+
Above we showed the shell reading the database from the filesystem
86+
directly. Instead we can run a server that the clients will interact
87+
with to make queries:
88+
89+
```
90+
glean-server --db-root /glean-demo/db --schema /glean-demo/schema/source --port 12345
91+
```
92+
93+
And now the shell can connect to the server:
94+
95+
```
96+
glean shell --service localhost:12345
97+
```
98+
99+
The commands work exactly the same as with local databases, but now it
100+
would also work over the network.
101+
102+
## Hyperlink demo
103+
104+
We have a small demo showing how Glean can enable code navigation. The <SrcFileLink file="glean/demo/Hyperlink.hs">glean-hyperlink</SrcFileLink> tool
105+
creates a webserver that serves hyperlinked source code using data
106+
from a specified Glean database.
107+
108+
We can navigate the React source code as follows. First start the
109+
Glean server:
110+
111+
```
112+
glean-server --db-root /glean-demo/db --schema /glean-demo/schema/source --port 12345
113+
```
114+
115+
Next start the Hyperlink server:
116+
117+
```
118+
glean-hyperlink --service localhost:12345 --db react --root /react-code --http 8888
119+
```
120+
121+
Now navigate to `http://localhost:8888` in your browser, and you
122+
should see a list of source files. Click on a file, and navigate
123+
around the code by clicking on a symbol reference to jump to its
124+
definition. Try something substantial like
125+
`react-dom/src/client/ReactDOMComponent.js`
126+
(http://localhost:8888/packages/react-dom/src/client/ReactDOMComponent.js) -
127+
note how Glean is accurately linking both local and imported
128+
symbols.

glean/website/docs/introduction.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ If you found yourself here by mistake, go back to the
2020

2121
</FbInternalOnly>
2222

23+
Just want to get started and read the docs later? Jump to [Building
24+
Glean](building.md).
25+
2326
## Overview
2427

2528
Glean is a system for working with facts about source code. It is
@@ -89,10 +92,27 @@ Glean consists of the following:
8992
language. Language-neutral abstractions can be built by <SrcFileLink
9093
file="glean/schema/source/codemarkup.angle">deriving facts using Angle</SrcFileLink>.
9194

95+
* **<SrcFileLink file="glean/glass">Glass</SrcFileLink>**,
96+
a language-agnostic symbol server. Glass is a server layer on top of
97+
Glean that exposes an API for performing common language-independent
98+
queries over Glean data, such as listing the symbols in a source
99+
file. Glass can be used as the basis for language tools; in fact
100+
Glass is used to power our Glean-based LSP server.
101+
102+
* A **<SrcFileLink file="glean/lsp">generic LSP
103+
server</SrcFileLink>**, built using Glean and Glass. This can be
104+
used to browse a large codebase in [VS
105+
Code](https://code.visualstudio.com/)[^3]: index the code using
106+
Glean, and connect VS Code to the LSP server to provide common
107+
code-navigation features such as go-to-definition, find-references,
108+
and symbol search.
109+
92110
[^1]: while we could in principle store the full AST, for efficiency
93111
reasons we typically store only the parts we need for the clients we
94112
want to support. Usually that means things like the locations of
95113
definitions and cross-references, but not expressions.
96114

97115
[^2]: If you're familiar with Datalog, it's worth noting that
98116
currently Angle is limited to non-recursive queries only.
117+
118+
[^3]: Or any IDE that supports LSP.

glean/website/docs/lsp.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
id: lsp
3+
title: Setting up the LSP server
4+
sidebar_label: Setting up the LSP server
5+
---
6+
7+
import {OssOnly, FbInternalOnly} from 'internaldocs-fb-helpers';
8+
import {SrcFile,SrcFileLink} from '@site/utils';
9+
10+
Glean comes with a generic LSP server that can be used for browsing
11+
large codebases in [VS Code](https://code.visualstudio.com/), or any
12+
IDE that supports the LSP protocol. This LSP server is intended to
13+
be used in a read-only way: it doesn't currently support updating
14+
the data if the source code is edited, but it can be useful for
15+
navigating a large codebase using familiar IDE features.
16+
17+
The steps to set it up are:
18+
19+
1. [Build and install Glean and glean-lsp](building.md)
20+
2. [Index your source code](indexer/intro.md) into a local DB
21+
2. Follow the instructions in `glean-lsp`'s <SrcFileLink
22+
file="glean/lsp/README.md">README.md</SrcFileLink> to set up the LSP server with VS Code, or your IDE.

glean/website/docs/trying.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ sidebar_label: Trying Glean
77
import {OssOnly, FbInternalOnly} from 'internaldocs-fb-helpers';
88
import {SrcFile,SrcFileLink} from '@site/utils';
99

10+
11+
:::warning
12+
13+
The Docker image is currently not working; however building Glean from
14+
scratch is now significantly easier than it was in the past, so we
15+
recommend just skipping ahead to [Building Glean from Source](building.md)
16+
17+
:::
18+
1019
We provide a Docker image containing a pre-built set of Glean binaries
1120
that you can try out. These images are built automatically by a
1221
[Github Action](https://github.com/facebookincubator/Glean/blob/master/.github/workflows/glean-docker.yml).

glean/website/sidebars.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ module.exports = {
1919
],
2020
external: [{
2121
'Quick Start': [
22-
'trying',
2322
'building',
23+
'lsp',
2424
'walkthrough',
25+
'docker',
2526
]
2627
}],
2728
}),

0 commit comments

Comments
 (0)