Skip to content

Commit 992e7e4

Browse files
author
automatic-merge
committed
Merge remote branch 'origin/master' into edge
2 parents 0a18783 + 53859ce commit 992e7e4

16 files changed

+765
-167
lines changed

integration/vscode/ada/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -723,13 +723,13 @@
723723
"when": "ADA_PROJECT_CONTEXT"
724724
},
725725
{
726-
"command": "ada.runMainAsk",
726+
"command": "ada.buildAndRunMainAsk",
727727
"title": "Ada: Build and run project main...",
728728
"icon": "$(run-all)",
729729
"when": "ADA_PROJECT_CONTEXT"
730730
},
731731
{
732-
"command": "ada.runMainLast",
732+
"command": "ada.buildAndRunMainLast",
733733
"title": "Ada: Build and run last used main",
734734
"icon": "$(run)",
735735
"when": "ADA_PROJECT_CONTEXT"
@@ -760,12 +760,12 @@
760760
],
761761
"editor/title/run": [
762762
{
763-
"command": "ada.runMainLast",
763+
"command": "ada.buildAndRunMainLast",
764764
"when": "editorLangId == ada",
765765
"group": "navigation@0"
766766
},
767767
{
768-
"command": "ada.runMainAsk",
768+
"command": "ada.buildAndRunMainAsk",
769769
"when": "editorLangId == ada",
770770
"group": "navigation@1"
771771
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import {
2+
CancellationError,
3+
CancellationToken,
4+
CodeLens,
5+
CodeLensProvider,
6+
DocumentSymbol,
7+
Event,
8+
ProviderResult,
9+
SymbolKind,
10+
TextDocument,
11+
commands,
12+
} from 'vscode';
13+
import { CMD_BUILD_AND_DEBUG_MAIN, CMD_BUILD_AND_RUN_MAIN } from './commands';
14+
import { getMains, getSymbols } from './helpers';
15+
16+
export class AdaCodeLensProvider implements CodeLensProvider {
17+
static readonly ENABLE_SPARK_CODELENS = false;
18+
19+
onDidChangeCodeLenses?: Event<void> | undefined;
20+
provideCodeLenses(
21+
document: TextDocument,
22+
token?: CancellationToken
23+
): ProviderResult<CodeLens[]> {
24+
const symbols = commands.executeCommand<DocumentSymbol[]>(
25+
'vscode.executeDocumentSymbolProvider',
26+
document.uri
27+
);
28+
29+
/**
30+
* For main procedures, provide Run and Debug CodeLenses.
31+
*/
32+
const res1 = getMains().then((mains) => {
33+
if (mains.some((m) => m == document.fileName)) {
34+
// It's a main file, so let's offer Run and Debug actions on the main subprogram
35+
return symbols.then((symbols) => {
36+
const functions = symbols.filter((s) => s.kind == SymbolKind.Function);
37+
if (functions.length > 0) {
38+
/**
39+
* We choose to provide the CodeLenses on the first
40+
* subprogram of the file. It may be possible that the
41+
* main subprogram is not the first one, but that's an
42+
* unlikely scenario that we choose not to handle for
43+
* the moment.
44+
*/
45+
return [
46+
new CodeLens(functions[0].range, {
47+
command: CMD_BUILD_AND_RUN_MAIN,
48+
title: '$(run) Run',
49+
arguments: [document.uri],
50+
}),
51+
// TODO implement this command
52+
new CodeLens(functions[0].range, {
53+
command: CMD_BUILD_AND_DEBUG_MAIN,
54+
title: '$(debug-alt-small) Debug',
55+
arguments: [document.uri],
56+
}),
57+
];
58+
} else {
59+
return [];
60+
}
61+
});
62+
} else {
63+
return [];
64+
}
65+
});
66+
67+
let res2;
68+
if (AdaCodeLensProvider.ENABLE_SPARK_CODELENS) {
69+
/**
70+
* This is tentative deactivated code in preparation of SPARK support.
71+
*/
72+
res2 = symbols.then<CodeLens[]>((symbols) => {
73+
const symbolKinds = [SymbolKind.Function];
74+
const recurseInto = [SymbolKind.Module, SymbolKind.Package, SymbolKind.Function];
75+
76+
// Create a named reduce function to implement a recursive visit of symbols
77+
const functions = getSymbols(symbols, symbolKinds, recurseInto, token);
78+
79+
return functions.map((f) => {
80+
if (token?.isCancellationRequested) {
81+
throw new CancellationError();
82+
}
83+
// TODO make SPARK codelenses conditional to the availability of SPARK on PATH
84+
return new CodeLens(f.range, {
85+
title: '$(play-circle) Prove',
86+
command: 'TODO',
87+
});
88+
});
89+
});
90+
} else {
91+
res2 = Promise.resolve([]);
92+
}
93+
94+
return Promise.all([res1, res2]).then((results) => {
95+
return results[0].concat(results[1]);
96+
});
97+
}
98+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
99+
resolveCodeLens?(codeLens: CodeLens, _token: CancellationToken): ProviderResult<CodeLens> {
100+
if (codeLens.command) {
101+
return codeLens;
102+
} else {
103+
throw new Error(`Cannot resolve CodeLens`);
104+
}
105+
}
106+
}

integration/vscode/ada/src/ExtensionState.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import * as vscode from 'vscode';
22
import { Disposable, LanguageClient } from 'vscode-languageclient/node';
3+
import { AdaCodeLensProvider } from './AdaCodeLensProvider';
34
import { createClient } from './clients';
5+
import { AdaInitialDebugConfigProvider, initializeDebugging } from './debugConfigProvider';
46
import { GnatTaskProvider } from './gnatTaskProvider';
57
import { GprTaskProvider } from './gprTaskProvider';
6-
import { registerTaskProviders } from './taskProviders';
78
import { TERMINAL_ENV_SETTING_NAME } from './helpers';
9+
import { registerTaskProviders } from './taskProviders';
810

911
/**
1012
* This class encapsulates all state that should be maintained throughout the
@@ -19,9 +21,17 @@ export class ExtensionState {
1921
public readonly adaClient: LanguageClient;
2022
public readonly gprClient: LanguageClient;
2123
public readonly context: vscode.ExtensionContext;
24+
public readonly dynamicDebugConfigProvider: {
25+
provideDebugConfigurations(
26+
_folder?: vscode.WorkspaceFolder | undefined
27+
): Promise<vscode.DebugConfiguration[]>;
28+
};
29+
public readonly initialDebugConfigProvider: AdaInitialDebugConfigProvider;
2230

2331
private registeredTaskProviders: Disposable[];
2432

33+
public readonly codelensProvider = new AdaCodeLensProvider();
34+
2535
constructor(context: vscode.ExtensionContext) {
2636
this.context = context;
2737
this.gprClient = createClient(
@@ -39,11 +49,17 @@ export class ExtensionState {
3949
'**/.{adb,ads,adc,ada}'
4050
);
4151
this.registeredTaskProviders = [];
52+
const result = initializeDebugging(this.context);
53+
this.initialDebugConfigProvider = result.providerInitial;
54+
this.dynamicDebugConfigProvider = result.providerDynamic;
4255
}
4356

4457
public start = async () => {
4558
await Promise.all([this.gprClient.start(), this.adaClient.start()]);
4659
this.registerTaskProviders();
60+
this.context.subscriptions.push(
61+
vscode.languages.registerCodeLensProvider('ada', this.codelensProvider)
62+
);
4763
};
4864

4965
public dispose = () => {

0 commit comments

Comments
 (0)