MCPcopy Create free account
hub / github.com/davidquinn/psi-header / ChangesTrackingController

Class ChangesTrackingController

src/changesTrackingController.ts:80–452  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78 * @class ChangesTrackingController
79 */
80export class ChangesTrackingController {
81 private _disposable: Disposable;
82 private _wsConfig: WorkspaceConfiguration;
83 private _config: ITrackingConfig;
84 private _author: string = 'You';
85
86 /**
87 * Creates an instance of ChangesTrackingController.
88 * @memberof ChangesTrackingController
89 */
90 constructor() {
91 this._getConfig();
92 const subscriptions: Disposable[] = [];
93 workspace.onWillSaveTextDocument(this._onWillSave, this, subscriptions);
94 workspace.onDidChangeConfiguration(this._onConfigChanged, this, subscriptions);
95 window.onDidChangeActiveTextEditor(this._onDidChangeActiveTextEditor, this, subscriptions);
96 this._disposable = Disposable.from(...subscriptions);
97 }
98
99 /**
100 * Dispose of the ChangesTrackingController.
101 *
102 * @memberof ChangesTrackingController
103 */
104 dispose(): void {
105 this._disposable.dispose();
106 }
107
108 /**
109 * Delegate method triggered whenever a document will be saved.
110 * Used to update an existing header or force a header if enforceHeader is true.
111 *
112 * @private
113 * @param {TextDocumentWillSaveEvent} e
114 * @memberof ChangesTrackingController
115 */
116 private _onWillSave(e: TextDocumentWillSaveEvent): void {
117 const activeTextEditor: TextEditor = window.activeTextEditor;
118 if (this._config.isActive) {
119 const doc: TextDocument = e.document;
120 const langConfig: ILangConfig = getLanguageConfig(this._wsConfig, doc.languageId, doc.fileName);
121 if (doc && doc.isDirty && this._want(doc.languageId, doc.fileName, langConfig.rootDirFileName)) {
122 const mainConfig: IConfig = getConfig(this._wsConfig, langConfig);
123 if (this._config.enforceHeader && this._docNeedsHeader(doc)) {
124 insertFileHeader();
125 }
126 const variables: IVariableList = getVariables(this._wsConfig, doc, mainConfig, langConfig, !this._config.updateLicenseVariables);
127 const template: Array<string> = getTemplateConfig(this._wsConfig, doc.languageId, doc.fileName).template;
128
129 const modDate: string = langConfig.modDate || this._config.modDate;
130 const modDateWithPrefix: string = langConfig.prefix + modDate;
131
132 const modAuthor: string = langConfig.modAuthor || this._config.modAuthor;
133 const modAuthorWithPrefix: string = langConfig.prefix + modAuthor;
134
135 const replaceList: Array<string> = langConfig.replace || this._config.replace;
136
137 let modDateTemplate: string = template.find((value) => {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected