Skip to content

Commit 5049b28

Browse files
committed
feat: improves the reporting of msgs in the logs
Adds substantial error and debug reporting in the logs. It also converts a lot of the `info` messages to `debug`
1 parent b8be284 commit 5049b28

File tree

4 files changed

+41
-29
lines changed

4 files changed

+41
-29
lines changed

src/extension.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ export async function activate(context: vscode.ExtensionContext) {
3232

3333
logger.info(`Extension Name: ${pkg.displayName}`);
3434
logger.info(`Extension Version: ${pkg.version}`);
35-
logger.info(`Linter set to: ${linterType}`);
36-
logger.info(`Formatter set to: ${formatterType}`);
37-
logger.info(`Autocomplete set to: ${autocompleteType}`);
38-
logger.info(`Hover set to: ${hoverType}`);
39-
logger.info(`Symbols set to: ${symbolsType}`);
35+
logger.info(`Linter set to: "${linterType}"`);
36+
logger.info(`Formatter set to: "${formatterType}"`);
37+
logger.info(`Autocomplete set to: "${autocompleteType}"`);
38+
logger.info(`Hover set to: "${hoverType}"`);
39+
logger.info(`Symbols set to: "${symbolsType}"`);
4040

4141
context.subscriptions.push(
4242
vscode.workspace.onDidChangeConfiguration(e => {

src/features/formatting-provider.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class FortranFormattingProvider implements vscode.DocumentFormattingEditP
3232
} else if (formatterName === 'findent') {
3333
return this.doFormatFindent(document);
3434
} else {
35-
this.logger.error('Cannot format document with formatter set to Disabled');
35+
this.logger.error('[format] Cannot format document with formatter set to Disabled');
3636
}
3737

3838
return undefined;
@@ -46,7 +46,7 @@ export class FortranFormattingProvider implements vscode.DocumentFormattingEditP
4646
private async doFormatFprettify(document: vscode.TextDocument): Promise<vscode.TextEdit[]> {
4747
// fprettify can only do FortranFreeFrom
4848
if (document.languageId !== 'FortranFreeForm') {
49-
this.logger.error(`fprettify can only format FortranFreeForm, change
49+
this.logger.error(`[format] fprettify can only format FortranFreeForm, change
5050
to findent for FortranFixedForm formatting`);
5151
return undefined;
5252
}
@@ -56,17 +56,17 @@ export class FortranFormattingProvider implements vscode.DocumentFormattingEditP
5656
const formatter: string = path.join(formatterPath, formatterName);
5757
// If no formatter is detected try and install it
5858
if (!which.sync(formatter, { nothrow: true })) {
59-
this.logger.warn(`Formatter: ${formatterName} not detected in your system.
60-
Attempting to install now.`);
59+
this.logger.warn(`[format] ${formatterName} not found. Attempting to install now.`);
6160
const msg = `Installing ${formatterName} through pip with --user option`;
6261
promptForMissingTool(formatterName, msg, 'Python', ['Install'], this.logger);
6362
}
6463

6564
const args: string[] = ['--stdout', ...this.getFormatterArgs()];
65+
this.logger.debug(`[format] fprettify args:`, args);
6666
const edits: vscode.TextEdit[] = [];
6767
const [stdout, stderr] = await spawnAsPromise(formatter, args, undefined, document.getText());
6868
edits.push(new vscode.TextEdit(getWholeFileRange(document), stdout));
69-
if (stderr) this.logger.info(`fprettify error output: ${stderr}`);
69+
if (stderr) this.logger.error(`[format] fprettify error output: ${stderr}`);
7070
return edits;
7171
}
7272

@@ -81,17 +81,17 @@ export class FortranFormattingProvider implements vscode.DocumentFormattingEditP
8181
const formatter: string = path.join(formatterPath, formatterName);
8282
// If no formatter is detected try and install it
8383
if (!which.sync(formatter, { nothrow: true })) {
84-
this.logger.warn(`Formatter: ${formatterName} not detected in your system.
85-
Attempting to install now.`);
84+
this.logger.warn(`[format] ${formatterName} not found! Attempting to install now.`);
8685
const msg = `Installing ${formatterName} through pip with --user option`;
8786
promptForMissingTool(formatterName, msg, 'Python', ['Install'], this.logger);
8887
}
8988

9089
const args: string[] = this.getFormatterArgs();
90+
this.logger.debug(`[format] findent args:`, args);
9191
const edits: vscode.TextEdit[] = [];
9292
const [stdout, stderr] = await spawnAsPromise(formatter, args, undefined, document.getText());
9393
edits.push(new vscode.TextEdit(getWholeFileRange(document), stdout));
94-
if (stderr) this.logger.info(`findent error output: ${stderr}`);
94+
if (stderr) this.logger.error(`[format] findent error output: ${stderr}`);
9595
return edits;
9696
}
9797

@@ -107,7 +107,7 @@ export class FortranFormattingProvider implements vscode.DocumentFormattingEditP
107107
this.formatter = this.workspace.get('formatting.formatter', 'Disabled');
108108

109109
if (!FORMATTERS.includes(this.formatter)) {
110-
this.logger.error(`Unsupported formatter: ${this.formatter}`);
110+
this.logger.error(`[format] Unsupported formatter: ${this.formatter}`);
111111
}
112112
return this.formatter;
113113
}
@@ -130,7 +130,7 @@ export class FortranFormattingProvider implements vscode.DocumentFormattingEditP
130130
private getFormatterPath(): string {
131131
const formatterPath: string = this.workspace.get('formatting.path', '');
132132
if (formatterPath !== '') {
133-
this.logger.info(`Formatter located in: ${formatterPath}`);
133+
this.logger.info(`[format] Formatter located in: ${formatterPath}`);
134134
}
135135

136136
return formatterPath;

src/features/linter-provider.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export class FortranLintingProvider {
8888
env.Path = `${path.dirname(command)}${path.delimiter}${env.Path}`;
8989
}
9090
}
91+
this.logger.info(`[lint] Compiler query command line: ${command} ${argList.join(' ')}`);
9192
const childProcess = cp.spawn(command, argList, {
9293
cwd: filePath,
9394
env: env,
@@ -101,11 +102,13 @@ export class FortranLintingProvider {
101102
compilerOutput += data;
102103
});
103104
childProcess.stderr.on('end', () => {
105+
this.logger.debug(`[lint] Compiler output:`, compilerOutput);
104106
let diagnostics = this.getLinterResults(compilerOutput);
105107
diagnostics = [...new Map(diagnostics.map(v => [JSON.stringify(v), v])).values()];
106108
this.diagnosticCollection.set(textDocument.uri, diagnostics);
107109
});
108110
childProcess.on('error', err => {
111+
this.logger.error(`[lint] Compiler error:`, err);
109112
console.log(`ERROR: ${err}`);
110113
});
111114
} else {
@@ -167,7 +170,7 @@ export class FortranLintingProvider {
167170
}
168171

169172
modout = resolveVariables(modout);
170-
this.logger.info(`Linter.moduleOutput: ${modFlag} ${modout}`);
173+
this.logger.debug(`[lint] moduleOutput: ${modFlag} ${modout}`);
171174
return [modFlag, modout];
172175
}
173176

@@ -195,7 +198,7 @@ export class FortranLintingProvider {
195198
// Update our cache input
196199
this.cache['includePaths'] = includePaths;
197200
// Output the original include paths
198-
this.logger.info(`Linter.include:\n${includePaths.join('\r\n')}`);
201+
if (includePaths.length > 0) this.logger.debug(`[lint] include:`, includePaths);
199202
// Resolve internal variables and expand glob patterns
200203
const resIncludePaths = includePaths.map(e => resolveVariables(e));
201204
// fast-glob cannot work with Windows paths
@@ -212,12 +215,12 @@ export class FortranLintingProvider {
212215
// Try to recover from fast-glob failing due to EACCES using slower more
213216
// robust glob.
214217
} catch (eacces) {
215-
this.logger.warn(`You lack read permissions for an include directory
218+
this.logger.warn(`[lint] You lack read permissions for an include directory
216219
or more likely a glob match from the input 'includePaths' list. This can happen when
217220
using overly broad root level glob patters e.g. /usr/lib/** .
218221
No reason to worry. I will attempt to recover.
219222
You should consider adjusting your 'includePaths' if linting performance is slow.`);
220-
this.logger.warn(`${eacces.message}`);
223+
this.logger.warn(`[lint] ${eacces.message}`);
221224
try {
222225
const globIncPaths: string[] = [];
223226
for (const i of resIncludePaths) {
@@ -228,7 +231,7 @@ export class FortranLintingProvider {
228231
return globIncPaths;
229232
// if we failed again then our includes are somehow wrong. Abort
230233
} catch (error) {
231-
this.logger.error(`Failed to recover: ${error}`);
234+
this.logger.error(`[lint] Include path glob resolution failed to recover: ${error}`);
232235
}
233236
}
234237
}
@@ -243,7 +246,7 @@ export class FortranLintingProvider {
243246
this.compiler = config.get<string>('compiler', 'gfortran');
244247
this.compilerPath = config.get<string>('compilerPath', '');
245248
if (this.compilerPath === '') this.compilerPath = which.sync(this.compiler);
246-
this.logger.info(`using linter: ${this.compiler} located in: ${this.compilerPath}`);
249+
this.logger.debug(`[lint] binary: "${this.compiler}" located in: "${this.compilerPath}"`);
247250
return this.compilerPath;
248251
}
249252

@@ -287,7 +290,7 @@ export class FortranLintingProvider {
287290
const lnStr: string = ln === -1 ? 'none' : ln.toString();
288291
args.push(`-ffree-line-length-${lnStr}`, `-ffixed-line-length-${lnStr}`);
289292
}
290-
this.logger.info(`Linter.arguments:\n${args.join('\r\n')}`);
293+
if (args.length > 0) this.logger.debug(`[lint] arguments:`, args);
291294

292295
// Resolve internal variables but do not apply glob pattern matching
293296
return args.map(e => resolveVariables(e));
@@ -540,7 +543,10 @@ export class FortranLintingProvider {
540543
* Regenerate the cache for the include files paths of the linter
541544
*/
542545
private rescanLinter() {
546+
this.logger.debug(`[lint] Resetting linter include paths cache`);
547+
this.logger.debug(`[lint] Current linter include paths cache:`, this.cache['includePaths']);
543548
this.cache['includePaths'] = [];
544549
this.getIncludePaths();
550+
this.logger.debug(`[lint] New linter include paths cache:`, this.cache['includePaths']);
545551
}
546552
}

src/lsp/client.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const clients: Map<string, LanguageClient> = new Map();
2222

2323
export class FortlsClient {
2424
constructor(private logger: Logger, private context?: vscode.ExtensionContext) {
25-
this.logger.info('Fortran Language Server');
25+
this.logger.debug('[lsp.client] Fortran Language Server -- constructor');
2626

2727
// if context is present
2828
if (context !== undefined) {
@@ -85,6 +85,7 @@ export class FortlsClient {
8585

8686
// Detect language server version and verify selected options
8787
this.version = this.getLSVersion(executablePath, args);
88+
this.logger.debug(`[lsp.client] Language Server version: ${this.version}`);
8889
if (!this.version) return;
8990
const serverOptions: ServerOptions = {
9091
command: executablePath,
@@ -110,9 +111,9 @@ export class FortlsClient {
110111
const fileRoot: string = path.dirname(document.uri.fsPath);
111112
if (clients.has(fileRoot)) return; // already registered
112113
this.logger.info(
113-
'Initialising Language Server for file: ' +
114-
`${document.uri.fsPath} with command-line options: ${args.join(', ')}`
114+
`[lsp.client] Initialising Language Server for file: ${document.uri.fsPath}`
115115
);
116+
this.logger.info(`[lsp.client] Language Server arguments: ${args.join(' ')}`);
116117
// Options to control the language client
117118
const clientOptions: LanguageClientOptions = {
118119
documentSelector: FortranDocumentSelector(fileRoot),
@@ -134,9 +135,9 @@ export class FortlsClient {
134135
folder = getOuterMostWorkspaceFolder(folder);
135136
if (clients.has(folder.uri.toString())) return; // already registered
136137
this.logger.info(
137-
'Initialising Language Server for workspace: ' +
138-
`${document.uri.fsPath} with command-line options: ${args.join(', ')}`
138+
`[lsp.client] Initialising Language Server for workspace: ${folder.uri.toString()}`
139139
);
140+
this.logger.info(`[lsp.client] Language Server arguments: ${args.join(' ')}`);
140141
// Options to control the language client
141142
const clientOptions: LanguageClientOptions = {
142143
documentSelector: FortranDocumentSelector(folder.uri.fsPath),
@@ -243,6 +244,7 @@ export class FortlsClient {
243244
args.push(`--pp_defs=${JSON.stringify(pp_defs)}`);
244245
}
245246

247+
this.logger.debug(`[lsp.client] Language Server arguments:`, args);
246248
return args;
247249
}
248250

@@ -259,6 +261,7 @@ export class FortlsClient {
259261
private getLSVersion(executablePath: string, args: string[]) {
260262
const results = spawnSync(executablePath, args.concat(['--version']));
261263
if (results.error) {
264+
this.logger.error(`[lsp.client] Unable to launch LS to check version:`, results.error);
262265
const selected = window.showErrorMessage(
263266
'Modern Fortran Error starting fortls: Check that fortls is in your PATH or that "fortran.fortls.path" is pointing to a fortls binary.',
264267
'Settings',
@@ -275,6 +278,7 @@ export class FortlsClient {
275278
return null;
276279
}
277280
if (results.status !== 0) {
281+
this.logger.error(`[lsp.client] Unable to verify input arguments with LS:`);
278282
const selected = window.showErrorMessage(
279283
'Error launching fortls: Please check that all selected options are supported by your language server version.',
280284
'Settings',
@@ -313,11 +317,12 @@ export class FortlsClient {
313317
if (opt === 'Install') {
314318
const install = spawnSync('pip', ['install', '--user', '--upgrade', LS_NAME]);
315319
if (install.error) {
320+
this.logger.error(`[lsp.client] Unable to install fortls:`, install.error);
316321
window.showErrorMessage('Had trouble installing fortls, please install manually');
317322
fortlsDisabled = true;
318323
}
319324
if (install.stdout) {
320-
this.logger.info(install.stdout.toString());
325+
this.logger.info(`[lsp.client] ${install.stdout.toString()}`);
321326
fortlsDisabled = false;
322327
}
323328
} else if (opt == 'Disable') {
@@ -336,9 +341,10 @@ export class FortlsClient {
336341
* Restart the language server
337342
*/
338343
private async restartLS(): Promise<void> {
339-
this.logger.info('Restarting language server...');
344+
this.logger.info('[lsp.client] Restarting language server...');
340345
vscode.window.showInformationMessage('Restarting language server...');
341346
await this.deactivate();
342347
await this.activate();
348+
this.logger.info('[lsp.client] Language server restarted');
343349
}
344350
}

0 commit comments

Comments
 (0)