logicaffeine_lsp/
code_lens.rs1use lsp_types::{CodeLens, Command, Range};
2
3use logicaffeine_language::token::BlockType;
4
5use crate::document::DocumentState;
6
7pub fn code_lenses(doc: &DocumentState, uri: &lsp_types::Url) -> Vec<CodeLens> {
12 let mut lenses = Vec::new();
13
14 for (name, block_type, span) in &doc.symbol_index.block_spans {
15 let range = Range {
16 start: doc.line_index.position(span.start),
17 end: doc.line_index.position(span.start),
18 };
19
20 let args = Some(vec![
21 serde_json::Value::String(uri.to_string()),
22 serde_json::Value::String(name.clone()),
23 ]);
24
25 match block_type {
26 BlockType::Main => {
27 lenses.push(CodeLens {
28 range,
29 command: Some(Command {
30 title: "Run".to_string(),
31 command: "logicaffeine.run".to_string(),
32 arguments: args,
33 }),
34 data: None,
35 });
36 }
37 BlockType::Theorem => {
38 lenses.push(CodeLens {
39 range,
40 command: Some(Command {
41 title: "Verify".to_string(),
42 command: "logicaffeine.verify".to_string(),
43 arguments: args.clone(),
44 }),
45 data: None,
46 });
47 lenses.push(CodeLens {
48 range,
49 command: Some(Command {
50 title: "Prove".to_string(),
51 command: "logicaffeine.prove".to_string(),
52 arguments: args,
53 }),
54 data: None,
55 });
56 }
57 BlockType::Proof => {
58 lenses.push(CodeLens {
59 range,
60 command: Some(Command {
61 title: "Check Proof".to_string(),
62 command: "logicaffeine.checkProof".to_string(),
63 arguments: args,
64 }),
65 data: None,
66 });
67 }
68 _ => {}
69 }
70 }
71
72 lenses
73}
74
75#[cfg(test)]
76#[path = "../../logicaffeine_tests/unit/logicaffeine_lsp/code_lens/tests.rs"]
77mod tests;