@@ -34,7 +34,12 @@ export function activate(context: ExtensionContext) {
3434
3535 context . subscriptions . push ( vscode . languages . registerCodeLensProvider (
3636 [ { pattern : '**/*.sql' } , { pattern : '**/*.fql' } ] ,
37- new FlinkSQLCodeLensProvider ( )
37+ new FqlCodeLensProvider ( )
38+ ) ) ;
39+
40+ context . subscriptions . push ( vscode . languages . registerReferenceProvider (
41+ [ { pattern : '**/*.sql' } , { pattern : '**/*.fql' } ] ,
42+ new FqlReferenceProvider ( )
3843 ) ) ;
3944
4045 context . subscriptions . push ( vscode . commands . registerCommand ( 'extension.showReferences' , ( uri : vscode . Uri , position : vscode . Position , locations : vscode . Location [ ] ) => {
@@ -59,7 +64,7 @@ export function activate(context: ExtensionContext) {
5964 vscode . TextEdit . replace ( range , format ( document . getText ( range ) ) ) ,
6065 ] ,
6166 } ) ;
62- context . subscriptions . push ( vscode . languages . registerRenameProvider ( selector , new MyRenameProvider ( ) ) ) ;
67+ context . subscriptions . push ( vscode . languages . registerRenameProvider ( selector , new FqlRenameProvider ( ) ) ) ;
6368
6469 // 注册插件的其他命令和功能...
6570}
@@ -115,7 +120,7 @@ function updateFeatureStatus() {
115120}
116121
117122
118- class MyRenameProvider implements vscode . RenameProvider {
123+ class FqlRenameProvider implements vscode . RenameProvider {
119124 provideRenameEdits ( document : vscode . TextDocument , position : vscode . Position , newName : string , token : vscode . CancellationToken ) : vscode . ProviderResult < vscode . WorkspaceEdit > {
120125 const wordRange = document . getWordRangeAtPosition ( position ) ;
121126 const originalWord = document . getText ( wordRange ) ;
@@ -135,7 +140,7 @@ class MyRenameProvider implements vscode.RenameProvider {
135140
136141
137142
138- class FlinkSQLCodeLensProvider implements vscode . CodeLensProvider {
143+ class FqlCodeLensProvider implements vscode . CodeLensProvider {
139144
140145
141146 provideCodeLenses ( document : vscode . TextDocument , token : vscode . CancellationToken ) : vscode . ProviderResult < vscode . CodeLens [ ] > {
@@ -179,6 +184,34 @@ class FlinkSQLCodeLensProvider implements vscode.CodeLensProvider {
179184 }
180185 }
181186 }
187+ return references ;
188+ }
189+ }
190+
191+ class FqlReferenceProvider implements vscode . ReferenceProvider {
192+ provideReferences ( document : vscode . TextDocument , position : vscode . Position , options : { includeDeclaration : boolean } , token : vscode . CancellationToken ) : vscode . ProviderResult < vscode . Location [ ] > {
193+ const wordRange = document . getWordRangeAtPosition ( position ) ;
194+ if ( ! wordRange ) {
195+ return [ ] ;
196+ }
197+ const word = document . getText ( wordRange ) ;
198+
199+ const references : vscode . Location [ ] = [ ] ;
200+
201+ for ( let line = 0 ; line < document . lineCount ; line ++ ) {
202+ const lineOfCode = document . lineAt ( line ) ;
203+ const index = lineOfCode . text . indexOf ( word ) ;
204+
205+ if ( index >= 0 ) {
206+ const referencePosition = new vscode . Position ( line , index ) ;
207+ const referenceRange = document . getWordRangeAtPosition ( referencePosition ) ;
208+ if ( referenceRange ) {
209+ const referenceLocation = new vscode . Location ( document . uri , referenceRange ) ;
210+ references . push ( referenceLocation ) ;
211+ }
212+ }
213+ }
214+
182215 return references ;
183216 }
184217}
0 commit comments