-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
* feat(codefix): codefix for diagnostics invalid casing * fix(codefix): remove language server code fix setting
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use strict'; | ||
import vscode = require('vscode'); | ||
|
||
export default class HtmlInvalidCasingActionProvider implements vscode.CodeActionProvider { | ||
private static commandId: string = 'aurelia-fix-invalid-casing'; | ||
private command: vscode.Disposable; | ||
|
||
public activate(subscriptions: vscode.Disposable[]) { | ||
this.command = vscode.commands.registerCommand(HtmlInvalidCasingActionProvider.commandId, this.fixInvalidCasing, this); | ||
subscriptions.push(this); | ||
} | ||
|
||
public provideCodeActions( | ||
document: vscode.TextDocument, | ||
range: vscode.Range, | ||
context: vscode.CodeActionContext, | ||
token: vscode.CancellationToken): vscode.Command[] { | ||
|
||
let diagnostic: vscode.Diagnostic = context.diagnostics[0]; | ||
let text = document.getText(diagnostic.range); | ||
const kebabCaseValidationRegex = /(.*)\.(bind|one-way|two-way|one-time|call|delegate|trigger)/; | ||
|
||
let result = kebabCaseValidationRegex.exec(text); | ||
let attribute = result[1]; | ||
let binding = result[2]; | ||
let fixedAttribute = attribute.split(/(?=[A-Z])/).map(s => s.toLowerCase()).join('-'); | ||
let fixedText = `${fixedAttribute}.${binding}`; | ||
let commands: vscode.Command[] = []; | ||
|
||
commands.push({ | ||
arguments: [document, diagnostic.range, fixedText], | ||
command: HtmlInvalidCasingActionProvider.commandId, | ||
title: `Rename ${attribute} to ${fixedAttribute}`, | ||
}); | ||
|
||
return commands; | ||
} | ||
|
||
public fixInvalidCasing(document, range, fixedText) { | ||
let edit = new vscode.WorkspaceEdit(); | ||
edit.replace(document.uri, range, fixedText); | ||
return vscode.workspace.applyEdit(edit); | ||
} | ||
|
||
public dispose(): void { | ||
this.command.dispose(); | ||
} | ||
} |