@@ -9,118 +9,93 @@ import * as vscodeLanguageClient from 'vscode-languageclient';
9
9
10
10
// See the comment on convertCompletionItemKind below
11
11
// Here's the monaco enum:
12
- // Method = 0,
13
- // Function = 1,
14
- // Constructor = 2,
15
- // Field = 3,
16
- // Variable = 4,
17
- // Class = 5,
18
- // Struct = 6,
19
- // Interface = 7,
20
- // Module = 8,
21
- // Property = 9,
22
- // Event = 10,
23
- // Operator = 11,
24
- // Unit = 12,
25
- // Value = 13,
26
- // Constant = 14,
27
- // Enum = 15,
28
- // EnumMember = 16,
29
- // Keyword = 17,
30
- // Text = 18,
31
- // Color = 19,
32
- // File = 20,
33
- // Reference = 21,
34
- // Customcolor = 22,
35
- // Folder = 23,
36
- // TypeParameter = 24,
37
- // Snippet = 25
12
+ enum monacoCompletionItemKind {
13
+ Method = 0 ,
14
+ Function = 1 ,
15
+ Constructor = 2 ,
16
+ Field = 3 ,
17
+ Variable = 4 ,
18
+ Class = 5 ,
19
+ Struct = 6 ,
20
+ Interface = 7 ,
21
+ Module = 8 ,
22
+ Property = 9 ,
23
+ Event = 10 ,
24
+ Operator = 11 ,
25
+ Unit = 12 ,
26
+ Value = 13 ,
27
+ Constant = 14 ,
28
+ Enum = 15 ,
29
+ EnumMember = 16 ,
30
+ Keyword = 17 ,
31
+ Text = 18 ,
32
+ Color = 19 ,
33
+ File = 20 ,
34
+ Reference = 21 ,
35
+ Customcolor = 22 ,
36
+ Folder = 23 ,
37
+ TypeParameter = 24 ,
38
+ Snippet = 25
39
+ }
38
40
//
39
- // Here's the vscode enum
40
- // const Text: 1;
41
- // const Method: 2;
42
- // const Function: 3;
43
- // const Constructor: 4;
44
- // const Field: 5;
45
- // const Variable: 6;
46
- // const Class: 7;
47
- // const Interface: 8;
48
- // const Module: 9;
49
- // const Property: 10;
50
- // const Unit: 11;
51
- // const Value: 12;
52
- // const Enum: 13;
53
- // const Keyword: 14;
54
- // const Snippet: 15;
55
- // const Color: 16;
56
- // const File: 17;
57
- // const Reference: 18;
58
- // const Folder: 19;
59
- // const EnumMember: 20;
60
- // const Constant: 21;
61
- // const Struct: 22;
62
- // const Event: 23;
63
- // const Operator: 24;
64
- // const TypeParameter: 25;
65
41
66
42
// Left side is the vscode value.
67
43
const mapCompletionItemKind : Map < number , number > = new Map < number , number > ( [
68
- [ 0 , 9 ] , // No value for zero in vscode
69
- [ 1 , 18 ] , // Text
70
- [ 2 , 0 ] , // Method
71
- [ 3 , 1 ] , // Function
72
- [ 4 , 2 ] , // Constructor
73
- [ 5 , 3 ] , // Field
74
- [ 6 , 4 ] , // Variable
75
- [ 7 , 5 ] , // Class
76
- [ 8 , 7 ] , // Interface
77
- [ 9 , 8 ] , // Module
78
- [ 10 , 9 ] , // Property
79
- [ 11 , 12 ] , // Unit
80
- [ 12 , 13 ] , // Value
81
- [ 13 , 15 ] , // Enum
82
- [ 14 , 17 ] , // Keyword
83
- [ 15 , 25 ] , // Snippet
84
- [ 16 , 19 ] , // Color
85
- [ 17 , 20 ] , // File
86
- [ 18 , 21 ] , // Reference
87
- [ 19 , 23 ] , // Folder
88
- [ 20 , 16 ] , // EnumMember
89
- [ 21 , 14 ] , // Constant
90
- [ 22 , 6 ] , // Struct
91
- [ 23 , 10 ] , // Event
92
- [ 24 , 11 ] , // Operator
93
- [ 25 , 24 ] // TypeParameter
44
+ [ vscode . CompletionItemKind . Text , monacoCompletionItemKind . Text ] , // Text
45
+ [ vscode . CompletionItemKind . Method , monacoCompletionItemKind . Method ] , // Method
46
+ [ vscode . CompletionItemKind . Function , monacoCompletionItemKind . Function ] , // Function
47
+ [ vscode . CompletionItemKind . Constructor , monacoCompletionItemKind . Constructor ] , // Constructor
48
+ [ vscode . CompletionItemKind . Field , monacoCompletionItemKind . Field ] , // Field
49
+ [ vscode . CompletionItemKind . Variable , monacoCompletionItemKind . Variable ] , // Variable
50
+ [ vscode . CompletionItemKind . Class , monacoCompletionItemKind . Class ] , // Class
51
+ [ vscode . CompletionItemKind . Interface , monacoCompletionItemKind . Interface ] , // Interface
52
+ [ vscode . CompletionItemKind . Module , monacoCompletionItemKind . Module ] , // Module
53
+ [ vscode . CompletionItemKind . Property , monacoCompletionItemKind . Property ] , // Property
54
+ [ vscode . CompletionItemKind . Unit , monacoCompletionItemKind . Unit ] , // Unit
55
+ [ vscode . CompletionItemKind . Value , monacoCompletionItemKind . Value ] , // Value
56
+ [ vscode . CompletionItemKind . Enum , monacoCompletionItemKind . Enum ] , // Enum
57
+ [ vscode . CompletionItemKind . Keyword , monacoCompletionItemKind . Keyword ] , // Keyword
58
+ [ vscode . CompletionItemKind . Snippet , monacoCompletionItemKind . Snippet ] , // Snippet
59
+ [ vscode . CompletionItemKind . Color , monacoCompletionItemKind . Color ] , // Color
60
+ [ vscode . CompletionItemKind . File , monacoCompletionItemKind . File ] , // File
61
+ [ vscode . CompletionItemKind . Reference , monacoCompletionItemKind . Reference ] , // Reference
62
+ [ vscode . CompletionItemKind . Folder , monacoCompletionItemKind . Folder ] , // Folder
63
+ [ vscode . CompletionItemKind . EnumMember , monacoCompletionItemKind . EnumMember ] , // EnumMember
64
+ [ vscode . CompletionItemKind . Constant , monacoCompletionItemKind . Constant ] , // Constant
65
+ [ vscode . CompletionItemKind . Struct , monacoCompletionItemKind . Struct ] , // Struct
66
+ [ vscode . CompletionItemKind . Event , monacoCompletionItemKind . Event ] , // Event
67
+ [ vscode . CompletionItemKind . Operator , monacoCompletionItemKind . Operator ] , // Operator
68
+ [ vscode . CompletionItemKind . TypeParameter , monacoCompletionItemKind . TypeParameter ] // TypeParameter
94
69
] ) ;
95
70
96
71
const mapJupyterKind : Map < string , number > = new Map < string , number > ( [
97
- [ 'method' , 0 ] ,
98
- [ 'function' , 1 ] ,
99
- [ 'constructor' , 2 ] ,
100
- [ 'field' , 3 ] ,
101
- [ 'variable' , 4 ] ,
102
- [ 'class' , 5 ] ,
103
- [ 'struct' , 6 ] ,
104
- [ 'interface' , 7 ] ,
105
- [ 'module' , 8 ] ,
106
- [ 'property' , 9 ] ,
107
- [ 'event' , 10 ] ,
108
- [ 'operator' , 11 ] ,
109
- [ 'unit' , 12 ] ,
110
- [ 'value' , 13 ] ,
111
- [ 'constant' , 14 ] ,
112
- [ 'enum' , 15 ] ,
113
- [ 'enumMember' , 16 ] ,
114
- [ 'keyword' , 17 ] ,
115
- [ 'text' , 18 ] ,
116
- [ 'color' , 19 ] ,
117
- [ 'file' , 20 ] ,
118
- [ 'reference' , 21 ] ,
119
- [ 'customcolor' , 22 ] ,
120
- [ 'folder' , 23 ] ,
121
- [ 'typeParameter' , 24 ] ,
122
- [ 'snippet' , 25 ] ,
123
- [ '<unknown>' , 25 ]
72
+ [ 'method' , monacoCompletionItemKind . Method ] ,
73
+ [ 'function' , monacoCompletionItemKind . Function ] ,
74
+ [ 'constructor' , monacoCompletionItemKind . Constructor ] ,
75
+ [ 'field' , monacoCompletionItemKind . Field ] ,
76
+ [ 'variable' , monacoCompletionItemKind . Variable ] ,
77
+ [ 'class' , monacoCompletionItemKind . Class ] ,
78
+ [ 'struct' , monacoCompletionItemKind . Struct ] ,
79
+ [ 'interface' , monacoCompletionItemKind . Interface ] ,
80
+ [ 'module' , monacoCompletionItemKind . Module ] ,
81
+ [ 'property' , monacoCompletionItemKind . Property ] ,
82
+ [ 'event' , monacoCompletionItemKind . Event ] ,
83
+ [ 'operator' , monacoCompletionItemKind . Operator ] ,
84
+ [ 'unit' , monacoCompletionItemKind . Unit ] ,
85
+ [ 'value' , monacoCompletionItemKind . Value ] ,
86
+ [ 'constant' , monacoCompletionItemKind . Constant ] ,
87
+ [ 'enum' , monacoCompletionItemKind . Enum ] ,
88
+ [ 'enumMember' , monacoCompletionItemKind . EnumMember ] ,
89
+ [ 'keyword' , monacoCompletionItemKind . Keyword ] ,
90
+ [ 'text' , monacoCompletionItemKind . Text ] ,
91
+ [ 'color' , monacoCompletionItemKind . Color ] ,
92
+ [ 'file' , monacoCompletionItemKind . File ] ,
93
+ [ 'reference' , monacoCompletionItemKind . Reference ] ,
94
+ [ 'customcolor' , monacoCompletionItemKind . Customcolor ] ,
95
+ [ 'folder' , monacoCompletionItemKind . Folder ] ,
96
+ [ 'typeParameter' , monacoCompletionItemKind . TypeParameter ] ,
97
+ [ 'snippet' , monacoCompletionItemKind . Snippet ] ,
98
+ [ '<unknown>' , monacoCompletionItemKind . Snippet ]
124
99
] ) ;
125
100
126
101
function convertToMonacoRange ( range : vscodeLanguageClient . Range | undefined ) : monacoEditor . IRange | undefined {
@@ -141,13 +116,15 @@ function convertToMonacoRange(range: vscodeLanguageClient.Range | undefined): mo
141
116
// import { EDITOR_DEFAULTS } from './common/config/editorOptions.js';
142
117
// Instead just use a map
143
118
function convertToMonacoCompletionItemKind ( kind ?: number ) : number {
144
- const value = kind ? mapCompletionItemKind . get ( kind ) : 9 ; // Property is 9
119
+ const value = kind ? mapCompletionItemKind . get ( kind ) : monacoCompletionItemKind . Property ; // Property is 9
145
120
if ( value ) {
146
121
return value ;
147
122
}
148
- return 9 ; // Property
123
+ return monacoCompletionItemKind . Property ;
149
124
}
150
125
126
+ const SnippetEscape = 4 ;
127
+
151
128
function convertToMonacoCompletionItem ( item : vscodeLanguageClient . CompletionItem , requiresKindConversion : boolean ) : monacoEditor . languages . CompletionItem {
152
129
// They should be pretty much identical? Except for ranges.
153
130
// tslint:disable-next-line: no-object-literal-type-assertion no-any
@@ -161,6 +138,14 @@ function convertToMonacoCompletionItem(item: vscodeLanguageClient.CompletionItem
161
138
result . insertText = result . label ;
162
139
}
163
140
141
+ // tslint:disable-next-line: no-any
142
+ const snippet = ( result . insertText as any ) as vscode . SnippetString ;
143
+ if ( snippet . value ) {
144
+ result . insertTextRules = SnippetEscape ;
145
+ // Monaco can't handle the snippetText value, so rewrite it.
146
+ result . insertText = snippet . value ;
147
+ }
148
+
164
149
// Make sure we don't have _documentPosition. It holds onto a huge tree of information
165
150
// tslint:disable-next-line: no-any
166
151
const resultAny = result as any ;
0 commit comments