From 2c1b2ba86f0724e6ce8e1d4995f3573772f02c73 Mon Sep 17 00:00:00 2001 From: Anthony Leonardo Gracio Date: Thu, 11 Jul 2024 12:37:26 +0000 Subject: [PATCH 1/7] Prioritize customized tasks over predefined ones To make sure that predefined tasks customized in the workspace's 'tasks.json' file are picked-up first when calling 'findTaskByName'. Also make sure to prepend 'ada: ' to the GNAT SAS basic task names in the GNAT SAS compound tasks. Add a basic test for this. For eng/ide/ada_language_server#1384 --- integration/vscode/ada/src/taskProviders.ts | 18 ++++++++--- .../ada/test/suite/general/tasks.test.ts | 32 +++++++++++++++++++ .../workspaces/general/.vscode/tasks.json | 19 +++++++++++ 3 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 integration/vscode/ada/test/workspaces/general/.vscode/tasks.json diff --git a/integration/vscode/ada/src/taskProviders.ts b/integration/vscode/ada/src/taskProviders.ts index aeae95b0e..adbf2096a 100644 --- a/integration/vscode/ada/src/taskProviders.ts +++ b/integration/vscode/ada/src/taskProviders.ts @@ -42,6 +42,8 @@ export interface SimpleTaskDef extends vscode.TaskDefinition { * This property should not occur at the same time as command and args. * {@link SimpleTaskProvider.resolveTask} checks that in case it occurs in * User task definitions and raises errors accordingly. + * The tasks' names should be prefixed by their source + * (e.g: 'ada: Build current project' instead of 'Build current project'). */ compound?: string[]; } @@ -180,8 +182,8 @@ const predefinedTasks: PredefinedTask[] = [ taskDef: { type: TASK_TYPE_ADA, compound: [ - 'Analyze the project with GNAT SAS', - 'Create a report after a GNAT SAS analysis', + 'ada: Analyze the project with GNAT SAS', + 'ada: Create a report after a GNAT SAS analysis', ], }, /** @@ -195,8 +197,8 @@ const predefinedTasks: PredefinedTask[] = [ taskDef: { type: TASK_TYPE_ADA, compound: [ - 'Analyze the current file with GNAT SAS', - 'Create a report after a GNAT SAS analysis', + 'ada: Analyze the current file with GNAT SAS', + 'ada: Create a report after a GNAT SAS analysis', ], }, /** @@ -856,7 +858,8 @@ abstract class SequentialExecution extends vscode.CustomExecution { } /** - * Finds and returns the task of the given name. + * Finds and returns the task of the given name, prioritizing the one + * defined/customized in the workspace's 'tasks.json' file if any. * * Task names contributed by the extension don't have the task type prefix in * the name while tasks coming from the workspace typically do since VS Code @@ -889,6 +892,11 @@ export async function findTaskByName( throw Error('The task list is empty.' + ` Cannot find task '${taskName}'`); } + // Sort the given tasks to put the workspace-defined ones first + // in the list. This allows to pick-up predefined tasks that + // have been customized by the user in priority. + tasks = tasks.sort(workspaceTasksFirst); + const task = tasks.find((v) => { return taskName == getConventionalTaskLabel(v) || taskName == v.name; }); diff --git a/integration/vscode/ada/test/suite/general/tasks.test.ts b/integration/vscode/ada/test/suite/general/tasks.test.ts index 9af87ce1b..774b45e1b 100644 --- a/integration/vscode/ada/test/suite/general/tasks.test.ts +++ b/integration/vscode/ada/test/suite/general/tasks.test.ts @@ -6,8 +6,11 @@ import { getEnclosingSymbol, getSelectedRegion } from '../../../src/commands'; import { exe, getProjectFile } from '../../../src/helpers'; import { SimpleTaskDef, + TASK_TYPE_ADA, createAdaTaskProvider, + findTaskByName, getConventionalTaskLabel, + isFromWorkspace, } from '../../../src/taskProviders'; import { activate, @@ -143,6 +146,35 @@ ada: Run main - src/test.adb - obj/test${exe} assert.equal(getSelectedRegion(vscode.window.activeTextEditor), '16:18'); }); + /** + * Verify that {@link findTaskByName} returns the predefined task that + * has been customized in the workspaces's 'tasks.json' file if any, and + * not the default predefined task from the extension's TaskProvider. + */ + test('Customized predefined task command line', async function () { + const prov = createAdaTaskProvider(); + + const adaTasks = await vscode.tasks.fetchTasks({ type: TASK_TYPE_ADA }); + const buildTask = await findTaskByName('ada: Build current project', adaTasks); + const resolved = await prov.resolveTask(buildTask); + assert(resolved); + assert(resolved.execution); + assert( + isFromWorkspace(resolved), + 'Build task does not come from workspace. Source is: ' + resolved.source + ); + + const exec = buildTask.execution as vscode.ShellExecution; + const actualCmd = getCmdLine(exec); + + // The '--no-object-check' switch has been added to the 'ada: Build current project' + // predefined task in the workspace's tasks.json file: check that it's indeed present + // in the returned task's command line. + const expectedCmd = `gprbuild -P ${projectPath} --no-object-check -cargs:ada -gnatef`; + + assert.strictEqual(actualCmd, expectedCmd); + }); + test('Obsolete task definition causes error', async function () { const obsoleteTaskDef: vscode.TaskDefinition = { type: 'ada', diff --git a/integration/vscode/ada/test/workspaces/general/.vscode/tasks.json b/integration/vscode/ada/test/workspaces/general/.vscode/tasks.json new file mode 100644 index 000000000..c8f7ad6c7 --- /dev/null +++ b/integration/vscode/ada/test/workspaces/general/.vscode/tasks.json @@ -0,0 +1,19 @@ +{ + "tasks": [ + { + "type": "ada", + "command": "gprbuild", + "args": [ + "${command:ada.gprProjectArgs}", + "--no-object-check", + "-cargs:ada", + "-gnatef" + ], + "problemMatcher": [ + "$ada" + ], + "group": "build", + "label": "ada: Build current project" + } + ] +} From c756e547f6a92a0d81ed7426f3250a83129bbe8e Mon Sep 17 00:00:00 2001 From: Anthony Leonardo Gracio Date: Wed, 10 Jul 2024 09:29:33 +0000 Subject: [PATCH 2/7] Add SARIF viewer in the extension pack For eng/ide/ada_language_server#1364 --- integration/vscode/ada/package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/integration/vscode/ada/package.json b/integration/vscode/ada/package.json index d5b93eea0..b510ab237 100644 --- a/integration/vscode/ada/package.json +++ b/integration/vscode/ada/package.json @@ -13,7 +13,8 @@ "Extension Packs" ], "extensionPack": [ - "ms-vscode.cpptools" + "ms-vscode.cpptools", + "ms-sarifvscode.sarif-viewer" ], "activationEvents": [ "workspaceContains:*.gpr", From 9f49dc4bdda7a656bcda02d68757c1e440919e36 Mon Sep 17 00:00:00 2001 From: Anthony Leonardo Gracio Date: Wed, 10 Jul 2024 10:07:56 +0000 Subject: [PATCH 3/7] Open the SARIF Viewer for tasks that emit SARIF For eng/ide/ada_language_server#1364 --- integration/vscode/ada/src/ExtensionState.ts | 100 +++++++++++++++--- integration/vscode/ada/src/helpers.ts | 12 ++- .../ada/test/suite/general/tasks.test.ts | 3 + integration/vscode/ada/test/suite/utils.ts | 8 +- 4 files changed, 103 insertions(+), 20 deletions(-) diff --git a/integration/vscode/ada/src/ExtensionState.ts b/integration/vscode/ada/src/ExtensionState.ts index 905b66a6b..0d02b41ba 100644 --- a/integration/vscode/ada/src/ExtensionState.ts +++ b/integration/vscode/ada/src/ExtensionState.ts @@ -7,14 +7,16 @@ import { logger } from './extension'; import { GnatTaskProvider } from './gnatTaskProvider'; import { initializeTesting } from './gnattest'; import { GprTaskProvider } from './gprTaskProvider'; -import { TERMINAL_ENV_SETTING_NAME } from './helpers'; +import { getArgValue, TERMINAL_ENV_SETTING_NAME } from './helpers'; import { + SimpleTaskDef, SimpleTaskProvider, TASK_TYPE_ADA, TASK_TYPE_SPARK, createAdaTaskProvider, createSparkTaskProvider, } from './taskProviders'; +import { isAbsolute } from 'path'; /** * This class encapsulates all state that should be maintained throughout the @@ -36,7 +38,7 @@ export class ExtensionState { }; public readonly initialDebugConfigProvider: AdaInitialDebugConfigProvider; - private registeredTaskProviders: Disposable[]; + private taskDisposables: Disposable[]; public readonly codelensProvider = new AdaCodeLensProvider(); public readonly testController: vscode.TestController; @@ -78,7 +80,7 @@ export class ExtensionState { [], '**/.{adb,ads,adc,ada}' ); - this.registeredTaskProviders = []; + this.taskDisposables = []; const result = initializeDebugging(this.context); this.initialDebugConfigProvider = result.providerInitial; this.dynamicDebugConfigProvider = result.providerDynamic; @@ -87,21 +89,25 @@ export class ExtensionState { public start = async () => { await Promise.all([this.gprClient.start(), this.adaClient.start()]); - this.registerTaskProviders(); + this.registerTaskDisposables(); this.context.subscriptions.push( vscode.languages.registerCodeLensProvider('ada', this.codelensProvider) ); }; public dispose = () => { - this.unregisterTaskProviders(); + this.unregisterTaskDisposables(); }; - public registerTaskProviders = (): void => { + /** + * Register all the task disposables needed by the extension (e.g: task providers, + * listeners...). + */ + public registerTaskDisposables = (): void => { this.adaTaskProvider = createAdaTaskProvider(); this.sparkTaskProvider = createSparkTaskProvider(); - this.registeredTaskProviders = [ + this.taskDisposables = [ vscode.tasks.registerTaskProvider(GnatTaskProvider.gnatType, new GnatTaskProvider()), vscode.tasks.registerTaskProvider( GprTaskProvider.gprTaskType, @@ -109,14 +115,25 @@ export class ExtensionState { ), vscode.tasks.registerTaskProvider(TASK_TYPE_ADA, this.adaTaskProvider), vscode.tasks.registerTaskProvider(TASK_TYPE_SPARK, this.sparkTaskProvider), + + // Add a listener on tasks to open the SARIF Viewer when the + // task that ends outputs a SARIF file. + vscode.tasks.onDidEndTaskProcess(async (e) => { + const task = e.execution.task; + await openSARIFViewerIfNeeded(task); + }), ]; }; - public unregisterTaskProviders = (): void => { - for (const item of this.registeredTaskProviders) { + /** + * Unregister all the task disposables needed by the extension (e.g: task providers, + * listeners...). + */ + public unregisterTaskDisposables = (): void => { + for (const item of this.taskDisposables) { item.dispose(); } - this.registeredTaskProviders = []; + this.taskDisposables = []; }; /** @@ -150,8 +167,8 @@ export class ExtensionState { ) { logger.info('project related settings have changed: clearing caches for tasks'); this.clearALSCache(); - this.unregisterTaskProviders(); - this.registerTaskProviders(); + this.unregisterTaskDisposables(); + this.registerTaskDisposables(); } // React to changes made in the environment variables, showing @@ -239,3 +256,62 @@ export class ExtensionState { return this.sparkTaskProvider; } } + +/** + * + * Open the SARIF Viewer if the given task outputs its results in + * a SARIF file (e.g: GNAT SAS Report task). + */ +async function openSARIFViewerIfNeeded(task: vscode.Task) { + const definition: SimpleTaskDef = task.definition; + + if (definition) { + const args = definition.args; + + if (args?.some((arg) => getArgValue(arg).includes('sarif'))) { + const execution = task.execution; + let cwd = undefined; + + if (execution && execution instanceof vscode.ShellExecution) { + cwd = execution.options?.cwd; + } + + if (!cwd && vscode.workspace.workspaceFolders) { + cwd = vscode.workspace.workspaceFolders[0].uri.fsPath; + } + + const sarifExt = vscode.extensions.getExtension('ms-sarifvscode.sarif-viewer'); + + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + const sarifExtAPI = sarifExt ? await sarifExt.activate() : undefined; + + if (cwd && sarifExtAPI) { + const cwdURI = vscode.Uri.file(cwd); + const outputFilePathArgRaw = args.find((arg) => + getArgValue(arg).includes('.sarif') + ); + + if (outputFilePathArgRaw) { + // Convert the raw argument into a string + const outputFilePathArg = getArgValue(outputFilePathArgRaw); + + // The SARIF output file can be specified as '--output=path/to/file.sarif': + // split the argument on '=' if that's the case, to retrieve only the file path + const outputFilePath = outputFilePathArg.includes('=') + ? outputFilePathArg.split('=').pop() + : outputFilePathArg; + + if (outputFilePath) { + const sarifFileURI = isAbsolute(outputFilePath) + ? vscode.Uri.file(outputFilePath) + : vscode.Uri.joinPath(cwdURI, outputFilePath); + + // eslint-disable-next-line max-len + // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access + await sarifExtAPI.openLogs([sarifFileURI]); + } + } + } + } + } +} diff --git a/integration/vscode/ada/src/helpers.ts b/integration/vscode/ada/src/helpers.ts index 13a63afa3..eae969f99 100644 --- a/integration/vscode/ada/src/helpers.ts +++ b/integration/vscode/ada/src/helpers.ts @@ -23,14 +23,13 @@ import { LanguageClient } from 'vscode-languageclient/node'; import winston from 'winston'; // eslint-disable-next-line @typescript-eslint/no-unused-vars import { existsSync } from 'fs'; -import { ExtensionState } from './ExtensionState'; import { EXTENSION_NAME, adaExtState, logger, mainOutputChannel } from './extension'; /* Whether we are under Windows */ const isWindows = process.platform === 'win32'; /** - * Substitue any variable reference present in the given string. VS Code + * Substitute any variable reference present in the given string. VS Code * variable references are listed here: * https://code.visualstudio.com/docs/editor/variables-reference * @param str - string to perform substitution on @@ -164,6 +163,15 @@ export function getEvaluatedTerminalEnv() { return custom_env; } +/** + * Get the given argument actual string value, converting it to a string if + * specified as {@link vscode.ShellQuotedString}. + * @returns a string containing the argument's actual value. + */ +export function getArgValue(a: string | vscode.ShellQuotedString): string { + return typeof a == 'string' ? a : a.value; +} + /** * Read the environment variables specified in the vscode setting * `terminal.integrated.env.` and set them in the given ProcessEnv object. diff --git a/integration/vscode/ada/test/suite/general/tasks.test.ts b/integration/vscode/ada/test/suite/general/tasks.test.ts index 774b45e1b..e254d1c6a 100644 --- a/integration/vscode/ada/test/suite/general/tasks.test.ts +++ b/integration/vscode/ada/test/suite/general/tasks.test.ts @@ -157,6 +157,9 @@ ada: Run main - src/test.adb - obj/test${exe} const adaTasks = await vscode.tasks.fetchTasks({ type: TASK_TYPE_ADA }); const buildTask = await findTaskByName('ada: Build current project', adaTasks); const resolved = await prov.resolveTask(buildTask); + const tasks: vscode.TaskDefinition[] = + vscode.workspace.getConfiguration('tasks').get('tasks') ?? []; + assert(tasks.length > 0, "No tasks registered in 'tasks.json'"); assert(resolved); assert(resolved.execution); assert( diff --git a/integration/vscode/ada/test/suite/utils.ts b/integration/vscode/ada/test/suite/utils.ts index bbff86a9e..06371e5d4 100644 --- a/integration/vscode/ada/test/suite/utils.ts +++ b/integration/vscode/ada/test/suite/utils.ts @@ -5,7 +5,7 @@ import path from 'path'; import * as vscode from 'vscode'; import { CodeLens, Uri, window, workspace } from 'vscode'; import { adaExtState } from '../../src/extension'; -import { setTerminalEnvironment } from '../../src/helpers'; +import { getArgValue, setTerminalEnvironment } from '../../src/helpers'; import { SimpleTaskProvider, findTaskByName, @@ -206,11 +206,7 @@ export async function testTask( let msg = `Got status ${execStatus ?? "'undefined'"} for task '${taskName}'`; if (task.execution instanceof vscode.ShellExecution) { const cmdLine = [task.execution.command].concat(task.execution.args).map((arg) => { - if (typeof arg == 'string') { - return arg; - } else { - return arg.value; - } + return getArgValue(arg); }); msg += ` with command line: ${cmdLine.join(' ')}`; From ae9248c48178a957eb6ed82d8b65e6aed28e44ae Mon Sep 17 00:00:00 2001 From: Anthony Leonardo Gracio Date: Tue, 16 Jul 2024 16:21:41 +0000 Subject: [PATCH 4/7] Customize the tasks.json programatically in the test To address https://gitlab.adacore-it.com/it/e3-core/-/issues/5 For eng/ide/ada_language_server#1384 --- .../ada/test/suite/general/tasks.test.ts | 67 +++++++++++++------ .../workspaces/general/.vscode/tasks.json | 18 +---- 2 files changed, 48 insertions(+), 37 deletions(-) diff --git a/integration/vscode/ada/test/suite/general/tasks.test.ts b/integration/vscode/ada/test/suite/general/tasks.test.ts index e254d1c6a..7d2b0d011 100644 --- a/integration/vscode/ada/test/suite/general/tasks.test.ts +++ b/integration/vscode/ada/test/suite/general/tasks.test.ts @@ -152,30 +152,57 @@ ada: Run main - src/test.adb - obj/test${exe} * not the default predefined task from the extension's TaskProvider. */ test('Customized predefined task command line', async function () { - const prov = createAdaTaskProvider(); - - const adaTasks = await vscode.tasks.fetchTasks({ type: TASK_TYPE_ADA }); - const buildTask = await findTaskByName('ada: Build current project', adaTasks); - const resolved = await prov.resolveTask(buildTask); - const tasks: vscode.TaskDefinition[] = + const initialTasks: vscode.TaskDefinition[] = vscode.workspace.getConfiguration('tasks').get('tasks') ?? []; - assert(tasks.length > 0, "No tasks registered in 'tasks.json'"); - assert(resolved); - assert(resolved.execution); - assert( - isFromWorkspace(resolved), - 'Build task does not come from workspace. Source is: ' + resolved.source - ); - const exec = buildTask.execution as vscode.ShellExecution; - const actualCmd = getCmdLine(exec); + try { + // Customize the 'ada: Build current project' task + const tasks: vscode.TaskDefinition[] = initialTasks.concat(); + const def: SimpleTaskDef = { + type: 'ada', + command: 'gprbuild', + problemMatcher: ['$ada'], + args: [ + '${command:ada.gprProjectArgs}', + '--no-object-check', + '-cargs:ada', + '-gnatef', + ], + label: 'ada: Build current project', + }; + tasks.push(def); + await vscode.workspace.getConfiguration().update('tasks.tasks', tasks); + + // Fetch the available tasks to find the one we have customized: make + // sure its source is 'workspace', since it has been manually customized. + + const prov = createAdaTaskProvider(); + const adaTasks = await vscode.tasks.fetchTasks({ type: TASK_TYPE_ADA }); + const buildTask = await findTaskByName('ada: Build current project', adaTasks); + const resolved = await prov.resolveTask(buildTask); + assert(resolved); + assert(resolved.execution); + assert( + isFromWorkspace(resolved), + 'Build task does not come from workspace. Source is: ' + resolved.source + ); - // The '--no-object-check' switch has been added to the 'ada: Build current project' - // predefined task in the workspace's tasks.json file: check that it's indeed present - // in the returned task's command line. - const expectedCmd = `gprbuild -P ${projectPath} --no-object-check -cargs:ada -gnatef`; + const exec = buildTask.execution as vscode.ShellExecution; + const actualCmd = getCmdLine(exec); - assert.strictEqual(actualCmd, expectedCmd); + // The '--no-object-check' switch has been added to the 'ada: Build current project' + // predefined task in the workspace's tasks.json file: check that it's indeed present + // in the returned task's command line. + const expectedCmd = `gprbuild -P ${projectPath} --no-object-check -cargs:ada -gnatef`; + + assert.strictEqual(actualCmd, expectedCmd); + } finally { + // Reset the 'tasks.tasks' setting. If the previous value was + // empty, update to 'undefined' so that the setting gets removed. + await vscode.workspace + .getConfiguration() + .update('tasks.tasks', initialTasks ?? undefined); + } }); test('Obsolete task definition causes error', async function () { diff --git a/integration/vscode/ada/test/workspaces/general/.vscode/tasks.json b/integration/vscode/ada/test/workspaces/general/.vscode/tasks.json index c8f7ad6c7..b37b3b460 100644 --- a/integration/vscode/ada/test/workspaces/general/.vscode/tasks.json +++ b/integration/vscode/ada/test/workspaces/general/.vscode/tasks.json @@ -1,19 +1,3 @@ { - "tasks": [ - { - "type": "ada", - "command": "gprbuild", - "args": [ - "${command:ada.gprProjectArgs}", - "--no-object-check", - "-cargs:ada", - "-gnatef" - ], - "problemMatcher": [ - "$ada" - ], - "group": "build", - "label": "ada: Build current project" - } - ] + "tasks": [] } From c8a4c4312bf02580915e78d0350b73e1a7e2ff21 Mon Sep 17 00:00:00 2001 From: Elie Richa Date: Fri, 12 Jul 2024 10:09:53 +0000 Subject: [PATCH 5/7] Format script and fix shellcheck warnings --- .github/workflows/pack-binaries.sh | 41 +++++++++++++++--------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/.github/workflows/pack-binaries.sh b/.github/workflows/pack-binaries.sh index 0406acfb9..a38fd1213 100755 --- a/.github/workflows/pack-binaries.sh +++ b/.github/workflows/pack-binaries.sh @@ -5,25 +5,24 @@ VSCE_TOKEN=$2 OVSX_TOKEN=$3 TAG=$4 # For master it's 24.0.999, while for tag it's the tag itself -function make_change_log() -{ - echo "# Release notes" - echo "" - for TAG_ID in `git tag --list --sort=-v:refname '2*'` ; do - DATE=`git show --no-patch --format=Date:%ad --date=short $TAG_ID |\ - grep Date: | sed -e s/Date://` - echo "## $TAG_ID ($DATE)" - git show --no-patch --format=%n $TAG_ID | sed -e '1,/Release notes/d' - done +function make_change_log() { + echo "# Release notes" + echo "" + for TAG_ID in $(git tag --list --sort=-v:refname '2*'); do + DATE=$(git show --no-patch --format=Date:%ad --date=short "$TAG_ID" | + grep Date: | sed -e s/Date://) + echo "## $TAG_ID ($DATE)" + git show --no-patch --format=%n "$TAG_ID" | sed -e '1,/Release notes/d' + done } -chmod -R -v +x als-*-$DEBUG als-{Linux,macOS}-${DEBUG}aarch64 +chmod -R -v +x als-*-"$DEBUG" als-{Linux,macOS}-"${DEBUG}"aarch64 -for X in Linux macOS Windows ; do - rsync -rva als-$X-$DEBUG/ integration/vscode/ada/ +for X in Linux macOS Windows; do + rsync -rva als-$X-"$DEBUG"/ integration/vscode/ada/ done -rsync -rva als-{Linux,macOS}-${DEBUG}aarch64/ integration/vscode/ada/ +rsync -rva als-{Linux,macOS}-"${DEBUG}"aarch64/ integration/vscode/ada/ # VS Code is supported on arm, arm64 and x64 so we only consider those # architectures @@ -32,16 +31,18 @@ rm -rf -v integration/vscode/ada/{arm,arm64,x64}/{linux,darwin,win32}/*.{debug,d pushd integration/vscode/ada sed -i -e "/version/s/[0-9][0-9.]*/$TAG/" package.json [ -z "$DEBUG" ] || sed -i -e '/^ "name"/s/ada/ada-debug/' \ - -e '/displayName/s/Ada/Ada (with debug info)/' package.json + -e '/displayName/s/Ada/Ada (with debug info)/' package.json -npm -v; node -v; which node +npm -v +node -v +which node npm install sudo npm install -g @vscode/vsce --unsafe-perm sudo npm install -g esbuild --unsafe-perm -make_change_log > CHANGELOG.md -if [[ ${GITHUB_REF##*/} = 2*.[0-9]*.[0-9]* ]] ; then - vsce publish -p "$VSCE_TOKEN" || true - npx ovsx publish -p "$OVSX_TOKEN" || true +make_change_log >CHANGELOG.md +if [[ ${GITHUB_REF##*/} = 2*.[0-9]*.[0-9]* ]]; then + vsce publish -p "$VSCE_TOKEN" || true + npx ovsx publish -p "$OVSX_TOKEN" || true fi vsce package || true popd From 7cebbc3f28baa8ec82b41c306e6cea6bb107ab31 Mon Sep 17 00:00:00 2001 From: Elie Richa Date: Fri, 12 Jul 2024 14:50:29 +0000 Subject: [PATCH 6/7] Simplify GitHub vscode workflow to only macOS and no publishing --- .github/workflows/build-binaries.sh | 2 +- .github/workflows/pack-binaries.sh | 103 ++++++++++++++++++++-------- 2 files changed, 74 insertions(+), 31 deletions(-) diff --git a/.github/workflows/build-binaries.sh b/.github/workflows/build-binaries.sh index 5661049c0..90f42cf8a 100755 --- a/.github/workflows/build-binaries.sh +++ b/.github/workflows/build-binaries.sh @@ -4,7 +4,7 @@ # -e causes the execution to terminate as soon as any command fails set -x -e DEBUG=$1 # Value is '' or 'debug' -RUNNER_OS=$2 # ${{ runner.os }} is Linux, Windiws, maxOS +RUNNER_OS=$2 # ${{ runner.os }} is Linux, Windows, macOS TAG=$3 # For master it's 24.0.999, while for tag it's the tag itself NO_REBASE=$4 # Specify this to skip the rebase over the edge branch. Used for local debugging. CROSS=$5 # '' for native, aarch64 for ARM cross diff --git a/.github/workflows/pack-binaries.sh b/.github/workflows/pack-binaries.sh index a38fd1213..c3d2ef63c 100755 --- a/.github/workflows/pack-binaries.sh +++ b/.github/workflows/pack-binaries.sh @@ -16,36 +16,79 @@ function make_change_log() { done } -chmod -R -v +x als-*-"$DEBUG" als-{Linux,macOS}-"${DEBUG}"aarch64 +function os_to_node_platform() { + case "$1" in + Linux) + echo -n "linux" + ;; + Windows) + echo -n "win32" + ;; + macOS) + echo -n "darwin" + ;; + esac +} + +function cross_to_node_arch() { + case "$1" in + aarch64) + echo -n "arm64" + ;; + *) + echo -n "x64" + ;; + esac +} + +ext_dir=integration/vscode/ada + +( + cd "$ext_dir" + + # Set package version based on the Git tag + sed -i -e "/version/s/[0-9][0-9.]*/$TAG/" package.json + # Change extension ID and name if we're in debug mode + [ -z "$DEBUG" ] || sed -i -e '/^ "name"/s/ada/ada-debug/' \ + -e '/displayName/s/Ada & SPARK/Ada & SPARK (with debug info)/' package.json -for X in Linux macOS Windows; do - rsync -rva als-$X-"$DEBUG"/ integration/vscode/ada/ + # Install NPM deps + npm -v + node -v + which node + npm install + + # Create change log + make_change_log >CHANGELOG.md +) + +# At the moment we only create VSIX-es for macOS on GitHub. Other platforms are +# provided elsewhere. +# shellcheck disable=SC2043 +for OS in macOS Windows Linux; do + for CROSS in "" "aarch64"; do + source=als-"$OS"-"$DEBUG""$CROSS" + if [ -d "$source" ]; then + # Make sure the file are executable + chmod -R -v +x "$source" + # Copy the binary in place + rsync -rva als-$OS-"$DEBUG""$CROSS"/ "$ext_dir"/ + # Delete debug info + rm -rf -v "$ext_dir"/{arm,arm64,x64}/{linux,darwin,win32}/*.{debug,dSYM} + + ( + cd "$ext_dir" + # Create the VSIX + npx vsce package --target "$(os_to_node_platform $OS)-$(cross_to_node_arch $CROSS)" + ) + + # Cleanup the binary directory + rm -rf -v "$ext_dir"/{arm,arm64,x64} + fi + done done -rsync -rva als-{Linux,macOS}-"${DEBUG}"aarch64/ integration/vscode/ada/ - -# VS Code is supported on arm, arm64 and x64 so we only consider those -# architectures -rm -rf -v integration/vscode/ada/{arm,arm64,x64}/{linux,darwin,win32}/*.{debug,dSYM} - -pushd integration/vscode/ada -sed -i -e "/version/s/[0-9][0-9.]*/$TAG/" package.json -[ -z "$DEBUG" ] || sed -i -e '/^ "name"/s/ada/ada-debug/' \ - -e '/displayName/s/Ada/Ada (with debug info)/' package.json - -npm -v -node -v -which node -npm install -sudo npm install -g @vscode/vsce --unsafe-perm -sudo npm install -g esbuild --unsafe-perm -make_change_log >CHANGELOG.md -if [[ ${GITHUB_REF##*/} = 2*.[0-9]*.[0-9]* ]]; then - vsce publish -p "$VSCE_TOKEN" || true - npx ovsx publish -p "$OVSX_TOKEN" || true -fi -vsce package || true -popd -mv -v integration/vscode/ada/*.vsix . -git checkout integration/vscode/ada/package.json -rm -rf integration/vscode/ada/{arm,arm64,x64}/{linux,darwin,win32} +# Move all .vsix packages to the root of the checkout +mv -v "$ext_dir"/*.vsix . +# Discard the package.json and package-lock.json changes +git checkout "$ext_dir"/package*.json From 86ee1d6749a93190a2a1e0f53c34b8d3f10404b1 Mon Sep 17 00:00:00 2001 From: Anthony Leonardo Gracio Date: Wed, 17 Jul 2024 13:20:42 +0000 Subject: [PATCH 7/7] Create two different traces config files for Ada and GPR Allowing to separate log files for Ada and GPR properly. For eng/ide/ada_language_server#1380 --- doc/traces.md | 10 +++++++--- source/ada/lsp-ada_driver.adb | 20 +++++++++++-------- .../.als/{traces.cfg => ada_ls_traces.cfg} | 0 3 files changed, 19 insertions(+), 11 deletions(-) rename testsuite/.als/{traces.cfg => ada_ls_traces.cfg} (100%) diff --git a/doc/traces.md b/doc/traces.md index 20e658576..f90fa2ddb 100644 --- a/doc/traces.md +++ b/doc/traces.md @@ -1,8 +1,12 @@ # ALS Trace File -Default trace file name is `$HOME/.als/traces.cfg`. This file gets automatically created -if not present on the disk. The first line of the traces file -defines the traces output stream (a filename in our case) and the other +Default trace file names are: + +* `$HOME/.als/ada_ls_traces.cfg` for the language server spawned for Ada projects/files, which produce `ada_ls_log..log` log files by default. +* `$HOME/.als/gpr_ls_traces.cfg` for the language server spawned for GPR project files, which produce `gpr_ls_log..log` log files by default. + +These files gets automatically created if not present on the disk. The first line of the +traces files defines the traces output stream (a filename in our case) and the other lines are used to enable or disable traces. Note that you can provide another traces file via the `--tracefile=` command line option. diff --git a/source/ada/lsp-ada_driver.adb b/source/ada/lsp-ada_driver.adb index 065332d24..3a916062d 100644 --- a/source/ada/lsp-ada_driver.adb +++ b/source/ada/lsp-ada_driver.adb @@ -269,12 +269,6 @@ procedure LSP.Ada_Driver is GNATdebug : constant Virtual_File := Create_From_Base (".gnatdebug"); - Default_Traces_File_Contents : constant String := - ">als.$T.txt:buffer_size=0" & Ada.Characters.Latin_1.LF - & "ALS.MAIN=yes" & Ada.Characters.Latin_1.LF - & "ALS.IN=no" & Ada.Characters.Latin_1.LF - & "ALS.OUT=no" & Ada.Characters.Latin_1.LF; - Traces_File : Virtual_File; Trace_File_Option : constant VSS.Command_Line.Value_Option := @@ -350,12 +344,22 @@ begin Traces_File := Create_From_Dir (Dir => ALS_Dir, - Base_Name => "traces.cfg"); + Base_Name => + (if VSS.Command_Line.Is_Specified (Language_GPR_Option) then + "gpr_ls" else "ada_ls") & "_traces.cfg"); -- No default traces file found: create one if not Traces_File.Is_Regular_File then declare - W_Traces_File : Writable_File; + W_Traces_File : Writable_File; + Default_Traces_File_Contents : constant String := + ">" + & (if VSS.Command_Line.Is_Specified (Language_GPR_Option) + then "gpr_ls" else "ada_ls") + & "_log.$T.log:buffer_size=0" & Ada.Characters.Latin_1.LF + & "ALS.MAIN=yes" & Ada.Characters.Latin_1.LF + & "ALS.IN=no" & Ada.Characters.Latin_1.LF + & "ALS.OUT=no" & Ada.Characters.Latin_1.LF; begin W_Traces_File := Traces_File.Write_File; W_Traces_File.Write (Default_Traces_File_Contents); diff --git a/testsuite/.als/traces.cfg b/testsuite/.als/ada_ls_traces.cfg similarity index 100% rename from testsuite/.als/traces.cfg rename to testsuite/.als/ada_ls_traces.cfg