flams_lsp/
capabilities.rs

1use async_lsp::lsp_types::{self as lsp, CompletionOptions};
2
3pub struct STeXSemanticTokens;
4impl STeXSemanticTokens {
5  pub const NAME:u32 = 0;           // dark blue          light blue  !
6  pub const KEYWORD:u32 = 1;        // violet             pink        !
7  pub const SYMBOL:u32 = 2;         // brown              red         !
8  pub const DECLARATION: u32 = 3;   // Dark Purple        dark brown  !
9  pub const REF_MACRO: u32 = 4;     // Lime               cyan        !
10  pub const VARIABLE:u32 = 5;       // ?
11  pub const LOCAL:u32 = 6;          // light blue         dark blue   !
12  // -------------------
13  pub const OPERATOR:u32 = 7;       // white
14  pub const TYPE_PARAMETER:u32 = 8; // math green
15  pub const TYPE:u32 = 9;           // same
16  pub const ENUM:u32 = 10;           // same
17  pub const MODIFIER: u32 = 11;     // yellow / nothing
18  pub const COMMENT: u32 = 12;      // dark green
19  pub const DECORATOR: u32 = 13;    // yellow / nothing
20}
21
22lazy_static::lazy_static! {
23  pub static ref SEMANTIC_TOKENS : lsp::SemanticTokensLegend = lsp::SemanticTokensLegend {
24    token_types: vec![
25      lsp::SemanticTokenType::ENUM_MEMBER,
26      lsp::SemanticTokenType::KEYWORD,
27      lsp::SemanticTokenType::STRING,
28      lsp::SemanticTokenType::REGEXP,
29      lsp::SemanticTokenType::NUMBER,
30      lsp::SemanticTokenType::VARIABLE,
31      lsp::SemanticTokenType::PROPERTY,
32      // ------------------------------
33      lsp::SemanticTokenType::OPERATOR,
34      lsp::SemanticTokenType::TYPE_PARAMETER,
35      lsp::SemanticTokenType::TYPE,
36      lsp::SemanticTokenType::ENUM,
37      lsp::SemanticTokenType::MODIFIER,
38      lsp::SemanticTokenType::COMMENT,
39      lsp::SemanticTokenType::DECORATOR,
40    ],
41    token_modifiers: vec![
42      //lsp::SemanticTokenModifier::DEPRECATED,
43    ]
44  };
45}
46
47
48#[must_use]
49#[allow(clippy::too_many_lines)]
50pub fn capabilities() -> lsp::ServerCapabilities { lsp::ServerCapabilities {
51  position_encoding: Some(lsp::PositionEncodingKind::UTF16),
52  text_document_sync: Some(lsp::TextDocumentSyncCapability::Options(lsp::TextDocumentSyncOptions {
53      open_close: Some(true),
54      change: Some(lsp::TextDocumentSyncKind::INCREMENTAL),
55      will_save: Some(false),
56      will_save_wait_until: Some(false),
57      save: Some(lsp::TextDocumentSyncSaveOptions::Supported(true)),
58  })),
59  semantic_tokens_provider:Some(lsp::SemanticTokensServerCapabilities::SemanticTokensRegistrationOptions(
60      lsp::SemanticTokensRegistrationOptions {
61          text_document_registration_options:tdro(),
62          semantic_tokens_options:lsp::SemanticTokensOptions {
63              work_done_progress_options:lsp::WorkDoneProgressOptions { work_done_progress:Some(true) },
64              range:Some(true),
65              full:Some(lsp::SemanticTokensFullOptions::Delta { delta: Some(true) }),
66              legend:SEMANTIC_TOKENS.clone()
67          },
68          static_registration_options:lsp::StaticRegistrationOptions { id:Some("stex-sem-tokens".to_string()) }
69      }
70  )),
71  moniker_provider:Some(lsp::OneOf::Right(lsp::MonikerServerCapabilities::RegistrationOptions(
72      lsp::MonikerRegistrationOptions {
73          text_document_registration_options:tdro(),
74          moniker_options:lsp::MonikerOptions { work_done_progress_options:lsp::WorkDoneProgressOptions { work_done_progress:Some(true) } }
75      }
76  ))),
77  document_symbol_provider: Some(lsp::OneOf::Right(lsp::DocumentSymbolOptions {
78      label:Some("FLAMS".to_string()),
79      work_done_progress_options:lsp::WorkDoneProgressOptions { work_done_progress:Some(true) }
80  })),
81  workspace_symbol_provider: Some(lsp::OneOf::Right(lsp::WorkspaceSymbolOptions {
82      work_done_progress_options:lsp::WorkDoneProgressOptions { work_done_progress:Some(true) },
83      resolve_provider:Some(true)
84  })),
85  workspace:Some(lsp::WorkspaceServerCapabilities {
86      workspace_folders:Some(lsp::WorkspaceFoldersServerCapabilities { supported:Some(true),change_notifications:Some(lsp::OneOf::Right("flams-change-listener".to_string())) }),
87      file_operations:Some(lsp::WorkspaceFileOperationsServerCapabilities {
88          did_create:Some(lsp::FileOperationRegistrationOptions { filters:fo_filter()}),
89          did_rename:Some(lsp::FileOperationRegistrationOptions { filters:fo_filter()}),
90          did_delete:Some(lsp::FileOperationRegistrationOptions { filters:fo_filter()}),
91          will_create:None,
92          will_delete:None,
93          will_rename:None
94      })
95  }),
96  references_provider: Some(lsp::OneOf::Right(lsp::ReferencesOptions {
97      work_done_progress_options:lsp::WorkDoneProgressOptions { work_done_progress:Some(true) }
98  })),
99  selection_range_provider: Some(lsp::SelectionRangeProviderCapability::RegistrationOptions(
100      lsp::SelectionRangeRegistrationOptions {
101        selection_range_options: lsp::SelectionRangeOptions {
102          work_done_progress_options: lsp::WorkDoneProgressOptions { work_done_progress: Some(true) }
103        },
104        registration_options: lsp::StaticTextDocumentRegistrationOptions { 
105          id: Some("stex-selec-range".to_string()),
106          document_selector: Some(doc_filter())
107        }
108      }
109  )),
110  hover_provider: Some(lsp::HoverProviderCapability::Options(
111    lsp::HoverOptions {
112      work_done_progress_options: lsp::WorkDoneProgressOptions { work_done_progress: Some(true) }
113    }
114  )),
115  completion_provider: Some(CompletionOptions {
116    resolve_provider: Some(true),
117    trigger_characters:None,
118    all_commit_characters:None,
119    work_done_progress_options: lsp::WorkDoneProgressOptions { work_done_progress: Some(true) },
120    completion_item:Some(lsp::CompletionOptionsCompletionItem {
121      label_details_support: Some(true)
122    })
123  }),
124  signature_help_provider: Some(lsp::SignatureHelpOptions {
125    trigger_characters:None,
126    retrigger_characters:None,
127    work_done_progress_options: lsp::WorkDoneProgressOptions { work_done_progress: Some(true) }
128  }),
129  definition_provider:Some(lsp::OneOf::Right(lsp::DefinitionOptions {
130    work_done_progress_options:lsp::WorkDoneProgressOptions { work_done_progress:Some(true) }
131  })),
132  type_definition_provider:Some(lsp::TypeDefinitionProviderCapability::Options(
133    lsp::StaticTextDocumentRegistrationOptions {
134      document_selector:Some(doc_filter()),
135      id:Some("stex-type-def".to_string())
136    }
137  )),
138  implementation_provider:Some(lsp::ImplementationProviderCapability::Options(
139    lsp::StaticTextDocumentRegistrationOptions {
140      document_selector:Some(doc_filter()),
141      id:Some("stex-impl".to_string())
142    }
143  )),
144  declaration_provider:Some(lsp::DeclarationCapability::RegistrationOptions(
145    lsp::DeclarationRegistrationOptions {
146      declaration_options: lsp::DeclarationOptions {
147        work_done_progress_options: lsp::WorkDoneProgressOptions { work_done_progress: Some(true) }
148      },
149      text_document_registration_options:tdro(),
150      static_registration_options:lsp::StaticRegistrationOptions { 
151        id:Some("stex-decl".to_string()) 
152      }
153    }
154  )),
155  document_highlight_provider:Some(lsp::OneOf::Right(lsp::DocumentHighlightOptions {
156    work_done_progress_options:lsp::WorkDoneProgressOptions { work_done_progress:Some(true) }
157  })),
158  code_action_provider:Some(lsp::CodeActionProviderCapability::Options(lsp::CodeActionOptions {
159    code_action_kinds:Some(vec![
160      lsp::CodeActionKind::QUICKFIX,
161      lsp::CodeActionKind::REFACTOR,
162      lsp::CodeActionKind::SOURCE,
163      lsp::CodeActionKind::SOURCE_ORGANIZE_IMPORTS,
164      lsp::CodeActionKind::SOURCE_FIX_ALL
165    ]),
166    work_done_progress_options:lsp::WorkDoneProgressOptions { work_done_progress:Some(true) },
167    resolve_provider:Some(true)
168  })),
169  code_lens_provider:Some(lsp::CodeLensOptions {
170    resolve_provider:Some(true)
171  }),
172  folding_range_provider:Some(lsp::FoldingRangeProviderCapability::Options(
173    lsp::StaticTextDocumentColorProviderOptions { 
174      document_selector: Some(doc_filter()),
175      id: Some("stex-folding-range".to_string())
176    }
177  )),
178  document_link_provider:Some(lsp::DocumentLinkOptions {
179    work_done_progress_options:lsp::WorkDoneProgressOptions { work_done_progress:Some(true) },
180    resolve_provider:Some(true)
181  }),
182  execute_command_provider:Some(lsp::ExecuteCommandOptions {
183    commands:vec![],
184    work_done_progress_options:lsp::WorkDoneProgressOptions { work_done_progress:Some(true) }
185  }),
186  inline_value_provider:Some(lsp::OneOf::Right(
187    lsp::InlineValueServerCapabilities::RegistrationOptions(
188      lsp::InlineValueRegistrationOptions{
189        text_document_registration_options:tdro(),
190        static_registration_options:lsp::StaticRegistrationOptions { id:Some("stex-inline-value".to_string()) },
191        inline_value_options:lsp::InlineValueOptions { work_done_progress_options:lsp::WorkDoneProgressOptions { work_done_progress:Some(true) } }
192      }
193    )
194  )),
195  inlay_hint_provider:Some(lsp::OneOf::Right(
196    lsp::InlayHintServerCapabilities::RegistrationOptions(
197      lsp::InlayHintRegistrationOptions {
198        text_document_registration_options:tdro(),
199        static_registration_options:lsp::StaticRegistrationOptions { id:Some("stex-inlay-hint".to_string()) },
200        inlay_hint_options:lsp::InlayHintOptions {
201          resolve_provider:Some(false),
202          work_done_progress_options:lsp::WorkDoneProgressOptions { work_done_progress:Some(true) } 
203        }
204      }
205    )
206  )),
207  diagnostic_provider:Some(lsp::DiagnosticServerCapabilities::RegistrationOptions(
208    lsp::DiagnosticRegistrationOptions {
209      text_document_registration_options:tdro(),
210      static_registration_options:lsp::StaticRegistrationOptions { id:Some("stex-diagnostic".to_string()) },
211      diagnostic_options:lsp::DiagnosticOptions {
212        work_done_progress_options:lsp::WorkDoneProgressOptions { work_done_progress:Some(true) },
213        identifier:Some("stex-diagnostic".to_string()),
214        inter_file_dependencies:true,
215        workspace_diagnostics:false // <- this does not seem to work
216      }
217    }
218  )),
219  linked_editing_range_provider:Some(
220    lsp::LinkedEditingRangeServerCapabilities::RegistrationOptions(
221      lsp::LinkedEditingRangeRegistrationOptions {
222        text_document_registration_options:tdro(),
223        static_registration_options:lsp::StaticRegistrationOptions { id:Some("stex-linked-editing-range".to_string()) },
224        linked_editing_range_options:lsp::LinkedEditingRangeOptions { work_done_progress_options:lsp::WorkDoneProgressOptions { work_done_progress:Some(true) } }
225      }
226    )
227  ),
228  rename_provider: Some(
229    lsp::OneOf::Right(
230    lsp::RenameOptions {
231      work_done_progress_options:lsp::WorkDoneProgressOptions { work_done_progress:Some(true) },
232      prepare_provider:Some(true),
233    }
234  )),
235  document_formatting_provider: None,
236  document_range_formatting_provider: None,
237  document_on_type_formatting_provider: None,
238  color_provider:None,
239  call_hierarchy_provider:Some(lsp::CallHierarchyServerCapability::Simple(true)),
240  //inline_completion_provider:None,
241  experimental:None
242}}
243
244fn tdro() -> lsp::TextDocumentRegistrationOptions {
245  lsp::TextDocumentRegistrationOptions {
246      document_selector:Some(doc_filter())
247  }
248}
249
250fn fo_filter() -> Vec<lsp::FileOperationFilter> {
251  vec![
252      lsp::FileOperationFilter {scheme:Some("file".to_string()),pattern:lsp::FileOperationPattern {
253          glob:"**/*.tex".to_string(),
254          matches:Some(lsp::FileOperationPatternKind::File),
255          options:None
256      }}
257  ]
258}
259
260fn doc_filter() -> Vec<lsp::DocumentFilter> {
261  vec![
262    lsp::DocumentFilter { language:Some("tex".to_string()),scheme:Some("file".to_string()),pattern:Some("**/*.tex".to_string()) },
263    lsp::DocumentFilter { language:Some("latex".to_string()),scheme:Some("file".to_string()),pattern:Some("**/*.tex".to_string()) },
264  ]
265}