Skip to content

Commit 4b0bbea

Browse files
committed
feat: adds option to set the log level
1 parent 5ae35f0 commit 4b0bbea

File tree

4 files changed

+45
-4
lines changed

4 files changed

+45
-4
lines changed

package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,19 @@
180180
],
181181
"markdownDescription": "Specify the word case to use when suggesting autocomplete options.",
182182
"order": 60
183+
},
184+
"fortran.logging.level": {
185+
"type": "string",
186+
"default": "Info",
187+
"enum": [
188+
"None",
189+
"Error",
190+
"Warn",
191+
"Info",
192+
"Debug"
193+
],
194+
"markdownDescription": "The log level for the extension.",
195+
"order": 70
183196
}
184197
}
185198
},
@@ -560,5 +573,11 @@
560573
"glob": "^8.0.3",
561574
"vscode-languageclient": "^8.0.2",
562575
"which": "^2.0.2"
576+
},
577+
"__metadata": {
578+
"id": "64379b4d-40cd-415a-8643-b07572d4a243",
579+
"publisherDisplayName": "The Fortran Programming Language",
580+
"publisherId": "0fb8288f-2952-4d83-8d25-46814faecc34",
581+
"isPreReleaseVersion": false
563582
}
564583
}

src/extension.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import { FortlsClient } from './lsp/client';
1212
import { FortranHoverProvider } from './features/hover-provider';
1313
import { FortranLintingProvider } from './features/linter-provider';
1414
import { EXTENSION_ID, FortranDocumentSelector } from './lib/tools';
15-
import { Logger } from './services/logging';
15+
import { getConfigLogLevel, Logger } from './services/logging';
1616
import { WhatsNew } from './features/commands';
1717

1818
// Make it global to catch errors when activation fails
19-
const logger = new Logger(vscode.window.createOutputChannel('Modern Fortran'));
19+
const logger = new Logger(vscode.window.createOutputChannel('Modern Fortran'), getConfigLogLevel());
2020

2121
export async function activate(context: vscode.ExtensionContext) {
2222
const config = vscode.workspace.getConfiguration(EXTENSION_ID);
@@ -35,6 +35,14 @@ export async function activate(context: vscode.ExtensionContext) {
3535
logger.info(`Hover set to: ${hoverType}`);
3636
logger.info(`Symbols set to: ${symbolsType}`);
3737

38+
context.subscriptions.push(
39+
vscode.workspace.onDidChangeConfiguration(e => {
40+
if (e.affectsConfiguration(`${EXTENSION_ID}.logging.level`)) {
41+
// Leave config field empty to fetch the most updated config values
42+
logger.setLogLevel(getConfigLogLevel());
43+
}
44+
})
45+
);
3846
// Linter is always activated but will only lint if compiler !== Disabled
3947
const linter = new FortranLintingProvider(logger);
4048
linter.activate(context.subscriptions);

src/services/logging.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { OutputChannel, window } from 'vscode';
1+
import { OutputChannel, window, workspace, WorkspaceConfiguration } from 'vscode';
2+
import { EXTENSION_ID } from '../lib/tools';
23

34
export enum LogLevel {
45
DEBUG = 0,
@@ -84,3 +85,15 @@ export class Logger {
8485
this.channel.appendLine(`[${LogLevel[level]} - ${title}] ${message}`);
8586
}
8687
}
88+
89+
/**
90+
* Gets the `fortran.logging.level` option from the workspace settings and converts
91+
* it a `LogLevel` enum value.
92+
* @param config workspace configuration object
93+
* @returns `LogLevel` enum value
94+
*/
95+
export function getConfigLogLevel(
96+
config: WorkspaceConfiguration = workspace.getConfiguration(EXTENSION_ID)
97+
): LogLevel {
98+
return LogLevel[config.get<string>('logging.level').toUpperCase() as keyof typeof LogLevel];
99+
}

test/fortran/.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
"fortran.fortls.directories": ["./**"],
1111
"fortran.fortls.excludeSuffixes": [".snap"],
1212
"fortran.fortls.excludeDirectories": [".vscode/"],
13-
"fortran.fortls.notifyInit": true
13+
"fortran.fortls.notifyInit": true,
14+
"fortran.logging.level": "Debug"
1415
}

0 commit comments

Comments
 (0)