6
6
getOpenedRepoHistory ,
7
7
removeOpenedRepoFromHistory ,
8
8
resetPendingUriToOpen ,
9
+ addOpenedRepoToHistory ,
9
10
} from './repoHistory' ;
10
11
11
12
// The kind of URIS we are handling will be like this:
@@ -130,15 +131,7 @@ export class Opener {
130
131
}
131
132
132
133
private async openNewWorkspace ( forceNewWindow = false ) {
133
- // has this repo been ever opened?
134
- const knownRepoInfo = await getOpenedRepoHistory ( this . context ) ;
135
- const knownRepo = knownRepoInfo [ this . repoName ] ;
136
- console . log ( `knownRepo ${ this . repoName } : ${ knownRepo } ` ) ;
137
- // if the repo is not found in the history, we're going to search for it in the config roots
138
- const repoPath = knownRepo
139
- ? vscode . Uri . file ( knownRepo )
140
- : await this . findFolderInConfigRoots ( ) ;
141
-
134
+ const repoPath = await this . findFolderInSources ( ) ;
142
135
if ( this . file ) {
143
136
// NOTE: opening a folder causes the extension to reload again.
144
137
// This means that if you want to open a file, you need to do it on extension activation.
@@ -152,6 +145,30 @@ export class Opener {
152
145
await this . openFolder ( repoPath , forceNewWindow ) ;
153
146
}
154
147
148
+ private async findFolderInSources ( ) : Promise < vscode . Uri | undefined > {
149
+ // has this repo been ever opened?
150
+ const knownRepoInfo = await getOpenedRepoHistory ( this . context ) ;
151
+ const knownRepo = knownRepoInfo [ this . repoName ] ;
152
+ console . log ( `knownRepo ${ this . repoName } : ${ knownRepo } ` ) ;
153
+ // if the repo is not found in the history, we're going to search for it in the config roots
154
+ if ( knownRepo ) {
155
+ return vscode . Uri . file ( knownRepo ) ;
156
+ }
157
+ const repoInRootsUri = await this . findFolderInConfigRoots ( ) ;
158
+ if ( repoInRootsUri ) {
159
+ // we're going to store the repo in the history
160
+ await addOpenedRepoToHistory (
161
+ {
162
+ name : this . repoName ,
163
+ uri : repoInRootsUri ,
164
+ } ,
165
+ this . context ,
166
+ ) ;
167
+ return repoInRootsUri ;
168
+ }
169
+ return undefined ;
170
+ }
171
+
155
172
private async getCurrentCommit (
156
173
repo : Repository ,
157
174
) : Promise < Branch | undefined > {
0 commit comments