-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: handle LS folderConfigs [IDE-502] (#491)
* feat: folderConfigs LS integration wip * fix: render base branch treenode correctly * feat: setBaseBranch command * chore: lint * fix: mock getFolderConfigs in tests * fix: show base branch node if no issues found * chroe: add missing keywords * chore: update CHANGELOG.md --------- Co-authored-by: Catalina Oyaneder <[email protected]>
- Loading branch information
Showing
24 changed files
with
267 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { IVSCodeWindow } from '../vscode/window'; | ||
import { FolderConfig, IConfiguration } from './configuration'; | ||
|
||
export interface IFolderConfigs { | ||
getFolderConfigs(config: IConfiguration): ReadonlyArray<FolderConfig>; | ||
getFolderConfig(config: IConfiguration, folderPath: string): FolderConfig | undefined; | ||
setFolderConfig(config: IConfiguration, folderConfig: FolderConfig): Promise<void>; | ||
setBranch(window: IVSCodeWindow, config: IConfiguration, folderPath: string): Promise<void>; | ||
resetFolderConfigsCache(): void; | ||
} | ||
|
||
export class FolderConfigs implements IFolderConfigs { | ||
private folderConfigsCache?: ReadonlyArray<FolderConfig>; | ||
|
||
getFolderConfig(config: IConfiguration, folderPath: string): FolderConfig | undefined { | ||
const folderConfigs = this.getFolderConfigs(config); | ||
return folderConfigs.find(i => i.folderPath === folderPath); | ||
} | ||
|
||
getFolderConfigs(config: IConfiguration): ReadonlyArray<FolderConfig> { | ||
if (this.folderConfigsCache !== undefined) { | ||
return this.folderConfigsCache; | ||
} | ||
const folderConfigs = config.getFolderConfigs(); | ||
this.folderConfigsCache = folderConfigs; | ||
|
||
return folderConfigs; | ||
} | ||
|
||
async setBranch(window: IVSCodeWindow, config: IConfiguration, folderPath: string): Promise<void> { | ||
const folderConfig = this.getFolderConfig(config, folderPath); | ||
|
||
if (!folderConfig) { | ||
return; | ||
} | ||
|
||
const branchName = await window.showInputBox({ | ||
placeHolder: '', | ||
validateInput: input => { | ||
const valid = this.validateBranchName(input, folderConfig.localBranches ?? []); | ||
if (!valid) { | ||
return "The chosen branch name doesn't exist."; | ||
} | ||
}, | ||
}); | ||
if (!branchName) { | ||
return; | ||
} | ||
|
||
folderConfig.baseBranch = branchName; | ||
await this.setFolderConfig(config, folderConfig); | ||
} | ||
|
||
private validateBranchName(branchName: string, branchList: string[]): boolean { | ||
return branchList.includes(branchName); | ||
} | ||
|
||
async setFolderConfig(config: IConfiguration, folderConfig: FolderConfig): Promise<void> { | ||
const currentFolderConfigs = this.getFolderConfigs(config); | ||
const finalFolderConfigs = currentFolderConfigs.map(i => | ||
i.folderPath === folderConfig.folderPath ? folderConfig : i, | ||
); | ||
await config.setFolderConfigs(finalFolderConfigs); | ||
} | ||
|
||
resetFolderConfigsCache() { | ||
this.folderConfigsCache = undefined; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.