Skip to content

Commit 5eabb82

Browse files
Add a getSourceDirs function helper
To encapsulate the 'als-source-dirs' LSP request. For eng/ide/ada_language_server#1515
1 parent 4731c8a commit 5eabb82

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

integration/vscode/ada/src/ExtensionState.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ import {
2525
} from './taskProviders';
2626
import { isAbsolute } from 'path';
2727

28+
/**
29+
* Return type of the 'als-source-dirs' LSP request.
30+
*/
31+
export type ALSSourceDirDescription = {
32+
name: string;
33+
uri: string;
34+
};
35+
2836
/**
2937
* This class encapsulates all state that should be maintained throughout the
3038
* lifecyle of the extension. This includes e.g. the Ada and GPR LSP clients,
@@ -56,6 +64,7 @@ export class ExtensionState {
5664
*/
5765
cachedProjectUri: vscode.Uri | undefined;
5866
cachedObjectDir: string | undefined;
67+
cachedSourceDirs: ALSSourceDirDescription[] | undefined;
5968
cachedTargetPrefix: string | undefined;
6069
cachedMains: string[] | undefined;
6170
cachedExecutables: string[] | undefined;
@@ -68,6 +77,7 @@ export class ExtensionState {
6877
private clearALSCache() {
6978
this.cachedProjectUri = undefined;
7079
this.cachedObjectDir = undefined;
80+
this.cachedSourceDirs = undefined;
7181
this.cachedTargetPrefix = undefined;
7282
this.cachedMains = undefined;
7383
this.cachedExecutables = undefined;
@@ -381,6 +391,20 @@ export class ExtensionState {
381391
return this.cachedObjectDir;
382392
}
383393

394+
/**
395+
*
396+
* @returns the list of source directorues defined in the project loaded by the ALS
397+
*/
398+
public async getSourceDirs(): Promise<ALSSourceDirDescription[]> {
399+
if (this.cachedSourceDirs === undefined) {
400+
this.cachedSourceDirs = (await this.adaClient.sendRequest(ExecuteCommandRequest.type, {
401+
command: 'als-source-dirs',
402+
})) as ALSSourceDirDescription[];
403+
}
404+
405+
return this.cachedSourceDirs;
406+
}
407+
384408
/**
385409
*
386410
* @returns the list of full paths of main sources defined in the project from the ALS

integration/vscode/ada/src/commands.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as vscode from 'vscode';
55
import { SymbolKind, commands } from 'vscode';
66
import { Disposable } from 'vscode-jsonrpc';
77
import { ExecuteCommandRequest } from 'vscode-languageclient';
8-
import { ExtensionState } from './ExtensionState';
8+
import { ALSSourceDirDescription, ExtensionState } from './ExtensionState';
99
import { AdaConfig, getOrAskForProgram, initializeConfig } from './debugConfigProvider';
1010
import { adaExtState, logger, mainOutputChannel } from './extension';
1111
import { findAdaMain, getProjectFileRelPath, getSymbols } from './helpers';
@@ -464,7 +464,6 @@ export async function checkSrcDirectories(atStartup = false, displayYesNoPopup =
464464
};
465465

466466
const foldersInSettings = vscode.workspace.getConfiguration().get('folders');
467-
const alsClient = adaExtState.adaClient;
468467
const doNotShowAgainKey = 'ada.addMissingDirsToWorkspace.doNotShowAgain';
469468
const doNotShowAgain = adaExtState.context.workspaceState.get(doNotShowAgainKey);
470469

@@ -473,13 +472,7 @@ export async function checkSrcDirectories(atStartup = false, displayYesNoPopup =
473472
// triggered at startup while the user previously clicked on the
474473
// 'Don't show again' button for this workspace
475474
if (foldersInSettings === undefined && !(atStartup && doNotShowAgain)) {
476-
const sourceDirs: ALSSourceDirDescription[] = (await alsClient.sendRequest(
477-
ExecuteCommandRequest.type,
478-
{
479-
command: 'als-source-dirs',
480-
},
481-
)) as ALSSourceDirDescription[];
482-
475+
const sourceDirs: ALSSourceDirDescription[] = await adaExtState.getSourceDirs();
483476
const isSubdirectory = (dir: string, parent: string) => {
484477
// Use lower-case on Windows since drives can be specified in VS Code
485478
// either with lower or upper case characters.

0 commit comments

Comments
 (0)