File tree Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Expand file tree Collapse file tree 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 = {
713713 iconPost ?: string
714714 }
715715 }
716+ /**
717+ * @default true
718+ */
719+ 'completionsAutoTrigger.jsx' : boolean
716720 /**
717721 * @default false
718722 */
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import { mergeSettingsFromScopes } from './mergeSettings'
1818import codeActionProvider from './codeActionProvider'
1919import nonTsCommands from './nonTsCommands'
2020import inlayHints from './inlayHints'
21+ import autoCompletionsTrigger from './autoCompletionsTrigger'
2122
2223let isActivated = false
2324// let erroredStatusBarItem: vscode.StatusBarItem | undefined
@@ -98,6 +99,7 @@ export const activateTsPlugin = (tsApi: { configurePlugin; onCompletionAccepted
9899 figIntegration ( )
99100 vueVolarSupport ( )
100101 inlayHints ( )
102+ autoCompletionsTrigger ( )
101103
102104 if ( process . env . PLATFORM === 'node' && process . env . NODE_ENV === 'development' ) {
103105 require ( './autoPluginReload' ) . default ( )
You can’t perform that action at this time.
0 commit comments