@@ -12,6 +12,12 @@ interface TextSnippet {
12
12
}
13
13
14
14
export function activate ( context : vscode . ExtensionContext ) : void {
15
+ const output = vscode . window . createOutputChannel ( 'Material-UI Snippets' )
16
+ output . appendLine ( 'Available snippets:' )
17
+ for ( const snippet of Object . values ( snippets ) ) {
18
+ output . appendLine ( ` ${ snippet . prefix } ` )
19
+ }
20
+
15
21
for ( const language of [ 'javascriptreact' , 'typescriptreact' ] ) {
16
22
let lastOptions : SnippetOptions | null = null
17
23
let lastSnippets : TextSnippet [ ]
@@ -50,44 +56,52 @@ export function activate(context: vscode.ExtensionContext): void {
50
56
) : vscode . ProviderResult <
51
57
vscode . CompletionItem [ ] | vscode . CompletionList
52
58
> {
53
- let insertPosition : vscode . Position = new vscode . Position ( 0 , 0 )
54
- let existingImports : Set < string > | null
59
+ output . appendLine ( 'provideCompletionItems() called' )
55
60
try {
56
- ; ( { insertPosition, existingImports } = getExistingImports (
57
- document
58
- ) )
61
+ let insertPosition : vscode . Position = new vscode . Position ( 0 , 0 )
62
+ let existingImports : Set < string > | null
63
+ try {
64
+ ; ( { insertPosition, existingImports } = getExistingImports (
65
+ document
66
+ ) )
67
+ } catch ( error ) {
68
+ existingImports = null
69
+ }
70
+ const result = [ ]
71
+ for ( const snippet of getSnippets ( {
72
+ language : language as any , // eslint-disable-line @typescript-eslint/no-explicit-any
73
+ formControlMode :
74
+ vscode . workspace
75
+ . getConfiguration ( 'material-ui-snippets' )
76
+ . get ( 'formControlMode' ) || 'controlled' ,
77
+ } ) ) {
78
+ const { prefix, description, body, imports } = snippet
79
+ const snippetCompletion = new vscode . CompletionItem ( prefix )
80
+ snippetCompletion . insertText = new vscode . SnippetString ( body )
81
+ snippetCompletion . documentation = new vscode . MarkdownString (
82
+ description
83
+ )
84
+ const finalExistingImports = existingImports
85
+ if ( finalExistingImports ) {
86
+ snippetCompletion . additionalTextEdits = [
87
+ vscode . TextEdit . insert (
88
+ insertPosition ,
89
+ [ ...Object . entries ( imports ) ]
90
+ . filter ( ( [ source ] ) => ! finalExistingImports . has ( source ) )
91
+ . map ( entry => entry [ 1 ] )
92
+ . join ( '\n' ) + '\n'
93
+ ) ,
94
+ ]
95
+ }
96
+ result . push ( snippetCompletion )
97
+ }
98
+ output . appendLine ( 'provideCompletionItems() returning' )
99
+ return result
59
100
} catch ( error ) {
60
- existingImports = null
61
- }
62
- const result = [ ]
63
- for ( const snippet of getSnippets ( {
64
- language : language as any , // eslint-disable-line @typescript-eslint/no-explicit-any
65
- formControlMode :
66
- vscode . workspace
67
- . getConfiguration ( 'material-ui-snippets' )
68
- . get ( 'formControlMode' ) || 'controlled' ,
69
- } ) ) {
70
- const { prefix, description, body, imports } = snippet
71
- const snippetCompletion = new vscode . CompletionItem ( prefix )
72
- snippetCompletion . insertText = new vscode . SnippetString ( body )
73
- snippetCompletion . documentation = new vscode . MarkdownString (
74
- description
101
+ output . appendLine (
102
+ 'provideCompletionItems() ERROR: ' + error . message
75
103
)
76
- const finalExistingImports = existingImports
77
- if ( finalExistingImports ) {
78
- snippetCompletion . additionalTextEdits = [
79
- vscode . TextEdit . insert (
80
- insertPosition ,
81
- [ ...Object . entries ( imports ) ]
82
- . filter ( ( [ source ] ) => ! finalExistingImports . has ( source ) )
83
- . map ( entry => entry [ 1 ] )
84
- . join ( '\n' ) + '\n'
85
- ) ,
86
- ]
87
- }
88
- result . push ( snippetCompletion )
89
104
}
90
- return result
91
105
} ,
92
106
} )
93
107
)
0 commit comments