|
1 | 1 | import * as fs from 'fs';
|
2 | 2 | import * as vscode from 'vscode';
|
| 3 | +import { installPythonTool } from './tools'; |
3 | 4 | import intrinsics from './fortran-intrinsics';
|
4 |
| -import { installTool, LANG_SERVER_TOOL_ID } from './tools'; |
| 5 | +import { LoggingService } from '../services/logging-service'; |
5 | 6 |
|
6 | 7 | // IMPORTANT: this should match the value
|
7 | 8 | // on the package.json otherwise the extension won't
|
@@ -109,24 +110,50 @@ export function isPositionInString(
|
109 | 110 | let saveKeywordToJson = keyword => {
|
110 | 111 | let doc = _loadDocString(keyword);
|
111 | 112 | let docObject = JSON.stringify({ keyword: keyword, docstr: doc });
|
112 |
| - fs.appendFile('src/docs/' + keyword + '.json', docObject, function(err) { |
| 113 | + fs.appendFile('src/docs/' + keyword + '.json', docObject, function (err) { |
113 | 114 | if (err) throw err;
|
114 | 115 | console.log('Saved!');
|
115 | 116 | });
|
116 | 117 | };
|
117 | 118 |
|
118 | 119 |
|
119 |
| -export function promptForMissingTool(tool: string) { |
| 120 | +/** |
| 121 | + * Install a package either a Python pip package or a VS Marketplace Extension. |
| 122 | + * |
| 123 | + * For the Python install supply the name of the package in PyPi |
| 124 | + * e.g. fortran-language-server |
| 125 | + * |
| 126 | + * For the VS Extension to be installed supply the id of the extension |
| 127 | + * e.g 'hansec.fortran-ls' |
| 128 | + * |
| 129 | + * @param tool name of the tool e.g. fortran-language-server |
| 130 | + * @param msg optional message for installing said package |
| 131 | + * @param toolType type of tool, supports `Python` (through pip) and 'VSExt' |
| 132 | + */ |
| 133 | +export function promptForMissingTool(tool: string, msg: string, toolType: string, logger?: LoggingService) { |
120 | 134 | const items = ['Install'];
|
121 |
| - let message = ''; |
122 |
| - if (tool === 'fortran-langserver') { |
123 |
| - message = |
124 |
| - 'You choose to use the fortranLanguageServer functionality but it is not installed. Please press the Install button to install it'; |
125 |
| - } |
126 |
| - vscode.window.showInformationMessage(message, ...items).then(selected => { |
127 |
| - if (selected === 'Install') { |
128 |
| - installTool(tool); |
129 |
| - } |
| 135 | + return new Promise((resolve, reject) => { |
| 136 | + resolve( |
| 137 | + vscode.window.showInformationMessage(msg, ...items).then(selected => { |
| 138 | + if (selected === 'Install') { |
| 139 | + switch (toolType) { |
| 140 | + case 'Python': |
| 141 | + installPythonTool(tool, logger); |
| 142 | + break; |
| 143 | + |
| 144 | + case 'VSExt': |
| 145 | + logger.logInfo(`Installing VS Marketplace Extension with id: ${tool}`); |
| 146 | + vscode.commands.executeCommand('workbench.extensions.installExtension', tool); |
| 147 | + logger.logInfo(`Extension ${tool} successfully installed`); |
| 148 | + break; |
| 149 | + |
| 150 | + default: |
| 151 | + logger.logError(`Failed to install tool: ${tool}`); |
| 152 | + break; |
| 153 | + } |
| 154 | + } |
| 155 | + }) |
| 156 | + ); |
130 | 157 | });
|
131 | 158 |
|
132 | 159 | }
|
0 commit comments