|
15 | 15 | -- of the license. --
|
16 | 16 | ----------------------------------------------------------------------------*/
|
17 | 17 |
|
| 18 | +import { none } from 'fp-ts/lib/Option'; |
18 | 19 | import * as vscode from 'vscode';
|
19 | 20 | import { SymbolKind } from 'vscode';
|
| 21 | +import { integer } from 'vscode-languageclient'; |
20 | 22 |
|
21 | 23 | enum taskKinds {
|
22 | 24 | examineProject, // Examine the project
|
@@ -63,13 +65,19 @@ export default class gnatproveTaskProvider implements vscode.TaskProvider<vscode
|
63 | 65 | else if (definition.taskKind == taskKinds.examineSubprogram
|
64 | 66 | || definition.taskKind == taskKinds.proveSubprogram)
|
65 | 67 | {
|
66 |
| - return getSubprogram(vscode.window.activeTextEditor) |
67 |
| - .then(subprogram => |
| 68 | + return getSubprogramSymbol(vscode.window.activeTextEditor) |
| 69 | + .then(Symbol => |
68 | 70 | {
|
69 |
| - let args = (definition.taskKind == taskKinds.examineSubprogram) ? ['--mode=flow'] : []; |
70 |
| - args = getGnatproveArgs(args.concat(['-u', '${fileBasename}', '--limit-subp=${fileBasename}:' + subprogram])); |
71 |
| - const shell = new vscode.ShellExecution('gnatprove', args); |
72 |
| - return new vscode.Task(definition, vscode.TaskScope.Workspace, task.name, 'ada', shell, '$ada'); |
| 71 | + if (Symbol) { |
| 72 | + const subprogram_line: string = (Symbol.range.start.line + 1).toString() |
| 73 | + let args = (definition.taskKind == taskKinds.examineSubprogram) ? ['--mode=flow'] : []; |
| 74 | + args = getGnatproveArgs(args.concat(['-u', '${fileBasename}', '--limit-subp=${fileBasename}:' + subprogram_line])); |
| 75 | + const shell = new vscode.ShellExecution('gnatprove', args); |
| 76 | + return new vscode.Task(definition, vscode.TaskScope.Workspace, task.name, 'ada', shell, '$ada'); |
| 77 | + } |
| 78 | + else { |
| 79 | + return task; |
| 80 | + } |
73 | 81 | });
|
74 | 82 | }
|
75 | 83 | else {
|
@@ -161,8 +169,16 @@ const getTasks = (): vscode.Task[] => {
|
161 | 169 | return result;
|
162 | 170 | };
|
163 | 171 |
|
164 |
| -const getSubprogram = async (editor: vscode.TextEditor | undefined): Promise<string> => { |
165 |
| - let subprogramLine = 0; |
| 172 | +/** |
| 173 | + * Return the DocumentSymbol associated to the subprogram enclosing the |
| 174 | + * the given editor's cursor position, if any. |
| 175 | + * @param {vscode.TextEditor | undefined} editor - The editor in which we want |
| 176 | + * to find the suprogram's body enclosing the cursor's position. |
| 177 | + * @return {vscode.DocumentSymbol | null} Return the symbol corresponding to the |
| 178 | + * enclosing subprogram or null if not found. |
| 179 | + */ |
| 180 | +export const getSubprogramSymbol = async (editor: vscode.TextEditor | undefined): Promise<vscode.DocumentSymbol|null> => { |
| 181 | + let subprogramLine = 0; |
166 | 182 | if (editor) {
|
167 | 183 | const line = editor.selection.active.line;
|
168 | 184 |
|
@@ -190,12 +206,12 @@ const getSubprogram = async (editor: vscode.TextEditor | undefined): Promise<str
|
190 | 206 | let scopeSymbols = subprograms.filter(sym => line >= sym.range.start.line && line <= sym.range.end.line);
|
191 | 207 | if (scopeSymbols.length > 0) {
|
192 | 208 | scopeSymbols.sort((a,b) => (a.range.end.line - a.range.start.line) - (b.range.end.line - b.range.start.line));
|
193 |
| - subprogramLine = scopeSymbols[0].range.start.line; |
| 209 | + return scopeSymbols[0]; |
194 | 210 | };
|
195 | 211 | };
|
196 |
| - // Line numbers start at 0 in VS Code, and at 1 in GNAT |
197 |
| - return (subprogramLine + 1).toString(); |
198 |
| -}; |
| 212 | + |
| 213 | + return null; |
| 214 | +} |
199 | 215 |
|
200 | 216 | const getSelectedRegion = (editor: vscode.TextEditor | undefined): string => {
|
201 | 217 | if (editor) {
|
|
0 commit comments