Implementation of tooltips on hover

This commit is contained in:
Olivier Guinart 2017-09-04 17:50:23 -07:00
parent 2886adcf50
commit 2967829f23
10 changed files with 2859 additions and 23 deletions

27
.vscode/launch.json vendored
View File

@ -1,13 +1,18 @@
// A launch configuration that launches the extension inside a new window
{
"version": "0.1.0",
"configurations": [
{
"name": "Launch Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ]
}
]
"version": "0.1.0",
"configurations": [
{
"name": "Launch Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceRoot}"
],
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/out/**/*.js"],
"preLaunchTask": "npm"
}
]
}

22
.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,22 @@
// A task runner that calls a custom npm script that compiles the extension.
{
"version": "0.1.0",
// we want to run npm
"command": "npm",
// the command is a shell script
"isShellCommand": true,
// show the output window only if unrecognized errors occur.
"showOutput": "silent",
// we run the custom script "compile" as defined in package.json
"args": ["run", "compile"],
// The tsc compiler is started in watching mode
"isWatching": true,
// use the standard tsc in watch mode problem matcher to find compile problems in the output.
"problemMatcher": "$tsc-watch"
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

2532
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -10,17 +10,40 @@
"categories": [
"Languages"
],
"activationEvents": [
"onLanguage:merlin32"
],
"main": "./out/extension",
"contributes": {
"languages": [{
"id": "merlin32",
"aliases": ["Merlin32", "merlin32"],
"extensions": [".s"],
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "merlin32",
"scopeName": "source.asm.merlin32",
"path": "./syntaxes/merlin32.tmLanguage.json"
}]
"languages": [
{
"id": "merlin32",
"aliases": [
"Merlin32",
"merlin32"
],
"extensions": [
".s"
],
"configuration": "./language-configuration.json"
}
],
"grammars": [
{
"language": "merlin32",
"scopeName": "source.asm.merlin32",
"path": "./syntaxes/merlin32.tmLanguage.json"
}
]
},
"scripts": {
"vscode:prepublish": "tsc -p ./",
"compile": "tsc -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install"
},
"devDependencies": {
"vscode": "^1.0.3",
"typescript": "^2.1.5",
"@types/node": "^6.0.52"
}
}
}

70
src/extension.ts Normal file
View File

@ -0,0 +1,70 @@
import * as vscode from 'vscode';
import * as data from '../strings/resources.json';
// this method is called when vs code is activated
export function activate(context: vscode.ExtensionContext) {
function initializeOpcodesRegex() {
let r : string = "\\b(";
for (var prop in data) {
if (prop != "--^") {
r += prop + "|";
}
}
// The last '|(--\\^)' group below is the ELUP synomym,
// not considered a word per regex standards, so not in \b boundaries group.
return r.substr(0, r.length - 1) + ")\\b|(--\\^)";
}
let regEx = new RegExp(initializeOpcodesRegex(), 'gi');
// create an empty decorator type (no need for border around the opcode nor different background color)
// this is just to enable hover.
const opcodesDecorationType = vscode.window.createTextEditorDecorationType({
});
let activeEditor = vscode.window.activeTextEditor;
if (activeEditor) {
triggerUpdateDecorations();
}
vscode.window.onDidChangeActiveTextEditor(editor => {
activeEditor = editor;
if (editor) {
triggerUpdateDecorations();
}
}, null, context.subscriptions);
vscode.workspace.onDidChangeTextDocument(event => {
if (activeEditor && event.document === activeEditor.document) {
triggerUpdateDecorations();
}
}, null, context.subscriptions);
var timeout = null;
function triggerUpdateDecorations() {
if (timeout) {
clearTimeout(timeout);
}
timeout = setTimeout(updateDecorations, 500);
}
function updateDecorations() {
if (!activeEditor) {
return;
}
const text = activeEditor.document.getText();
const opcodes: vscode.DecorationOptions[] = [];
let match;
while (match = regEx.exec(text)) {
const startPos = activeEditor.document.positionAt(match.index);
const endPos = activeEditor.document.positionAt(match.index + match[0].length);
const decoration = { range: new vscode.Range(startPos, endPos), hoverMessage: data[match[0].toUpperCase()] };
opcodes.push(decoration);
}
if (opcodes.length > 0) {
activeEditor.setDecorations(opcodesDecorationType, opcodes);
}
}
}

166
strings/resources.json Normal file
View File

@ -0,0 +1,166 @@
{
"ADR": "Define ADdRess (3 bytes)",
"ADRL": "Define ADdRess Long (4 bytes)",
"ASC": "Define ASCii (\" positive, ' negative)",
"CHK": "Place a CHecKsum in object code",
"DA": "Define Address (2 bytes)",
"DB": "Define Byte (1 byte)",
"DC": "???",
"DCI": "Define Dextral Character Inverted",
"DDB": "Define Double Byte (2 bytes)",
"DE": "???",
"DFB": "DeFine Byte (1 byte)",
"DS": "Define Storage (x bytes) (e.g. DS 10 (put $00 in 10 bytes), DS 10,$80 (put $80 in 10 bytes))",
"DW": "Define Word (2 bytes)",
"FLS": "Define FLaShing text",
"HEX": "Define HEX data (1 byte)",
"INV": "Define INVerse text",
"REV": "Define REVerse",
"STR": "Define STRing with leading length (1 byte)",
"STRL": "Define STRing Long with leading length (2 bytes)",
"ANOP": "???",
"AST": "Send a line of ASTerisks",
"CYC": "Calculate and print CYCle times for the code",
"DAT": "DATe stamp assembly listing",
"DEND": "Dummy section END",
"DO": "DO directive",
"DSK": "Define the name of the output binary after the directive",
"DUM": "DUMmy section start",
"ELSE": "ELSE condition",
"ELUP": "End of LUP",
"--^": "End of LUP",
"END": "END of source file",
"EQU": "Define constant values (same as =)",
"ERR": "Force ERRor",
"EXP": "Macro EXPand control",
"FIN": "Mandatory ENDdirective for IF and DO ",
"IF": "IF condition",
"KBD": "Define label from KeyBoarD",
"LNK": "Relocate code (same as DSK in Merlin 32)",
"LONGA": "???",
"LONGI": "???",
"LST": "LiSTing control",
"LSTDO": "LiSTDO OFF areas of code",
"LUP": "Repeat portions of the code (until the --^ directive)",
"MX": "Set the size for M (Accumulator) and X (X and Y Registers)",
"ORG": "Must be followed by the program's origin, e.g. org $800",
"PAG": "New PAGe",
"PAU": "PAUse",
"PUT": "Insert the content of a source file",
"PUTBIN": "???",
"REL": "Use at the start of the program to write 16 bit relocatable code",
"SAV": "Define the name of the output binary before the directive",
"SKP": "SKiP lines",
"START": "???",
"SW": "SWeet16 opcodes",
"TR": "TRuncate control",
"TTL": "TiTLe heading",
"TYP": "Set the output file type (one byte: $00-$FF)",
"USE": "Insert macros",
"USING": "???",
"USR": "???",
"XC": "???",
"ADC": "ADd with Carry",
"ADCL": "ADd with Carry Long",
"AND": "Bitwise AND with accumulator",
"ANDL": "Bitwise AND with accumulator, Long",
"ASL": "ASL shifts all bits left one position. 0 is shifted into bit 0 and the original bit 7 is shifted into the Carry",
"BCC": "Branch if Carry Clear",
"BCS": "Branch if Carry Set",
"BEQ": "Branch if EQual/Branch if zero",
"BIT": "BIt Test",
"BMI": "Branch if MInus value",
"BNE": "Branch if Not Equal/Branch if not zero",
"BPL": "Branch if PLus value",
"BRA": "BRanch Always",
"BRK": "Software BReaK",
"BRL": "BRanch always Long",
"BVC": "Branch if oVerflow Clear",
"BVS": "Branch if oVerflow Set",
"CLC": "CLear Carry flag",
"CLD": "CLear Decimal flag",
"CLI": "CLear Interrupt flag",
"CLV": "CLear oVerflow flag",
"CMP": "CoMPare accumulator with memory",
"CMPL": "CoMPare accumulator with memory, Long",
"COP": "COProcessor empowerment (interrupt)",
"CPX": "ComPare X with memory",
"CPY": "ComPare Y with memory",
"DEC": "DECrement accumulator or memory",
"DEX": "DEcrement X",
"DEY": "Decrement Y",
"EOR": "Exclusive OR accumulator with memory",
"EORL": "Exclusive OR accumulator with memory, Long",
"INC": "INCrement accumulator or memory",
"INX": "INcrement X",
"INY": "INcrement Y",
"JML": "JuMp, Long",
"JMP": "JuMP",
"JMPL": "JuMP, Long",
"JSL": "Jump to Subroutine, Long",
"JSR": "Jump to SubRoutine",
"LDA": "LoaD Accumulator",
"LDAL": "LoaD Accumulator, Long",
"LDX": "LoaD X register",
"LDY": "LoaD Y register",
"LSR": "LSR shifts all bits right one position. 0 is shifted into bit 7 and the original bit 0 is shifted into the Carry",
"MVN": "Block MoVe Negative",
"MVP": "Block MoVe Positive",
"NOP": "No OPeration",
"ORA": "Bitwise OR Accumulator with memory",
"ORAL": "Bitwise OR Accumulator with memory, Long",
"PEA": "Push Effective Address",
"PEI": "Push Effective Indirect address",
"PER": "Push program countEr Relative",
"PHA": "PusH Accumulator",
"PHB": "PusH data Bank register",
"PHD": "PusH Direct page register",
"PHK": "PusH program banK register",
"PHP": "PusH Processor status flags",
"PHX": "PusH X",
"PHY": "PusH Y",
"PLA": "Pull Accumulator",
"PLB": "Pull data Bank register",
"PLD": "Pull Direct page register",
"PLP": "Pull Processor status flags",
"PLX": "Pull X",
"PLY": "Pull Y",
"REP": "REset Processor status flag",
"ROL": "ROtate Left accumulator or memory",
"ROR": "ROtate Right accumulator or memory",
"RTI": "ReTurn from Interrupt",
"RTL": "ReTurn from subroutine, Long",
"RTS": "ReTurn from Subroutine; pulls the top two bytes off the stack (low byte first) and transfers program control to that address+1",
"SBC": "SuBtract with Carry",
"SBCL": "SuBtract with Carry Long",
"SEC": "SEt Carry flag",
"SED": "SEt Decimal flag",
"SEI": "SEt Interrupt flag",
"SEP": "SEt Processor status flag",
"STA": "STore Accumulator to memory",
"STAL": "STore Accumulator to memory, Long",
"STP": "SToP the clock",
"STX": "STore X to memory",
"STY": "STore Y to memory",
"STZ": "STore Zero to memory",
"TAX": "Transfer Accumulator to X",
"TAY": "Transfer Accumulator to Y",
"TCD": "Transfer aCcumulator to Direct page",
"TCS": "Transfer aCcumulator to Stack page",
"TDC": "Transfer Direct page to aCcumulator",
"TRB": "Test and Reset Bit",
"TSB": "Test and Set Bit",
"TSC": "Transfer Stack pointer to aCcumulator",
"TSX": "Transfer Stack pointer to X",
"TXA": "Transfer X to Accumulator",
"TXS": "Transfer X to Stack pointer",
"TXY": "Transfer X to Y",
"TYA": "Transfer Y to Accumulator",
"TYX": "Transfer Y to X",
"WAI": "WAIt for interrupt",
"WDM": "Reserved for future use, it performs no operation",
"XBA": "EXchange low and high byte of the Accumulator",
"XCE": "EXchange Carry and Emulation"
}

3
strings/resources.json.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
interface Resources {}
declare const value: Resources;
export = value;

15
tsconfig.json Normal file
View File

@ -0,0 +1,15 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"outDir": "out",
"lib": [
"es6"
],
"sourceMap": true,
"rootDir": "src"
},
"exclude": [
"node_modules"
]
}