@@ -53,6 +53,73 @@ pub struct GetCompletionsParams {
53
53
pub position : TextSize ,
54
54
}
55
55
56
+ #[ derive( Debug , Default , Serialize , Deserialize ) ]
57
+ #[ cfg_attr( feature = "schema" , derive( schemars:: JsonSchema ) ) ]
58
+ pub struct CompletionResult {
59
+ pub ( crate ) items : Vec < CompletionItem > ,
60
+ }
61
+
62
+ #[ cfg( feature = "db-connection" ) ]
63
+ impl IntoIterator for CompletionResult {
64
+ type Item = CompletionItem ;
65
+ type IntoIter = <Vec < CompletionItem > as IntoIterator >:: IntoIter ;
66
+ fn into_iter ( self ) -> Self :: IntoIter {
67
+ self . items . into_iter ( )
68
+ }
69
+ }
70
+
71
+ #[ cfg( feature = "db-connection" ) ]
72
+ impl From < pgt_completions:: CompletionResult > for CompletionResult {
73
+ fn from ( external : pgt_completions:: CompletionResult ) -> Self {
74
+ CompletionResult {
75
+ items : external. items . into_iter ( ) . map ( Into :: into) . collect ( ) ,
76
+ }
77
+ }
78
+ }
79
+
80
+ #[ cfg( feature = "db-connection" ) ]
81
+ impl From < pgt_completions:: CompletionItem > for CompletionItem {
82
+ fn from ( external : pgt_completions:: CompletionItem ) -> Self {
83
+ CompletionItem {
84
+ label : external. label ,
85
+ score : external. score ,
86
+ description : external. description ,
87
+ preselected : external. preselected ,
88
+ kind : external. kind . into ( ) ,
89
+ }
90
+ }
91
+ }
92
+
93
+ #[ cfg( feature = "db-connection" ) ]
94
+ impl From < pgt_completions:: CompletionItemKind > for CompletionItemKind {
95
+ fn from ( external : pgt_completions:: CompletionItemKind ) -> Self {
96
+ match external {
97
+ pgt_completions:: CompletionItemKind :: Table => CompletionItemKind :: Table ,
98
+ pgt_completions:: CompletionItemKind :: Function => CompletionItemKind :: Function ,
99
+ pgt_completions:: CompletionItemKind :: Column => CompletionItemKind :: Column ,
100
+ }
101
+ }
102
+ }
103
+
104
+ #[ derive( Debug , PartialEq , Eq , Serialize , Deserialize ) ]
105
+ #[ cfg_attr( feature = "schema" , derive( schemars:: JsonSchema ) ) ]
106
+ #[ serde( rename_all = "camelCase" ) ]
107
+ pub enum CompletionItemKind {
108
+ Table ,
109
+ Function ,
110
+ Column ,
111
+ }
112
+
113
+ #[ derive( Debug , Serialize , Deserialize ) ]
114
+ #[ cfg_attr( feature = "schema" , derive( schemars:: JsonSchema ) ) ]
115
+ pub struct CompletionItem {
116
+ pub label : String ,
117
+ pub ( crate ) score : i32 ,
118
+ pub description : String ,
119
+ pub preselected : bool ,
120
+ pub kind : CompletionItemKind ,
121
+ }
122
+
56
123
#[ derive( Debug , serde:: Serialize , serde:: Deserialize ) ]
57
124
#[ cfg_attr( feature = "schema" , derive( schemars:: JsonSchema ) ) ]
58
125
pub struct PullDiagnosticsResult {
@@ -118,7 +185,7 @@ pub trait Workspace: Send + Sync + RefUnwindSafe {
118
185
fn get_completions (
119
186
& self ,
120
187
params : GetCompletionsParams ,
121
- ) -> Result < pgt_completions :: CompletionResult , WorkspaceError > ;
188
+ ) -> Result < CompletionResult , WorkspaceError > ;
122
189
123
190
/// Update the global settings for this workspace
124
191
fn update_settings ( & self , params : UpdateSettingsParams ) -> Result < ( ) , WorkspaceError > ;
0 commit comments