Skip to content

Commit 3b35ea8

Browse files
committed
support rename operation
1 parent ee0e7a3 commit 3b35ea8

4 files changed

Lines changed: 29 additions & 5 deletions

File tree

out/extension.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

out/extension.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@
5656
".sql",
5757
".fql"
5858
],
59-
"configuration": "./language-configuration.json"
59+
"configuration": "./language-configuration.json",
60+
"capabilities" : {
61+
"renameProvider" : "true"
62+
}
6063
}
6164
],
6265
"grammars": [

src/extension.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ const format = (text: string): string => {
2525
return sqlFormatter.format(text, config);
2626
};
2727

28+
const selector = 'flink-sql'
29+
2830
export 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

Comments
 (0)