1
- "use strict" ;
2
- import * as vscode from "vscode" ;
3
- import {
4
- CodeFragmentProvider ,
5
- CodeFragmentGroupTreeItem
6
- } from "./codeFragmentsTreeItem" ;
7
- import { FragmentManager } from "./fragmentManager" ;
8
- import { SnippetCompletionItemProvider , addAutoImport } from "./snippetLoader" ;
1
+ 'use strict' ;
2
+ import * as vscode from 'vscode' ;
3
+ import { CodeFragmentProvider , CodeFragmentGroupTreeItem } from './codeFragmentsTreeItem' ;
4
+ import { FragmentManager } from './fragmentManager' ;
5
+ import { SnippetCompletionItemProvider , addAutoImport } from './snippetLoader' ;
9
6
10
7
export async function activate ( context : vscode . ExtensionContext ) {
11
8
const fragmentManager = new FragmentManager ( context ) ;
12
9
const codeFragmentProvider = new CodeFragmentProvider ( fragmentManager ) ;
13
10
14
11
const additionalEdits = ( editBuilder : vscode . TextEditorEdit , label : string ) => {
15
- const { leadingControlChars, importPosition, match, lastMatchingIndex } = addAutoImport ( vscode . window . activeTextEditor . document ) ;
12
+ const { leadingControlChars, importPosition, match, lastMatchingIndex } = addAutoImport (
13
+ vscode . window . activeTextEditor . document
14
+ ) ;
16
15
if ( match . indexOf ( label ) === - 1 ) {
17
16
// we do not have the import, need to insert it
18
17
if ( lastMatchingIndex === - 1 ) {
@@ -21,34 +20,30 @@ export async function activate(context: vscode.ExtensionContext) {
21
20
editBuilder . insert ( importPosition , leadingControlChars ? `${ leadingControlChars } ${ label } ,` : ` ${ label } , ` ) ;
22
21
}
23
22
}
24
- }
23
+ } ;
25
24
26
25
const insertCodeFragment = fragmentId => {
27
26
if ( ! fragmentId ) {
28
27
vscode . window . showInformationMessage (
29
- " Insert a code fragment into the editor by clicking on it in the Code Fragments view."
28
+ ' Insert a code fragment into the editor by clicking on it in the Code Fragments view.'
30
29
) ;
31
30
}
32
31
33
32
const editor = vscode . window . activeTextEditor ;
34
33
if ( ! editor ) {
35
- vscode . window . showInformationMessage (
36
- "Open a file in the editor to insert a fragment."
37
- ) ;
34
+ vscode . window . showInformationMessage ( 'Open a file in the editor to insert a fragment.' ) ;
38
35
return ;
39
36
}
40
37
41
38
const content = fragmentManager . getFragmentContent ( fragmentId ) ;
42
39
43
40
if ( content ) {
44
41
// new SnippetCompletionItemProvider().provideCompletionItems();
45
- vscode . window . activeTextEditor . insertSnippet (
46
- new vscode . SnippetString ( content . content )
47
- ) . then ( ( ) => {
48
- const config = vscode . workspace . getConfiguration ( "codeFragments" ) ;
49
- const autoImport : boolean = config . get ( "autoImport" ) ;
42
+ vscode . window . activeTextEditor . insertSnippet ( new vscode . SnippetString ( content . content ) ) . then ( ( ) => {
43
+ const config = vscode . workspace . getConfiguration ( 'codeFragments' ) ;
44
+ const autoImport : boolean = config . get ( 'autoImport' ) ;
50
45
if ( autoImport ) {
51
- vscode . window . activeTextEditor . edit ( ( editBuilder ) => additionalEdits ( editBuilder , content . label ) ) ;
46
+ vscode . window . activeTextEditor . edit ( editBuilder => additionalEdits ( editBuilder , content . label ) ) ;
52
47
}
53
48
} ) ;
54
49
}
@@ -60,17 +55,14 @@ export async function activate(context: vscode.ExtensionContext) {
60
55
61
56
const gotoDocumentation = ( group : CodeFragmentGroupTreeItem ) => {
62
57
if ( ! group ) {
63
- vscode . window . showInformationMessage ( " Nothing passed" ) ;
58
+ vscode . window . showInformationMessage ( ' Nothing passed' ) ;
64
59
}
65
- const url = `${
66
- group . category . toLowerCase ( ) === "beta" ? "experimental" : group . category
67
- } / ${ group . label } `. toLowerCase ( ) ;
60
+ const url = `${ group . category . toLowerCase ( ) === 'beta' ? 'experimental' : group . category } / ${
61
+ group . label
62
+ } `. toLowerCase ( ) ;
68
63
// console.info(`https://www.patternfly.org/${group.version || 'v4'}/documentation/react/${url}`);
69
64
vscode . env . openExternal (
70
- vscode . Uri . parse (
71
- `https://www.patternfly.org/${ group . version ||
72
- "v4" } /documentation/react/${ url } `
73
- )
65
+ vscode . Uri . parse ( `https://www.patternfly.org/${ group . version || 'v4' } /documentation/react/${ url } ` )
74
66
) ;
75
67
} ;
76
68
@@ -89,101 +81,66 @@ export async function activate(context: vscode.ExtensionContext) {
89
81
} ;
90
82
91
83
const onUpdateConfiguration = ( event : vscode . ConfigurationChangeEvent ) => {
92
- if ( event . affectsConfiguration ( "codeFragments" ) ) {
93
- const config = vscode . workspace . getConfiguration ( "codeFragments" ) ;
94
- fragmentManager . toggleCommentsInFragments (
95
- config . get ( "includeCommentsInFragment" )
96
- ) ;
97
- fragmentManager . toggleAutoImport (
98
- config . get ( "autoImport" )
99
- ) ;
100
- fragmentManager . updateVersionUsed ( config . get ( "patternflyRelease" ) ) ;
84
+ if ( event . affectsConfiguration ( 'codeFragments' ) ) {
85
+ const config = vscode . workspace . getConfiguration ( 'codeFragments' ) ;
86
+ fragmentManager . toggleCommentsInFragments ( config . get ( 'includeCommentsInFragment' ) ) ;
87
+ fragmentManager . toggleAutoImport ( config . get ( 'autoImport' ) ) ;
88
+ fragmentManager . updateVersionUsed ( config . get ( 'patternflyRelease' ) ) ;
101
89
fragmentManager . reimportDefaults ( ) ;
102
90
}
103
91
} ;
104
92
105
93
fragmentManager . initialize ( ) ;
106
94
107
- vscode . window . registerTreeDataProvider ( " codeFragments" , codeFragmentProvider ) ;
95
+ vscode . window . registerTreeDataProvider ( ' codeFragments' , codeFragmentProvider ) ;
108
96
109
97
vscode . workspace . onDidChangeConfiguration ( onUpdateConfiguration ) ;
110
98
99
+ context . subscriptions . push ( vscode . commands . registerCommand ( 'codeFragments.insertCodeFragment' , insertCodeFragment ) ) ;
100
+ context . subscriptions . push ( vscode . commands . registerCommand ( 'codeFragments.refreshFragments' , refreshFragments ) ) ;
101
+ context . subscriptions . push ( vscode . commands . registerCommand ( 'codeFragments.gotoDocumentation' , gotoDocumentation ) ) ;
111
102
context . subscriptions . push (
112
- vscode . commands . registerCommand (
113
- "codeFragments.insertCodeFragment" ,
114
- insertCodeFragment
115
- )
103
+ vscode . commands . registerCommand ( 'codeFragments.toggleCommentsInFragments' , toggleCommentsInFragments )
116
104
) ;
105
+ context . subscriptions . push ( vscode . commands . registerCommand ( 'codeFragments.autoImportCommand' , toggleAutoImport ) ) ;
117
106
context . subscriptions . push (
118
- vscode . commands . registerCommand (
119
- "codeFragments.refreshFragments" ,
120
- refreshFragments
121
- )
107
+ vscode . commands . registerCommand ( 'codeFragments.switchVersion_2020.02' , ( ) => switchVersion ( '2020.02' ) )
122
108
) ;
123
109
context . subscriptions . push (
124
- vscode . commands . registerCommand (
125
- "codeFragments.gotoDocumentation" ,
126
- gotoDocumentation
127
- )
110
+ vscode . commands . registerCommand ( 'codeFragments.switchVersion_2020.01' , ( ) => switchVersion ( '2020.01' ) )
128
111
) ;
129
112
context . subscriptions . push (
130
- vscode . commands . registerCommand (
131
- "codeFragments.toggleCommentsInFragments" ,
132
- toggleCommentsInFragments
133
- )
113
+ vscode . commands . registerCommand ( 'codeFragments.switchVersion_2019.11' , ( ) => switchVersion ( '2019.11' ) )
134
114
) ;
135
115
context . subscriptions . push (
136
- vscode . commands . registerCommand (
137
- "codeFragments.autoImportCommand" ,
138
- toggleAutoImport
139
- )
140
- ) ;
141
- context . subscriptions . push (
142
- vscode . commands . registerCommand ( "codeFragments.switchVersion_2020.02" , ( ) =>
143
- switchVersion ( "2020.02" )
144
- )
145
- ) ;
146
- context . subscriptions . push (
147
- vscode . commands . registerCommand ( "codeFragments.switchVersion_2020.01" , ( ) =>
148
- switchVersion ( "2020.01" )
149
- )
150
- ) ;
151
- context . subscriptions . push (
152
- vscode . commands . registerCommand ( "codeFragments.switchVersion_2019.11" , ( ) =>
153
- switchVersion ( "2019.11" )
154
- )
155
- ) ;
156
- context . subscriptions . push (
157
- vscode . commands . registerCommand ( "codeFragments.switchVersion_2019.10" , ( ) =>
158
- switchVersion ( "2019.10" )
159
- )
116
+ vscode . commands . registerCommand ( 'codeFragments.switchVersion_2019.10' , ( ) => switchVersion ( '2019.10' ) )
160
117
) ;
161
118
162
119
// push these 2 subscriptions last
163
- const config = vscode . workspace . getConfiguration ( " codeFragments" ) ;
164
- const release : string = config . get ( " patternflyRelease" ) ;
165
- const autoImport : boolean = config . get ( " autoImport" ) ;
120
+ const config = vscode . workspace . getConfiguration ( ' codeFragments' ) ;
121
+ const release : string = config . get ( ' patternflyRelease' ) ;
122
+ const autoImport : boolean = config . get ( ' autoImport' ) ;
166
123
const languageSelectors : vscode . DocumentSelector = [
167
- " typescript" ,
168
- " typescriptreact" ,
169
- " javascript" ,
170
- " javascriptreact" ,
171
- " html" ,
172
- " plaintext" ,
173
- " markdown"
124
+ ' typescript' ,
125
+ ' typescriptreact' ,
126
+ ' javascript' ,
127
+ ' javascriptreact' ,
128
+ ' html' ,
129
+ ' plaintext' ,
130
+ ' markdown'
174
131
] ;
175
132
context . subscriptions . push (
176
133
vscode . languages . registerCompletionItemProvider (
177
134
languageSelectors ,
178
135
new SnippetCompletionItemProvider ( release , true , autoImport ) ,
179
- "#"
136
+ '#'
180
137
)
181
138
) ;
182
139
context . subscriptions . push (
183
140
vscode . languages . registerCompletionItemProvider (
184
141
languageSelectors ,
185
142
new SnippetCompletionItemProvider ( release , false , autoImport ) ,
186
- "!"
143
+ '!'
187
144
)
188
145
) ;
189
146
}
0 commit comments