microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
language_service/src/protocol.rs
62lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | /// Represents a span of text used by the Language Server API |
| 5 | #[derive(Debug, PartialEq)] |
| 6 | pub struct Span { |
| 7 | pub start: u32, |
| 8 | pub end: u32, |
| 9 | } |
| 10 | |
| 11 | #[derive(Copy, Clone, Debug, PartialEq)] |
| 12 | #[allow(clippy::module_name_repetitions)] |
| 13 | pub enum CompletionItemKind { |
| 14 | // It would have been nice to match these enum values to the ones used by |
| 15 | // VS Code and Monaco, but unfortunately those two disagree on the values. |
| 16 | // So we define our own unique enum here to reduce confusion. |
| 17 | Function, |
| 18 | Interface, |
| 19 | Keyword, |
| 20 | Module, |
| 21 | } |
| 22 | |
| 23 | #[derive(Debug)] |
| 24 | #[allow(clippy::module_name_repetitions)] |
| 25 | pub struct CompletionList { |
| 26 | pub items: Vec<CompletionItem>, |
| 27 | } |
| 28 | |
| 29 | #[derive(Debug)] |
| 30 | #[allow(clippy::module_name_repetitions)] |
| 31 | pub struct CompletionItem { |
| 32 | pub label: String, |
| 33 | pub kind: CompletionItemKind, |
| 34 | pub sort_text: Option<String>, |
| 35 | pub detail: Option<String>, |
| 36 | pub additional_text_edits: Option<Vec<(Span, String)>>, |
| 37 | } |
| 38 | |
| 39 | impl CompletionItem { |
| 40 | #[must_use] |
| 41 | pub fn new(label: String, kind: CompletionItemKind) -> Self { |
| 42 | CompletionItem { |
| 43 | label, |
| 44 | kind, |
| 45 | sort_text: None, |
| 46 | detail: None, |
| 47 | additional_text_edits: None, |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | #[derive(Debug, PartialEq)] |
| 53 | pub struct Definition { |
| 54 | pub source: String, |
| 55 | pub offset: u32, |
| 56 | } |
| 57 | |
| 58 | #[derive(Debug, PartialEq)] |
| 59 | pub struct Hover { |
| 60 | pub contents: String, |
| 61 | pub span: Span, |
| 62 | } |