@@ -7,13 +7,21 @@ import { fireOtherStudioAction, OtherStudioAction, StudioActions } from "../../c
7
7
import { projectContentsFromUri , studioOpenDialogFromURI } from "../../utils/FileProviderUtil" ;
8
8
import {
9
9
classNameRegex ,
10
+ getServerName ,
10
11
isClassDeployed ,
11
12
notNull ,
12
13
outputChannel ,
13
14
redirectDotvscodeRoot ,
14
15
workspaceFolderOfUri ,
15
16
} from "../../utils/index" ;
16
- import { config , FILESYSTEM_SCHEMA , intLangId , macLangId , workspaceState } from "../../extension" ;
17
+ import {
18
+ config ,
19
+ FILESYSTEM_READONLY_SCHEMA ,
20
+ FILESYSTEM_SCHEMA ,
21
+ intLangId ,
22
+ macLangId ,
23
+ workspaceState ,
24
+ } from "../../extension" ;
17
25
import { addIsfsFileToProject , modifyProject } from "../../commands/project" ;
18
26
import { DocumentContentProvider } from "../DocumentContentProvider" ;
19
27
import { Document , UserAction } from "../../api/atelier" ;
@@ -184,13 +192,53 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
184
192
this . _fireSoon ( { type : vscode . FileChangeType . Changed , uri } ) ;
185
193
}
186
194
187
- public stat ( uri : vscode . Uri ) : Promise < vscode . FileStat > {
195
+ public async stat ( uri : vscode . Uri ) : Promise < vscode . FileStat > {
196
+ let entryPromise : Promise < Entry > ;
197
+ let result : Entry ;
188
198
const redirectedUri = redirectDotvscodeRoot ( uri ) ;
189
199
if ( redirectedUri . path !== uri . path ) {
190
200
// When redirecting the /.vscode subtree we must fill in as-yet-unvisited folders to fix https://github.com/intersystems-community/vscode-objectscript/issues/1143
191
- return this . _lookup ( redirectedUri , true ) ;
201
+ entryPromise = this . _lookup ( redirectedUri , true ) ;
202
+ } else {
203
+ entryPromise = this . _lookup ( uri ) ;
204
+ }
205
+
206
+ // If this is our readonly variant there's no point checking server-side whether the file sould be marked readonly
207
+ if ( uri . scheme === FILESYSTEM_READONLY_SCHEMA ) {
208
+ return entryPromise ;
209
+ }
210
+
211
+ if ( entryPromise instanceof File ) {
212
+ // previously resolved as a file
213
+ result = entryPromise ;
214
+ } else if ( entryPromise instanceof Promise && uri . path . split ( "/" ) . pop ( ) ?. split ( "." ) . length > 1 ) {
215
+ // apparently a file, so resolve ahead of adding permissions
216
+ result = await entryPromise ;
217
+ } else {
218
+ // otherwise return the promise
219
+ return entryPromise ;
220
+ }
221
+
222
+ //
223
+ if ( result instanceof File ) {
224
+ const api = new AtelierAPI ( uri ) ;
225
+ const serverName = getServerName ( uri ) ;
226
+ if ( serverName . slice ( - 4 ) . toLowerCase ( ) == ".cls" ) {
227
+ if ( await isClassDeployed ( serverName , api ) ) {
228
+ result . permissions |= vscode . FilePermission . Readonly ;
229
+ return result ;
230
+ }
231
+ }
232
+
233
+ // Does server-side source control report it as editable?
234
+ const query = "select * from %Atelier_v1_Utils.Extension_GetStatus(?)" ;
235
+ const statusObj = await api . actionQuery ( query , [ serverName ] ) ;
236
+ const docStatus = statusObj . result . content . pop ( ) ;
237
+ if ( docStatus ) {
238
+ result . permissions = docStatus . editable ? undefined : result . permissions | vscode . FilePermission . Readonly ;
239
+ }
192
240
}
193
- return this . _lookup ( uri ) ;
241
+ return result ;
194
242
}
195
243
196
244
public async readDirectory ( uri : vscode . Uri ) : Promise < [ string , vscode . FileType ] [ ] > {
0 commit comments