Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
rouzwelt committed Feb 14, 2024
1 parent 2d293e5 commit 022dffe
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 725 deletions.
322 changes: 35 additions & 287 deletions client/src/browserClient.ts

Large diffs are not rendered by default.

368 changes: 39 additions & 329 deletions client/src/nodeClient.ts

Large diffs are not rendered by default.

26 changes: 4 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
},
Expand Down Expand Up @@ -93,25 +93,7 @@
],
"configurationDefaults": {
"[rainlang]": {
"editor.semanticHighlighting.enabled": true,
"editor.language.colorizedBracketPairs": [
[
"<",
">"
],
[
"(",
")"
],
[
"{",
"}"
],
[
"[",
"]"
]
]
"editor.semanticHighlighting.enabled": true
}
},
"configuration": {
Expand Down
6 changes: 6 additions & 0 deletions rain-language-configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
["(", ")"],
["[", "]"],
],
"colorizedBracketPairs": [
["<", ">"],
["{", "}"],
["(", ")"],
["[", "]"],
],
"autoClosingPairs": [
{ "open": "<", "close": ">" },
{ "open": "(", "close": ")" },
Expand Down
4 changes: 2 additions & 2 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 9 additions & 28 deletions server/src/browserServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -70,7 +66,7 @@ connection.onInitialize(async(params: InitializeParams) => {
},
hoverProvider: true,
executeCommandProvider: {
commands: ["_compile"]
commands: ["_compose"]
},
semanticTokensProvider: {
legend: {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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];
}
});

Expand Down
54 changes: 9 additions & 45 deletions server/src/nodeServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -66,7 +62,7 @@ connection.onInitialize(async(params) => {
},
hoverProvider: true,
executeCommandProvider: {
commands: ["_compile"]
commands: ["_compose"]
},
semanticTokensProvider: {
legend: {
Expand Down Expand Up @@ -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];
}
});

Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion test/completion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
]
Expand Down
1 change: 1 addition & 0 deletions test/test-workspace/completion.rain
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
#literal 2
#expression
_: lit
2 changes: 1 addition & 1 deletion test/test-workspace/diagnostics.rain
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

---
#expression
_: int-add(1) 10
5 changes: 3 additions & 2 deletions test/workspace/constants/constants.rain
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#value 0x123
---
#value 0x1234

#other-value 0b101
#other-value 123

#my-address 0x1234567890123456789012345678901234567890

Expand Down
22 changes: 14 additions & 8 deletions test/workspace/test.rain
Original file line number Diff line number Diff line change
@@ -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));
using-words-from 0x123
_: int-add<'kj value kjh.my-address>(1 int-max(.value))

0 comments on commit 022dffe

Please sign in to comment.