Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const mocks = vi.hoisted(() => ({
readFile: vi.fn(),
readdir: vi.fn(),
showWarningMessage: vi.fn(),
tryGetLogicAppCustomCodeFunctionsProjects: vi.fn(),
tryGetLogicAppProjectRoot: vi.fn(),
getDotNetCommand: vi.fn(),
}));
Expand Down Expand Up @@ -52,10 +51,6 @@ vi.mock('../../utils/verifyIsProject', () => ({
tryGetLogicAppProjectRoot: mocks.tryGetLogicAppProjectRoot,
}));

vi.mock('../../utils/customCodeUtils', () => ({
tryGetLogicAppCustomCodeFunctionsProjects: mocks.tryGetLogicAppCustomCodeFunctionsProjects,
}));

vi.mock('../../utils/dotnet/dotnet', () => ({
getDotNetCommand: mocks.getDotNetCommand,
}));
Expand Down Expand Up @@ -93,14 +88,21 @@ describe('LogicAppsLanguageServer', () => {
beforeEach(() => {
vi.clearAllMocks();
mocks.createFileSystemWatcher.mockReturnValue({ onDidChange: vi.fn() });
mocks.getGlobalSetting.mockReturnValue(dependenciesPath);
mocks.getGlobalSetting.mockImplementation((key: string) => {
if (key === 'autoRuntimeDependenciesValidationAndInstallation') {
return true;
}
if (key === 'autoRuntimeDependenciesPath') {
return dependenciesPath;
}
return undefined;
});
mocks.getWorkspaceFolderPath.mockResolvedValue('D:\\workspace');
mocks.languageClient.mockImplementation(() => ({ start: vi.fn().mockResolvedValue(undefined) }));
mocks.pathExists.mockResolvedValue(false);
mocks.readFile.mockResolvedValue('{}');
mocks.readdir.mockResolvedValue([]);
mocks.tryGetLogicAppProjectRoot.mockResolvedValue(projectPath);
mocks.tryGetLogicAppCustomCodeFunctionsProjects.mockResolvedValue(['D:\\workspace\\custom-code-project']);
mocks.getDotNetCommand.mockReturnValue('D:\\dependencies\\DotNetSDK\\dotnet.exe');
mocks.getAzureConnectorDetailsForLocalProject.mockResolvedValue({
accessToken: 'Bearer token',
Expand All @@ -120,19 +122,6 @@ describe('LogicAppsLanguageServer', () => {
expect(mocks.showWarningMessage).not.toHaveBeenCalled();
});

it('does not start or prompt for Azure connector metadata when no linked custom code project is found', async () => {
mocks.tryGetLogicAppCustomCodeFunctionsProjects.mockResolvedValue([]);

await new LogicAppsLanguageServer({} as any).start();

expect(mocks.tryGetLogicAppCustomCodeFunctionsProjects).toHaveBeenCalledWith(projectPath);
expect(mocks.pathExists).not.toHaveBeenCalled();
expect(mocks.readdir).not.toHaveBeenCalled();
expect(mocks.getAzureConnectorDetailsForLocalProject).not.toHaveBeenCalled();
expect(mocks.languageClient).not.toHaveBeenCalled();
expect(mocks.showWarningMessage).not.toHaveBeenCalled();
});

it('does not scan a missing SDK directory', async () => {
mocks.pathExists.mockImplementation(async (filePath: string) => filePath === lspServerPath);

Expand Down Expand Up @@ -195,4 +184,93 @@ describe('LogicAppsLanguageServer', () => {
);
expect(languageClient.start).toHaveBeenCalledOnce();
});

describe('manual mode (autoRuntimeDependenciesValidationAndInstallation = false)', () => {
const manualDllPath = 'C:\\custom\\LSPServer\\SdkLspServer.dll';
const manualNupkgPath = 'C:\\custom\\LanguageServerLogicApps\\Microsoft.Azure.Workflows.Sdk.1.0.0-preview.1.nupkg';

beforeEach(() => {
mocks.getGlobalSetting.mockImplementation((key: string) => {
if (key === 'autoRuntimeDependenciesValidationAndInstallation') {
return false;
}
if (key === 'languageServerDLLPath') {
return manualDllPath;
}
if (key === 'languageServerNupkgPath') {
return manualNupkgPath;
}
return undefined;
});
});

it('uses explicit path settings when auto-validation is off', async () => {
const languageClient = { start: vi.fn().mockResolvedValue(undefined) };
mocks.languageClient.mockReturnValue(languageClient);
mocks.pathExists.mockResolvedValue(true);

await new LogicAppsLanguageServer({} as any).start();

expect(mocks.languageClient).toHaveBeenCalledWith(
'logicAppsLanguageServer',
'Logic Apps language server',
{
run: {
command: 'D:\\dependencies\\DotNetSDK\\dotnet.exe',
args: [manualDllPath, '--sdk', manualNupkgPath],
},
debug: {
command: 'D:\\dependencies\\DotNetSDK\\dotnet.exe',
args: [manualDllPath, '--sdk', manualNupkgPath],
},
},
expect.objectContaining({
initializationOptions: expect.objectContaining({
apiConfig: expect.objectContaining({
bearerToken: 'Bearer token',
}),
}),
})
);
expect(languageClient.start).toHaveBeenCalledOnce();
});

it('warns and does not start when DLL path does not exist', async () => {
mocks.pathExists.mockImplementation(async (filePath: string) => filePath !== manualDllPath);

await new LogicAppsLanguageServer({} as any).start();

expect(mocks.showWarningMessage).toHaveBeenCalledWith(
expect.stringContaining('Install or repair Logic Apps language server dependencies')
);
expect(mocks.languageClient).not.toHaveBeenCalled();
});

it('warns and does not start when nupkg path does not exist', async () => {
mocks.pathExists.mockImplementation(async (filePath: string) => filePath !== manualNupkgPath);

await new LogicAppsLanguageServer({} as any).start();

expect(mocks.showWarningMessage).toHaveBeenCalledWith(
expect.stringContaining('Install or repair Logic Apps language server SDK dependencies')
);
expect(mocks.languageClient).not.toHaveBeenCalled();
});

it('returns undefined for both paths when settings are empty', async () => {
mocks.getGlobalSetting.mockImplementation((key: string) => {
if (key === 'autoRuntimeDependenciesValidationAndInstallation') {
return false;
}
return undefined;
});

await new LogicAppsLanguageServer({} as any).start();

expect(mocks.showWarningMessage).toHaveBeenCalledWith(
'Install or repair Logic Apps language server dependencies before starting C# workflow authoring.'
);
expect(mocks.languageClient).not.toHaveBeenCalled();
});
});
});
28 changes: 22 additions & 6 deletions apps/vs-code-designer/src/app/languageServer/languageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import type { IActionContext } from '@microsoft/vscode-azext-utils';
import { callWithTelemetryAndErrorHandling } from '@microsoft/vscode-azext-utils';
import {
autoRuntimeDependenciesPathSettingKey,
autoRuntimeDependenciesValidationAndInstallationSetting,
connectionsFileName,
languageServerDLLPathSettingKey,
languageServerNupkgPathSettingKey,
lspDirectory,
onStartLanguageServerProtocol,
workflowAppApiVersion,
Expand All @@ -20,7 +23,6 @@ import type { AzureConnectorDetails } from '@microsoft/vscode-extension-logic-ap
import { getAzureConnectorDetailsForLocalProject } from '../utils/codeless/common';
import * as vscode from 'vscode';
import { filterCompletionResult } from './completionFilter';
import { tryGetLogicAppCustomCodeFunctionsProjects } from '../utils/customCodeUtils';
import { getDotNetCommand } from '../utils/dotnet/dotnet';

export default class LogicAppsLanguageServer {
Expand All @@ -46,11 +48,6 @@ export default class LogicAppsLanguageServer {
return;
}

const customCodeProjectPaths = await tryGetLogicAppCustomCodeFunctionsProjects(this.projectPath);
if (!customCodeProjectPaths || customCodeProjectPaths.length === 0) {
return;
}

const { lspServerPath, sdkNupkgPath } = await this.getSDKPaths();

this.lspServerPath = lspServerPath;
Expand Down Expand Up @@ -178,6 +175,25 @@ export default class LogicAppsLanguageServer {
}

private async getSDKPaths() {
const autoValidate = getGlobalSetting<boolean>(autoRuntimeDependenciesValidationAndInstallationSetting);

if (!autoValidate) {
// Manual mode: read explicit path settings
const lspServerPath = getGlobalSetting<string>(languageServerDLLPathSettingKey) || undefined;
const sdkNupkgPath = getGlobalSetting<string>(languageServerNupkgPathSettingKey) || undefined;

if (lspServerPath && !(await fse.pathExists(lspServerPath))) {
return { lspServerPath: undefined, sdkNupkgPath };
}

if (sdkNupkgPath && !(await fse.pathExists(sdkNupkgPath))) {
return { lspServerPath, sdkNupkgPath: undefined };
}
Comment on lines +185 to +191

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — removed the duplicate warnings from getSDKPaths(). Now only start() shows the appropriate message when paths are undefined, avoiding duplicate popups.


return { lspServerPath, sdkNupkgPath };
}

// Auto mode: construct paths from dependenciesPath
const dependenciesPath = getGlobalSetting<string>(autoRuntimeDependenciesPathSettingKey);
if (!dependenciesPath) {
return { lspServerPath: undefined, sdkNupkgPath: undefined };
Expand Down
33 changes: 31 additions & 2 deletions apps/vs-code-designer/src/app/utils/__test__/binaries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,37 @@ describe('binaries', () => {
expect(updateGlobalSetting).toHaveBeenCalledWith('funcCoreToolsBinaryPath', 'func');
});

it('should set default paths in devContainer workspace', async () => {
(getGlobalSetting as Mock).mockReturnValue(true);
it('should not overwrite existing paths in devContainer workspace', async () => {
(getGlobalSetting as Mock).mockImplementation((key: string) => {
if (key === 'autoRuntimeDependenciesValidationAndInstallation') {
return true;
}
if (key === 'dotnetBinaryPath') {
return '/custom/path/dotnet';
}
if (key === 'nodeJsBinaryPath') {
return '/custom/path/node';
}
if (key === 'funcCoreToolsBinaryPath') {
return '/custom/path/func';
}
return undefined;
});
const devContainerModule = await import('../devContainerUtils');
vi.mocked(devContainerModule.isDevContainerWorkspace).mockResolvedValue(true);

Comment on lines +578 to 596

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — updated the mock to return realistic path strings (/custom/path/dotnet, /custom/path/node, /custom/path/func) instead of a boolean, making the test more representative of actual usage.

await installBinaries(context);

expect(updateGlobalSetting).not.toHaveBeenCalled();
});

it('should set default paths in devContainer workspace when paths are not set', async () => {
(getGlobalSetting as Mock).mockImplementation((key: string) => {
if (key === 'autoRuntimeDependenciesValidationAndInstallation') {
return true;
}
return undefined;
});
const devContainerModule = await import('../devContainerUtils');
vi.mocked(devContainerModule.isDevContainerWorkspace).mockResolvedValue(true);

Expand Down
12 changes: 9 additions & 3 deletions apps/vs-code-designer/src/app/utils/binaries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,15 @@ export async function installBinaries(context: IActionContext) {
await onboardBinaries(context);
context.telemetry.properties.autoRuntimeDependenciesValidationAndInstallationSetting = 'true';
} else {
await updateGlobalSetting(dotNetBinaryPathSettingKey, DependencyDefaultPath.dotnet);
await updateGlobalSetting(nodeJsBinaryPathSettingKey, DependencyDefaultPath.node);
await updateGlobalSetting(funcCoreToolsBinaryPathSettingKey, DependencyDefaultPath.funcCoreTools);
if (!getGlobalSetting<string>(dotNetBinaryPathSettingKey)) {
await updateGlobalSetting(dotNetBinaryPathSettingKey, DependencyDefaultPath.dotnet);
}
if (!getGlobalSetting<string>(nodeJsBinaryPathSettingKey)) {
await updateGlobalSetting(nodeJsBinaryPathSettingKey, DependencyDefaultPath.node);
}
if (!getGlobalSetting<string>(funcCoreToolsBinaryPathSettingKey)) {
await updateGlobalSetting(funcCoreToolsBinaryPathSettingKey, DependencyDefaultPath.funcCoreTools);
}
context.telemetry.properties.autoRuntimeDependenciesValidationAndInstallationSetting = 'false';
}
}
2 changes: 2 additions & 0 deletions apps/vs-code-designer/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ export const dotNetBinaryPathSettingKey = 'dotnetBinaryPath';
export const nodeJsBinaryPathSettingKey = 'nodeJsBinaryPath';
export const funcCoreToolsBinaryPathSettingKey = 'funcCoreToolsBinaryPath';
export const dependencyTimeoutSettingKey = 'dependencyTimeout';
export const languageServerDLLPathSettingKey = 'languageServerDLLPath';
export const languageServerNupkgPathSettingKey = 'languageServerNupkgPath';
export const unitTestExplorer = 'unitTestExplorer';
export const verifyConnectionKeysSetting = 'verifyConnectionKeys';
export const useSmbDeployment = 'useSmbDeploymentForHybrid';
Expand Down
Loading