Skip to content

Commit 88932ca

Browse files
authored
Implement a Language Server for Technique (#79)
Introduce a new top-level command _technique language_ to run a server for the Language Server Protocol (LSP). This works by consuming JSON-RPC messages sent over stdin from an editor or IDE and then handling various methods being invoked. This implementation currently handles reporting compiler errors and re-formatting the document. This gave us reason to extend the ranges shown in error messages to more accurately convey the location of the problematic code. Both the carets shown in textual errors in _technique check_ and the red squiggle shown under erroneous code in an IDE benefit from this. Finally, we've added `-` as a valid filename, indicating that input to be checked or formatted is to be taken from standard input.
2 parents f6bd78b + 29d98cd commit 88932ca

File tree

15 files changed

+1497
-214
lines changed

15 files changed

+1497
-214
lines changed

Cargo.lock

Lines changed: 340 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "technique"
3-
version = "0.4.2"
3+
version = "0.4.3"
44
edition = "2021"
55
description = "A domain specific language for procedures."
66
authors = [ "Andrew Cowie" ]
@@ -9,10 +9,14 @@ license = "MIT"
99

1010
[dependencies]
1111
clap = { version = "4.5.16", features = [ "wrap_help" ] }
12+
lsp-server = "0.7.9"
13+
lsp-types = "0.95"
1214
owo-colors = "4"
1315
regex = "1.11.1"
1416
serde = { version = "1.0.209", features = [ "derive" ] }
17+
serde_json = "1.0"
1518
tinytemplate = "1.2.1"
19+
1620
tracing = "0.1.40"
1721
tracing-subscriber = { version = "0.3.18", features = [ "env-filter" ] }
1822

src/editor/mod.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use lsp_server::Connection;
2+
use lsp_types::{
3+
InitializeParams, OneOf, ServerCapabilities, TextDocumentSyncCapability, TextDocumentSyncKind,
4+
};
5+
use tracing::{debug, info};
6+
7+
mod server;
8+
9+
pub(crate) fn run_language_server() {
10+
debug!("Starting Technique Language Server");
11+
12+
let (connection, threads) = Connection::stdio();
13+
14+
let capabilities = serde_json::to_value(ServerCapabilities {
15+
text_document_sync: Some(TextDocumentSyncCapability::Kind(TextDocumentSyncKind::FULL)),
16+
document_formatting_provider: Some(OneOf::Left(true)),
17+
..Default::default()
18+
})
19+
.unwrap();
20+
21+
// extract any initialization parameters passed from the editor.
22+
if let Ok(params) = connection.initialize(capabilities) {
23+
let _params = serde_json::from_value::<InitializeParams>(params).unwrap();
24+
25+
info!("Technique Language Server starting on stdin");
26+
27+
let server = server::TechniqueLanguageServer::new();
28+
29+
if let Err(e) = server.run(connection) {
30+
eprintln!("Server error: {}", e);
31+
}
32+
}
33+
34+
threads
35+
.join()
36+
.unwrap();
37+
}

0 commit comments

Comments
 (0)