From 124d92a40d640ef45b7ce04d23b93b6307e44e0a Mon Sep 17 00:00:00 2001 From: gjsjohnmurray Date: Fri, 10 Jul 2020 17:33:56 +0100 Subject: [PATCH] fix #193 Add 'isfs-readonly' scheme --- package.json | 13 +++++++++---- src/api/index.ts | 12 ++++++++++-- src/commands/compile.ts | 10 ++++++++-- src/commands/serverActions.ts | 8 ++++++-- src/debug/debugSession.ts | 9 ++++++--- src/extension.ts | 22 ++++++++++++++++++++-- src/providers/DocumentContentProvider.ts | 8 +++++--- 7 files changed, 64 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 2b730527..cfbee017 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,10 @@ { "name": "Oleg Dmitrovich", "email": "doublefint@gmail.com" + }, + { + "name": "John Murray", + "email": "johnm@georgejames.com" } ], "engines": { @@ -60,6 +64,7 @@ "onLanguage:xml", "onView:ObjectScriptExplorer", "onFileSystem:isfs", + "onFileSystem:isfs-readonly", "onFileSystem:objectscript", "onDebugInitialConfigurations" ], @@ -137,7 +142,7 @@ }, { "command": "vscode-objectscript.serverCommands.other", - "when": "vscode-objectscript.connectActive && resourceScheme == isfs || vscode-objectscript.connectActive && !editorIsOpen" + "when": "vscode-objectscript.connectActive && resourceScheme =~ /^isfs(-readonly)?$/ || vscode-objectscript.connectActive && !editorIsOpen" }, { "command": "vscode-objectscript.serverCommands.contextOther", @@ -226,7 +231,7 @@ }, { "command": "vscode-objectscript.serverCommands.contextOther", - "when": "resourceScheme == isfs && editorLangId =~ /^objectscript/ && vscode-objectscript.connectActive", + "when": "resourceScheme =~ /^isfs(-readonly)?$/ && editorLangId =~ /^objectscript/ && vscode-objectscript.connectActive", "group": "objectscript@5" } ], @@ -239,7 +244,7 @@ { "command": "vscode-objectscript.serverCommands.other", "group": "navigation@2", - "when": "vscode-objectscript.connectActive && resourceScheme == isfs" + "when": "vscode-objectscript.connectActive && resourceScheme =~ /^isfs(-readonly)?$/" } ], @@ -268,7 +273,7 @@ }, { "command": "vscode-objectscript.serverCommands.contextOther", - "when": "resourceScheme == isfs && resourceLangId =~ /^objectscript/ && vscode-objectscript.connectActive", + "when": "resourceScheme =~ /^isfs(-readonly)?$/ && resourceLangId =~ /^objectscript/ && vscode-objectscript.connectActive", "group": "objectscript@3" } ] diff --git a/src/api/index.ts b/src/api/index.ts index afc12b49..a3092408 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -4,7 +4,15 @@ import * as request from "request-promise"; import * as url from "url"; import * as vscode from "vscode"; import * as Cache from "vscode-cache"; -import { config, extensionContext, FILESYSTEM_SCHEMA, workspaceState, panel, checkConnection } from "../extension"; +import { + config, + extensionContext, + FILESYSTEM_SCHEMA, + FILESYSTEM_READONLY_SCHEMA, + workspaceState, + panel, + checkConnection, +} from "../extension"; import { currentWorkspaceFolder, outputConsole, outputChannel } from "../utils"; const DEFAULT_API_VERSION = 1; @@ -78,7 +86,7 @@ export class AtelierAPI { let namespace; if (wsOrFile) { if (wsOrFile instanceof vscode.Uri) { - if (wsOrFile.scheme === FILESYSTEM_SCHEMA) { + if (wsOrFile.scheme === FILESYSTEM_SCHEMA || wsOrFile.scheme === FILESYSTEM_READONLY_SCHEMA) { workspaceFolderName = wsOrFile.authority; const { query } = url.parse(decodeURIComponent(wsOrFile.toString()), true); if (query) { diff --git a/src/commands/compile.ts b/src/commands/compile.ts index f8945434..a3a1c062 100644 --- a/src/commands/compile.ts +++ b/src/commands/compile.ts @@ -3,7 +3,13 @@ import glob = require("glob"); import path = require("path"); import vscode = require("vscode"); import { AtelierAPI } from "../api"; -import { config, documentContentProvider, FILESYSTEM_SCHEMA, fileSystemProvider } from "../extension"; +import { + config, + documentContentProvider, + FILESYSTEM_SCHEMA, + FILESYSTEM_READONLY_SCHEMA, + fileSystemProvider, +} from "../extension"; import { DocumentContentProvider } from "../providers/DocumentContentProvider"; import { currentFile, CurrentFile, outputChannel } from "../utils"; import { RootNode } from "../explorer/models/rootNode"; @@ -53,7 +59,7 @@ export async function loadChanges(files: CurrentFile[]): Promise { const content = (data.result.content || []).join(file.eol === vscode.EndOfLine.LF ? "\n" : "\r\n"); if (file.uri.scheme === "file") { fs.writeFileSync(file.fileName, content); - } else if (file.uri.scheme === FILESYSTEM_SCHEMA) { + } else if (file.uri.scheme === FILESYSTEM_SCHEMA || file.uri.scheme === FILESYSTEM_READONLY_SCHEMA) { fileSystemProvider.writeFile(file.uri, Buffer.from(content), { overwrite: true, create: false, diff --git a/src/commands/serverActions.ts b/src/commands/serverActions.ts index 8a01666e..0768d590 100644 --- a/src/commands/serverActions.ts +++ b/src/commands/serverActions.ts @@ -1,5 +1,5 @@ import * as vscode from "vscode"; -import { config, workspaceState, checkConnection, FILESYSTEM_SCHEMA } from "../extension"; +import { config, workspaceState, checkConnection, FILESYSTEM_SCHEMA, FILESYSTEM_READONLY_SCHEMA } from "../extension"; import { currentWorkspaceFolder, terminalWithDocker, currentFile } from "../utils"; import { mainCommandMenu, mainSourceControlMenu } from "./studio"; import { AtelierAPI } from "../api"; @@ -96,7 +96,11 @@ export async function serverActions(): Promise { id: "openClassReference", label: "Open Class Reference", }); - if (!vscode.window.activeTextEditor || vscode.window.activeTextEditor.document.uri.scheme === FILESYSTEM_SCHEMA) { + if ( + !vscode.window.activeTextEditor || + vscode.window.activeTextEditor.document.uri.scheme === FILESYSTEM_SCHEMA || + vscode.window.activeTextEditor.document.uri.scheme === FILESYSTEM_READONLY_SCHEMA + ) { actions.push({ id: "serverSourceControlMenu", label: "Server Source Control...", diff --git a/src/debug/debugSession.ts b/src/debug/debugSession.ts index 93c07d08..422748fc 100644 --- a/src/debug/debugSession.ts +++ b/src/debug/debugSession.ts @@ -17,7 +17,7 @@ import { DebugProtocol } from "vscode-debugprotocol"; import WebSocket = require("ws"); import { AtelierAPI } from "../api"; import * as xdebug from "./xdebugConnection"; -import { FILESYSTEM_SCHEMA } from "../extension"; +import { FILESYSTEM_SCHEMA, FILESYSTEM_READONLY_SCHEMA } from "../extension"; import * as url from "url"; import { DocumentContentProvider } from "../providers/DocumentContentProvider"; import { formatPropertyValue } from "./utils"; @@ -40,7 +40,7 @@ interface AttachRequestArguments extends DebugProtocol.AttachRequestArguments { export async function convertClientPathToDebugger(localPath: string, namespace: string): Promise { const { protocol, pathname, query } = url.parse(decodeURIComponent(localPath), true, true); let fileName = localPath; - if (protocol && protocol === `${FILESYSTEM_SCHEMA}:`) { + if (protocol && (protocol === `${FILESYSTEM_SCHEMA}:` || protocol === `${FILESYSTEM_READONLY_SCHEMA}:`)) { if (query.ns && query.ns !== "") { namespace = query.ns.toString(); } @@ -205,7 +205,10 @@ export class ObjectScriptDebugSession extends LoggingDebugSession { await this._debugTargetSet.wait(1000); const filePath = args.source.path; - const uri = filePath.startsWith(FILESYSTEM_SCHEMA) ? vscode.Uri.parse(filePath) : vscode.Uri.file(filePath); + const uri = + filePath.startsWith(FILESYSTEM_SCHEMA) || filePath.startsWith(FILESYSTEM_READONLY_SCHEMA) + ? vscode.Uri.parse(filePath) + : vscode.Uri.file(filePath); const fileUri = await convertClientPathToDebugger(args.source.path, this._namespace); const [, fileName] = fileUri.match(/\|([^|]+)$/); diff --git a/src/extension.ts b/src/extension.ts index f9094382..bc10e216 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -7,7 +7,13 @@ const { workspace, window } = vscode; export const OBJECTSCRIPT_FILE_SCHEMA = "objectscript"; export const OBJECTSCRIPTXML_FILE_SCHEMA = "objectscriptxml"; export const FILESYSTEM_SCHEMA = "isfs"; -export const schemas = [OBJECTSCRIPT_FILE_SCHEMA, OBJECTSCRIPTXML_FILE_SCHEMA, FILESYSTEM_SCHEMA]; +export const FILESYSTEM_READONLY_SCHEMA = "isfs-readonly"; +export const schemas = [ + OBJECTSCRIPT_FILE_SCHEMA, + OBJECTSCRIPTXML_FILE_SCHEMA, + FILESYSTEM_SCHEMA, + FILESYSTEM_READONLY_SCHEMA, +]; import * as url from "url"; import WebSocket = require("ws"); @@ -380,9 +386,15 @@ export async function activate(context: vscode.ExtensionContext): Promise packageJson.enableProposedApi && typeof vscode.workspace.registerFileSearchProvider === "function" ? vscode.workspace.registerFileSearchProvider(FILESYSTEM_SCHEMA, new FileSearchProvider()) : null, + packageJson.enableProposedApi && typeof vscode.workspace.registerFileSearchProvider === "function" + ? vscode.workspace.registerFileSearchProvider(FILESYSTEM_READONLY_SCHEMA, new FileSearchProvider()) + : null, packageJson.enableProposedApi && typeof vscode.workspace.registerTextSearchProvider === "function" ? vscode.workspace.registerTextSearchProvider(FILESYSTEM_SCHEMA, new TextSearchProvider()) : null, + packageJson.enableProposedApi && typeof vscode.workspace.registerTextSearchProvider === "function" + ? vscode.workspace.registerTextSearchProvider(FILESYSTEM_READONLY_SCHEMA, new TextSearchProvider()) + : null, ].filter(notNull); context.subscriptions.push( @@ -518,7 +530,13 @@ export async function activate(context: vscode.ExtensionContext): Promise vscode.workspace.registerTextDocumentContentProvider(OBJECTSCRIPT_FILE_SCHEMA, documentContentProvider), vscode.workspace.registerTextDocumentContentProvider(OBJECTSCRIPTXML_FILE_SCHEMA, xmlContentProvider), - vscode.workspace.registerFileSystemProvider(FILESYSTEM_SCHEMA, fileSystemProvider, { isCaseSensitive: true }), + vscode.workspace.registerFileSystemProvider(FILESYSTEM_SCHEMA, fileSystemProvider, { + isCaseSensitive: true, + }), + vscode.workspace.registerFileSystemProvider(FILESYSTEM_READONLY_SCHEMA, fileSystemProvider, { + isCaseSensitive: true, + isReadonly: true, + }), vscode.languages.setLanguageConfiguration("objectscript-class", getLanguageConfiguration("class")), vscode.languages.setLanguageConfiguration("objectscript", getLanguageConfiguration("routine")), vscode.languages.setLanguageConfiguration("objectscript-macros", getLanguageConfiguration("routine")), diff --git a/src/providers/DocumentContentProvider.ts b/src/providers/DocumentContentProvider.ts index abd90cdc..20f607a7 100644 --- a/src/providers/DocumentContentProvider.ts +++ b/src/providers/DocumentContentProvider.ts @@ -5,7 +5,7 @@ import * as vscode from "vscode"; import { AtelierAPI } from "../api"; import { getFileName } from "../commands/export"; -import { config, FILESYSTEM_SCHEMA, OBJECTSCRIPT_FILE_SCHEMA } from "../extension"; +import { config, FILESYSTEM_SCHEMA, FILESYSTEM_READONLY_SCHEMA, OBJECTSCRIPT_FILE_SCHEMA } from "../extension"; import { currentWorkspaceFolder, workspaceFolderUri } from "../utils"; export class DocumentContentProvider implements vscode.TextDocumentContentProvider { @@ -27,11 +27,12 @@ export class DocumentContentProvider implements vscode.TextDocumentContentProvid if (vfs === undefined) { vfs = config("serverSideEditing"); } + let scheme = vfs ? FILESYSTEM_SCHEMA : OBJECTSCRIPT_FILE_SCHEMA; workspaceFolder = workspaceFolder && workspaceFolder !== "" ? workspaceFolder : currentWorkspaceFolder(); const isCsp = name.includes("/"); const wFolderUri = workspaceFolderUri(workspaceFolder); let uri: vscode.Uri; - if (wFolderUri.scheme === FILESYSTEM_SCHEMA) { + if (wFolderUri.scheme === FILESYSTEM_SCHEMA || wFolderUri.scheme === FILESYSTEM_READONLY_SCHEMA) { const fileExt = name.split(".").pop(); const fileName = name .split(".") @@ -42,6 +43,7 @@ export class DocumentContentProvider implements vscode.TextDocumentContentProvid path: `/${name}`, }); vfs = true; + scheme = wFolderUri.scheme; } else { const found = this.getAsFile(name, workspaceFolder); if (found) { @@ -59,7 +61,7 @@ export class DocumentContentProvider implements vscode.TextDocumentContentProvid .join(fileExt.match(/cls/i) ? "/" : "."); name = fileName + "." + fileExt; uri = vscode.Uri.file(name).with({ - scheme: vfs ? FILESYSTEM_SCHEMA : OBJECTSCRIPT_FILE_SCHEMA, + scheme: scheme, }); if (workspaceFolder && workspaceFolder !== "") { uri = uri.with({