Skip to content

Commit

Permalink
Merge remote branch 'origin/master' into edge
Browse files Browse the repository at this point in the history
  • Loading branch information
automatic-merge committed Feb 17, 2024
2 parents 0a18783 + 53859ce commit 992e7e4
Show file tree
Hide file tree
Showing 16 changed files with 765 additions and 167 deletions.
8 changes: 4 additions & 4 deletions integration/vscode/ada/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -723,13 +723,13 @@
"when": "ADA_PROJECT_CONTEXT"
},
{
"command": "ada.runMainAsk",
"command": "ada.buildAndRunMainAsk",
"title": "Ada: Build and run project main...",
"icon": "$(run-all)",
"when": "ADA_PROJECT_CONTEXT"
},
{
"command": "ada.runMainLast",
"command": "ada.buildAndRunMainLast",
"title": "Ada: Build and run last used main",
"icon": "$(run)",
"when": "ADA_PROJECT_CONTEXT"
Expand Down Expand Up @@ -760,12 +760,12 @@
],
"editor/title/run": [
{
"command": "ada.runMainLast",
"command": "ada.buildAndRunMainLast",
"when": "editorLangId == ada",
"group": "navigation@0"
},
{
"command": "ada.runMainAsk",
"command": "ada.buildAndRunMainAsk",
"when": "editorLangId == ada",
"group": "navigation@1"
}
Expand Down
106 changes: 106 additions & 0 deletions integration/vscode/ada/src/AdaCodeLensProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import {
CancellationError,
CancellationToken,
CodeLens,
CodeLensProvider,
DocumentSymbol,
Event,
ProviderResult,
SymbolKind,
TextDocument,
commands,
} from 'vscode';
import { CMD_BUILD_AND_DEBUG_MAIN, CMD_BUILD_AND_RUN_MAIN } from './commands';
import { getMains, getSymbols } from './helpers';

export class AdaCodeLensProvider implements CodeLensProvider {
static readonly ENABLE_SPARK_CODELENS = false;

onDidChangeCodeLenses?: Event<void> | undefined;
provideCodeLenses(
document: TextDocument,
token?: CancellationToken
): ProviderResult<CodeLens[]> {
const symbols = commands.executeCommand<DocumentSymbol[]>(
'vscode.executeDocumentSymbolProvider',
document.uri
);

/**
* For main procedures, provide Run and Debug CodeLenses.
*/
const res1 = getMains().then((mains) => {
if (mains.some((m) => m == document.fileName)) {
// It's a main file, so let's offer Run and Debug actions on the main subprogram
return symbols.then((symbols) => {
const functions = symbols.filter((s) => s.kind == SymbolKind.Function);
if (functions.length > 0) {
/**
* We choose to provide the CodeLenses on the first
* subprogram of the file. It may be possible that the
* main subprogram is not the first one, but that's an
* unlikely scenario that we choose not to handle for
* the moment.
*/
return [
new CodeLens(functions[0].range, {
command: CMD_BUILD_AND_RUN_MAIN,
title: '$(run) Run',
arguments: [document.uri],
}),
// TODO implement this command
new CodeLens(functions[0].range, {
command: CMD_BUILD_AND_DEBUG_MAIN,
title: '$(debug-alt-small) Debug',
arguments: [document.uri],
}),
];
} else {
return [];
}
});
} else {
return [];
}
});

let res2;
if (AdaCodeLensProvider.ENABLE_SPARK_CODELENS) {
/**
* This is tentative deactivated code in preparation of SPARK support.
*/
res2 = symbols.then<CodeLens[]>((symbols) => {
const symbolKinds = [SymbolKind.Function];
const recurseInto = [SymbolKind.Module, SymbolKind.Package, SymbolKind.Function];

// Create a named reduce function to implement a recursive visit of symbols
const functions = getSymbols(symbols, symbolKinds, recurseInto, token);

return functions.map((f) => {
if (token?.isCancellationRequested) {
throw new CancellationError();
}
// TODO make SPARK codelenses conditional to the availability of SPARK on PATH
return new CodeLens(f.range, {
title: '$(play-circle) Prove',
command: 'TODO',
});
});
});
} else {
res2 = Promise.resolve([]);
}

return Promise.all([res1, res2]).then((results) => {
return results[0].concat(results[1]);
});
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
resolveCodeLens?(codeLens: CodeLens, _token: CancellationToken): ProviderResult<CodeLens> {
if (codeLens.command) {
return codeLens;
} else {
throw new Error(`Cannot resolve CodeLens`);
}
}
}
18 changes: 17 additions & 1 deletion integration/vscode/ada/src/ExtensionState.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import * as vscode from 'vscode';
import { Disposable, LanguageClient } from 'vscode-languageclient/node';
import { AdaCodeLensProvider } from './AdaCodeLensProvider';
import { createClient } from './clients';
import { AdaInitialDebugConfigProvider, initializeDebugging } from './debugConfigProvider';
import { GnatTaskProvider } from './gnatTaskProvider';
import { GprTaskProvider } from './gprTaskProvider';
import { registerTaskProviders } from './taskProviders';
import { TERMINAL_ENV_SETTING_NAME } from './helpers';
import { registerTaskProviders } from './taskProviders';

/**
* This class encapsulates all state that should be maintained throughout the
Expand All @@ -19,9 +21,17 @@ export class ExtensionState {
public readonly adaClient: LanguageClient;
public readonly gprClient: LanguageClient;
public readonly context: vscode.ExtensionContext;
public readonly dynamicDebugConfigProvider: {
provideDebugConfigurations(
_folder?: vscode.WorkspaceFolder | undefined
): Promise<vscode.DebugConfiguration[]>;
};
public readonly initialDebugConfigProvider: AdaInitialDebugConfigProvider;

private registeredTaskProviders: Disposable[];

public readonly codelensProvider = new AdaCodeLensProvider();

constructor(context: vscode.ExtensionContext) {
this.context = context;
this.gprClient = createClient(
Expand All @@ -39,11 +49,17 @@ export class ExtensionState {
'**/.{adb,ads,adc,ada}'
);
this.registeredTaskProviders = [];
const result = initializeDebugging(this.context);
this.initialDebugConfigProvider = result.providerInitial;
this.dynamicDebugConfigProvider = result.providerDynamic;
}

public start = async () => {
await Promise.all([this.gprClient.start(), this.adaClient.start()]);
this.registerTaskProviders();
this.context.subscriptions.push(
vscode.languages.registerCodeLensProvider('ada', this.codelensProvider)
);
};

public dispose = () => {
Expand Down
Loading

0 comments on commit 992e7e4

Please sign in to comment.