Skip to content

Commit 29a7d57

Browse files
Accept task bodies and packages for subp box command
These symbols are returned as SymbolKind.Module by the ALS. For #1153
1 parent 58f6110 commit 29a7d57

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

integration/vscode/ada/src/extension.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ import {
2323
LanguageClientOptions,
2424
Middleware,
2525
ServerOptions,
26+
SymbolKind,
2627
} from 'vscode-languageclient/node';
2728
import { platform } from 'os';
2829
import * as process from 'process';
2930
import GnatTaskProvider from './gnatTaskProvider';
3031
import GprTaskProvider from './gprTaskProvider';
31-
import { getSubprogramSymbol } from './gnatTaskProvider';
32+
import { getEnclosingSymbol } from './gnatTaskProvider';
3233
import { alsCommandExecutor } from './alsExecuteCommand';
3334
import { ALSClientFeatures } from './alsClientFeatures';
3435
import { substituteVariables } from './helpers';
@@ -242,7 +243,8 @@ function createClient(
242243
async function addSupbrogramBox() {
243244
const activeEditor = vscode.window.activeTextEditor;
244245

245-
await getSubprogramSymbol(activeEditor).then(async (symbol) => {
246+
await getEnclosingSymbol(
247+
activeEditor, [SymbolKind.Function, SymbolKind.Module]).then(async (symbol) => {
246248
if (symbol !== null) {
247249
const name: string = symbol.name ?? '';
248250
const insertPos = new vscode.Position(symbol.range.start.line, 0);

integration/vscode/ada/src/gnatTaskProvider.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ interface TaskProperties {
4242
* or '' if not found.
4343
*/
4444
const limitSubp = async (): Promise<string> => {
45-
return getSubprogramSymbol(vscode.window.activeTextEditor).then((Symbol) => {
45+
return getEnclosingSymbol(vscode.window.activeTextEditor, [SymbolKind.Function]).then((Symbol) => {
4646
if (Symbol) {
4747
const subprogram_line: string = (Symbol.range.start.line + 1).toString();
4848
return `--limit-subp=\${fileBasename}:${subprogram_line}`;
@@ -282,16 +282,16 @@ async function getTasks(): Promise<vscode.Task[]> {
282282
}
283283

284284
/**
285-
* Return the DocumentSymbol associated to the subprogram enclosing the
285+
* Return the closest DocumentSymbol of the given kinds enclosing the
286286
* the given editor's cursor position, if any.
287287
* @param editor - The editor in which we want
288-
* to find the suprogram's body enclosing the cursor's position.
289-
* @returns Return the symbol corresponding to the
290-
* enclosing subprogram or null if not found.
288+
* to find the closest symbol enclosing the cursor's position.
289+
* @returns Return the closest enclosing symbol.
291290
*/
292-
export const getSubprogramSymbol = async (
293-
editor: vscode.TextEditor | undefined
294-
): Promise<vscode.DocumentSymbol | null> => {
291+
export async function getEnclosingSymbol (
292+
editor: vscode.TextEditor | undefined,
293+
kinds: vscode.SymbolKind[]
294+
): Promise<vscode.DocumentSymbol | null> {
295295
if (editor) {
296296
const line = editor.selection.active.line;
297297

@@ -301,25 +301,25 @@ export const getSubprogramSymbol = async (
301301
editor.document.uri
302302
);
303303

304-
// Then select all subprograms
305-
const subprograms: vscode.DocumentSymbol[] = [];
304+
// Then filter them according to the specified kinds
305+
const filtered_symbols: vscode.DocumentSymbol[] = [];
306306

307-
const getAllSubprograms = (symbols: vscode.DocumentSymbol[]) => {
307+
const getAllSymbols = (symbols: vscode.DocumentSymbol[]) => {
308308
let sym;
309309
for (sym of symbols) {
310-
if (sym.kind == SymbolKind.Function) {
311-
subprograms.push(sym);
310+
if (sym.kind in kinds) {
311+
filtered_symbols.push(sym);
312312
}
313313
if (sym.kind == SymbolKind.Function || sym.kind == SymbolKind.Module) {
314-
getAllSubprograms(sym.children);
314+
getAllSymbols(sym.children);
315315
}
316316
}
317317
};
318318

319-
getAllSubprograms(symbols);
319+
getAllSymbols(symbols);
320320

321-
// Finally select from the subprograms the smallest one containing the current line
322-
const scopeSymbols = subprograms.filter(
321+
// Finally select from the filtered symbols the smallest one containing the current line
322+
const scopeSymbols = filtered_symbols.filter(
323323
(sym) => line >= sym.range.start.line && line <= sym.range.end.line
324324
);
325325
if (scopeSymbols.length > 0) {

0 commit comments

Comments
 (0)