Skip to content

Commit ccb003d

Browse files
committed
Adds Don't Show Again action when fortls is missing
1 parent ad4e257 commit ccb003d

File tree

4 files changed

+47
-27
lines changed

4 files changed

+47
-27
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@
221221
"uppercase"
222222
],
223223
"description": "Specify the word case to use when suggesting autocomplete options (One of 'lowercase' or 'upercase')"
224+
},
225+
"fortran.ignoreWarning.fortls": {
226+
"type": "boolean",
227+
"default": false,
228+
"description": "Hide error message when the fortran-language-server is not detected"
224229
}
225230
}
226231
},

src/extension.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ export function activate(context: vscode.ExtensionContext) {
7171
enable hover, peeking, gotos and many more.
7272
For a full list of features the language server adds see:
7373
https://github.com/hansec/fortran-language-server`;
74-
promptForMissingTool(LANG_SERVER_TOOL_ID, msg, 'Python', loggingService);
74+
75+
if (!extensionConfig.get('ignoreWarning.fortls')) {
76+
promptForMissingTool(
77+
LANG_SERVER_TOOL_ID,
78+
msg,
79+
'Python',
80+
['Install', "Don't Show Again"],
81+
loggingService,
82+
() => {
83+
extensionConfig.update('ignoreWarning.fortls', true);
84+
}
85+
);
86+
}
7587
}
7688
}

src/features/formatting-provider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class FortranFormattingProvider implements vscode.DocumentFormattingEditP
5151
this.logger.logWarning(`Formatter: ${formatterName} not detected in your system.
5252
Attempting to install now.`);
5353
const msg = `Installing ${formatterName} through pip with --user option`;
54-
promptForMissingTool(formatterName, msg, 'Python');
54+
promptForMissingTool(formatterName, msg, 'Python', ['Install'], this.logger);
5555
}
5656

5757
const args: string[] = [document.fileName, ...this.getFormatterArgs()];
@@ -90,7 +90,7 @@ export class FortranFormattingProvider implements vscode.DocumentFormattingEditP
9090
this.logger.logWarning(`Formatter: ${formatterName} not detected in your system.
9191
Attempting to install now.`);
9292
const msg = `Installing ${formatterName} through pip with --user option`;
93-
promptForMissingTool(formatterName, msg, 'Python');
93+
promptForMissingTool(formatterName, msg, 'Python', ['Install'], this.logger);
9494
}
9595

9696
// Annoyingly findent only outputs to a file and not to a stream so

src/lib/tools.ts

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,40 +47,43 @@ export function FortranDocumentSelector(folder?: vscode.WorkspaceFolder) {
4747
* e.g 'hansec.fortran-ls'
4848
*
4949
* @param tool name of the tool e.g. fortran-language-server
50-
* @param msg optional message for installing said package
50+
* @param msg message for installing said package
5151
* @param toolType type of tool, supports `Python` (through pip) and 'VSExt'
52+
* @param opts options for the prompt. "Install" and "Don't Show Again" are coded
53+
* @param logger log channel output
54+
* @param action a void function for an action to perform when "Don't Show Again" is pressed
5255
*/
5356
export function promptForMissingTool(
5457
tool: string,
5558
msg: string,
5659
toolType: string,
57-
logger?: LoggingService
60+
opts: string[],
61+
logger?: LoggingService,
62+
action?: () => void
5863
) {
5964
const items = ['Install'];
60-
return new Promise((resolve, reject) => {
61-
resolve(
62-
vscode.window.showInformationMessage(msg, ...items).then(selected => {
63-
if (selected === 'Install') {
64-
switch (toolType) {
65-
case 'Python':
66-
installPythonTool(tool, logger);
67-
break;
65+
return vscode.window.showInformationMessage(msg, ...opts).then(selected => {
66+
if (selected === 'Install') {
67+
switch (toolType) {
68+
case 'Python':
69+
installPythonTool(tool, logger);
70+
break;
6871

69-
case 'VSExt':
70-
logger.logInfo(`Installing VS Marketplace Extension with id: ${tool}`);
71-
vscode.commands.executeCommand('extension.open', tool);
72-
vscode.commands.executeCommand('workbench.extensions.installExtension', tool);
73-
logger.logInfo(`Extension ${tool} successfully installed`);
74-
break;
72+
case 'VSExt':
73+
logger.logInfo(`Installing VS Marketplace Extension with id: ${tool}`);
74+
vscode.commands.executeCommand('extension.open', tool);
75+
vscode.commands.executeCommand('workbench.extensions.installExtension', tool);
76+
logger.logInfo(`Extension ${tool} successfully installed`);
77+
break;
7578

76-
default:
77-
logger.logError(`Failed to install tool: ${tool}`);
78-
vscode.window.showErrorMessage(`Failed to install tool: ${tool}`);
79-
break;
80-
}
81-
}
82-
})
83-
);
79+
default:
80+
logger.logError(`Failed to install tool: ${tool}`);
81+
vscode.window.showErrorMessage(`Failed to install tool: ${tool}`);
82+
break;
83+
}
84+
} else if (selected === "Don't Show Again") {
85+
action();
86+
}
8487
});
8588
}
8689

0 commit comments

Comments
 (0)