diff --git a/client/src/browserClient.ts b/client/src/browserClient.ts index e94f330..a93e916 100644 --- a/client/src/browserClient.ts +++ b/client/src/browserClient.ts @@ -29,9 +29,6 @@ export async function activate(context: vscode.ExtensionContext) { // directories to check for rain documents, default is "src" let watched: vscode.Uri[] = []; - // // auto compile mappings - // const compile = { onSave: [] }; - // channel for rainlang compiler let compilerChannel: vscode.OutputChannel; @@ -39,7 +36,7 @@ export async function activate(context: vscode.ExtensionContext) { const clientOptions: LanguageClientOptions = { documentSelector: [ { language: "rainlang" }, - { pattern: "*rainconfig.json", language: "json" }, + // { pattern: "*rainconfig.json", language: "json" }, ], synchronize: {}, // initializationOptions: JSON.stringify(initConfig) @@ -60,7 +57,7 @@ export async function activate(context: vscode.ExtensionContext) { vscode.commands.registerCommand("rainlang.stop", stop), vscode.commands.registerCommand("rainlang.restart", restart), // vscode.commands.registerCommand("rainlang.onsave", updateOnSaveCompile), - vscode.commands.registerCommand("rainlang.compile", compileCurrentHandler), + vscode.commands.registerCommand("rainlang.compose", composeHandler), // vscode.commands.registerCommand("rainlang.compile.all", compileAllHandler) ); @@ -91,81 +88,52 @@ export async function activate(context: vscode.ExtensionContext) { } // handler for rainlang compiler, send the request to server and logs the result in output channel - async function compileCurrentHandler() { + async function composeHandler() { if (client && extStatus.active) { const expKeys = Array.from((await vscode.window.showInputBox({ title: "Expression Names", placeHolder: "binding-1 binding-2 ...", prompt: "specify the expression names in order by a whitespace seperating them" })).matchAll(/[^\s]+/g)).map(v => v[0]); - const result = await vscode.commands.executeCommand( - "_compile", - vscode.window.activeTextEditor.document.languageId, - vscode.window.activeTextEditor.document.uri.toString(), - JSON.stringify(expKeys), - "uri" - // { - // start: vscode.window.activeTextEditor.selection.start, - // end: vscode.window.activeTextEditor.selection.end, - // } - ); if (!compilerChannel) compilerChannel = vscode.window.createOutputChannel( "Rain Language Compiler", - "json" + // "code-runner-output" ); - compilerChannel.show(true); - if (result) compilerChannel.appendLine(format( - JSON.stringify(result, null, 2), - { parser: "json", plugins: [ babelParser ] } - )); - else compilerChannel.appendLine("undefined"); + try { + const result = await vscode.commands.executeCommand( + "_compose", + vscode.window.activeTextEditor.document.languageId, + vscode.window.activeTextEditor.document.uri.toString(), + JSON.stringify(expKeys), + // { + // start: vscode.window.activeTextEditor.selection.start, + // end: vscode.window.activeTextEditor.selection.end, + // } + ); + compilerChannel.show(true); + if (result[1]) { + compilerChannel.appendLine([ + new Date(), + result[0], + ].join("\n\n")); + } else { + compilerChannel.appendLine([ + new Date(), + JSON.stringify(result[0], null, 2), + ].join("\n\n")); + } + } catch (e) { + console.log(e); + compilerChannel.show(true); + compilerChannel.appendLine([ + new Date(), + JSON.stringify(e, null, 2), + ].join("\n\n")); + } } else vscode.window.showErrorMessage("rain language server is not running!"); } - // // handler for rainlang compiler by sending the request to server for a mapping - // async function compileAllHandler() { - // if (client && extStatus.active) { - // const workspaceEdit = new vscode.WorkspaceEdit(); - // for (const map of compile.onSave) { - // try { - // const fileContent = uint8ArrayToString( - // await vscode.workspace.fs.readFile(map.input) - // ); - // const result = await vscode.commands.executeCommand( - // "_compile", - // "rainlang", - // fileContent, - // JSON.stringify(map.entrypoints), - // "file" - // ); - // const contents = Uint8Array.from( - // Array.from(result - // ? format( - // JSON.stringify(result, null, 2), - // { parser: "json", plugins: [ babelParser ] } - // ) - // : "\"failed to compile!\"" - // ).map(char => char.charCodeAt(0)) - // ); - // workspaceEdit.createFile( - // map.output, - // { overwrite: true, contents } - // ); - // } - // catch { /**/ } - // } - // vscode.workspace.applyEdit(workspaceEdit); - // } - // else vscode.window.showErrorMessage("rain language server is not running!"); - // } - - // function updateOnSaveCompile() { - // if (extStatus.onsave) extStatus.onsave = false; - // else extStatus.onsave = true; - // updateStatus(); - // } - async function restart() { if (!extStatus.active) { vscode.window.showWarningMessage("rain language server is not running!"); @@ -182,7 +150,6 @@ export async function activate(context: vscode.ExtensionContext) { } else { watched = []; - // compile.onSave = []; configUri = undefined; disposables.forEach(v => v?.dispose()); disposables = []; @@ -211,35 +178,7 @@ export async function activate(context: vscode.ExtensionContext) { } catch { watched = []; - // compile.onSave = []; } - // if (extStatus.onsave) { - // const saveMap = compile.onSave.find(v => v.input.toString() === e.uri.toString()); - // if (saveMap) { - // const workspaceEdit = new vscode.WorkspaceEdit(); - // const result = await vscode.commands.executeCommand( - // "_compile", - // e.languageId, - // e.uri.toString(), - // JSON.stringify(saveMap.entrypoints), - // "uri" - // ); - // const contents = Uint8Array.from( - // Array.from(result - // ? format( - // JSON.stringify(result, null, 2), - // { parser: "json", plugins: [ babelParser ] } - // ) - // : "\"failed to compile!\"" - // ).map(char => char.charCodeAt(0)) - // ); - // workspaceEdit.createFile( - // saveMap.output, - // { overwrite: true, contents } - // ); - // vscode.workspace.applyEdit(workspaceEdit); - // } - // } })); disposables.push(vscode.workspace.onDidCreateFiles(async created => { @@ -260,7 +199,6 @@ export async function activate(context: vscode.ExtensionContext) { } catch { watched = []; - // compile.onSave = []; client.sendNotification("unwatch-all"); break; } @@ -276,7 +214,6 @@ export async function activate(context: vscode.ExtensionContext) { try { if (deleted.files[i].toString() === configUri.toString()) { watched = []; - // compile.onSave = []; configUri = undefined; client.sendNotification("unwatch-all"); break; @@ -307,7 +244,6 @@ export async function activate(context: vscode.ExtensionContext) { } catch { watched = []; - // compile.onSave = []; client.sendNotification("unwatch-all"); break; } @@ -322,7 +258,6 @@ export async function activate(context: vscode.ExtensionContext) { break; } watched = []; - // compile.onSave = []; configUri = undefined; client.sendNotification("unwatch-all"); break; @@ -364,7 +299,6 @@ export async function activate(context: vscode.ExtensionContext) { } catch { watched = []; - // compile.onSave = []; } } })); @@ -405,48 +339,6 @@ export async function activate(context: vscode.ExtensionContext) { const newWatched: vscode.Uri[] = []; await client.sendNotification("unwatch-all"); updateMetaStore(content, workspaceRootUri); - // if ( - // content?.src?.length > 0 && - // Array.isArray(content.src) && - // content.src.every((v: any) => - // typeof v === "object" && - // v.input !== undefined && - // v.output !== undefined && - // v.entrypoints !== undefined && - // typeof v.input === "string" && - // typeof v.output === "string" && - // v.input.endsWith(".rain") && - // Array.isArray(v.entrypoints) && - // v.entrypoints.length > 0 && - // v.entrypoints.every((e: any) => typeof e === "string") - // ) - // ) { - // compile.onSave = content.src.map((v: any) => ({ - // input: vscode.Uri.joinPath( - // workspaceRootUri, - // v.input - // ), - // output: vscode.Uri.joinPath( - // workspaceRootUri, - // v.output.endsWith(".json") ? v.output : v.output + ".json" - // ), - // entrypoints: v.entrypoints - // })); - // for (const {input} of compile.onSave) { - // promiseGroup1.push(vscode.workspace.fs.stat(input).then(stat => { - // if (stat.type === vscode.FileType.File) { - // promiseGroup2.push(vscode.workspace.fs.readFile(input).then( - // v => client.sendNotification( - // "watch-dotrain", - // [input.toString(), uint8ArrayToString(v)] - // ), - // () => { /**/ } - // )); - // } - // })); - // newWatched.push(input); - // } - // } // find .rains on startup and send them to server for storing in meta store if ( @@ -566,149 +458,5 @@ async function updateMetaStore(content: any, workspaceRootUri: vscode.Uri): Prom content.subgraphs.every((v: any) => typeof v === "string") ) subgraphs.push(...content.subgraphs); } - // if (Array.isArray(content?.meta) && content.length > 0) { - // for (let i = 0; i < content.meta.length; i++) { - // const meta = content.meta[i]; - // const keys = Object.keys(meta); - // if ( - // keys.length >= 1 && - // ( - // ( - // keys.includes("binary") && - // !keys.includes("hex") && - // typeof meta.binary === "string" - // ) || ( - // keys.includes("hex") && - // !keys.includes("binary") && - // typeof meta.hex === "string" - // ) - // ) - // ) { - // if (keys.includes("binary")) { - // const uri = vscode.Uri.joinPath(workspaceRootUri, meta.binary); - // try { - // metas.push(hexlify(await vscode.workspace.fs.readFile(uri))); - // } - // catch { /**/ } - // } - // if (keys.includes("hex")) { - // const uri = vscode.Uri.joinPath(workspaceRootUri, meta.hex); - // try { - // metas.push(uint8ArrayToString(await vscode.workspace.fs.readFile(uri))); - // } - // catch { /**/ } - // } - // } - // } - // } - // if (typeof content.deployers === "object" && content.deployers !== null) { - // const items = Object.entries(content.deployers); - // for (let i = 0; i < items.length; i ++) { - // const [hash, details] = items[i]; - // if ( - // /^0x[a-fA-F0-9]+$/.test(hash) && - // typeof details === "object" && - // details !== null && - // Object.keys(details).length >= 5 && - // "expressionDeployer" in details && - // typeof details.expressionDeployer === "string" && - // "parser" in details && - // typeof details.parser === "string" && - // "store" in details && - // typeof details.store === "string" && - // "interpreter" in details && - // typeof details.interpreter === "string" && - // "constructionMeta" in details && - // typeof details.constructionMeta === "object" && - // details.constructionMeta !== null && - // ( - // ( - // "binary" in details.constructionMeta && - // !("hex" in details.constructionMeta) && - // typeof details.constructionMeta.binary === "string" - // ) || ( - // "hex" in details.constructionMeta && - // !("binary" in details.constructionMeta) && - // typeof details.constructionMeta.hex === "string" - // ) - // ) - // ) { - // try { - // const parserPath = vscode.Uri.joinPath(workspaceRootUri, details.parser); - // const parserArtifact = JSON.parse( - // uint8ArrayToString(await vscode.workspace.fs.readFile(parserPath)) - // ); - // const parser = typeof parserArtifact.deployedBytecode.object === "string" && parserArtifact.deployedBytecode.object - // ? parserArtifact.deployedBytecode.object - // : undefined; - - // const storePath = vscode.Uri.joinPath(workspaceRootUri, details.store); - // const storeArtifact = JSON.parse( - // uint8ArrayToString(await vscode.workspace.fs.readFile(storePath)) - // ); - // const store = typeof storeArtifact.deployedBytecode.object === "string" && storeArtifact.deployedBytecode.object - // ? storeArtifact.deployedBytecode.object - // : undefined; - - // const interpreterPath = vscode.Uri.joinPath( - // workspaceRootUri, - // details.interpreter - // ); - // const interpreterArtifact = JSON.parse( - // uint8ArrayToString(await vscode.workspace.fs.readFile(interpreterPath)) - // ); - // const interpreter = typeof interpreterArtifact.deployedBytecode.object === "string" && interpreterArtifact.deployedBytecode.object - // ? interpreterArtifact.deployedBytecode.object - // : undefined; - - // const deployerPath = vscode.Uri.joinPath( - // workspaceRootUri, - // details.expressionDeployer - // ); - // const deployerArtifact = JSON.parse( - // uint8ArrayToString(await vscode.workspace.fs.readFile(deployerPath)) - // ); - // const deployerDeployedBytecode = typeof deployerArtifact.deployedBytecode.object === "string" && deployerArtifact.deployedBytecode.object - // ? deployerArtifact.deployedBytecode.object - // : undefined; - // const deployerBytecode = typeof deployerArtifact.bytecode.object === "string" && deployerArtifact.bytecode.object - // ? deployerArtifact.bytecode.object - // : undefined; - - // if (!parser || !store || !interpreter || !deployerBytecode || !deployerDeployedBytecode) throw ""; - - // let metaBytes = null; - // if ("hex" in details.constructionMeta && typeof details.constructionMeta.hex === "string") { - // const uri = vscode.Uri.joinPath( - // workspaceRootUri, - // details.constructionMeta.hex - // ); - // metaBytes = uint8ArrayToString(await vscode.workspace.fs.readFile(uri)); - // } - // if ("binary" in details.constructionMeta && typeof details.constructionMeta.binary === "string") { - // const uri = vscode.Uri.joinPath( - // workspaceRootUri, - // details.constructionMeta.binary - // ); - // metaBytes = hexlify(await vscode.workspace.fs.readFile(uri)); - // } - - // if (!metaBytes) throw ""; - - // deployers.push([ - // hash, - // metaBytes, - // deployerBytecode, - // deployerDeployedBytecode, - // parser, - // store, - // interpreter - // ]); - // } - // catch { /**/ } - // } - // } - // } - client.sendNotification("update-meta-store", [subgraphs]); } diff --git a/client/src/nodeClient.ts b/client/src/nodeClient.ts index 4f6f7c8..d78fbe5 100644 --- a/client/src/nodeClient.ts +++ b/client/src/nodeClient.ts @@ -5,8 +5,7 @@ import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind } f let client: LanguageClient; -const defaultConfigPath1 = "./rainconfig.json"; -const defaultConfigPath2 = "./.rainconfig.json"; +const defaultConfigPath = "./rainconfig.json"; export async function activate(context: vscode.ExtensionContext) { @@ -28,9 +27,6 @@ export async function activate(context: vscode.ExtensionContext) { // directories to check for rain documents, default is "src" let watched: vscode.Uri[] = []; - // // auto compile mappings - // const compile = { onSave: [] }; - // channel for rainlang compiler let compilerChannel: vscode.OutputChannel; @@ -53,7 +49,7 @@ export async function activate(context: vscode.ExtensionContext) { const clientOptions: LanguageClientOptions = { documentSelector: [ { language: "rainlang" }, - { pattern: "*rainconfig.json", language: "json" } + // { pattern: "*rainconfig.json", language: "json" } ], synchronize: { // Notify the server about file changes to ".clientrc files contained in the workspace @@ -64,42 +60,6 @@ export async function activate(context: vscode.ExtensionContext) { // initializationOptions: initConfig }; - // get the initial settings and pass them as initialzeOptions to server - // const initSettings = vscode.workspace.getConfiguration("rainlang"); - - // setting the config file at startup - // const configPath = initSettings.config - // ? initSettings.config as string - // : defaultConfigPath; - - // const configPath = defaultConfigPath; - - // // setup the config file on config change - // vscode.workspace.onDidChangeConfiguration(async e => { - // if (e.affectsConfiguration("rainlang.config")) { - // try { - // if (workspaceRootUri) { - // const newPath = vscode.workspace.getConfiguration("rainlang").config; - // const newConfigPath = newPath && typeof newPath === "string" - // ? newPath - // : defaultConfigPath; - // configUri = vscode.Uri.joinPath(workspaceRootUri, newConfigPath); - // const content = JSON.parse( - // (await vscode.workspace.fs.readFile(configUri)).toString() - // ); - // processConfig(content); - // } - // } - // catch { - // watched = []; - // compile.onSave = []; - // vscode.window.showErrorMessage( - // "Cannot find or read the config file" - // ); - // } - // } - // }); - // setup the statusbar const statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left); statusBar.text = "rainlang-ext"; @@ -112,7 +72,7 @@ export async function activate(context: vscode.ExtensionContext) { vscode.commands.registerCommand("rainlang.stop", stop), vscode.commands.registerCommand("rainlang.restart", restart), // vscode.commands.registerCommand("rainlang.onsave", updateOnSaveCompile), - vscode.commands.registerCommand("rainlang.compile", compileCurrentHandler), + vscode.commands.registerCommand("rainlang.compose", composeHandler), // vscode.commands.registerCommand("rainlang.compile.all", compileAllHandler) ); @@ -142,76 +102,53 @@ export async function activate(context: vscode.ExtensionContext) { statusBar.show(); } - // handler for rainlang compiler, send the request to server and logs the result in output channel - async function compileCurrentHandler() { + // handler for rainlang composer, send the request to server and logs the result in output channel + async function composeHandler() { if (client && extStatus.active) { const expKeys = Array.from((await vscode.window.showInputBox({ title: "Expression Names", placeHolder: "binding-1 binding-2 ...", prompt: "specify the expression names in order by a whitespace seperating them" })).matchAll(/[^\s]+/g)).map(v => v[0]); - const result = await vscode.commands.executeCommand( - "_compile", - vscode.window.activeTextEditor.document.languageId, - vscode.window.activeTextEditor.document.uri.toString(), - expKeys, - "uri" - // { - // start: vscode.window.activeTextEditor.selection.start, - // end: vscode.window.activeTextEditor.selection.end, - // } - ); if (!compilerChannel) compilerChannel = vscode.window.createOutputChannel( "Rain Language Compiler", - "json" + // "code-runner-output" ); - compilerChannel.show(true); - if (result) compilerChannel.appendLine(format( - JSON.stringify(result, null, 2), - { parser: "json" } - )); - else compilerChannel.appendLine("undefined"); + try { + const result = await vscode.commands.executeCommand( + "_compose", + vscode.window.activeTextEditor.document.languageId, + vscode.window.activeTextEditor.document.uri.toString(), + expKeys, + // { + // start: vscode.window.activeTextEditor.selection.start, + // end: vscode.window.activeTextEditor.selection.end, + // } + ); + compilerChannel.show(true); + if (result[1]) { + compilerChannel.appendLine([ + new Date(), + result[0], + ].join("\n\n")); + } else { + compilerChannel.appendLine([ + new Date(), + JSON.stringify(result[0], null, 2), + ].join("\n\n")); + } + } catch(e) { + console.log(e); + compilerChannel.show(true); + compilerChannel.appendLine([ + new Date(), + JSON.stringify(e, null, 2), + ].join("\n\n")); + } } else vscode.window.showErrorMessage("rain language server is not running!"); } - // // handler for rainlang compiler by sending the request to server for a mapping - // async function compileAllHandler() { - // if (client && extStatus.active) { - // const workspaceEdit = new vscode.WorkspaceEdit(); - // for (const map of compile.onSave) { - // try { - // const fileContent = (await vscode.workspace.fs.readFile(map.input)).toString(); - // const result = await vscode.commands.executeCommand( - // "_compile", - // "rainlang", - // fileContent, - // map.entrypoints, - // "file" - // ); - // const contents: Uint8Array = Buffer.from( - // result - // ? format(JSON.stringify(result, null, 2), { parser: "json" }) - // : "\"failed to compile!\"" - // ); - // workspaceEdit.createFile( - // map.output, - // { overwrite: true, contents } - // ); - // } - // catch { /**/ } - // } - // vscode.workspace.applyEdit(workspaceEdit); - // } - // else vscode.window.showErrorMessage("rain language server is not running!"); - // } - - // function updateOnSaveCompile() { - // if (extStatus.onsave) extStatus.onsave = false; - // else extStatus.onsave = true; - // updateStatus(); - // } - async function restart() { if (!extStatus.active) { vscode.window.showWarningMessage("rain language server is not running!"); @@ -225,7 +162,6 @@ export async function activate(context: vscode.ExtensionContext) { } else { watched = []; - // compile.onSave = []; configUri = undefined; disposables.forEach(v => v?.dispose()); disposables = []; @@ -254,31 +190,7 @@ export async function activate(context: vscode.ExtensionContext) { } catch { watched = []; - // compile.onSave = []; } - // if (extStatus.onsave) { - // const saveMap = compile.onSave.find(v => v.input.toString() === e.uri.toString()); - // if (saveMap) { - // const workspaceEdit = new vscode.WorkspaceEdit(); - // const result = await vscode.commands.executeCommand( - // "_compile", - // e.languageId, - // e.uri.toString(), - // saveMap.entrypoints, - // "uri" - // ); - // const contents: Uint8Array = Buffer.from( - // result - // ? format(JSON.stringify(result, null, 2), { parser: "json" }) - // : "\"failed to compile!\"" - // ); - // workspaceEdit.createFile( - // saveMap.output, - // { overwrite: true, contents } - // ); - // vscode.workspace.applyEdit(workspaceEdit); - // } - // } })); disposables.push(vscode.workspace.onDidCreateFiles(async created => { @@ -297,7 +209,6 @@ export async function activate(context: vscode.ExtensionContext) { } catch { watched = []; - // compile.onSave = []; client.sendNotification("unwatch-all"); break; } @@ -313,7 +224,6 @@ export async function activate(context: vscode.ExtensionContext) { try { if (deleted.files[i].toString() === configUri.toString()) { watched = []; - // compile.onSave = []; configUri = undefined; client.sendNotification("unwatch-all"); break; @@ -342,7 +252,6 @@ export async function activate(context: vscode.ExtensionContext) { } catch { watched = []; - // compile.onSave = []; client.sendNotification("unwatch-all"); break; } @@ -352,12 +261,11 @@ export async function activate(context: vscode.ExtensionContext) { for (let i = 0; i < renamed.files.length; i++) { try { if (renamed.files[i].oldUri.toString() === configUri.toString()) { - if(renamed.files[i].newUri.toString() ===defaultConfigUri?.toString()){ + if(renamed.files[i].newUri.toString() === defaultConfigUri?.toString()){ configUri = defaultConfigUri; break; } watched = []; - // compile.onSave = []; configUri = undefined; client.sendNotification("unwatch-all"); break; @@ -402,7 +310,7 @@ export async function activate(context: vscode.ExtensionContext) { // wait for server to fully start // await sleep(6000); try { - defaultConfigUri = vscode.Uri.joinPath(workspaceRootUri, defaultConfigPath1); + defaultConfigUri = vscode.Uri.joinPath(workspaceRootUri, defaultConfigPath); configUri = defaultConfigUri; const content = JSON.parse( (await vscode.workspace.fs.readFile(configUri)).toString() @@ -411,7 +319,6 @@ export async function activate(context: vscode.ExtensionContext) { } catch { watched = []; - // compile.onSave = []; } } })); @@ -472,49 +379,6 @@ export async function activate(context: vscode.ExtensionContext) { const promiseGroup3: any[] = []; await client.sendNotification("unwatch-all"); updateMetaStore(content, workspaceRootUri); - // if ( - // content?.src?.length > 0 && - // Array.isArray(content.src) && - // content.src.every((v: any) => - // typeof v === "object" && - // v.input !== undefined && - // v.output !== undefined && - // v.entrypoints !== undefined && - // typeof v.input === "string" && - // typeof v.output === "string" && - // v.input.endsWith(".rain") && - // Array.isArray(v.entrypoints) && - // v.entrypoints.length > 0 && - // v.entrypoints.every((e: any) => typeof e === "string") - // ) - // ) { - // compile.onSave = content.src.map((v: any) => ({ - // input: path.isAbsolute(v.input) - // ? vscode.Uri.parse(v.input) - // : vscode.Uri.joinPath(workspaceRootUri, v.input), - // output: path.isAbsolute(v.input) - // ? vscode.Uri.parse(v.output) - // : vscode.Uri.joinPath( - // workspaceRootUri, - // v.output.endsWith(".json") ? v.output : v.output + ".json" - // ), - // entrypoints: v.entrypoints - // })); - // for (const {input} of compile.onSave) { - // promiseGroup1.push(vscode.workspace.fs.stat(input).then(stat => { - // if (stat.type === vscode.FileType.File) { - // promiseGroup3.push(vscode.workspace.fs.readFile(input).then( - // v => client.sendNotification( - // "watch-dotrain", - // [input.toString(), v.toString()] - // ), - // () => { /**/ } - // )); - // } - // })); - // newWatched.push(input); - // } - // } // find .rains on startup and send them to server for storing in meta store if ( @@ -612,159 +476,5 @@ async function updateMetaStore(content: any, workspaceRootUri: vscode.Uri): Prom content.subgraphs.every((v: any) => typeof v === "string") ) subgraphs.push(...content.subgraphs); } - // if (Array.isArray(content?.meta) && content.length > 0) { - // for (let i = 0; i < content.meta.length; i++) { - // const meta = content.meta[i]; - // const keys = Object.keys(meta); - // if ( - // keys.length >= 1 && - // ( - // ( - // keys.includes("binary") && - // !keys.includes("hex") && - // typeof meta.binary === "string" - // ) || ( - // keys.includes("hex") && - // !keys.includes("binary") && - // typeof meta.hex === "string" - // ) - // ) - // ) { - // if (keys.includes("binary")) { - // const uri = path.isAbsolute(meta.binary) - // ? vscode.Uri.parse(meta.binary) - // : vscode.Uri.joinPath(workspaceRootUri, meta.binary); - // try { - // metas.push(hexlify(await vscode.workspace.fs.readFile(uri))); - // } - // catch { /**/ } - // } - // if (keys.includes("hex")) { - // const uri = path.isAbsolute(meta.hex) - // ? vscode.Uri.parse(meta.hex) - // : vscode.Uri.joinPath(workspaceRootUri, meta.hex); - // try { - // metas.push((await vscode.workspace.fs.readFile(uri)).toString()); - // } - // catch { /**/ } - // } - // } - // } - // } - // if (typeof content.deployers === "object" && content.deployers !== null) { - // const items = Object.entries(content.deployers); - // for (let i = 0; i < items.length; i ++) { - // const [hash, details] = items[i]; - // if ( - // /^0x[a-fA-F0-9]+$/.test(hash) && - // typeof details === "object" && - // details !== null && - // Object.keys(details).length >= 5 && - // "expressionDeployer" in details && - // typeof details.expressionDeployer === "string" && - // "parser" in details && - // typeof details.parser === "string" && - // "store" in details && - // typeof details.store === "string" && - // "interpreter" in details && - // typeof details.interpreter === "string" && - // "constructionMeta" in details && - // typeof details.constructionMeta === "object" && - // details.constructionMeta !== null && - // ( - // ( - // "binary" in details.constructionMeta && - // !("hex" in details.constructionMeta) && - // typeof details.constructionMeta.binary === "string" - // ) || ( - // "hex" in details.constructionMeta && - // !("binary" in details.constructionMeta) && - // typeof details.constructionMeta.hex === "string" - // ) - // ) - // ) { - // try { - // const parserPath = path.isAbsolute(details.parser) - // ? vscode.Uri.parse(details.parser) - // : vscode.Uri.joinPath(workspaceRootUri, details.parser); - // const parserArtifact = JSON.parse( - // (await vscode.workspace.fs.readFile(parserPath)).toString() - // ); - // const parser = typeof parserArtifact.deployedBytecode.object === "string" && parserArtifact.deployedBytecode.object - // ? parserArtifact.deployedBytecode.object - // : undefined; - - // const storePath = path.isAbsolute(details.store) - // ? vscode.Uri.parse(details.store) - // : vscode.Uri.joinPath(workspaceRootUri, details.store); - // const storeArtifact = JSON.parse( - // (await vscode.workspace.fs.readFile(storePath)).toString() - // ); - // const store = typeof storeArtifact.deployedBytecode.object === "string" && storeArtifact.deployedBytecode.object - // ? storeArtifact.deployedBytecode.object - // : undefined; - - // const interpreterPath = path.isAbsolute(details.interpreter) - // ? vscode.Uri.parse(details.interpreter) - // : vscode.Uri.joinPath(workspaceRootUri, details.interpreter); - // const interpreterArtifact = JSON.parse( - // (await vscode.workspace.fs.readFile(interpreterPath)).toString() - // ); - // const interpreter = typeof interpreterArtifact.deployedBytecode.object === "string" && interpreterArtifact.deployedBytecode.object - // ? interpreterArtifact.deployedBytecode.object - // : undefined; - - // const deployerPath = path.isAbsolute(details.expressionDeployer) - // ? vscode.Uri.parse(details.expressionDeployer) - // : vscode.Uri.joinPath(workspaceRootUri, details.expressionDeployer); - // const deployerArtifact = JSON.parse( - // (await vscode.workspace.fs.readFile(deployerPath)).toString() - // ); - // const deployerDeployedBytecode = typeof deployerArtifact.deployedBytecode.object === "string" && deployerArtifact.deployedBytecode.object - // ? deployerArtifact.deployedBytecode.object - // : undefined; - // const deployerBytecode = typeof deployerArtifact.bytecode.object === "string" && deployerArtifact.bytecode.object - // ? deployerArtifact.bytecode.object - // : undefined; - - // if (!parser || !store || !interpreter || !deployerBytecode || !deployerDeployedBytecode) throw ""; - - // let metaBytes = null; - // if ("hex" in details.constructionMeta && typeof details.constructionMeta.hex === "string") { - // const uri = path.isAbsolute(details.constructionMeta.hex) - // ? vscode.Uri.parse(details.constructionMeta.hex) - // : vscode.Uri.joinPath( - // workspaceRootUri, - // details.constructionMeta.hex - // ); - // metaBytes = (await vscode.workspace.fs.readFile(uri)).toString(); - // } - // if ("binary" in details.constructionMeta && typeof details.constructionMeta.binary === "string") { - // const uri = path.isAbsolute(details.constructionMeta.binary) - // ? vscode.Uri.parse(details.constructionMeta.binary) - // : vscode.Uri.joinPath( - // workspaceRootUri, - // details.constructionMeta.binary - // ); - // metaBytes = hexlify(await vscode.workspace.fs.readFile(uri)); - // } - - // if (!metaBytes) throw ""; - - // deployers.push([ - // hash, - // metaBytes, - // deployerBytecode, - // deployerDeployedBytecode, - // parser, - // store, - // interpreter - // ]); - // } - // catch { /**/ } - // } - // } - // } - client.sendNotification("update-meta-store", [subgraphs]); } diff --git a/package.json b/package.json index 8992e8f..a6b4fde 100644 --- a/package.json +++ b/package.json @@ -52,15 +52,15 @@ "title": "Restart Rain Language Server" }, { - "command": "rainlang.compile", - "title": "Rainlang Compile Current" + "command": "rainlang.compose", + "title": "Rainlang Compose" } ], "menus": { "editor/context": [ { "when": "resourceLangId == rainlang", - "command": "rainlang.compile" + "command": "rainlang.compose" } ] }, @@ -93,25 +93,7 @@ ], "configurationDefaults": { "[rainlang]": { - "editor.semanticHighlighting.enabled": true, - "editor.language.colorizedBracketPairs": [ - [ - "<", - ">" - ], - [ - "(", - ")" - ], - [ - "{", - "}" - ], - [ - "[", - "]" - ] - ] + "editor.semanticHighlighting.enabled": true } }, "configuration": { diff --git a/rain-language-configuration.json b/rain-language-configuration.json index bf3f948..24f226c 100644 --- a/rain-language-configuration.json +++ b/rain-language-configuration.json @@ -12,6 +12,12 @@ ["(", ")"], ["[", "]"], ], + "colorizedBracketPairs": [ + ["<", ">"], + ["{", "}"], + ["(", ")"], + ["[", "]"], + ], "autoClosingPairs": [ { "open": "<", "close": ">" }, { "open": "(", "close": ")" }, diff --git a/server/package-lock.json b/server/package-lock.json index 4ba6e1e..8ade242 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -27,7 +27,7 @@ "node_modules/@rainlanguage/dotrain": { "version": "6.0.0", "resolved": "file:../../dotrain/rainlanguage-dotrain-6.0.0.tgz", - "integrity": "sha512-miZ1z7kRYmz8/2/CbyyOhHVgMGIJsTBw3Au6n7Ox9VScD9eYVhlmgFoTTOCwEcH8BXn6goc3RkzQNuhux8DR8g==", + "integrity": "sha512-5oZcr7/qETW2e9C46ZeTRoHzVI9mZpCm+mtt+ytNvgmQps4hzZKCejE4X06H4fNO0ex2CIxb2XN6bGKE1LDmfw==", "license": "CAL-1.0", "dependencies": { "buffer": "^6.0.3", @@ -200,7 +200,7 @@ "dependencies": { "@rainlanguage/dotrain": { "version": "file:../../dotrain/rainlanguage-dotrain-6.0.0.tgz", - "integrity": "sha512-miZ1z7kRYmz8/2/CbyyOhHVgMGIJsTBw3Au6n7Ox9VScD9eYVhlmgFoTTOCwEcH8BXn6goc3RkzQNuhux8DR8g==", + "integrity": "sha512-5oZcr7/qETW2e9C46ZeTRoHzVI9mZpCm+mtt+ytNvgmQps4hzZKCejE4X06H4fNO0ex2CIxb2XN6bGKE1LDmfw==", "requires": { "buffer": "^6.0.3", "vscode-languageserver-protocol": "^3.17.5", diff --git a/server/src/browserServer.ts b/server/src/browserServer.ts index 95e6588..acac959 100644 --- a/server/src/browserServer.ts +++ b/server/src/browserServer.ts @@ -2,14 +2,10 @@ import { TextDocument } from "vscode-languageserver-textdocument"; import { Range, hexlify, - arrayify, MetaStore, - keccak256, RainDocument, TextDocumentItem, RainLanguageServices, - // DeployerQueryResponse, - // getDeployedBytecodeMetaHash } from "@rainlanguage/dotrain"; import { TextEdit, @@ -70,7 +66,7 @@ connection.onInitialize(async(params: InitializeParams) => { }, hoverProvider: true, executeCommandProvider: { - commands: ["_compile"] + commands: ["_compose"] }, semanticTokensProvider: { legend: { @@ -102,17 +98,6 @@ connection.onInitialized(() => { connection.sendNotification("request-config", workspaceRootUri); }); -// // update meta store when config has changed and revalidate documents -// connection.onNotification("update-meta-store", async e => { -// try { -// for (const d of e[1]) metaStore.update(keccak256(d), d); -// for (let i = 0; i < e[2].length; i++) metaStore.update(e[2][i][0], e[2][i][1]); -// metaStore.addSubgraphs(e[0]); -// // documents.all().forEach(v => validate(v, v.getText(), v.version)); -// } -// catch { /**/ } -// }); - // update meta store when config has changed and revalidate documents connection.onNotification("update-meta-store", async e => { try { @@ -141,26 +126,22 @@ connection.onNotification("reval-all", () => { // executes rain compile command connection.onExecuteCommand(async e => { - if (e.command === "_compile") { + if (e.command === "_compose") { const langId = e.arguments![0]; - const uriOrFile = e.arguments![1]; + const uri = e.arguments![1]; const expKeys = JSON.parse(e.arguments![2]); - const isUri = e.arguments![3] === "uri"; if (langId === "rainlang") { - let _td; - if (isUri) _td = documents.get(uriOrFile)?.getText(); - else _td = uriOrFile; + const _td = documents.get(uri)?.getText(); if (_td) { try { - return await RainDocument.composeTextAsync(_td, expKeys, metaStore); - } - catch (err) { - return err; + return [await RainDocument.composeTextAsync(_td, expKeys, metaStore), true]; + } catch(e) { + return [e, false]; } } - else return null; + else return [undefined, false]; } - else return null; + else return [undefined, false]; } }); diff --git a/server/src/nodeServer.ts b/server/src/nodeServer.ts index 472bbe9..fd78170 100644 --- a/server/src/nodeServer.ts +++ b/server/src/nodeServer.ts @@ -2,14 +2,10 @@ import { TextDocument } from "vscode-languageserver-textdocument"; import { Range, hexlify, - arrayify, MetaStore, - keccak256, RainDocument, TextDocumentItem, RainLanguageServices, - // DeployerQueryResponse, - // getDeployedBytecodeMetaHash } from "@rainlanguage/dotrain"; import { TextEdit, @@ -66,7 +62,7 @@ connection.onInitialize(async(params) => { }, hoverProvider: true, executeCommandProvider: { - commands: ["_compile"] + commands: ["_compose"] }, semanticTokensProvider: { legend: { @@ -127,26 +123,22 @@ connection.onNotification("reval-all", () => { // executes rain compile command connection.onExecuteCommand(async e => { - if (e.command === "_compile") { + if (e.command === "_compose") { const langId = e.arguments![0]; - const uriOrFile = e.arguments![1]; + const uri = e.arguments![1]; const expKeys = e.arguments![2]; - const isUri = e.arguments![3] === "uri"; if (langId === "rainlang") { - let _td; - if (isUri) _td = documents.get(uriOrFile)?.getText(); - else _td = uriOrFile; + const _td = documents.get(uri)?.getText(); if (_td) { try { - return await RainDocument.composeTextAsync(_td, expKeys, metaStore); - } - catch (err) { - return err; + return [await RainDocument.composeTextAsync(_td, expKeys, metaStore), true]; + } catch(e) { + return [e, false]; } } - else return null; + else return [undefined, false]; } - else return null; + else return [undefined, false]; } }); @@ -212,34 +204,6 @@ documents.onDidSave(e => { } }); -// connection.workspace.onDidDeleteFiles(deleted => { -// let shouldValidate = false; -// deleted.files.forEach(v => { -// if (v.uri.endsWith(".rain")) { -// // const hash = metaStore.dotrainCache[v.uri]; -// metaStore.deleteDotrain(v.uri); -// const existed = hashMap.delete(v.uri); -// if (existed && !shouldValidate) shouldValidate = true; -// // if (hash !== undefined) hashMap.forEach((imports, uri) => { -// // if (imports.find(e => e.hash.toLowerCase() === hash.toLowerCase())) { -// // const doc = documents.get(uri); -// // if (doc) validate(doc, doc.getText(), doc.version); -// // } -// // }); -// } -// else { -// hashMap.forEach((_, uri) => { -// if (uri.startsWith(v.uri)) { -// if (!shouldValidate) shouldValidate = true; -// metaStore.deleteDotrain(uri); -// hashMap.delete(uri); -// } -// }); -// } -// }); -// if (shouldValidate) documents.all().forEach(v => validate(v, v.getText(), v.version)); -// }); - connection.onDidChangeWatchedFiles(_change => { // Monitored files have change in VSCode connection.console.log("We received an file change event"); diff --git a/test/completion.test.ts b/test/completion.test.ts index 8af9750..b831b97 100644 --- a/test/completion.test.ts +++ b/test/completion.test.ts @@ -35,7 +35,7 @@ suite("Rainlang Code Completion", () => { ); test("Should provide filtered completion items based on provided position", async () => { - await testCompletion(docUri, new vscode.Position(2, 6), { + await testCompletion(docUri, new vscode.Position(3, 6), { items: [ { label: "literal", kind: vscode.CompletionItemKind.Constant }, ] diff --git a/test/test-workspace/completion.rain b/test/test-workspace/completion.rain index 2f7e66f..acf8b7c 100644 --- a/test/test-workspace/completion.rain +++ b/test/test-workspace/completion.rain @@ -1,3 +1,4 @@ +--- #literal 2 #expression _: lit \ No newline at end of file diff --git a/test/test-workspace/diagnostics.rain b/test/test-workspace/diagnostics.rain index 50d2e3d..1393795 100644 --- a/test/test-workspace/diagnostics.rain +++ b/test/test-workspace/diagnostics.rain @@ -1,3 +1,3 @@ - +--- #expression _: int-add(1) 10 \ No newline at end of file diff --git a/test/workspace/constants/constants.rain b/test/workspace/constants/constants.rain index 171abba..6dbc207 100644 --- a/test/workspace/constants/constants.rain +++ b/test/workspace/constants/constants.rain @@ -1,6 +1,7 @@ -#value 0x123 +--- +#value 0x1234 -#other-value 0b101 +#other-value 123 #my-address 0x1234567890123456789012345678901234567890 diff --git a/test/workspace/test.rain b/test/workspace/test.rain index 0b510df..34f986a 100644 --- a/test/workspace/test.rain +++ b/test/workspace/test.rain @@ -1,17 +1,23 @@ +some-key: kjh +some-other-key: + inner: + - test test +--- /* This is test */ /* import ./constants/constants.rain to root */ -@ another-dotrain 0xc509e3a2bd58cb0062fb80c6d9f2e40cb815694f5733c3041c2c620a46f6ad94 - elided 12 /* rebind the elided binding in the import */ - 'elided twelve /* and then rename to avoid shadowing the elided binding below */ - 'value const /* rename the value so it wont shadow the constant binding below */ +@ kjh 0xaf77eb4dfbd7d49ae5fa46c3cc6b9150985bd04f4d0a974d10a9396a0e2b41ac + /* elided 12 /* rebind the elided binding in the import */ + /* 'elided twelve /* and then rename to avoid shadowing the elided binding below + 'value const rename the value so it wont shadow the constant binding below */ #value 1e13 #elided ! this is elided, rebind before using - +#kj + _ _: add(1 2 0x1234546757567567 kjh.other-value kjh.my-address) div(12 12); + #main - _: another-dotrain.my-address, - var: .another-dotrain.twelve, - _: int-add(var int-max(.value)); \ No newline at end of file + using-words-from 0x123 + _: int-add<'kj value kjh.my-address>(1 int-max(.value)) \ No newline at end of file