Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set file readonly if class is deployed or if server-side source control reports it not editable #1399

Merged
12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,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": {
gjsjohnmurray marked this conversation as resolved.
Show resolved Hide resolved
"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 @@ -1688,7 +1695,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;
gjsjohnmurray marked this conversation as resolved.
Show resolved Hide resolved
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