|
8 | 8 |
|
9 | 9 | setup_error = nil
|
10 | 10 | install_error = nil
|
| 11 | +reboot = false |
11 | 12 |
|
12 |
| -# Read the initialize request before even starting the server. We need to do this to figure out the workspace URI. |
13 |
| -# Editors are not required to spawn the language server process on the same directory as the workspace URI, so we need |
14 |
| -# to ensure that we're setting up the bundle in the right place |
15 |
| -$stdin.binmode |
16 |
| -headers = $stdin.gets("\r\n\r\n") |
17 |
| -content_length = headers[/Content-Length: (\d+)/i, 1].to_i |
18 |
| -raw_initialize = $stdin.read(content_length) |
| 13 | +workspace_uri = ARGV.first |
| 14 | + |
| 15 | +raw_initialize = if workspace_uri && !workspace_uri.start_with?("--") |
| 16 | + # If there's an argument without `--`, then it's the server asking to compose the bundle and passing to this |
| 17 | + # executable the workspace URI. We can't require gems at this point, so we built a fake initialize request manually |
| 18 | + reboot = true |
| 19 | + "{\"params\":{\"workspaceFolders\":[{\"uri\":\"#{workspace_uri}\"}]}}" |
| 20 | +else |
| 21 | + # Read the initialize request before even starting the server. We need to do this to figure out the workspace URI. |
| 22 | + # Editors are not required to spawn the language server process on the same directory as the workspace URI, so we need |
| 23 | + # to ensure that we're setting up the bundle in the right place |
| 24 | + $stdin.binmode |
| 25 | + headers = $stdin.gets("\r\n\r\n") |
| 26 | + content_length = headers[/Content-Length: (\d+)/i, 1].to_i |
| 27 | + $stdin.read(content_length) |
| 28 | +end |
19 | 29 |
|
20 | 30 | # Compose the Ruby LSP bundle in a forked process so that we can require gems without polluting the main process
|
21 | 31 | # `$LOAD_PATH` and `Gem.loaded_specs`. Windows doesn't support forking, so we need a separate path to support it
|
@@ -91,6 +101,13 @@ rescue StandardError => e
|
91 | 101 | $LOAD_PATH.unshift(File.expand_path("../lib", __dir__))
|
92 | 102 | end
|
93 | 103 |
|
| 104 | +# When performing a lockfile re-boot, this executable is invoked to set up the composed bundle ahead of time. In this |
| 105 | +# flow, we are not booting the LSP yet, just checking if the bundle is valid before rebooting |
| 106 | +if reboot |
| 107 | + # Use the exit status to signal to the server if composing the bundle succeeded |
| 108 | + exit(install_error || setup_error ? 1 : 0) |
| 109 | +end |
| 110 | + |
94 | 111 | # Now that the bundle is set up, we can begin actually launching the server. Note that `Bundler.setup` will have already
|
95 | 112 | # configured the load path using the version of the Ruby LSP present in the composed bundle. Do not push any Ruby LSP
|
96 | 113 | # paths into the load path manually or we may end up requiring the wrong version of the gem
|
|
0 commit comments