@@ -32,6 +32,15 @@ export function activate(context: ExtensionContext) {
3232 // 获取初始配置
3333 updateFeatureStatus ( ) ;
3434
35+ context . subscriptions . push ( vscode . languages . registerCodeLensProvider (
36+ [ { pattern : '**/*.sql' } , { pattern : '**/*.fql' } ] ,
37+ new FlinkSQLCodeLensProvider ( )
38+ ) ) ;
39+
40+ context . subscriptions . push ( vscode . commands . registerCommand ( 'extension.showReferences' , ( uri : vscode . Uri , position : vscode . Position , locations : vscode . Location [ ] ) => {
41+ vscode . commands . executeCommand ( 'editor.action.showReferences' , uri , position , locations ) ;
42+ } ) ) ;
43+
3544 // 监听配置更改事件
3645 context . subscriptions . push (
3746 vscode . workspace . onDidChangeConfiguration ( ( e ) => {
@@ -122,4 +131,54 @@ class MyRenameProvider implements vscode.RenameProvider {
122131
123132 return edit ;
124133 }
134+ }
135+
136+
137+
138+ class FlinkSQLCodeLensProvider implements vscode . CodeLensProvider {
139+
140+
141+ provideCodeLenses ( document : vscode . TextDocument , token : vscode . CancellationToken ) : vscode . ProviderResult < vscode . CodeLens [ ] > {
142+ const codeLenses = [ ] ;
143+ for ( let line = 0 ; line < document . lineCount ; line ++ ) {
144+ const lineOfCode = document . lineAt ( line ) ;
145+ // 添加你的SQL语法检测逻辑
146+ if ( / C R E A T E T E M P O R A R Y | C R E A T E T A B L E / i. test ( lineOfCode . text ) ) {
147+ codeLenses . push ( new vscode . CodeLens ( lineOfCode . range ) ) ;
148+ }
149+ }
150+ return codeLenses ;
151+ }
152+ resolveCodeLens ?( codeLens : vscode . CodeLens , token : vscode . CancellationToken ) : vscode . ProviderResult < vscode . CodeLens > {
153+ const editor = vscode . window . activeTextEditor ;
154+ if ( ! editor ) {
155+ return ;
156+ }
157+
158+ const document = editor . document ;
159+ const tableName = document . getText ( codeLens . range ) ;
160+ const references = this . findReferences ( document , tableName ) ;
161+
162+ if ( references . length > 0 ) {
163+ codeLens . command = {
164+ title : `${ references . length } reference(s) to ${ tableName } ` ,
165+ command : "extension.showReferences" ,
166+ arguments : [ document . uri , codeLens . range . start , references ]
167+ } ;
168+ }
169+ return codeLens ;
170+ }
171+
172+ findReferences ( document : vscode . TextDocument | undefined , tableName : string | undefined ) : vscode . Range [ ] {
173+ const references = [ ] ;
174+ if ( document && tableName ) {
175+ for ( let line = 0 ; line < document . lineCount ; line ++ ) {
176+ const lineOfCode = document . lineAt ( line ) ;
177+ if ( lineOfCode . text . includes ( tableName ) ) {
178+ references . push ( lineOfCode . range ) ;
179+ }
180+ }
181+ }
182+ return references ;
183+ }
125184}
0 commit comments