Skip to content

Commit

Permalink
Set file readonly if class is deployed or if server-side source contr…
Browse files Browse the repository at this point in the history
…ol reports it not editable (#1399)

* Mark as readonly deployed classes and source-control-protected ISFS documents

* Add `objectscript.serverSourceControl.respectEditableStatus` setting

* Improve description of `respectEditableStatus`

Co-authored-by: Brett Saviano <bsaviano@intersystems.com>

* Apply feedback

* Be consistently explicit about `false` defaults on boolean config properties

* Revert addition of boolean property defaults in `objectscript.export`

---------

Co-authored-by: Brett Saviano <bsaviano@intersystems.com>
  • Loading branch information
gjsjohnmurray and isc-bsaviano authored Jul 15, 2024
1 parent c426c7a commit 54a0e43
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 6 deletions.
12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1325,7 +1325,14 @@
"objectscript.serverSourceControl.disableOtherActionTriggers": {
"description": "Prevent server-side source control 'other action' triggers from firing.",
"type": "boolean",
"scope": "resource"
"scope": "resource",
"default": false
},
"objectscript.serverSourceControl.respectEditableStatus": {
"markdownDescription": "Set `isfs` document readonly if GetStatus method of server-side source control class returns Editable = 0.",
"type": "boolean",
"scope": "resource",
"default": false
},
"objectscript.export": {
"type": "object",
Expand Down Expand Up @@ -1703,7 +1710,8 @@
},
"stopOnEntry": {
"type": "boolean",
"description": "Automatically stop target after attach. If not specified, target does not stop."
"description": "Automatically stop target after attach. If not specified, target does not stop.",
"default": false
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/providers/FileSystemProvider/File.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export class File implements vscode.FileStat {
public ctime: number;
public mtime: number;
public size: number;
public permissions?: vscode.FilePermission;
public fileName: string;
public name: string;
public data?: Uint8Array;
Expand Down
57 changes: 53 additions & 4 deletions src/providers/FileSystemProvider/FileSystemProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ import {
redirectDotvscodeRoot,
workspaceFolderOfUri,
} from "../../utils/index";
import { config, FILESYSTEM_SCHEMA, intLangId, macLangId, workspaceState } from "../../extension";
import {
config,
FILESYSTEM_READONLY_SCHEMA,
FILESYSTEM_SCHEMA,
intLangId,
macLangId,
workspaceState,
} from "../../extension";
import { addIsfsFileToProject, modifyProject } from "../../commands/project";
import { DocumentContentProvider } from "../DocumentContentProvider";
import { Document, UserAction } from "../../api/atelier";
Expand Down Expand Up @@ -184,13 +191,55 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
this._fireSoon({ type: vscode.FileChangeType.Changed, uri });
}

public stat(uri: vscode.Uri): Promise<vscode.FileStat> {
public async stat(uri: vscode.Uri): Promise<vscode.FileStat> {
let entryPromise: Promise<Entry>;
let result: Entry;
const redirectedUri = redirectDotvscodeRoot(uri);
if (redirectedUri.path !== uri.path) {
// When redirecting the /.vscode subtree we must fill in as-yet-unvisited folders to fix https://github.com/intersystems-community/vscode-objectscript/issues/1143
return this._lookup(redirectedUri, true);
entryPromise = this._lookup(redirectedUri, true);
} else {
entryPromise = this._lookup(uri);
}

// If this is our readonly variant there's no point checking server-side whether the file sould be marked readonly
if (uri.scheme === FILESYSTEM_READONLY_SCHEMA) {
return entryPromise;
}

if (entryPromise instanceof File) {
// previously resolved as a file
result = entryPromise;
} else if (entryPromise instanceof Promise && uri.path.split("/").pop()?.split(".").length > 1) {
// apparently a file, so resolve ahead of adding permissions
result = await entryPromise;
} else {
// otherwise return the promise
return entryPromise;
}

//
if (result instanceof File) {
const api = new AtelierAPI(uri);
const serverName = isCSPFile(uri) ? uri.path : uri.path.slice(1).replace(/\//g, ".");
if (serverName.slice(-4).toLowerCase() == ".cls") {
if (await isClassDeployed(serverName, api)) {
result.permissions |= vscode.FilePermission.Readonly;
return result;
}
}

// Does server-side source control report it as editable?
if (vscode.workspace.getConfiguration("objectscript.serverSourceControl", uri)?.get("respectEditableStatus")) {
const query = "select * from %Atelier_v1_Utils.Extension_GetStatus(?)";
const statusObj = await api.actionQuery(query, [serverName]);
const docStatus = statusObj.result?.content?.pop();
if (docStatus) {
result.permissions = docStatus.editable ? undefined : result.permissions | vscode.FilePermission.Readonly;
}
}
}
return this._lookup(uri);
return result;
}

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

0 comments on commit 54a0e43

Please sign in to comment.