version 0.1.0

This commit is contained in:
koniifer 2024-09-28 15:34:34 +01:00
parent ffc9763d42
commit a95e98a650
10 changed files with 2701 additions and 214 deletions

5
.gitignore vendored
View file

@ -6,9 +6,12 @@
!.vscode/extensions.json
!.vscode/*.code-snippets
node_modules/*
out/*
# Local History for Visual Studio Code
.history/
# Built Visual Studio Code Extensions
*.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,
},
]
}

View file

@ -1,3 +1,11 @@
# hblang-vscode
syntax highlighting for hblang in vscode
syntax highlighting for hblang in vscode
# Usage guide:
1. run `cargo install hblang --git https://git.ablecorp.us/ableos/holey-bytes`
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
3. log out and log back in (or something, idk)

View file

@ -1,31 +1,79 @@
{
"comments": {
"lineComment": "//",
"blockComment": ["/*", "*/"]
},
"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": "\"" }
],
"folding": {
"markers": {
"start": "^\\s*//\\s*#region\\b",
"end": "^\\s*//\\s*#endregion\\b"
}
}
}
"comments": {
"lineComment": "//",
"blockComment": [
"/*",
"*/"
]
},
"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": "\""
}
],
"folding": {
"markers": {
"start": "^\\s*//\\s*#region\\b",
"end": "^\\s*//\\s*#endregion\\b"
}
},
"indentationRules": {
"increaseIndentPattern": "{",
"decreaseIndentPattern": "}"
},
}

2221
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,27 +1,69 @@
{
"name": "hblang",
"repository": {"url": "https://git.ablecorp.us/aurlex/hblang-vscode"},
"publisher": "aurlex",
"displayName": "hblang",
"description": "Syntax highlighting for holey-bytes lang",
"version": "0.0.1",
"engines": {
"vscode": "^1.0.0"
},
"categories": [
"Programming Languages"
],
"contributes": {
"languages": [{
"id": "hblang",
"aliases": ["hblang", "hblang"],
"extensions": [".hb"],
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "hblang",
"scopeName": "source.hblang",
"path": "./syntaxes/hblang.tmLanguage.json"
}]
}
}
"name": "hblang",
"repository": {
"url": "https://git.ablecorp.us/koniifer/hblang-vscode"
},
"publisher": "koniifer",
"displayName": "hblang",
"description": "Syntax highlighter and formatter for holey-bytes lang",
"version": "0.1.0",
"engines": {
"vscode": "^1.75.0"
},
"main": "./out/main.js",
"categories": [
"Programming Languages",
"Formatters"
],
"activationEvents": [
"onLanguage:hblang",
"onCommand:extension.formatDocument"
],
"contributes": {
"languages": [
{
"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"
}
}
}
]
},
"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.0.0",
"webpack-cli": "^4.0.0"
}
}

66
src/main.ts Normal file
View file

@ -0,0 +1,66 @@
import * as vscode from 'vscode';
import { spawn } from 'child_process';
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
export function activate(context: vscode.ExtensionContext) {
// Register a document formatting edit provider for the language
context.subscriptions.push(
vscode.languages.registerDocumentFormattingEditProvider('hblang', {
async provideDocumentFormattingEdits(document: vscode.TextDocument): Promise<vscode.TextEdit[]> {
try {
const formattedText = await formatDocument(document.fileName);
const edit = new vscode.TextEdit(
new vscode.Range(0, 0, document.lineCount, 0),
formattedText
);
return [edit];
} catch (error: unknown) {
if (error instanceof Error) {
vscode.window.showErrorMessage(`Formatting failed: ${error.message}`);
} else {
vscode.window.showErrorMessage(`Formatting failed: ${String(error)}`);
}
return []; // Return an empty array if formatting fails
}
}
})
);
}
export function deactivate() { }
async function formatDocument(path: string): Promise<string> {
return new Promise((resolve, reject) => {
const child = spawn('hbc', ['--fmt-stdout', path], { shell: true });
let formattedText = '';
// Capture the output
child.stdout.on('data', (data) => {
formattedText += data.toString();
});
// Handle errors
child.stderr.on('data', (data) => {
reject(new Error(data.toString()));
});
// Handle process exit
child.on('exit', (code) => {
if (code === 0) {
resolve(formattedText);
} else {
reject(new Error(`Formatter exited with code ${code}`));
}
});
});
}

View file

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

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"
]
}

34
webpack.config.js Normal file
View file

@ -0,0 +1,34 @@
const path = require('path');
module.exports = {
mode: 'production',
entry: './src/main.ts',
output: {
path: path.resolve(__dirname, 'out'),
filename: 'main.js',
libraryTarget: 'commonjs2' // This is correct for VS Code extensions
},
resolve: {
extensions: ['.ts', '.js'],
fallback: {
// For Node.js core modules not available in browser context, you set them to false
"child_process": false, // Not used in browser context
"fs": false, // Not used in browser context
"os": require.resolve("os-browserify/browser"), // Polyfill for os
"path": require.resolve("path-browserify"), // Polyfill for path
},
},
externals: {
vscode: 'commonjs vscode' // Externalize the vscode module
},
module: {
rules: [
{
test: /\.ts$/,
use: 'ts-loader',
exclude: /node_modules/
}
]
},
target: 'node' // Specify the target environment as Node.js
};