File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 323323 {
324324 "command" : " fixedGitStageFile" ,
325325 "title" : " Fixed Git Stage File"
326+ },
327+ {
328+ "command" : " stylexSnippet" ,
329+ "title" : " Stylex Snippet"
326330 }
327331 ],
328332 "configuration" : {
Original file line number Diff line number Diff line change 1+ import * as vscode from 'vscode'
2+ import { registerExtensionCommand } from 'vscode-framework'
3+
4+ export default ( ) => {
5+ registerExtensionCommand ( 'stylexSnippet' , async ( ) => {
6+ const editor = vscode . window . activeTextEditor
7+ if ( ! editor ) return
8+ let { line } = editor . selection . active
9+ let regexMatch
10+ const predicateRegex = / c o n s t ( [ \w \d ] + ) = s t y l e x .c r e a t e \( { / i
11+ while ( line > 0 ) {
12+ const { text } = editor . document . lineAt ( line )
13+ if ( predicateRegex . test ( text ) ) {
14+ regexMatch = predicateRegex . exec ( text ) ! [ 1 ] !
15+ break
16+ }
17+
18+ line --
19+ }
20+
21+ if ( ! regexMatch ) return
22+ const insideProps = editor . document . lineAt ( editor . selection . active ) . text . includes ( '...stylex.props' )
23+ const snippet = insideProps
24+ ? new vscode . SnippetString ( ) . appendText ( `${ regexMatch } .` )
25+ : new vscode . SnippetString ( ) . appendText ( `{...stylex.props(${ regexMatch } .` ) . appendTabstop ( 0 ) . appendText ( ')}' )
26+
27+ await editor . insertSnippet ( snippet )
28+ await vscode . commands . executeCommand ( 'editor.action.triggerSuggest' )
29+ } )
30+ }
You can’t perform that action at this time.
0 commit comments