Fork of daniellemaywood.uk/gleam — Wasm codegen work
2.0 kB
69 lines
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: 2022 The Gleam contributors
3
4use crate::{
5 build_lock::{BuildLock, Guard},
6 fs::ProjectIO,
7};
8use gleam_core::{
9 Result,
10 build::{Mode, NullTelemetry, Target},
11 paths::ProjectPaths,
12};
13use gleam_language_server::{LanguageServer, LockGuard, Locker};
14
15pub fn main() -> Result<()> {
16 tracing::info!("language_server_starting");
17
18 if std::io::IsTerminal::is_terminal(&std::io::stdin()) {
19 eprintln!(
20 "Hello human!
21
22This command is intended to be run by language server clients such
23as a text editor rather than being run directly in the console.
24
25Many editors will automatically start the language server for you
26when you open a Gleam project. If yours does not you may need to
27look up how to configure your editor to use a language server.
28
29If you are seeing this in the logs of your editor you can safely
30ignore this message.
31
32If you have run `gleam lsp` yourself in your terminal then exit
33this program by pressing ctrl+c.
34"
35 );
36 }
37
38 // Create the transport. Includes the stdio (stdin and stdout) versions but this could
39 // also be implemented to use sockets or HTTP.
40 let (connection, io_threads) = lsp_server::Connection::stdio();
41
42 // Run the server and wait for the two threads to end, typically by trigger
43 // LSP Exit event.
44 LanguageServer::new(&connection, ProjectIO::new())?.run()?;
45
46 // Shut down gracefully.
47 drop(connection);
48 io_threads.join().expect("joining_lsp_threads");
49
50 tracing::info!("language_server_stopped");
51 Ok(())
52}
53
54#[derive(Debug)]
55pub struct LspLocker(BuildLock);
56
57impl LspLocker {
58 pub fn new(paths: &ProjectPaths, target: Target) -> Result<Self> {
59 let build_lock = BuildLock::new_target(paths, Mode::Lsp, target)?;
60 Ok(Self(build_lock))
61 }
62}
63
64impl Locker for LspLocker {
65 fn lock_for_build(&self) -> Result<LockGuard> {
66 let guard: Guard = self.0.lock(&NullTelemetry)?;
67 Ok(LockGuard(Box::new(guard)))
68 }
69}