Skip to content

Commit 740d1b3

Browse files
committed
Mark as readonly deployed classes and source-control-protected ISFS documents
1 parent ffa55d0 commit 740d1b3

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

src/providers/FileSystemProvider/File.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export class File implements vscode.FileStat {
55
public ctime: number;
66
public mtime: number;
77
public size: number;
8+
public permissions?: vscode.FilePermission;
89
public fileName: string;
910
public name: string;
1011
public data?: Uint8Array;

src/providers/FileSystemProvider/FileSystemProvider.ts

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,21 @@ import { fireOtherStudioAction, OtherStudioAction, StudioActions } from "../../c
77
import { projectContentsFromUri, studioOpenDialogFromURI } from "../../utils/FileProviderUtil";
88
import {
99
classNameRegex,
10+
getServerName,
1011
isClassDeployed,
1112
notNull,
1213
outputChannel,
1314
redirectDotvscodeRoot,
1415
workspaceFolderOfUri,
1516
} 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";
1725
import { addIsfsFileToProject, modifyProject } from "../../commands/project";
1826
import { DocumentContentProvider } from "../DocumentContentProvider";
1927
import { Document, UserAction } from "../../api/atelier";
@@ -184,13 +192,53 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
184192
this._fireSoon({ type: vscode.FileChangeType.Changed, uri });
185193
}
186194

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;
188198
const redirectedUri = redirectDotvscodeRoot(uri);
189199
if (redirectedUri.path !== uri.path) {
190200
// 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+
}
192240
}
193-
return this._lookup(uri);
241+
return result;
194242
}
195243

196244
public async readDirectory(uri: vscode.Uri): Promise<[string, vscode.FileType][]> {

0 commit comments

Comments
 (0)