cairo_language_server/lsp/
ext.rs

1//! CairoLS extensions to the Language Server Protocol.
2
3use std::path::PathBuf;
4
5use lsp_types::notification::Notification;
6use lsp_types::request::Request;
7use lsp_types::{TextDocumentPositionParams, Url};
8use serde::{Deserialize, Serialize};
9
10/// Provides content of virtual file from the database.
11pub(crate) struct ProvideVirtualFile;
12
13#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
14pub(crate) struct ProvideVirtualFileRequest {
15    pub uri: Url,
16}
17
18#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
19pub(crate) struct ProvideVirtualFileResponse {
20    pub content: Option<String>,
21}
22
23impl Request for ProvideVirtualFile {
24    type Params = ProvideVirtualFileRequest;
25    type Result = ProvideVirtualFileResponse;
26    const METHOD: &'static str = "vfs/provide";
27}
28
29/// Collects information about all Cairo crates that are currently being analyzed.
30pub struct ViewAnalyzedCrates;
31
32impl Request for ViewAnalyzedCrates {
33    type Params = ();
34    type Result = String;
35    const METHOD: &'static str = "cairo/viewAnalyzedCrates";
36}
37
38/// Provides string with code after macros expansion.
39pub struct ExpandMacro;
40
41impl Request for ExpandMacro {
42    type Params = TextDocumentPositionParams;
43    type Result = Option<String>;
44    const METHOD: &'static str = "cairo/expandMacro";
45}
46
47/// Notifies about corelib version mismatch.
48#[derive(Debug)]
49pub struct CorelibVersionMismatch;
50
51impl Notification for CorelibVersionMismatch {
52    type Params = String;
53    const METHOD: &'static str = "cairo/corelib-version-mismatch";
54}
55
56/// Collects versions of LS and it's dependencies.
57#[derive(Debug)]
58pub struct ToolchainInfo;
59
60#[derive(Serialize, Deserialize)]
61pub struct PathAndVersion {
62    pub path: PathBuf,
63    pub version: String,
64}
65
66#[derive(Serialize, Deserialize)]
67pub struct ToolchainInfoResponse {
68    pub ls: PathAndVersion,
69    pub scarb: Option<PathAndVersion>,
70}
71
72impl Request for ToolchainInfo {
73    type Params = ();
74    type Result = ToolchainInfoResponse;
75    const METHOD: &'static str = "cairo/toolchainInfo";
76}
77
78#[cfg(feature = "testing")]
79pub mod testing {
80    use lsp_types::notification::Notification;
81
82    /// Notifies about the end of project updating.
83    #[derive(Debug)]
84    pub struct ProjectUpdatingFinished;
85
86    impl Notification for ProjectUpdatingFinished {
87        type Params = ();
88        const METHOD: &'static str = "cairo/projectUpdatingFinished";
89    }
90}