Skip to content

Commit 15db3e9

Browse files
committed
refactor(linter): make activate return subs
1 parent 9d88a75 commit 15db3e9

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export async function activate(context: vscode.ExtensionContext) {
4949
// Linter is always activated but will only lint if compiler !== Disabled
5050
const linterCache = path.join(context.storageUri.fsPath);
5151
const linter = new FortranLintingProvider(logger, linterCache);
52-
linter.activate(context);
52+
context.subscriptions.push(...(await linter.activate()));
5353
vscode.languages.registerCodeActionsProvider(FortranDocumentSelector(), linter);
5454

5555
if (formatterType !== 'Disabled') {

src/features/linter-provider.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export class FortranLintingProvider {
172172
private pathCache = new Map<string, GlobPaths>();
173173
private settings: LinterSettings;
174174
private linter: GNULinter | GNUModernLinter | IntelLinter | NAGLinter;
175-
private disposables: vscode.Disposable[];
175+
private subscriptions: vscode.Disposable[] = [];
176176

177177
public provideCodeActions(
178178
document: vscode.TextDocument,
@@ -183,14 +183,12 @@ export class FortranLintingProvider {
183183
return;
184184
}
185185

186-
public async activate(context: vscode.ExtensionContext) {
186+
public async activate(): Promise<vscode.Disposable[]> {
187187
// Register Linter commands
188-
context.subscriptions.push(
189-
vscode.commands.registerCommand(RescanLint, this.rescanLinter, this)
190-
);
191-
context.subscriptions.push(vscode.commands.registerCommand(InitLint, this.initialize, this));
192-
context.subscriptions.push(vscode.commands.registerCommand(CleanLintFiles, this.clean, this));
193-
context.subscriptions.push(
188+
this.subscriptions.push(vscode.commands.registerCommand(RescanLint, this.rescanLinter, this));
189+
this.subscriptions.push(vscode.commands.registerCommand(InitLint, this.initialize, this));
190+
this.subscriptions.push(vscode.commands.registerCommand(CleanLintFiles, this.clean, this));
191+
this.subscriptions.push(
194192
vscode.commands.registerCommand(
195193
CleanLintDiagnostics,
196194
() => {
@@ -199,7 +197,7 @@ export class FortranLintingProvider {
199197
this
200198
)
201199
);
202-
context.subscriptions.push(
200+
this.subscriptions.push(
203201
vscode.commands.registerTextEditorCommand(
204202
BuildRun,
205203
async (textEditor: vscode.TextEditor, edit: vscode.TextEditorEdit, ...args: any[]) => {
@@ -208,7 +206,7 @@ export class FortranLintingProvider {
208206
this
209207
)
210208
);
211-
context.subscriptions.push(
209+
this.subscriptions.push(
212210
vscode.commands.registerTextEditorCommand(
213211
BuildDebug,
214212
async (textEditor: vscode.TextEditor, edit: vscode.TextEditorEdit, ...args: any[]) => {
@@ -218,31 +216,33 @@ export class FortranLintingProvider {
218216
)
219217
);
220218

221-
vscode.workspace.onDidOpenTextDocument(this.doLint, this, this.disposables);
219+
vscode.workspace.onDidOpenTextDocument(this.doLint, this, this.subscriptions);
222220
vscode.workspace.onDidCloseTextDocument(
223221
doc => {
224222
this.fortranDiagnostics.delete(doc.uri);
225223
},
226224
this,
227-
this.disposables
225+
this.subscriptions
228226
);
229227

230-
vscode.workspace.onDidSaveTextDocument(this.doLint, this, this.disposables);
228+
vscode.workspace.onDidSaveTextDocument(this.doLint, this, this.subscriptions);
231229
// Run the linter for all open documents i.e. docs loaded in memory
232230
vscode.workspace.textDocuments.forEach(this.doLint, this);
233231

234232
// Update settings on Configuration change
235233
vscode.workspace.onDidChangeConfiguration(e => {
236234
this.settings.update(e);
237-
}, this.disposables);
235+
}, this.subscriptions);
238236

239237
if (this.settings.initialize) this.initialize();
238+
239+
return this.subscriptions;
240240
}
241241

242242
public dispose(): void {
243243
this.fortranDiagnostics.clear();
244244
this.fortranDiagnostics.dispose();
245-
this.disposables.forEach(d => d.dispose());
245+
this.subscriptions.forEach(d => d.dispose());
246246
}
247247

248248
/**

0 commit comments

Comments
 (0)