File tree 3 files changed +29
-0
lines changed
3 files changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+ import * as vscode from 'vscode'
2
+ import { defaultLanguageSupersets } from '@zardoy/vscode-utils/build/langs'
3
+ import { getExtensionSetting } from 'vscode-framework'
4
+ import { sendCommand } from './sendCommand'
5
+
6
+ const jsxAttributesAutoTrigger = ( ) => {
7
+ vscode . workspace . onDidChangeTextDocument ( async ( { contentChanges, document, reason } ) => {
8
+ const editor = vscode . window . activeTextEditor
9
+ if ( document !== editor ?. document || contentChanges . length === 0 ) return
10
+ if ( contentChanges [ 0 ] ! . text !== ' ' ) return
11
+ if ( ! [ ...defaultLanguageSupersets . react , 'javascript' ] . includes ( document . languageId ) ) return
12
+ if ( ! getExtensionSetting ( 'completionsAutoTrigger.jsx' ) ) return
13
+ const path = await sendCommand ( 'getNodePath' , { document, position : editor . selection . active } )
14
+ if ( ! path ) return
15
+ if ( [ 'JsxSelfClosingElement' , 'JsxOpeningElement' ] . includes ( path . at ( - 1 ) ?. kindName ?? '' ) ) {
16
+ await vscode . commands . executeCommand ( 'editor.action.triggerSuggest' )
17
+ }
18
+ } )
19
+ }
20
+
21
+ export default ( ) => {
22
+ jsxAttributesAutoTrigger ( )
23
+ }
Original file line number Diff line number Diff line change @@ -713,6 +713,10 @@ export type Configuration = {
713
713
iconPost ?: string
714
714
}
715
715
}
716
+ /**
717
+ * @default true
718
+ */
719
+ 'completionsAutoTrigger.jsx' : boolean
716
720
/**
717
721
* @default false
718
722
*/
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import { mergeSettingsFromScopes } from './mergeSettings'
18
18
import codeActionProvider from './codeActionProvider'
19
19
import nonTsCommands from './nonTsCommands'
20
20
import inlayHints from './inlayHints'
21
+ import autoCompletionsTrigger from './autoCompletionsTrigger'
21
22
22
23
let isActivated = false
23
24
// let erroredStatusBarItem: vscode.StatusBarItem | undefined
@@ -98,6 +99,7 @@ export const activateTsPlugin = (tsApi: { configurePlugin; onCompletionAccepted
98
99
figIntegration ( )
99
100
vueVolarSupport ( )
100
101
inlayHints ( )
102
+ autoCompletionsTrigger ( )
101
103
102
104
if ( process . env . PLATFORM === 'node' && process . env . NODE_ENV === 'development' ) {
103
105
require ( './autoPluginReload' ) . default ( )
You can’t perform that action at this time.
0 commit comments