()
| 40 | * @returns |
| 41 | */ |
| 42 | export function insertFileHeader() { |
| 43 | const editor: TextEditor = window.activeTextEditor; |
| 44 | if (!editor) { |
| 45 | window.showErrorMessage('psi-header requires an active document.'); |
| 46 | return; |
| 47 | } |
| 48 | const wsConfig: WorkspaceConfiguration = workspace.getConfiguration(BASE_SETTINGS); |
| 49 | const langConfig: ILangConfig = getLanguageConfig(wsConfig, editor.document.languageId, editor.document.fileName); |
| 50 | const template: Array<string> = getTemplateConfig(wsConfig, editor.document.languageId, editor.document.fileName).template; |
| 51 | const config: IConfig = getConfig(wsConfig, langConfig); |
| 52 | const variables: IVariableList = getVariables(wsConfig, editor.document, config, langConfig); |
| 53 | |
| 54 | // console.log(`insertFileHeader into ${editor.document.fileName}`); |
| 55 | |
| 56 | if (config.forceToTop) { |
| 57 | const position = new Position(0, 0); |
| 58 | editor.selection = new Selection(position, position); |
| 59 | } |
| 60 | |
| 61 | editor.edit(function(edit) { |
| 62 | edit.insert(editor.selection.active, merge(template, langConfig, variables, config, editor)); |
| 63 | }); |
| 64 | } |
no test coverage detected