lspkit_server/
capabilities.rs1use std::collections::BTreeSet;
7
8use lspkit_vfs::PositionEncoding;
9
10#[non_exhaustive]
12#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
13pub enum TextSync {
14 None,
16 Full,
18 #[default]
20 Incremental,
21}
22
23#[non_exhaustive]
25#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
26pub enum Feature {
27 Completion,
29 Hover,
31 Definition,
33 References,
35 DiagnosticsPull,
37}
38
39#[non_exhaustive]
41#[derive(Debug, Clone)]
42pub struct Capabilities {
43 encoding: PositionEncoding,
44 text_sync: TextSync,
45 features: BTreeSet<Feature>,
46}
47
48impl Capabilities {
49 #[must_use]
51 pub fn new() -> Self {
52 Self {
53 encoding: PositionEncoding::default(),
54 text_sync: TextSync::default(),
55 features: BTreeSet::new(),
56 }
57 }
58
59 #[must_use]
61 pub fn position_encoding(mut self, encoding: PositionEncoding) -> Self {
62 self.encoding = encoding;
63 self
64 }
65
66 #[must_use]
68 pub fn text_sync(mut self, kind: TextSync) -> Self {
69 self.text_sync = kind;
70 self
71 }
72
73 #[must_use]
75 pub fn enable(mut self, feature: Feature) -> Self {
76 self.features.insert(feature);
77 self
78 }
79
80 #[must_use]
82 pub fn has(&self, feature: Feature) -> bool {
83 self.features.contains(&feature)
84 }
85
86 #[must_use]
88 pub fn encoding(&self) -> PositionEncoding {
89 self.encoding
90 }
91
92 #[must_use]
94 pub fn text_sync_kind(&self) -> TextSync {
95 self.text_sync
96 }
97
98 #[must_use]
100 pub fn features(&self) -> Vec<Feature> {
101 self.features.iter().copied().collect()
102 }
103}
104
105impl Default for Capabilities {
106 fn default() -> Self {
107 Self::new()
108 }
109}