import { ExtensionContext , languages , ReferenceProvider , TextDocument , Position , Location , Range , RenameProvider , WorkspaceEdit , ProviderResult } from 'vscode' ; import { Global } from '../core/Global' ; import { ExtensionModule } from '~/modules' ; import { KeyDetector , Analyst } from '~/core' ; class Provider implements ReferenceProvider , RenameProvider { async provideReferences ( document , position ) { if ( ! Global . enabled ) return [ ] ; const key = KeyDetector . getKey ( document , position ) ; if ( ! key ) return [ ] ; return await Analyst . getAllOccurrenceLocations ( key ) ; } prepareRename ( document , position ) { const result = KeyDetector . getKeyAndRange ( document , position ) ; if ( ! result ) return ; const { key , range } = result ; return { range , placeholder : key } ; } async provideRenameEdits ( document , position , newName ) { if ( ! Global . enabled ) return ; const key = KeyDetector . getKey ( document , position ) ; if ( ! key ) return ; return await Global . loader . renameKey ( key , newName ) ; } constructor ( public readonly ctx ) { } } const m = ( ctx ) => { const provider = new Provider ( ctx ) ; return [ languages . registerReferenceProvider ( Global . getDocumentSelectors ( ) , provider ) , languages . registerRenameProvider ( Global . getDocumentSelectors ( ) , provider ) , ] ; } ; export default m ;