@@ -8,61 +8,63 @@ export default {
8
8
} ,
9
9
10
10
onInitialized ( ) {
11
- subscribe ( "completions" , async ( _message , { document, offset, completions } ) => {
12
- const text = document . getText ( ) ;
13
- const startOfLine = text . lastIndexOf ( "\n" , offset - 1 ) + 1 ;
14
- const textBeforePosition = text . slice ( startOfLine , offset ) ;
15
- if ( textBeforePosition . trim ( ) . endsWith ( "\"if\":" ) ) {
16
- completions . push ( ...ifThenPatternCompletion ( ) ) ;
11
+ subscribe ( "completions" , async ( _message , { schemaDocument, offset, completions } ) => {
12
+ const currentProperty = schemaDocument . findNodeAtOffset ( offset ) ;
13
+ if ( currentProperty && currentProperty . pointer . endsWith ( "/if" ) ) {
14
+ completions . push ( ...ifThenPatternCompletion ) ;
17
15
}
16
+
17
+ // const text = document.getText();
18
+ // const startOfLine = text.lastIndexOf("\n", offset - 1) + 1;
19
+ // const textBeforePosition = text.slice(startOfLine, offset);
20
+ // if (textBeforePosition.trim().endsWith("\"if\":")) {
21
+ // completions.push(...ifThenPatternCompletion());
22
+ // }
18
23
} ) ;
19
24
}
20
25
} ;
21
26
22
- function ifThenPatternCompletion ( ) {
23
- return [
24
- {
25
- label : "if/then" ,
26
- kind : CompletionItemKind . Snippet ,
27
- insertText : `{
28
- "type": "object",
29
- "properties": {
30
- "{varName}": { "const": "{value}" }
31
- },
32
- "required": ["{varName}"]
33
- },
34
-
35
- "then": {
36
- }` ,
37
- documentation : "Basic if/then pattern with a single condition and corresponding schema."
27
+ const ifThenPatternCompletion = [
28
+ {
29
+ label : "if/then" ,
30
+ kind : CompletionItemKind . Snippet ,
31
+ insertText : `{
32
+ "type": "object",
33
+ "properties": {
34
+ "{varName}": { "const": "{value}" }
35
+ },
36
+ "required": ["{varName}"]
38
37
},
39
- {
40
- label : "If/then/else" ,
41
- kind : CompletionItemKind . Snippet ,
42
- insertText : `{
43
- "type": "object",
44
- "properties": {
45
- "{varName}": { "const": "{value}" }
46
- },
47
- "required": ["{varName}"]
48
- },
49
- "then": {
50
- },
51
- "else": {
52
- }` ,
53
- documentation : "Conditional object structure with if/then/else logic"
38
+ "then": {
39
+ }` ,
40
+ documentation : "Basic if/then pattern with a single condition and corresponding schema."
41
+ } ,
42
+ {
43
+ label : "If/then/else" ,
44
+ kind : CompletionItemKind . Snippet ,
45
+ insertText : `{
46
+ "type": "object",
47
+ "properties": {
48
+ "{varName}": { "const": "{value}" }
49
+ },
50
+ "required": ["{varName}"]
54
51
},
55
- {
56
- label : "true" ,
57
- kind : CompletionItemKind . Snippet ,
58
- insertText : `true` ,
59
- documentation : "if true"
52
+ "then": {
60
53
},
61
- {
62
- label : "false" ,
63
- kind : CompletionItemKind . Snippet ,
64
- insertText : `false` ,
65
- documentation : "if false"
66
- }
67
- ] ;
68
- }
54
+ "else": {
55
+ }` ,
56
+ documentation : "Conditional object structure with if/then/else logic"
57
+ } ,
58
+ {
59
+ label : "true" ,
60
+ kind : CompletionItemKind . Snippet ,
61
+ insertText : `true` ,
62
+ documentation : "if true"
63
+ } ,
64
+ {
65
+ label : "false" ,
66
+ kind : CompletionItemKind . Snippet ,
67
+ insertText : `false` ,
68
+ documentation : "if false"
69
+ }
70
+ ] ;
0 commit comments