aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--.vscode/extensions.json9
-rw-r--r--.vscode/launch.json340
-rw-r--r--.vscode/tasks.json47
-rw-r--r--DEBUGGING.md62
-rw-r--r--README.md11
-rw-r--r--editors/code/src/config.ts7
7 files changed, 470 insertions, 7 deletions
diff --git a/.gitignore b/.gitignore
index 68158e41c..25e2b01b4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,5 @@
2crates/*/target 2crates/*/target
3**/*.rs.bk 3**/*.rs.bk
4.idea/* 4.idea/*
5.vscode/*
6*.log 5*.log
7*.iml 6*.iml
diff --git a/.vscode/extensions.json b/.vscode/extensions.json
new file mode 100644
index 000000000..027eeabc4
--- /dev/null
+++ b/.vscode/extensions.json
@@ -0,0 +1,9 @@
1{
2 // See http://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
3 // Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
4
5 // List of extensions which should be recommended for users of this workspace.
6 "recommendations": ["vadimcn.vscode-lldb"],
7 // List of extensions recommended by VS Code that should not be recommended for users of this workspace.
8 "unwantedRecommendations": []
9}
diff --git a/.vscode/launch.json b/.vscode/launch.json
new file mode 100644
index 000000000..9aafc8bd3
--- /dev/null
+++ b/.vscode/launch.json
@@ -0,0 +1,340 @@
1{
2 // Use IntelliSense to learn about possible attributes.
3 // Hover to view descriptions of existing attributes.
4 // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5 "version": "0.2.0",
6 "configurations": [
7 {
8 "name": "Debug Extension",
9 "type": "extensionHost",
10 "request": "launch",
11 "runtimeExecutable": "${execPath}",
12 "args": [
13 "--extensionDevelopmentPath=${workspaceFolder}/editors/code",
14 "--disable-extensions"
15 ],
16 "env": {
17 "__RA_LSP_SERVER_DEBUG": "${workspaceFolder}/target/debug/ra_lsp_server"
18 },
19 "outFiles": ["${workspaceFolder}/editors/code/out/**/*.js"],
20 "preLaunchTask": "Build All"
21 },
22 {
23 "name": "Debug Lsp Server",
24 "type": "lldb",
25 "request": "attach",
26 "program": "${workspaceFolder}/target/debug/ra_lsp_server",
27 "pid": "${command:pickMyProcess}",
28 "sourceLanguages": ["rust"]
29 },
30 {
31 "type": "lldb",
32 "request": "launch",
33 "name": "Debug unit tests in library 'gen_lsp_server'",
34 "cargo": {
35 "args": ["test", "--no-run", "--lib", "--package=gen_lsp_server"],
36 "filter": {
37 "kind": "lib"
38 }
39 },
40 "args": [],
41 "cwd": "${workspaceFolder}"
42 },
43 {
44 "type": "lldb",
45 "request": "launch",
46 "name": "Debug unit tests in library 'ra_analysis'",
47 "cargo": {
48 "args": ["test", "--no-run", "--lib", "--package=ra_analysis"],
49 "filter": {
50 "kind": "lib"
51 }
52 },
53 "args": [],
54 "cwd": "${workspaceFolder}"
55 },
56 {
57 "type": "lldb",
58 "request": "launch",
59 "name": "Debug test 'tests'",
60 "cargo": {
61 "args": ["build", "--test=tests", "--package=ra_analysis"],
62 "filter": {
63 "kind": "bin"
64 }
65 },
66 "args": [],
67 "cwd": "${workspaceFolder}"
68 },
69 {
70 "type": "lldb",
71 "request": "launch",
72 "name": "Debug unit tests in test 'tests'",
73 "cargo": {
74 "args": ["test", "--no-run", "--test=tests", "--package=ra_analysis"],
75 "filter": {
76 "kind": "bin"
77 }
78 },
79 "args": [],
80 "cwd": "${workspaceFolder}"
81 },
82 {
83 "type": "lldb",
84 "request": "launch",
85 "name": "Debug unit tests in library 'ra_hir'",
86 "cargo": {
87 "args": ["test", "--no-run", "--lib", "--package=ra_hir"],
88 "filter": {
89 "kind": "lib"
90 }
91 },
92 "args": [],
93 "cwd": "${workspaceFolder}"
94 },
95 {
96 "type": "lldb",
97 "request": "launch",
98 "name": "Debug unit tests in library 'ra_db'",
99 "cargo": {
100 "args": ["test", "--no-run", "--lib", "--package=ra_db"],
101 "filter": {
102 "kind": "lib"
103 }
104 },
105 "args": [],
106 "cwd": "${workspaceFolder}"
107 },
108 {
109 "type": "lldb",
110 "request": "launch",
111 "name": "Debug unit tests in library 'ra_editor'",
112 "cargo": {
113 "args": ["test", "--no-run", "--lib", "--package=ra_editor"],
114 "filter": {
115 "kind": "lib"
116 }
117 },
118 "args": [],
119 "cwd": "${workspaceFolder}"
120 },
121 {
122 "type": "lldb",
123 "request": "launch",
124 "name": "Debug unit tests in library 'ra_syntax'",
125 "cargo": {
126 "args": ["test", "--no-run", "--lib", "--package=ra_syntax"],
127 "filter": {
128 "kind": "lib"
129 }
130 },
131 "args": [],
132 "cwd": "${workspaceFolder}"
133 },
134 {
135 "type": "lldb",
136 "request": "launch",
137 "name": "Debug test 'test'",
138 "cargo": {
139 "args": ["build", "--test=test", "--package=ra_syntax"],
140 "filter": {
141 "kind": "bin"
142 }
143 },
144 "args": [],
145 "cwd": "${workspaceFolder}"
146 },
147 {
148 "type": "lldb",
149 "request": "launch",
150 "name": "Debug unit tests in test 'test'",
151 "cargo": {
152 "args": ["test", "--no-run", "--test=test", "--package=ra_syntax"],
153 "filter": {
154 "kind": "bin"
155 }
156 },
157 "args": [],
158 "cwd": "${workspaceFolder}"
159 },
160 {
161 "type": "lldb",
162 "request": "launch",
163 "name": "Debug unit tests in library 'test_utils'",
164 "cargo": {
165 "args": ["test", "--no-run", "--lib", "--package=test_utils"],
166 "filter": {
167 "kind": "lib"
168 }
169 },
170 "args": [],
171 "cwd": "${workspaceFolder}"
172 },
173 {
174 "type": "lldb",
175 "request": "launch",
176 "name": "Debug executable 'ra_cli'",
177 "cargo": {
178 "args": ["build", "--bin=ra_cli", "--package=ra_cli"],
179 "filter": {
180 "kind": "bin"
181 }
182 },
183 "args": [],
184 "cwd": "${workspaceFolder}"
185 },
186 {
187 "type": "lldb",
188 "request": "launch",
189 "name": "Debug unit tests in executable 'ra_cli'",
190 "cargo": {
191 "args": ["test", "--no-run", "--bin=ra_cli", "--package=ra_cli"],
192 "filter": {
193 "kind": "bin"
194 }
195 },
196 "args": [],
197 "cwd": "${workspaceFolder}"
198 },
199 {
200 "type": "lldb",
201 "request": "launch",
202 "name": "Debug unit tests in library 'tools'",
203 "cargo": {
204 "args": ["test", "--no-run", "--lib", "--package=tools"],
205 "filter": {
206 "kind": "lib"
207 }
208 },
209 "args": [],
210 "cwd": "${workspaceFolder}"
211 },
212 {
213 "type": "lldb",
214 "request": "launch",
215 "name": "Debug executable 'tools'",
216 "cargo": {
217 "args": ["build", "--bin=tools", "--package=tools"],
218 "filter": {
219 "kind": "bin"
220 }
221 },
222 "args": [],
223 "cwd": "${workspaceFolder}"
224 },
225 {
226 "type": "lldb",
227 "request": "launch",
228 "name": "Debug unit tests in executable 'tools'",
229 "cargo": {
230 "args": ["test", "--no-run", "--bin=tools", "--package=tools"],
231 "filter": {
232 "kind": "bin"
233 }
234 },
235 "args": [],
236 "cwd": "${workspaceFolder}"
237 },
238 {
239 "type": "lldb",
240 "request": "launch",
241 "name": "Debug test 'cli'",
242 "cargo": {
243 "args": ["build", "--test=cli", "--package=tools"],
244 "filter": {
245 "kind": "bin"
246 }
247 },
248 "args": [],
249 "cwd": "${workspaceFolder}"
250 },
251 {
252 "type": "lldb",
253 "request": "launch",
254 "name": "Debug unit tests in test 'cli'",
255 "cargo": {
256 "args": ["test", "--no-run", "--test=cli", "--package=tools"],
257 "filter": {
258 "kind": "bin"
259 }
260 },
261 "args": [],
262 "cwd": "${workspaceFolder}"
263 },
264 {
265 "type": "lldb",
266 "request": "launch",
267 "name": "Debug unit tests in library 'ra_lsp_server'",
268 "cargo": {
269 "args": ["test", "--no-run", "--lib", "--package=ra_lsp_server"],
270 "filter": {
271 "kind": "lib"
272 }
273 },
274 "args": [],
275 "cwd": "${workspaceFolder}"
276 },
277 {
278 "type": "lldb",
279 "request": "launch",
280 "name": "Debug executable 'ra_lsp_server'",
281 "cargo": {
282 "args": ["build", "--bin=ra_lsp_server", "--package=ra_lsp_server"],
283 "filter": {
284 "kind": "bin"
285 }
286 },
287 "args": [],
288 "cwd": "${workspaceFolder}"
289 },
290 {
291 "type": "lldb",
292 "request": "launch",
293 "name": "Debug unit tests in executable 'ra_lsp_server'",
294 "cargo": {
295 "args": [
296 "test",
297 "--no-run",
298 "--bin=ra_lsp_server",
299 "--package=ra_lsp_server"
300 ],
301 "filter": {
302 "kind": "bin"
303 }
304 },
305 "args": [],
306 "cwd": "${workspaceFolder}"
307 },
308 {
309 "type": "lldb",
310 "request": "launch",
311 "name": "Debug test 'heavy_tests'",
312 "cargo": {
313 "args": ["build", "--test=heavy_tests", "--package=ra_lsp_server"],
314 "filter": {
315 "kind": "bin"
316 }
317 },
318 "args": [],
319 "cwd": "${workspaceFolder}"
320 },
321 {
322 "type": "lldb",
323 "request": "launch",
324 "name": "Debug unit tests in test 'heavy_tests'",
325 "cargo": {
326 "args": [
327 "test",
328 "--no-run",
329 "--test=heavy_tests",
330 "--package=ra_lsp_server"
331 ],
332 "filter": {
333 "kind": "bin"
334 }
335 },
336 "args": [],
337 "cwd": "${workspaceFolder}"
338 }
339 ]
340}
diff --git a/.vscode/tasks.json b/.vscode/tasks.json
new file mode 100644
index 000000000..045cee326
--- /dev/null
+++ b/.vscode/tasks.json
@@ -0,0 +1,47 @@
1// See https://go.microsoft.com/fwlink/?LinkId=733558
2// for the documentation about the tasks.json format
3{
4 "version": "2.0.0",
5 "tasks": [
6 {
7 "type": "npm",
8 "script": "compile",
9 "label": "Build Extension",
10 "problemMatcher": {
11 "owner": "typescript",
12 "pattern": "$tsc",
13 "fileLocation": ["relative", "${workspaceRoot}/editors/code"]
14 },
15 "path": "editors/code/"
16 },
17 {
18 "label": "Build Lsp",
19 "type": "shell",
20 "command": "cargo build",
21 "problemMatcher": {
22 "owner": "rust",
23 "fileLocation": ["relative", "${workspaceRoot}"],
24 "pattern": [
25 {
26 "regexp": "^(warning|warn|error)(?:\\[(.*?)\\])?: (.*)$",
27 "severity": 1,
28 "code": 2,
29 "message": 3
30 },
31 {
32 "regexp": "^[\\s->=]*(.*?):(\\d*):(\\d*)\\s*$",
33 "file": 1,
34 "line": 2,
35 "column": 3
36 }
37 ]
38 }
39 },
40 {
41 "label": "Build All",
42 "group": "build",
43 "dependsOn": ["Build Extension", "Build Lsp"],
44 "problemMatcher": []
45 }
46 ]
47}
diff --git a/DEBUGGING.md b/DEBUGGING.md
new file mode 100644
index 000000000..0fa8ae29c
--- /dev/null
+++ b/DEBUGGING.md
@@ -0,0 +1,62 @@
1# Debugging vs Code plugin and the Language Server
2
3Install [LLDB](https://lldb.llvm.org/) and the [LLDB Extension](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb).
4
5Checkout rust rust-analyzer and open it in vscode.
6
7```
8$ git clone https://github.com/rust-analyzer/rust-analyzer.git --depth 1
9$ cd rust-analyzer
10$ code .
11```
12
13- To attach to the `lsp server` in linux you'll have to run:
14
15 `echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope`
16
17 This enables ptrace on non forked processes
18
19- Ensure the dependencies for the extension are installed, run the `npm: install - editors/code` task in vscode.
20
21- Launch the `Debug Extension`, this will build the extension and the `lsp server`.
22
23- A new instance of vscode with `[Extension Development Host]` in the title.
24
25 Don't worry about disabling `rls` all other extensions will be disabled but this one.
26
27- In the new vscode instance open a rust project, and navigate to a rust file
28
29- In the original vscode start an additional debug session (the three periods in the launch) and select `Debug Lsp Server`.
30
31- A list of running processes should appear select the `ra_lsp_server` from this repo.
32
33- Navigate to `crates/ra_lsp_server/src/main_loop.rs` and add a breakpoint to the `on_task` function.
34
35- Go back to the `[Extension Development Host]` instance and hover over a rust variable and your breakpoint should hit.
36
37## Demo
38
39![demonstration of debugging](./images/Rls_Debug.gif)
40
41## Troubleshooting
42
43### Can't find the `ra_lsp_server` process
44
45It could be a case of just jumping the gun.
46
47The `ra_lsp_server` is only started once the `onLanguage:rust` activation.
48
49Make sure you open a rust file in the `[Extension Development Host]` and try again.
50
51### Can't connect to `ra_lsp_server`
52
53Make sure you have run `echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope`.
54
55By default this should reset back to 1 everytime you log in.
56
57### Breakpoints are never being hit
58
59Check your version of `lldb` if it's version 6 and lower use the `classic` adapter type.
60It's `lldb.adapterType` in settings file.
61
62If you're running `lldb` version 7 change the lldb adapter type to `bundled` or `native`.
diff --git a/README.md b/README.md
index cbb72c8cf..304c2620a 100644
--- a/README.md
+++ b/README.md
@@ -14,7 +14,6 @@ Work on the Rust Analyzer is sponsored by
14 14
15[![Ferrous Systems](https://ferrous-systems.com/images/ferrous-logo-text.svg)](https://ferrous-systems.com/) 15[![Ferrous Systems](https://ferrous-systems.com/images/ferrous-logo-text.svg)](https://ferrous-systems.com/)
16 16
17
18## Quick Start 17## Quick Start
19 18
20Rust analyzer builds on Rust >= 1.31.0 and uses the 2018 edition. 19Rust analyzer builds on Rust >= 1.31.0 and uses the 2018 edition.
@@ -36,6 +35,11 @@ $ cargo install --path crates/ra_lsp_server
36See [these instructions](./editors/README.md) for VS Code setup and the list of 35See [these instructions](./editors/README.md) for VS Code setup and the list of
37features (some of which are VS Code specific). 36features (some of which are VS Code specific).
38 37
38## Debugging
39
40See [these instructions](./DEBUGGING.md) for VS Code setup and the list of
41features (some of which are VS Code specific).
42
39## Current Status and Plans 43## Current Status and Plans
40 44
41Rust analyzer aims to fill the same niche as the official [Rust Language 45Rust analyzer aims to fill the same niche as the official [Rust Language
@@ -53,11 +57,11 @@ The near/mid term plan is to work independently of the main rustc compiler and
53implement at least simplistic versions of name resolution, macro expansion and 57implement at least simplistic versions of name resolution, macro expansion and
54type inference. The purpose is two fold: 58type inference. The purpose is two fold:
55 59
56* to quickly bootstrap usable and useful language server: solution that covers 60- to quickly bootstrap usable and useful language server: solution that covers
57 80% of Rust code will be useful for IDEs, and will be vastly simpler than 100% 61 80% of Rust code will be useful for IDEs, and will be vastly simpler than 100%
58 solution. 62 solution.
59 63
60* to understand how the consumer-side of compiler API should look like 64- to understand how the consumer-side of compiler API should look like
61 (especially it's on-demand aspects). If you have `get_expression_type` 65 (especially it's on-demand aspects). If you have `get_expression_type`
62 function, you can write a ton of purely-IDE features on top of it, even if the 66 function, you can write a ton of purely-IDE features on top of it, even if the
63 function is only partially correct. Pluging in the precise function afterwards 67 function is only partially correct. Pluging in the precise function afterwards
@@ -77,7 +81,6 @@ implemented in Rust: [https://discord.gg/sx3RQZB](https://discord.gg/sx3RQZB).
77 81
78See [CONTRIBUTING.md](./CONTRIBUTING.md) and [ARCHITECTURE.md](./ARCHITECTURE.md) 82See [CONTRIBUTING.md](./CONTRIBUTING.md) and [ARCHITECTURE.md](./ARCHITECTURE.md)
79 83
80
81## License 84## License
82 85
83Rust analyzer is primarily distributed under the terms of both the MIT 86Rust analyzer is primarily distributed under the terms of both the MIT
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts
index cd0c6e6e2..cc7a10f76 100644
--- a/editors/code/src/config.ts
+++ b/editors/code/src/config.ts
@@ -2,9 +2,11 @@ import * as vscode from 'vscode';
2 2
3import { Server } from './server'; 3import { Server } from './server';
4 4
5const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG;
6
5export class Config { 7export class Config {
6 public highlightingOn = true; 8 public highlightingOn = true;
7 public raLspServerPath = 'ra_lsp_server'; 9 public raLspServerPath = RA_LSP_DEBUG || 'ra_lsp_server';
8 10
9 constructor() { 11 constructor() {
10 vscode.workspace.onDidChangeConfiguration(_ => 12 vscode.workspace.onDidChangeConfiguration(_ =>
@@ -24,7 +26,8 @@ export class Config {
24 } 26 }
25 27
26 if (config.has('raLspServerPath')) { 28 if (config.has('raLspServerPath')) {
27 this.raLspServerPath = config.get('raLspServerPath') as string; 29 this.raLspServerPath =
30 RA_LSP_DEBUG || (config.get('raLspServerPath') as string);
28 } 31 }
29 } 32 }
30} 33}