Hediet TypeScript Refactorings
This is a VS Code Extension for refactorings that I had time and fun to program.
Feel free to use them too.
Supported Refactorings
- Convert string concatenation to string template
Supported Actions
- Faster Smart Select. Selects the next top node that is child of an array
- Convert expression statement to destructuring statement
Other Features
- Set a directory with custom refactorings (see settings).
An example refactoring looks like this:
import {
RefactorProviderBase,
typescript,
RefactorFilter,
RefactorCollector,
findChild,
} from "@hediet/ts-lsp/dist/src/api";
import {
hotClass,
enableHotReload,
registerUpdateReconciler,
} from "@hediet/node-reload";
enableHotReload({ entryModule: module });
registerUpdateReconciler(module);
@hotClass(module)
export default class RefactorProvider extends RefactorProviderBase {
protected collectRefactors(
context: {
program: typescript.Program;
range: typescript.TextRange;
sourceFile: typescript.SourceFile;
},
filter: RefactorFilter,
collector: RefactorCollector
): void {
const n = findChild(context.sourceFile, context.range.pos);
// TODO: do sth. with n here
}
}
| |