mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-14 01:25:37 -05:00
the fix open in designer menu item is not available after script is updated with newly added create table statements (#20522)
* make open in designer available after a script is updated with a new create table statement * uppercase
This commit is contained in:
@@ -65,6 +65,11 @@ export enum TaskExecutionMode {
|
||||
|
||||
export type AddDatabaseReferenceSettings = ISystemDatabaseReferenceSettings | IDacpacReferenceSettings | IProjectReferenceSettings;
|
||||
|
||||
interface FileWatcherStatus {
|
||||
fileWatcher: vscode.FileSystemWatcher;
|
||||
containsCreateTableStatement: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Controller for managing lifecycle of projects
|
||||
*/
|
||||
@@ -78,7 +83,8 @@ export class ProjectsController {
|
||||
private azureSqlClient: AzureSqlClient;
|
||||
private autorestHelper: AutorestHelper;
|
||||
|
||||
projFileWatchers = new Map<string, vscode.FileSystemWatcher>();
|
||||
private projFileWatchers = new Map<string, vscode.FileSystemWatcher>();
|
||||
private fileWatchers = new Map<string, FileWatcherStatus>();
|
||||
|
||||
constructor(private _outputChannel: vscode.OutputChannel) {
|
||||
this.netCoreTool = new NetCoreTool(this._outputChannel);
|
||||
@@ -890,6 +896,41 @@ export class ProjectsController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a file in the editor and adds a file watcher to check if a create table statement has been added
|
||||
* @param fileSystemUri uri of file
|
||||
* @param node node of file in the tree
|
||||
*/
|
||||
public async openFileWithWatcher(fileSystemUri: vscode.Uri, node: FileNode): Promise<void> {
|
||||
await vscode.commands.executeCommand(constants.vscodeOpenCommand, fileSystemUri);
|
||||
const projectTargetVersion = (node.root as ProjectRootTreeItem).project.getProjectTargetVersion();
|
||||
const initiallyContainsCreateTableStatement = await utils.fileContainsCreateTableStatement(fileSystemUri.fsPath, projectTargetVersion);
|
||||
|
||||
const fileWatcher: vscode.FileSystemWatcher = vscode.workspace.createFileSystemWatcher(fileSystemUri.fsPath);
|
||||
this.fileWatchers.set(fileSystemUri.fsPath, { fileWatcher: fileWatcher, containsCreateTableStatement: initiallyContainsCreateTableStatement });
|
||||
|
||||
fileWatcher.onDidChange(async (uri: vscode.Uri) => {
|
||||
const afterContainsCreateTableStatement = await utils.fileContainsCreateTableStatement(fileSystemUri.fsPath, projectTargetVersion);
|
||||
const previousStatus = this.fileWatchers.get(uri.fsPath)?.containsCreateTableStatement;
|
||||
|
||||
// if the contains create table statement status is different, reload the project so that the "Open in Designer" menu option
|
||||
// on the file node is there if a create table statement has been added or removed if it's been removed
|
||||
if (previousStatus !== afterContainsCreateTableStatement) {
|
||||
utils.getDataWorkspaceExtensionApi().refreshProjectsTree();
|
||||
this.fileWatchers.get(uri.fsPath)!.containsCreateTableStatement = afterContainsCreateTableStatement;
|
||||
}
|
||||
});
|
||||
|
||||
// stop watching for changes to the file after it's closed
|
||||
const closeSqlproj = vscode.workspace.onDidCloseTextDocument((d) => {
|
||||
if (this.fileWatchers.has(d.uri.fsPath)) {
|
||||
this.fileWatchers.get(d.uri.fsPath)?.fileWatcher.dispose();
|
||||
this.fileWatchers.delete(d.uri.fsPath);
|
||||
closeSqlproj.dispose();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads the given project. Throws an error if given project is not a valid open project.
|
||||
* @param context
|
||||
|
||||
Reference in New Issue
Block a user