@@ -42,7 +42,7 @@ interface TaskProperties {
4242 * or '' if not found.
4343 */
4444const 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