Compare commits

..

20 commits

Author SHA1 Message Date
koniifer 9d4a8b8246 Update README.md 2025-02-02 06:56:24 -06:00
koniifer a33019b088 fix more 2024-12-21 17:22:26 +00:00
koniifer cb7011ac46 fixes & support new char & array syntaxes 2024-12-21 17:04:31 +00:00
koniifer 8cbf55a627 fix missing keywords 2024-12-18 19:25:11 +00:00
koniifer 04d662ee42 minor update 2024-12-16 13:23:50 +00:00
koniifer 18199666d8 forgot to bump version 2024-11-30 23:22:55 +00:00
koniifer bb58baa09c maybe working 2024-11-30 23:22:30 +00:00
koniifer fa7a4bd245 update & improve grammar somewhat 2024-11-15 21:20:50 +00:00
koniifer 99f66d803a better instructions 2024-11-10 15:07:40 -06:00
koniifer bc84098b77 patch 2024-11-08 21:50:37 +00:00
koniifer d146f51e59 bump version 2024-11-08 21:49:29 +00:00
koniifer 8ad44334d8 0.2.1, bug fixes and new match new compiler 2024-11-08 21:49:10 +00:00
koniifer 69a82a563e don't make people use nightly as default, that is stupid 2024-11-08 13:22:32 -06:00
koniifer c3ade921d7 release 0.2.0
+ error linting
+ clearer missing hblang message
+ misc
2024-11-07 18:59:47 +00:00
koniifer 7c48aa6cad update readme for common problem 2024-10-25 05:32:52 -05:00
koniifer 4b5bb991f7 good enough formatter 2024-09-30 12:57:01 +01:00
koniifer 9098604bf0 fix struct highlight 2024-09-28 16:27:58 +01:00
koniifer adaccda70b fixes 2024-09-28 16:12:59 +01:00
koniifer a95e98a650 version 0.1.0 2024-09-28 15:34:34 +01:00
aurlex ffc9763d42 fix vscode version compat issue 2024-07-23 21:44:13 +01:00
12 changed files with 2883 additions and 214 deletions

5
.gitignore vendored
View file

@ -6,9 +6,12 @@
!.vscode/extensions.json !.vscode/extensions.json
!.vscode/*.code-snippets !.vscode/*.code-snippets
node_modules/*
out/*
# Local History for Visual Studio Code # Local History for Visual Studio Code
.history/ .history/
# Built Visual Studio Code Extensions # Built Visual Studio Code Extensions
*.vsix *.vsix

15
.vscode/launch.json vendored Normal file
View file

@ -0,0 +1,15 @@
{
"version": "0.1.0",
"configurations": [
{
"name": "Launch Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceRoot}"
],
"sourceMaps": true,
},
]
}

13
.vscodeignore Normal file
View file

@ -0,0 +1,13 @@
# ---> VisualStudioCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets
# Local History for Visual Studio Code
.history/
# Built Visual Studio Code Extensions
*.vsix

View file

@ -1,3 +1,14 @@
# hblang-vscode # hblang-vscode
syntax highlighting for hblang in vscode syntax highlighting for hblang in vscode
# Usage guide:
1. `cargo +nightly install hblang --git https://git.ablecorp.us/ableos/holey-bytes hbc --debug`
> remember to keep this updated
2.
- add `$HOME/.cargo/bin` (or wherever you installed hblang) to `$PATH`
> in bash, `export PATH=$PATH:$HOME/.cargo/bin`<br>
> in other shells, there may be other ways
- alternatively, add the path you installed hblang to the extension settings
3. log out and log back in (or something, idk)

View file

@ -1,31 +1,79 @@
{ {
"comments": { "comments": {
"lineComment": "//", "lineComment": "//",
"blockComment": ["/*", "*/"] "blockComment": [
}, "/*",
"brackets": [ "*/"
["{", "}"], ]
["[", "]"], },
["(", ")"] "brackets": [
], [
"autoClosingPairs": [ "{",
{ "open": "{", "close": "}" }, "}"
{ "open": "[", "close": "]" }, ],
{ "open": "(", "close": ")" }, [
{ "open": "\"", "close": "\"", "notIn": ["string"] }, "[",
{ "open": "/*", "close": "*/", "notIn": ["string"] } "]"
], ],
"surroundingPairs": [ [
{ "open": "{", "close": "}" }, "(",
{ "open": "[", "close": "]" }, ")"
{ "open": "(", "close": ")" }, ]
{ "open": "\"", "close": "\"" } ],
], "autoClosingPairs": [
"folding": { {
"markers": { "open": "{",
"start": "^\\s*//\\s*#region\\b", "close": "}"
"end": "^\\s*//\\s*#endregion\\b" },
} {
} "open": "[",
} "close": "]"
},
{
"open": "(",
"close": ")"
},
{
"open": "\"",
"close": "\"",
"notIn": [
"string"
]
},
{
"open": "/*",
"close": "*/",
"notIn": [
"string"
]
}
],
"surroundingPairs": [
{
"open": "{",
"close": "}"
},
{
"open": "[",
"close": "]"
},
{
"open": "(",
"close": ")"
},
{
"open": "\"",
"close": "\""
}
],
"folding": {
"markers": {
"start": "{\n",
"end": "}"
}
},
"indentationRules": {
"increaseIndentPattern": "{\\s+",
"decreaseIndentPattern": "\\s+}\\$"
},
}

2233
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,27 +1,80 @@
{ {
"name": "hblang", "name": "hblang",
"repository": {"url": "https://git.ablecorp.us/aurlex/hblang-vscode"}, "repository": {
"publisher": "aurlex", "url": "https://git.ablecorp.us/koniifer/hblang-vscode"
"displayName": "hblang", },
"description": "Syntax highlighting for holey-bytes lang", "publisher": "koniifer",
"version": "0.0.1", "displayName": "hblang",
"engines": { "description": "Syntax, formatting, and linting for holey-bytes lang",
"vscode": "^1.91.0" "version": "0.2.8",
}, "engines": {
"categories": [ "vscode": "^1.75.0"
"Programming Languages" },
], "main": "./out/main.js",
"contributes": { "categories": [
"languages": [{ "Programming Languages",
"id": "hblang", "Formatters",
"aliases": ["hblang", "hblang"], "Linters"
"extensions": [".hb"], ],
"configuration": "./language-configuration.json" "activationEvents": [
}], "onCommand:extension.formatDocument"
"grammars": [{ ],
"language": "hblang", "contributes": {
"scopeName": "source.hblang", "languages": [
"path": "./syntaxes/hblang.tmLanguage.json" {
}] "id": "hblang",
} "aliases": [
} "hblang"
],
"extensions": [
".hb"
],
"configuration": "./language-configuration.json"
}
],
"grammars": [
{
"language": "hblang",
"scopeName": "source.hblang",
"path": "./syntaxes/hblang.tmLanguage.json"
}
],
"formatters": [
{
"language": "hblang",
"provider": {
"provideDocumentFormattingEdits": {
"command": "editor.action.formatDocument"
}
}
}
],
"configuration": {
"title": "hblang",
"properties": {
"hblang.compilerPath": {
"type": "string",
"default": "PATH",
"description": "Set the optional path for the hbc compiler. If set to 'PATH', it will rely on the system to provide hbc.",
"scope": "machine-overridable"
}
}
}
},
"scripts": {
"vscode:prepublish": "webpack",
"compile": "webpack --mode production",
"watch": "webpack --watch --mode development"
},
"devDependencies": {
"@types/vscode": "^1.75.0",
"os-browserify": "^0.3.0",
"path-browserify": "^1.0.1",
"stream-browserify": "^3.0.0",
"ts-loader": "^9.5.1",
"typescript": "^4.0.0",
"vscode": "^1.1.37",
"webpack": "^5.97.1",
"webpack-cli": "^4.10.0"
}
}

158
src/main.ts Normal file
View file

@ -0,0 +1,158 @@
import * as vscode from "vscode";
import { execFile } from "child_process";
import * as fs from "fs";
import * as path from "path";
const DEFAULT_EXECUTABLE = "hbc";
let diagnosticCollection: vscode.DiagnosticCollection;
function getExecutablePath(): string {
const config = vscode.workspace.getConfiguration("hblang");
return config.get<string>("compilerPath") === "PATH"
? DEFAULT_EXECUTABLE
: config.get<string>("compilerPath")!;
}
function isAbleosRepo(document: vscode.TextDocument): boolean {
const workspaceFolder = vscode.workspace.getWorkspaceFolder(document.uri);
if (!workspaceFolder) return false;
return workspaceFolder.name.toLowerCase().includes("ableos");
}
async function runCommand(
filePath: string,
args: string[],
cwd: string,
): Promise<string> {
return new Promise((resolve, reject) => {
execFile(getExecutablePath(), args, { cwd }, (error, stdout, stderr) => {
if (error && error.code === "ENOENT") {
vscode.window.showErrorMessage(
"hblang compiler not found. Ensure 'hbc' is installed and available in PATH."
);
return reject(new Error(`Compiler not found: ${stderr || stdout}`));
}
return error
? reject(new Error(stderr || `Exit code: ${error.code}`))
: resolve(stdout);
});
});
}
async function provideDocumentFormattingEdits(
document: vscode.TextDocument
): Promise<vscode.TextEdit[]> {
const tempFilePath = path.join(
path.dirname(document.uri.fsPath),
`temp_${path.basename(document.uri.fsPath)}`
);
try {
await document.save();
await fs.promises.writeFile(tempFilePath, document.getText());
const args = ["--fmt-stdout", tempFilePath];
if (isAbleosRepo(document)) {
args.push("--path-resolver", "ableos");
}
const workspaceFolder = vscode.workspace.getWorkspaceFolder(document.uri);
if (!workspaceFolder) {
throw new Error("Workspace folder not found.");
}
const stdout = await runCommand(tempFilePath, args, workspaceFolder.uri.fsPath);
const fullRange = new vscode.Range(
document.positionAt(0),
document.positionAt(document.getText().length)
);
return [vscode.TextEdit.replace(fullRange, stdout)];
} catch (error) {
if (error instanceof Error) {
vscode.window.showErrorMessage(`Formatting failed: ${error.message}`);
} else {
vscode.window.showErrorMessage(`Formatting failed: Unknown error`);
}
return [];
} finally {
fs.promises.unlink(tempFilePath).catch(console.error);
}
}
async function lintDocument(document: vscode.TextDocument) {
const args = [document.uri.fsPath];
if (isAbleosRepo(document)) {
args.push("--path-resolver", "ableos");
}
try {
const workspaceFolder = vscode.workspace.getWorkspaceFolder(document.uri);
if (!workspaceFolder) { };
const stderr = await runCommand(document.uri.fsPath, args, workspaceFolder?.uri.fsPath || document.uri.fsPath);
diagnosticCollection.set(document.uri, parseLintingErrors(stderr));
} catch (error) {
if (error instanceof Error) {
diagnosticCollection.set(document.uri, parseLintingErrors(error.message));
} else {
vscode.window.showErrorMessage("Error linting hblang document.");
}
}
}
function parseLintingErrors(stderr: string): vscode.Diagnostic[] {
return stderr
.split("\n")
.filter((line) => line && !line.includes("missing main function"))
.map((lineText) => {
const match = lineText.match(/^([^:]+):(\d+):(\d+):\s*(.+)$/);
if (!match) return null;
const [abc, , lineStr, columnStr, message] = match;
const lineNum = parseInt(lineStr, 10) - 1;
const columnNum = parseInt(columnStr, 10) - 1;
const severity = abc.startsWith("(W) ")
? vscode.DiagnosticSeverity.Warning
: vscode.DiagnosticSeverity.Error;
return new vscode.Diagnostic(
new vscode.Range(
lineNum,
columnNum,
lineNum,
columnNum + message.length
),
message,
severity
);
})
.filter(Boolean) as vscode.Diagnostic[];
}
export function activate(context: vscode.ExtensionContext) {
diagnosticCollection = vscode.languages.createDiagnosticCollection("hblang");
context.subscriptions.push(diagnosticCollection);
vscode.workspace.onDidSaveTextDocument(async (document) => {
if (document.languageId === "hblang") {
await lintDocument(document);
if (diagnosticCollection.get(document.uri)?.length === 0) {
vscode.commands.executeCommand(
"editor.action.formatDocument",
document
);
}
}
});
vscode.languages.registerDocumentFormattingEditProvider("hblang", {
provideDocumentFormattingEdits,
});
}

View file

@ -1,157 +1,241 @@
{ {
"scopeName": "source.hblang", "scopeName": "source.hblang",
"name": "hblang", "name": "hblang",
"fileTypes": ["hb"], "fileTypes": [
"patterns": [ "hb"
{ ],
"include": "#comments" "patterns": [
}, {
{ "include": "#all"
"include": "#strings" }
}, ],
{ "repository": {
"include": "#keywords" "all": {
}, "patterns": [
{ {
"include": "#types" "include": "#comment"
}, },
{ {
"include": "#declarations" "include": "#string"
}, },
{ {
"include": "#functions" "include": "#struct"
}, },
{ {
"include": "#macros" "include": "#keyword"
}, },
{ {
"include": "#structs" "include": "#number"
}, },
{ {
"include": "#arrays" "include": "#punctuation"
}, },
{ {
"include": "#pointers" "include": "#function"
}, },
{ {
"include": "#operators" "include": "#operator"
} },
], {
"repository": { "include": "#variable"
"comments": { },
"patterns": [ {
{ "include": "#type"
"name": "comment.block.hblang", },
"begin": "/\\*", {
"end": "\\*/" "include": "#array"
}, }
{ ]
"name": "comment.line.double-slash.hblang", },
"begin": "//", "parameter": {
"end": "$" "patterns": [
} {
] "name": "variable.parameter.hblang",
}, "match": "\\b\\w+\\s*:\\s*(?:\\^)?[\\w\\$]+\\b"
"strings": { }
"patterns": [ ]
{ },
"name": "string.quoted.double.hblang", "number": {
"begin": "\"", "patterns": [
"end": "\"" {
} "name": "constant.numeric.float.hblang",
] "match": "\\b\\d+\\.\\d+\\b"
}, },
"keywords": { {
"patterns": [ "name": "constant.numeric.hex.hblang",
{ "match": "0x[0-9A-Fa-f]+"
"name": "keyword.control.hblang", },
"match": "\\b(loop|break|if|else|return)\\b" {
} "name": "constant.numeric.binary.hblang",
] "match": "0b[0-1]+"
}, },
"types": { {
"patterns": [ "name": "constant.numeric.octal.hblang",
{ "match": "0o[0-7]+"
"name": "storage.type.hblang", },
"match": "\\b(uint|int|void|u\\d+|i\\d+|f\\d+)\\b" {
} "name": "constant.numeric.decimal.hblang",
] "match": "\\b\\d+\\b"
}, }
"declarations": { ]
"patterns": [ },
{ "comment": {
"name": "variable.other.declaration.hblang", "patterns": [
"match": "\\b[A-Z_][A-Z0-9_]*\\b" {
}, "name": "comment.block.hblang",
{ "begin": "/\\*",
"name": "variable.other.assignment.hblang", "end": "\\*/"
"match": "\\b[a-z_][a-z0-9_]*\\b" },
} {
] "name": "comment.line.double-slash.hblang",
}, "begin": "//",
"operators": { "end": "$"
"patterns": [ }
{ ]
"name": "keyword.operator.hblang", },
"match": "\\b(\\^|\\*|&|<<|>>|>>>|<<=|>>=|>>>=|\\+|\\-|\\*|\\/|%|\\|\\||&&|!|==|!=|<|<=|>|>=|\\||&|\\^|~|<<|>>|\\+=|-=|\\*=|\\/=|%=|\\|=|&=|\\^=|~=|<<=|>>=|>>>|@\\w+)\\b" "string": {
} "patterns": [
] {
}, "name": "string.quoted.double.hblang",
"functions": { "begin": "\"",
"patterns": [ "end": "\"",
{ "patterns": [
"name": "entity.name.function.hblang", {
"match": "\\b[a-z_][a-z0-9_]*\\b(?=\\()" "name": "constant.character.escape.hblang",
} "match": "\\\\."
] }
}, ]
"macros": { },
"patterns": [ {
{ "name": "string.quoted.single.hblang",
"name": "entity.name.macro.hblang", "begin": "'",
"match": "@\\b[a-z_][a-z0-9_]*\\b" "end": "'",
} "patterns": [
] {
}, "name": "constant.character.escape.hblang",
"structs": { "match": "\\\\."
"patterns": [ }
{ ]
"name": "storage.type.struct.hblang", }
"match": "\\b[a-zA-Z_][a-zA-Z0-9_]*\\s*:=\\s*struct\\b" ]
}, },
{ "keyword": {
"name": "storage.type.struct.hblang", "patterns": [
"match": "\\b\\.[a-zA-Z_][a-zA-Z0-9_]*\\b" {
} "name": "keyword.control.hblang",
] "match": "(?<!\\w)\\b(fn|loop|break|if|else|return|packed|continue|true|false|struct|idk|die|null|defer|union|enum|match)\\b(?!\\w)"
}, }
"arrays": { ]
"patterns": [ },
{ "type": {
"name": "storage.type.array.hblang", "patterns": [
"match": "\\[\\b[a-zA-Z_][a-zA-Z0-9_]*\\b\\]" {
}, "name": "storage.type.hblang",
{ "match": "(?<!\\w)\\b(f(32|64)|uint|int|u(8|16|32)|i(8|16|32)|void|bool|type|never)\\b(?!\\w)"
"name": "storage.type.array.hblang", }
"match": "\\[\\b[a-zA-Z_][a-zA-Z0-9_]*\\b;\\s*\\d+\\]" ]
} },
] "variable": {
}, "patterns": [
"pointers": { {
"patterns": [ "name": "variable.declaration.hblang",
{ "match": "\\b\\w+\\b(?=\\s*:=)"
"name": "storage.modifier.pointer.hblang", },
"match": "\\^+" {
}, "name": "variable.assignment.hblang",
{ "match": "\\b\\w+\\b(?=\\s*=(?!=))"
"name": "keyword.operator.dereference.hblang", },
"match": "\\*+" {
}, "name": "variable.member.hblang",
{ "match": "(?<=\\.)\\w+\\b"
"name": "keyword.operator.reference.hblang", }
"match": "\\&+" ]
} },
] "operator": {
} "patterns": [
} {
} "name": "keyword.operator.assignment.hblang",
"match": ":="
},
{
"name": "keyword.operator.assignment.hblang",
"match": "=(?!=)"
},
{
"name": "keyword.operator.hblang",
"match": "(\\$|\\?|@|<<=|>>=|>=|<=|\\^=|\\+=|-=|\\*=|\\/=|%=|\\|=|&=|\\^|\\*|&|<<|>>|\\+|\\-|\\/|%|\\||!|==|!=|<|>)"
}
]
},
"struct": {
"patterns": [
{
"name": "entity.name.type.struct.hblang",
"match": "\\b[A-Z]\\w*\\b"
}
]
},
"punctuation": {
"patterns": [
{
"name": "punctuation.terminator.statement.hblang",
"match": ";|\\.|,|(?<!:):(?!=)"
}
]
},
"function": {
"patterns": [
{
"name": "meta.function.declaration.hblang",
"begin": "(\\b\\w+\\b)\\s*(:=)\\s*(fn)\\s*\\(",
"end": "\\)",
"beginCaptures": {
"1": {
"name": "entity.name.function.hblang"
},
"2": {
"name": "keyword.operator.assignment.hblang"
},
"3": {
"name": "keyword.control.hblang"
}
},
"patterns": [
{
"include": "#all"
}
]
},
{
"name": "meta.function.call.hblang",
"begin": "@?\\w+\\s*\\(",
"end": "\\)",
"beginCaptures": {
"0": {
"name": "entity.name.function.hblang"
}
},
"patterns": [
{
"include": "#all"
}
]
}
]
},
"array": {
"patterns": [
{
"name": "meta.array.initialization.hblang",
"begin": "\\.\\[",
"end": "\\]",
"patterns": [
{
"include": "#all"
}
]
}
]
}
}
}

3
tests/dont-erase.hb Normal file
View file

@ -0,0 +1,3 @@
main := fn(): void {
undefined_identifier
}

15
tsconfig.json Normal file
View file

@ -0,0 +1,15 @@
{
"compilerOptions": {
"target": "ES6",
"module": "commonjs",
"outDir": "./out",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"include": [
"src/**/*.ts"
]
}

33
webpack.config.js Normal file
View file

@ -0,0 +1,33 @@
const path = require('path');
module.exports = {
mode: 'production',
entry: './src/main.ts',
output: {
path: path.resolve(__dirname, 'out'),
filename: 'main.js',
libraryTarget: 'commonjs2'
},
resolve: {
extensions: ['.ts', '.js'],
fallback: {
"child_process": false,
"fs": false,
"os": require.resolve("os-browserify/browser"),
"path": require.resolve("path-browserify"),
},
},
externals: {
vscode: 'commonjs vscode'
},
module: {
rules: [
{
test: /\.ts$/,
use: 'ts-loader',
exclude: /node_modules/
}
]
},
target: 'node'
};