Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**@type {import('eslint').Linter.Config} */
// eslint-disable-next-line no-undef
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
],
rules: {
'semi': [2, "always"],
'@typescript-eslint/no-unused-vars': 0,
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/explicit-module-boundary-types': 0,
'@typescript-eslint/no-non-null-assertion': 0,
}
};
18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,24 @@
"engines": {
"vscode": "^1.25.0"
},
"activationEvents": [
"*"
],
"main": "./out/extension.js",
"scripts": {
"vscode:prepublish": "npm run compile",
"compile": "tsc -p ./",
"lint": "eslint \"src/**/*.ts\"",
"watch": "tsc -watch -p ./"
},
"devDependencies": {
"@types/node": "^16.18.34",
"@types/vscode": "^1.73.0",
"@typescript-eslint/eslint-plugin": "^6.7.0",
"@typescript-eslint/parser": "^6.7.0",
"eslint": "^8.26.0",
"typescript": "^5.2.2"
},
"icon": "assets/exapunks.png",
"keywords": [
"EXAPUNKS",
Expand Down
93 changes: 93 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/

import * as vscode from 'vscode';

export function activate(context: vscode.ExtensionContext) {

const provider = vscode.languages.registerCompletionItemProvider('exa', {

provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, context: vscode.CompletionContext) {
const completions = [];

// Handle @{} and don't double autocomplete other commands.
const linePrefix = document.lineAt(position).text.slice(0, position.character);
if (linePrefix.includes(' ')) {
if (linePrefix.includes('@')) {
const moveCursorCommand: vscode.Command = {
title: "Move cursor left between brackets",
command: "cursorLeft"
};
const c = new vscode.CompletionItem('@{}');
c.command = moveCursorCommand;
c.range = new vscode.Range(position.translate(0, -1), position);
completions.push(c);
return completions;
} else {
// return undefined to allow general text matching
return undefined;
}
}

const lines = [
'@END',
'DROP',
'HALT',
'KILL',
'MAKE',
'MODE',
'NOOP',
'WIPE',

'@REP N',
'ADDI R/N R/N R',
'COPY R/N R',
'DIVI R/N R/N R',
'FILE R',
'FJMP L',
'GRAB R/N',
'HOST R',
'JUMP L',
'LINK R/N',
'MARK L',
'MODI R/N R/N R',
'MULI R/N R/N R',
'RAND R/N R/N R',
'REPL L',
'SEEK R/N',
'SUBI R/N R/N R',
'SWIZ R/N R/N R',
'TEST MRD/EOF',
'TEST R/N = R/N',
'TJMP L',
'VOID F',
];

for (const line of lines) {
const split = line.split(' ');
const k = split[0];
const c = new vscode.CompletionItem(line);
const elements = [k];
if (split.length > 1) {
if (split[1] == 'MRD/EOF') {
elements.push("${1|MRD,EOF|}");
} else {
// Just add space to end so command can be followed immediately by argument
elements.push('');
}
}
if (k.startsWith('@')) {
c.range = new vscode.Range(position.translate(0, -1), position);
}

c.insertText = new vscode.SnippetString(elements.join(' '));
completions.push(c);
}
return completions;
},

}, '@');

context.subscriptions.push(provider);
}
4 changes: 4 additions & 0 deletions syntaxes/exa.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
{
"match": "(?i)\\b(TEST MRD|TEST EOF|TEST)\\b",
"name": "keyword.control.exa"
},
{
"match": "(?i)(@REP|@END|@{|,|})",
"name": "keyword.control.exa"
}
]
},
Expand Down
17 changes: 17 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es2020",
"lib": [
"es2020"
],
"outDir": "out",
"sourceMap": true,
"strict": true,
"rootDir": "src"
},
"exclude": [
"node_modules",
".vscode-test"
]
}