Kenvh/editdatatabname (#2906)

* Remove unnecessary string encoding on edit data naming

* Cleaning up duplication in the naming methods.

* fix typo in method name
This commit is contained in:
kenvanhyning
2018-10-18 12:58:07 -07:00
committed by GitHub
parent bfe44c1621
commit 8a570069f8

View File

@@ -124,7 +124,7 @@ export class QueryEditorService implements IQueryEditorService {
try {
// Create file path and file URI
let objectName = schemaName ? schemaName + '.' + tableName : tableName;
let filePath = this.createEditDataFileName(objectName);
let filePath = this.createPrefixedSqlFilePath(objectName);
let docUri: URI = URI.from({ scheme: Schemas.untitled, path: filePath });
// Create a sql document pane with accoutrements
@@ -265,45 +265,26 @@ export class QueryEditorService implements IQueryEditorService {
////// Private functions
private createUntitledSqlFilePath(): string {
let sqlFileName = (counter: number): string => {
return `${untitledFilePrefix}${counter}`;
};
let counter = 1;
// Get document name and check if it exists
let filePath = sqlFileName(counter);
while (fs.existsSync(filePath)) {
counter++;
filePath = sqlFileName(counter);
}
// check if this document name already exists in any open documents
let untitledEditors = this._untitledEditorService.getAll();
while (untitledEditors.find(x => x.getName().toUpperCase() === filePath.toUpperCase())) {
counter++;
filePath = sqlFileName(counter);
}
return filePath;
return this.createPrefixedSqlFilePath(untitledFilePrefix);
}
private createEditDataFileName(tableName: string): string {
let editDataFileName = (counter: number): string => {
return encodeURIComponent(`${tableName}_${counter}`);
private createPrefixedSqlFilePath(prefix: string): string {
let prefixFileName = (counter: number): string => {
return `${prefix}_${counter}`;
};
let counter = 1;
// Get document name and check if it exists
let filePath = editDataFileName(counter);
let filePath = prefixFileName(counter);
while (fs.existsSync(filePath)) {
counter++;
filePath = editDataFileName(counter);
filePath = prefixFileName(counter);
}
let untitledEditors = this._untitledEditorService.getAll();
while (untitledEditors.find(x => x.getName().toUpperCase() === filePath.toUpperCase())) {
counter++;
filePath = editDataFileName(counter);
filePath = prefixFileName(counter);
}
return filePath;