@@ -31,6 +31,7 @@ import {
31
31
getEvaluatedCustomEnv ,
32
32
setCustomEnvironment ,
33
33
} from './helpers' ;
34
+ import { ExecuteCommandRequest } from 'vscode-languageclient/node' ;
34
35
35
36
const ADA_CONTEXT = 'ADA_PROJECT_CONTEXT' ;
36
37
export let contextClients : ContextClients ;
@@ -111,66 +112,76 @@ type ALSSourceDirDescription = {
111
112
*
112
113
*/
113
114
async function checkSrcDirectories ( alsClient : LanguageClient ) {
114
- if ( vscode . workspace . workspaceFile !== undefined ) {
115
- await alsClient
116
- . sendRequest < [ ALSSourceDirDescription ] > ( 'workspace/alsSourceDirs' )
117
- . then ( async ( source_dirs ) => {
118
- const workspace_folders = vscode . workspace . workspaceFolders ?? [ ] ;
119
- const workspace_dirs_to_add : { uri : vscode . Uri ; name ?: string | undefined } [ ] = [ ] ;
120
-
121
- for ( const source_dir of source_dirs ) {
122
- const source_dir_uri = vscode . Uri . parse ( source_dir . uri ) ;
123
- const source_dir_path = source_dir_uri . path ;
124
-
125
- const is_subdirectory = ( dir : string , parent : string ) => {
126
- // Use lower-case on Windows since drives can be specified in VS Code
127
- // either with lower or upper case characters.
128
- if ( process . platform == 'win32' ) {
129
- dir = dir . toLowerCase ( ) ;
130
- parent = parent . toLowerCase ( ) ;
131
- }
115
+ const foldersInSettings = vscode . workspace . getConfiguration ( ) . get ( 'folders' ) ?? [ ] ;
116
+
117
+ // Don't propose any popup if we multi-root workspace folders are already set
118
+ // explicitly in the workspace's settings.
119
+ if ( foldersInSettings !== undefined ) {
120
+ const sourceDirs : ALSSourceDirDescription [ ] = ( await alsClient . sendRequest (
121
+ ExecuteCommandRequest . type ,
122
+ {
123
+ command : 'als-source-dirs' ,
124
+ }
125
+ ) ) as ALSSourceDirDescription [ ] ;
126
+
127
+ const isSubdirectory = ( dir : string , parent : string ) => {
128
+ // Use lower-case on Windows since drives can be specified in VS Code
129
+ // either with lower or upper case characters.
130
+ if ( process . platform == 'win32' ) {
131
+ dir = dir . toLowerCase ( ) ;
132
+ parent = parent . toLowerCase ( ) ;
133
+ }
134
+
135
+ return dir . startsWith ( parent + '/' ) ;
136
+ } ;
137
+
138
+ const workspaceFolders = vscode . workspace . workspaceFolders ?? [ ] ;
139
+ const workspaceDirsToAdd : { uri : vscode . Uri ; name ?: string | undefined } [ ] = [ ] ;
140
+
141
+ for ( const source_dir of sourceDirs ) {
142
+ const sourceDirURI = vscode . Uri . parse ( source_dir . uri ) ;
143
+ const sourceDirPath = sourceDirURI . path ;
144
+
145
+ // If the source directory is not under one of the workspace folders and
146
+ // if it's not already present in the workspace's folders, push
147
+ // this source directory to the workspace folders to add later.
148
+ if (
149
+ ! workspaceFolders . some (
150
+ ( workspaceFolder ) =>
151
+ workspaceFolder . uri . path == sourceDirPath ||
152
+ isSubdirectory ( sourceDirPath , workspaceFolder . uri . path )
153
+ )
154
+ ) {
155
+ workspaceDirsToAdd . push ( {
156
+ name : source_dir . name ,
157
+ uri : sourceDirURI ,
158
+ } ) ;
159
+ }
160
+ }
132
161
133
- return dir . startsWith ( parent + '/' ) ;
134
- } ;
135
-
136
- // If the source directory is not under one of the workspace folders, push
137
- // this source directory to the workspace folders to add later.
138
- if (
139
- ! workspace_folders . some ( ( workspace_folder ) =>
140
- is_subdirectory ( source_dir_path , workspace_folder . uri . path )
141
- )
142
- ) {
143
- workspace_dirs_to_add . push ( {
144
- name : source_dir . name ,
145
- uri : source_dir_uri ,
146
- } ) ;
162
+ // If there are some source directories missing in the workspace, ask the user
163
+ // to add them in his workspace.
164
+ if ( workspaceDirsToAdd . length > 0 ) {
165
+ await vscode . window
166
+ . showInformationMessage (
167
+ 'Some project source directories are not \
168
+ listed in your workspace: do you want to add them?' ,
169
+ 'Yes' ,
170
+ 'No'
171
+ )
172
+ . then ( ( answer ) => {
173
+ if ( answer === 'Yes' ) {
174
+ for ( const workspaceDir of workspaceDirsToAdd ) {
175
+ vscode . workspace . updateWorkspaceFolders (
176
+ vscode . workspace . workspaceFolders
177
+ ? vscode . workspace . workspaceFolders . length
178
+ : 0 ,
179
+ null ,
180
+ workspaceDir
181
+ ) ;
182
+ }
147
183
}
148
- }
149
-
150
- // If there are some source directories missing in the workspace, ask the user
151
- // to add them in his workspace.
152
- if ( workspace_dirs_to_add . length > 0 ) {
153
- await vscode . window
154
- . showInformationMessage (
155
- 'Some project source directories are not ' ,
156
- 'listed in your workspace: do you want to add them?' ,
157
- 'Yes' ,
158
- 'No'
159
- )
160
- . then ( ( answer ) => {
161
- if ( answer === 'Yes' ) {
162
- for ( const workspace_dir of workspace_dirs_to_add ) {
163
- vscode . workspace . updateWorkspaceFolders (
164
- vscode . workspace . workspaceFolders
165
- ? vscode . workspace . workspaceFolders . length
166
- : 0 ,
167
- null ,
168
- workspace_dir
169
- ) ;
170
- }
171
- }
172
- } ) ;
173
- }
174
- } ) ;
184
+ } ) ;
185
+ }
175
186
}
176
187
}
0 commit comments