You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 28, 2022. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+40-13Lines changed: 40 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,27 +29,31 @@ Running `lsp-adapter --help` shows you some of its options:
29
29
Usage: lsp-adapter [OPTIONS] LSP_COMMAND_ARGS...
30
30
31
31
Options:
32
+
-beforeInitializeHook string
33
+
A program to run after cloning the repository, but before the 'initialize' call is forwarded to the language server. (For example, you can use this to run a script to install dependencies for the project). The program's cwd will be the workspace's cache directory, and it will also be passed the cache directory as an argument.
(HACK) If non-empty, send 'textDocument/didOpen' notifications with the specified language field (e.x. 'python') to the language server for every file.
37
+
(HACK) If non-empty, send 'textDocument/didOpen' notifications with the specified language field (e.x. 'python') to the language server for every file.
36
38
-glob string
37
-
A colon (:) separated list of file globs to sync locally. By default we place all files into the workspace, but some language servers may only look at a subset of files. Specifying this allows us to avoid syncing all files. Note: This is done by basename only.
39
+
A colon (:) separated list of file globs to sync locally. By default we place all files into the workspace, but some language servers may only look at a subset of files. Specifying this allows us to avoid syncing all files. Note: This is done by basename only.
38
40
-jsonrpc2IDRewrite string
39
-
(HACK) Rewrite jsonrpc2 ID. none (default) is no rewriting. string will use a string ID. number will use a number ID. Useful for language servers with non-spec complaint JSONRPC2 implementations. (default "none")
41
+
(HACK) Rewrite jsonrpc2 ID. none (default) is no rewriting. string will use a string ID. number will use number ID. Useful for language servers with non-spec complaint JSONRPC2 implementations. (default "none")
42
+
-pprofAddr string
43
+
server listen address for pprof
40
44
-proxyAddress string
41
-
proxy server listen address (tcp) (default "127.0.0.1:8080")
45
+
proxy server listen address (tcp) (default "127.0.0.1:8080")
42
46
-trace
43
-
trace logs to stderr
47
+
trace logs to stderr (default true)
44
48
```
49
+
45
50
## How to Use `lsp-adapter`
46
51
47
52
`lsp-adapter` proxies requests between your Sourcegraph instance and the language server, and modifies them in such a way that allows for the two to communicate correctly. In order to do this, we need to know
48
53
49
54
- How to connect `lsp-adapter` to the language server
50
55
- How to connect to your Sourcegraph instance to `lsp-adapter`
51
56
52
-
53
57
### Connect `lsp-adapter` to the Language Server
54
58
55
59
`lsp-adapter` can talk to language servers over standard I/O.
@@ -64,19 +68,19 @@ lsp-adapter rls
64
68
65
69
Any stderr output from the binary will also appear in `lsp-adapter`'s logs.
66
70
67
-
68
71
### Connect Sourcegraph to `lsp-adapter`
69
72
70
-
1. Use the `-proxyAddress` flag to tell `lsp-adapter` what address to listen for connections from Sourcegraph on. For example, I can tell `lsp-adapter` to listen on my local `8080` port with `-proxyAddress=127.0.0.1:8080`.
73
+
1.Use the `-proxyAddress` flag to tell `lsp-adapter` what address to listen for connections from Sourcegraph on. For example, I can tell `lsp-adapter` to listen on my local `8080` port with `-proxyAddress=127.0.0.1:8080`.
71
74
72
-
2. We then need to add a new entry to the `"langservers"` field in the site configuration in order to point Sourcegraph at `lsp-adapter` (similar to the steps in [this document](https://about.sourcegraph.com/docs/code-intelligence/install-manual)). For example, if `lsp-adapter` is connected to the Rust language server, and the `lsp-adapter` itself is listening on `127.0.0.1:8080`:
75
+
2.We then need to add a new entry to the `"langservers"` field in the site configuration in order to point Sourcegraph at `lsp-adapter` (similar to the steps in [this document](https://about.sourcegraph.com/docs/code-intelligence/install-manual)). For example, if `lsp-adapter` is connected to the Rust language server, and the `lsp-adapter` itself is listening on `127.0.0.1:8080`:
73
76
74
77
```json
75
78
{
76
-
"language": "rust",
77
-
"address": "tcp://127.0.0.1:8080"
79
+
"language": "rust",
80
+
"address": "tcp://127.0.0.1:8080"
78
81
}
79
82
```
83
+
80
84
would be the new entry that needs to be added to the `"langservers"` field.
81
85
82
86
## Example Commands
@@ -111,7 +115,30 @@ Most language servers will only ever look at files that match a set of known pat
111
115
112
116
Some language servers do not follow the LSP spec correctly and refuse to work unless the `textDocument/didOpen` notification has been sent. See [this commit](https://github.com/sourcegraph/lsp-adapter/commit/1228a1fbaf102aa44575cec6802a5a211d117ee1) for more context. If the language server that you’re trying to use has this issue, try setting the `didOpenLanguage` flag (example: if a python language server had this issue - use `./lsp-adapter -didOpenLanguage=python ...`) to work around it.
113
117
114
-
115
118
## JSONRPC2 ID Rewrite Hack
116
119
117
120
Some language servers do not follow the JSONRPC2 spec correctly and fail if the Request ID is not a number of string. If the language server that you’re trying to use has this issue, try setting the `jsonrpc2IDRewrite` flag (example: if a rust language server had this issue - use `./lsp-adapter -jsonrpc2IDRewrite=number ...`) to work around it.
121
+
122
+
## Before Initialization Hook
123
+
124
+
Some language servers need to run setup scripts (to install dependencies, for example) in order to provide code intelligence. By using the `-beforeInitializeHook` flag, you can specify a program/script that will run after the repository is cloned to workspace's cache directory, but before the language server receives the `initalize` request. The program's `cwd` will be the cache directory (which will also be passed as an argument for convenience).
125
+
126
+
For example, if you have the following script named `hook.sh`:
127
+
128
+
```shell
129
+
#!/bin/sh
130
+
set -x
131
+
echo$(pwd)
132
+
```
133
+
134
+
After specifying the hook via `lsp-adapter -beforeInitializeHook='/test.sh'` You will see output like
135
+
136
+
```shell
137
+
2018/06/20 21:11:45 uris.go:25: Cloned workspace to /tmp/proxy-cache/3bb76102-a73b-4442-a03e-930c59e1fdcb
Copy file name to clipboardExpand all lines: proxy.go
+6Lines changed: 6 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -32,6 +32,7 @@ var (
32
32
didOpenLanguage=flag.String("didOpenLanguage", "", "(HACK) If non-empty, send 'textDocument/didOpen' notifications with the specified language field (e.x. 'python') to the language server for every file.")
33
33
jsonrpc2IDRewrite=flag.String("jsonrpc2IDRewrite", "none", "(HACK) Rewrite jsonrpc2 ID. none (default) is no rewriting. string will use a string ID. number will use number ID. Useful for language servers with non-spec complaint JSONRPC2 implementations.")
34
34
glob=flag.String("glob", "", "A colon (:) separated list of file globs to sync locally. By default we place all files into the workspace, but some language servers may only look at a subset of files. Specifying this allows us to avoid syncing all files. Note: This is done by basename only.")
35
+
beforeInitHook=flag.String("beforeInitializeHook", "", "A program to run after cloning the repository, but before the 'initialize' call is forwarded to the language server. (For example, you can use this to run a script to install dependencies for the project). The program's cwd will be the workspace's cache directory, and it will also be passed the cache directory as an argument.")
35
36
trace=flag.Bool("trace", true, "trace logs to stderr")
0 commit comments