@@ -25,6 +25,8 @@ const format = (text: string): string => {
2525 return sqlFormatter . format ( text , config ) ;
2626} ;
2727
28+ const selector = 'flink-sql'
29+
2830export function activate ( context : ExtensionContext ) {
2931
3032 // 获取初始配置
@@ -39,7 +41,7 @@ export function activate(context: ExtensionContext) {
3941 } )
4042 ) ;
4143
42- vscode . languages . registerDocumentRangeFormattingEditProvider ( 'flink-sql' , {
44+ vscode . languages . registerDocumentRangeFormattingEditProvider ( selector , {
4345 provideDocumentRangeFormattingEdits : (
4446 document : vscode . TextDocument ,
4547 range : vscode . Range ,
@@ -48,7 +50,7 @@ export function activate(context: ExtensionContext) {
4850 vscode . TextEdit . replace ( range , format ( document . getText ( range ) ) ) ,
4951 ] ,
5052 } ) ;
51-
53+ context . subscriptions . push ( vscode . languages . registerRenameProvider ( selector , new MyRenameProvider ( ) ) ) ;
5254
5355 // 注册插件的其他命令和功能...
5456}
@@ -101,4 +103,23 @@ function updateFeatureStatus() {
101103 }
102104 } ) ;
103105 }
106+ }
107+
108+
109+ class MyRenameProvider implements vscode . RenameProvider {
110+ provideRenameEdits ( document : vscode . TextDocument , position : vscode . Position , newName : string , token : vscode . CancellationToken ) : vscode . ProviderResult < vscode . WorkspaceEdit > {
111+ const wordRange = document . getWordRangeAtPosition ( position ) ;
112+ const originalWord = document . getText ( wordRange ) ;
113+
114+ const edit = new vscode . WorkspaceEdit ( ) ;
115+ for ( let i = 0 ; i < document . lineCount ; i ++ ) {
116+ const line = document . lineAt ( i ) ;
117+ const start = line . text . indexOf ( originalWord ) ;
118+ if ( start >= 0 ) {
119+ edit . replace ( document . uri , new vscode . Range ( new vscode . Position ( i , start ) , new vscode . Position ( i , start + originalWord . length ) ) , newName ) ;
120+ }
121+ }
122+
123+ return edit ;
124+ }
104125}
0 commit comments