mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-03-29 16:20:29 -04:00
[SQL-bindings] remove watcher for files (#20250)
* remove watcher for files * nit
This commit is contained in:
@@ -25,11 +25,6 @@ export interface ILocalSettingsJson {
|
|||||||
ConnectionStrings?: { [key: string]: string };
|
ConnectionStrings?: { [key: string]: string };
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IFileFunctionObject {
|
|
||||||
filePromise: Promise<string>;
|
|
||||||
watcherDisposable: vscode.Disposable;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* copied and modified from vscode-azurefunctions extension
|
* copied and modified from vscode-azurefunctions extension
|
||||||
* https://github.com/microsoft/vscode-azurefunctions/blob/main/src/funcConfig/local.settings.ts
|
* https://github.com/microsoft/vscode-azurefunctions/blob/main/src/funcConfig/local.settings.ts
|
||||||
@@ -198,42 +193,6 @@ export async function getSettingsFile(projectFolder: string): Promise<string | u
|
|||||||
return path.join(projectFolder, 'local.settings.json');
|
return path.join(projectFolder, 'local.settings.json');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* New azure function file watcher and watcher disposable to be used to watch for changes to the azure function project
|
|
||||||
* @param projectFolder is the parent directory to the project file
|
|
||||||
* @returns the function file path once created and the watcher disposable
|
|
||||||
*/
|
|
||||||
export function waitForNewFunctionFile(projectFolder: string): IFileFunctionObject {
|
|
||||||
const watcher = vscode.workspace.createFileSystemWatcher((
|
|
||||||
new vscode.RelativePattern(projectFolder, '**/*.cs')), false, true, true);
|
|
||||||
const filePromise = new Promise<string>((resolve, _) => {
|
|
||||||
watcher.onDidCreate((e) => {
|
|
||||||
resolve(e.fsPath);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
return {
|
|
||||||
filePromise,
|
|
||||||
watcherDisposable: watcher
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves the new host project file once it has created and the watcher disposable
|
|
||||||
* @returns the host file path once created and the watcher disposable
|
|
||||||
*/
|
|
||||||
export function waitForNewHostFile(): IFileFunctionObject {
|
|
||||||
const watcher = vscode.workspace.createFileSystemWatcher('**/host.json', false, true, true);
|
|
||||||
const filePromise = new Promise<string>((resolve, _) => {
|
|
||||||
watcher.onDidCreate((e) => {
|
|
||||||
resolve(e.fsPath);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
return {
|
|
||||||
filePromise,
|
|
||||||
watcherDisposable: watcher
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the required nuget package to the project
|
* Adds the required nuget package to the project
|
||||||
* @param selectedProjectFile is the users selected project file path
|
* @param selectedProjectFile is the users selected project file path
|
||||||
|
|||||||
@@ -83,20 +83,6 @@ export function generateQuotedFullName(schema: string, objectName: string): stri
|
|||||||
return `[${escapeClosingBrackets(schema)}].[${escapeClosingBrackets(objectName)}]`;
|
return `[${escapeClosingBrackets(schema)}].[${escapeClosingBrackets(objectName)}]`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a promise that will reject after the specified timeout
|
|
||||||
* @param errorMessage error message to be returned in the rejection
|
|
||||||
* @param ms timeout in milliseconds. Default is 10 seconds
|
|
||||||
* @returns a promise that rejects after the specified timeout
|
|
||||||
*/
|
|
||||||
export function timeoutPromise(errorMessage: string, ms: number = 10000): Promise<string> {
|
|
||||||
return new Promise((_, reject) => {
|
|
||||||
setTimeout(() => {
|
|
||||||
reject(new TimeoutError(errorMessage));
|
|
||||||
}, ms);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a unique file name
|
* Gets a unique file name
|
||||||
* Increment the file name by adding 1 to function name if the file already exists
|
* Increment the file name by adding 1 to function name if the file already exists
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ export async function createAzureFunction(node?: ITreeNodeInfo): Promise<void> {
|
|||||||
TelemetryReporter.sendActionEvent(TelemetryViews.CreateAzureFunctionWithSqlBinding, TelemetryActions.startCreateAzureFunctionWithSqlBinding);
|
TelemetryReporter.sendActionEvent(TelemetryViews.CreateAzureFunctionWithSqlBinding, TelemetryActions.startCreateAzureFunctionWithSqlBinding);
|
||||||
let connectionInfo: IConnectionInfo | undefined;
|
let connectionInfo: IConnectionInfo | undefined;
|
||||||
let isCreateNewProject: boolean = false;
|
let isCreateNewProject: boolean = false;
|
||||||
let newFunctionFileObject: azureFunctionsUtils.IFileFunctionObject | undefined;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// check to see if Azure Functions Extension is installed
|
// check to see if Azure Functions Extension is installed
|
||||||
@@ -101,9 +100,6 @@ export async function createAzureFunction(node?: ITreeNodeInfo): Promise<void> {
|
|||||||
// user has an azure function project open
|
// user has an azure function project open
|
||||||
projectFolder = path.dirname(projectFile);
|
projectFolder = path.dirname(projectFile);
|
||||||
}
|
}
|
||||||
// create a system file watcher for the project folder
|
|
||||||
newFunctionFileObject = azureFunctionsUtils.waitForNewFunctionFile(projectFolder);
|
|
||||||
|
|
||||||
// Get connection string parameters and construct object name from prompt or connectionInfo given
|
// Get connection string parameters and construct object name from prompt or connectionInfo given
|
||||||
let objectName: string | undefined;
|
let objectName: string | undefined;
|
||||||
let selectedBindingType: BindingType | undefined;
|
let selectedBindingType: BindingType | undefined;
|
||||||
@@ -263,9 +259,6 @@ export async function createAzureFunction(node?: ITreeNodeInfo): Promise<void> {
|
|||||||
.withAdditionalProperties(propertyBag)
|
.withAdditionalProperties(propertyBag)
|
||||||
.withConnectionInfo(connectionInfo).send();
|
.withConnectionInfo(connectionInfo).send();
|
||||||
|
|
||||||
// check for the new function file to be created and dispose of the file system watcher
|
|
||||||
const timeoutForFunctionFile = utils.timeoutPromise(constants.timeoutAzureFunctionFileError);
|
|
||||||
await Promise.race([newFunctionFileObject.filePromise, timeoutForFunctionFile]);
|
|
||||||
telemetryStep = 'finishCreateFunction';
|
telemetryStep = 'finishCreateFunction';
|
||||||
propertyBag.telemetryStep = telemetryStep;
|
propertyBag.telemetryStep = telemetryStep;
|
||||||
exitReason = ExitReason.finishCreate;
|
exitReason = ExitReason.finishCreate;
|
||||||
@@ -275,15 +268,9 @@ export async function createAzureFunction(node?: ITreeNodeInfo): Promise<void> {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
let errorType = utils.getErrorType(error);
|
let errorType = utils.getErrorType(error);
|
||||||
propertyBag.telemetryStep = telemetryStep;
|
propertyBag.telemetryStep = telemetryStep;
|
||||||
if (errorType === 'TimeoutError') {
|
// an error occurred during createFunction
|
||||||
// this error can be cause by many different scenarios including timeout or error occurred during createFunction
|
exitReason = ExitReason.error;
|
||||||
exitReason = ExitReason.timeout;
|
void vscode.window.showErrorMessage(constants.errorNewAzureFunction(error));
|
||||||
console.log('Timed out waiting for Azure Function project to be created. This may not necessarily be an error, for example if the user canceled out of the create flow.');
|
|
||||||
} else {
|
|
||||||
// else an error would occur during the createFunction
|
|
||||||
exitReason = ExitReason.error;
|
|
||||||
void vscode.window.showErrorMessage(constants.errorNewAzureFunction(error));
|
|
||||||
}
|
|
||||||
TelemetryReporter.createErrorEvent(TelemetryViews.CreateAzureFunctionWithSqlBinding, TelemetryActions.exitCreateAzureFunctionQuickpick, undefined, errorType)
|
TelemetryReporter.createErrorEvent(TelemetryViews.CreateAzureFunctionWithSqlBinding, TelemetryActions.exitCreateAzureFunctionQuickpick, undefined, errorType)
|
||||||
.withAdditionalProperties(propertyBag).send();
|
.withAdditionalProperties(propertyBag).send();
|
||||||
return;
|
return;
|
||||||
@@ -292,7 +279,6 @@ export async function createAzureFunction(node?: ITreeNodeInfo): Promise<void> {
|
|||||||
propertyBag.exitReason = exitReason;
|
propertyBag.exitReason = exitReason;
|
||||||
TelemetryReporter.createActionEvent(TelemetryViews.CreateAzureFunctionWithSqlBinding, TelemetryActions.exitCreateAzureFunctionQuickpick)
|
TelemetryReporter.createActionEvent(TelemetryViews.CreateAzureFunctionWithSqlBinding, TelemetryActions.exitCreateAzureFunctionQuickpick)
|
||||||
.withAdditionalProperties(propertyBag).send();
|
.withAdditionalProperties(propertyBag).send();
|
||||||
newFunctionFileObject?.watcherDisposable.dispose();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import * as fs from 'fs';
|
|||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as should from 'should';
|
import * as should from 'should';
|
||||||
import * as sinon from 'sinon';
|
import * as sinon from 'sinon';
|
||||||
import * as TypeMoq from 'typemoq';
|
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import * as azureFunctionUtils from '../../common/azureFunctionsUtils';
|
import * as azureFunctionUtils from '../../common/azureFunctionsUtils';
|
||||||
import * as constants from '../../common/constants';
|
import * as constants from '../../common/constants';
|
||||||
@@ -90,9 +89,6 @@ describe('AzureFunctionsService', () => {
|
|||||||
sinon.stub(azureFunctionUtils, 'setLocalAppSetting').withArgs(sinon.match.any, 'SqlConnectionString', 'testConnectionString').resolves((true));
|
sinon.stub(azureFunctionUtils, 'setLocalAppSetting').withArgs(sinon.match.any, 'SqlConnectionString', 'testConnectionString').resolves((true));
|
||||||
sinon.stub(utils, 'executeCommand').resolves('downloaded nuget package');
|
sinon.stub(utils, 'executeCommand').resolves('downloaded nuget package');
|
||||||
|
|
||||||
const testWatcher = TypeMoq.Mock.ofType<vscode.FileSystemWatcher>().object;
|
|
||||||
sinon.stub(azureFunctionUtils, 'waitForNewFunctionFile').withArgs(sinon.match.any).returns({ filePromise: Promise.resolve('TestFileCreated'), watcherDisposable: testWatcher });
|
|
||||||
|
|
||||||
should(connectionInfo.database).equal('my_db', 'Initial ConnectionInfo database should be my_db');
|
should(connectionInfo.database).equal('my_db', 'Initial ConnectionInfo database should be my_db');
|
||||||
await azureFunctionService.createAzureFunction(tableTestNode);
|
await azureFunctionService.createAzureFunction(tableTestNode);
|
||||||
|
|
||||||
@@ -127,9 +123,6 @@ describe('AzureFunctionsService', () => {
|
|||||||
sinon.stub(azureFunctionUtils, 'setLocalAppSetting').withArgs(sinon.match.any, 'SqlConnectionString', 'testConnectionString').resolves((true));
|
sinon.stub(azureFunctionUtils, 'setLocalAppSetting').withArgs(sinon.match.any, 'SqlConnectionString', 'testConnectionString').resolves((true));
|
||||||
sinon.stub(utils, 'executeCommand').resolves('downloaded nuget package');
|
sinon.stub(utils, 'executeCommand').resolves('downloaded nuget package');
|
||||||
|
|
||||||
const testWatcher = TypeMoq.Mock.ofType<vscode.FileSystemWatcher>().object;
|
|
||||||
sinon.stub(azureFunctionUtils, 'waitForNewFunctionFile').withArgs(sinon.match.any).returns({ filePromise: Promise.resolve('TestFileCreated'), watcherDisposable: testWatcher });
|
|
||||||
|
|
||||||
showErrorMessageSpy = sinon.spy(vscode.window, 'showErrorMessage'); // error message spy to be used for checking tests
|
showErrorMessageSpy = sinon.spy(vscode.window, 'showErrorMessage'); // error message spy to be used for checking tests
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -221,9 +214,6 @@ describe('AzureFunctionsService', () => {
|
|||||||
sinon.stub(azureFunctionUtils, 'setLocalAppSetting').withArgs(sinon.match.any, 'SqlConnectionString', 'testConnectionString').resolves((true));
|
sinon.stub(azureFunctionUtils, 'setLocalAppSetting').withArgs(sinon.match.any, 'SqlConnectionString', 'testConnectionString').resolves((true));
|
||||||
sinon.stub(utils, 'executeCommand').resolves('downloaded nuget package');
|
sinon.stub(utils, 'executeCommand').resolves('downloaded nuget package');
|
||||||
|
|
||||||
const testWatcher = TypeMoq.Mock.ofType<vscode.FileSystemWatcher>().object;
|
|
||||||
sinon.stub(azureFunctionUtils, 'waitForNewFunctionFile').withArgs(sinon.match.any).returns({ filePromise: Promise.resolve('TestFileCreated'), watcherDisposable: testWatcher });
|
|
||||||
|
|
||||||
showErrorMessageSpy = sinon.spy(vscode.window, 'showErrorMessage'); // error message spy to be used for checking tests
|
showErrorMessageSpy = sinon.spy(vscode.window, 'showErrorMessage'); // error message spy to be used for checking tests
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user