Skip to content

Commit 22e8563

Browse files
committedJun 7, 2019
Added a configuration for default header template.
1 parent cd1e3d8 commit 22e8563

File tree

6 files changed

+65
-8
lines changed

6 files changed

+65
-8
lines changed
 

‎CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ Author: Sidharth Mishra
66

77
All notable changes to the "topper" extension will be documented in this file.
88

9+
### [v1.1.0]
10+
11+
- Added a new configuration parameter called `topper.defaultHeaderTemplate`. This parameter allows to customize the default header template across all the languages in case a custom language specific template is not defined yet. The language ID used for the default header template is `default` and it should not be tinkered with!!!
12+
913
### [v1.0.0]
1014

1115
**[!!!] This release has breaking changes and might need some configuration from your part for the first time you start using it –– especially on older files that were annotated with older versions of Topper. No worries for new users and new files.**

‎README.md

+24-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
# Topper
22

33
```
4-
Version: 1.0.0
4+
Version: 1.1.0
55
```
66

77
`Topper` is a file header utility. It will add a header to the file depending on the configurations made by you.
88

99
## Features
1010

11-
> Note: the GIF below is deprecated, will be replacing it with a new one soon.
12-
13-
> [DEPRECATED] The gif below shows how to use the `Topper` extension. Valid for extension version <= 0.4.0
14-
15-
![](https://zippy.gfycat.com/LeanNeatEasternnewt.gif)
11+
Make yourself a language and profile specific beautiful or helpful file header. Have fun!
1612

1713
## Extension Settings
1814

@@ -45,6 +41,28 @@ The default setting is:
4541

4642
You can add any number of profiles to the list. You also have the ability to add in any number of parameters here in your profiles. This way you can use those parameters in the header templates.
4743

44+
### `topper.defaultHeaderTemplate`: This configuration allows you to set a default header template across all the langauges in case you haven't defined a custom language specific header template. The language ID used for this header template is `default` and it should not be tinkered with. By default its value is:
45+
46+
```json
47+
{
48+
"default": {
49+
"headerBegin": "/**",
50+
"headerPrefix": "*",
51+
"headerEnd": "*/",
52+
"template": [
53+
"${headerBegin}",
54+
"${headerPrefix} ${fileName}",
55+
"${headerPrefix} @author ${author}",
56+
"${headerPrefix} @description ${description}",
57+
"${headerPrefix} @created ${createdDate}",
58+
"${headerPrefix} @copyright ${copyright}",
59+
"${headerPrefix} @last-modified ${lastModifiedDate}",
60+
"${headerEnd}"
61+
]
62+
}
63+
}
64+
```
65+
4866
### `topper.headerTemplates`: This is the list of all the header templates you configure depending upon the languages being used.
4967

5068
The list of language Ids can be found here: [https://code.visualstudio.com/docs/languages/identifiers](https://code.visualstudio.com/docs/languages/identifiers).

‎package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+22-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "topper",
33
"displayName": "topper",
44
"description": "A fileheader utility.",
5-
"version": "1.0.0",
5+
"version": "1.1.0",
66
"publisher": "sidmishraw",
77
"engines": {
88
"vscode": "^1.13.0"
@@ -48,6 +48,27 @@
4848
}
4949
]
5050
},
51+
"topper.defaultHeaderTemplate": {
52+
"type": "object",
53+
"description": "The default header template that can be used for all languages if no-custom template is defined. The default language ID is `default`. Please don't use some other language ID for the default header template.",
54+
"default": {
55+
"default": {
56+
"headerBegin": "/**",
57+
"headerPrefix": "*",
58+
"headerEnd": "*/",
59+
"template": [
60+
"${headerBegin}",
61+
"${headerPrefix} ${fileName}",
62+
"${headerPrefix} @author ${author}",
63+
"${headerPrefix} @description ${description}",
64+
"${headerPrefix} @created ${createdDate}",
65+
"${headerPrefix} @copyright ${copyright}",
66+
"${headerPrefix} @last-modified ${lastModifiedDate}",
67+
"${headerEnd}"
68+
]
69+
}
70+
}
71+
},
5172
"topper.headerTemplates": {
5273
"type": "array",
5374
"description": "Configure the templates for the headers depending on the languageId inferred by the editor. The list of language Ids can be found here: https://code.visualstudio.com/docs/languages/identifiers. \nIf the file's languageId is not configured here, it defaults to the `defaultCStyled` header template. \nPlease do not delete this template. Copy it over when configuring this section. \nNote: Please keep the `defaultCStyled` as the first element in the list of all the header templates. \nFor more information, refer to the Readme.md.",

‎src/topper/service.ts

+8
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ import {
5252
DEFAULT_DATETIME_FORMAT,
5353
INSERT_AT_ROW,
5454
INSERT_AT_COL,
55+
DEFAULT_HEADER_TEMPLATE,
56+
DEFAULT_LANGUAGE_ID,
5557
} from './topper';
5658
import { Optional } from '../util/optional';
5759
import { stat } from 'fs';
@@ -145,6 +147,12 @@ function getSelectedHeaderTemplate(headerTemplates: HeaderTemplate[], languageId
145147
* @returns the default header template, used mostly for C-styled languages.
146148
*/
147149
function getDefaultHeaderTemplate(): LanguageHeaderTemplate {
150+
const defaultHeaderTemplate: HeaderTemplate | undefined = workspace.getConfiguration(TOPPER).get(DEFAULT_HEADER_TEMPLATE);
151+
if (defaultHeaderTemplate) {
152+
// return the configured default header template if it is available, else
153+
// fallback to the hard-coded default.
154+
return defaultHeaderTemplate[DEFAULT_LANGUAGE_ID];
155+
}
148156
return new LanguageHeaderTemplate('/**', '*', '*/', [
149157
'${headerBegin}',
150158
'${headerPrefix} ${fileName}',

‎src/topper/topper.ts

+6
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ export const CUSTOM_TEMPLATE_PARAMETERS = 'customTemplateParameters';
6464
/** the key for header templates defined in the topper config. */
6565
export const HEADER_TEMPLATES = 'headerTemplates';
6666

67+
/** the key for the default header template used for all the languages if no custom template is defined. */
68+
export const DEFAULT_HEADER_TEMPLATE = 'defaultHeaderTemplate';
69+
70+
/** the default language ID to be used for the default header template. */
71+
export const DEFAULT_LANGUAGE_ID = 'default';
72+
6773
// list of intrinsic parameter names that topper provides
6874
//
6975
/** the file name. It is a key whose value is defined by topper. */

0 commit comments

Comments
 (0)