Skip to content

Commit

Permalink
Fix decorator tree now updating if the decorator file didn't exist be…
Browse files Browse the repository at this point in the history
…fore initializing the extension
  • Loading branch information
luisfontes19 committed May 14, 2023
1 parent 266ac7f commit e1ca397
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/fileDecorator/FileDecorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export class FileDecorator implements FileDecorationProvider {

private eventEmitter: EventEmitter<Uri | Uri[]>
public onDidChangeFileDecorations: Event<Uri | Uri[] | undefined>
public onCreatedDecoratorFile: undefined | ((filepath: string) => void) = undefined

// this variable is used to track if the .vscode folder exists for a workspace
// since we need to check this for every file in the file tree, its better to cache it
Expand Down Expand Up @@ -151,6 +152,7 @@ export class FileDecorator implements FileDecorationProvider {
return newFile
}


private ensureVscodeFolderExists(workspace: string) {
const vscodeFolder = vscodeFolderPathForWorkspace(workspace)

Expand All @@ -165,7 +167,10 @@ export class FileDecorator implements FileDecorationProvider {
}

private writeDecoratorsFile(filePath: string, content: any) {
const existed = fs.existsSync(filePath)
fs.writeFileSync(filePath, JSON.stringify(content, null, 2))

if (!existed && this.onCreatedDecoratorFile) this.onCreatedDecoratorFile(filePath)
}

private migrateDecoratorsFile(oldFilePath: string, newFilePath: string) {
Expand Down
2 changes: 2 additions & 0 deletions src/fileDecorator/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export const customDecorator = (fileDecorator: FileDecorator) => {


export const setupDecoratorTree = (fileDecorator: FileDecorator) => {
fileDecorator.onCreatedDecoratorFile = (filepath: string) => treeProvider.refresh(fileDecorator)

const treeProvider = new DecoratorsTreeviewProvider()
const tree = vscode.window.createTreeView("swissknife-decorators-tree", { treeDataProvider: treeProvider })
tree.onDidChangeSelection((e: any) => treeProvider.onSelectionChange(e))
Expand Down

0 comments on commit e1ca397

Please sign in to comment.