From 5c520a6569b708c7444804f34cb9713db06d5c43 Mon Sep 17 00:00:00 2001 From: babywolf Date: Fri, 24 Apr 2026 11:42:04 +0100 Subject: [PATCH] chore: add .inc file support and fix tests --- .github/workflows/test.yml | 4 +- extension.js | 4 +- package.json | 3 +- src/config.v | 2 +- tests/test_diags.sh | 85 ++++++++++++++++++++++++++++++++++++-- 5 files changed, 88 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2ec9dde..2351726 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,7 +29,7 @@ jobs: run: | mkdir -p ~/.local/bin cp src/gaslsp ~/.local/bin/gaslsp - cp -r src/tables ~/.local/bin/ + cp src/tables/*.csv ~/.local/bin/ chmod +x tests/integration.sh tests/test_diags.sh tests/integration.sh @@ -53,7 +53,7 @@ jobs: run: | mkdir -p ~/.local/bin cp src/gaslsp ~/.local/bin/gaslsp + cp src/tables/*.csv ~/.local/bin/ cp tests/test_diags ~/.local/bin/test_diags - cp -r src/tables ~/.local/bin/ chmod +x tests/test_diags.sh WORKSPACE="$(pwd)" tests/test_diags.sh diff --git a/extension.js b/extension.js index c80dd9e..8bb3dda 100644 --- a/extension.js +++ b/extension.js @@ -39,10 +39,10 @@ function activate(context) { const clientOptions = { documentSelector: [ { scheme: 'file', language: '{asm,gas}' }, - { scheme: 'file', pattern: '**/*.{s,S,asm}' }, + { scheme: 'file', pattern: '**/*.{s,S,asm,inc}' }, ], synchronize: { - fileEvents: workspace.createFileSystemWatcher('**/*.{s,S,asm}') + fileEvents: workspace.createFileSystemWatcher('**/*.{s,S,asm,inc}') }, outputChannel: outputChannel, }; diff --git a/package.json b/package.json index e4d51ff..62a3399 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,8 @@ "onLanguage:gas", "workspaceContains:**/*.s", "workspaceContains:**/*.S", - "workspaceContains:**/*.asm" + "workspaceContains:**/*.asm", + "workspaceContains:**/*.inc" ], "main": "./extension.js", "contributes": { diff --git a/src/config.v b/src/config.v index c3146e5..053f1c8 100644 --- a/src/config.v +++ b/src/config.v @@ -72,7 +72,7 @@ pub mut: pub struct GeneralConfig { pub mut: mode string = 'auto' - extensions []string = ['.s', '.S', '.asm'] + extensions []string = ['.s', '.S', '.asm', '.inc'] recursive bool = true } diff --git a/tests/test_diags.sh b/tests/test_diags.sh index bcff3dd..b895b85 100755 --- a/tests/test_diags.sh +++ b/tests/test_diags.sh @@ -1,10 +1,87 @@ #!/bin/bash -# Test all diagnostic codes locally using the V test binary +# Test all diagnostic codes locally SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" LSP="${LSP:-$HOME/.local/bin/gaslsp}" +WORKSPACE_BASE="${WORKSPACE:-$SCRIPT_DIR}" -export LSP -export WORKSPACE +test_diag() { + local name="$1" + local code="$2" + local content="$3" + + echo -n "Testing $name (code $code)... " + + # Create temp file in workspace root + local tmpfile="$WORKSPACE_BASE/tmp_${code}.s" + echo -e "$content" > "$tmpfile" + + python3 -c " +import json +import subprocess +import sys +import os -"$SCRIPT_DIR/test_diags" \ No newline at end of file +def msg(method, params, id=1): + body = json.dumps({'jsonrpc': '2.0', 'id': id, 'method': method, 'params': params}) + return ('Content-Length: %d\r\n\r\n%s' % (len(body), body)).encode() + +def notif(method, params): + body = json.dumps({'jsonrpc': '2.0', 'method': method, 'params': params}) + return ('Content-Length: %d\r\n\r\n%s' % (len(body), body)).encode() + +lsp = os.environ.get('LSP', '/home/baby/.local/bin/gaslsp') +ws = os.environ.get('WORKSPACE_BASE', '$WORKSPACE_BASE') +code = '$code' + +reqs = [msg('initialize', {'rootUri': 'file://' + ws}), notif('initialized', {})] + +with open('$tmpfile', 'r') as f: + file_content = f.read() + +reqs.append(msg('textDocument/didOpen', { + 'textDocument': {'uri': 'file://$tmpfile', 'text': file_content, 'version': 1} +}, id=2)) + +reqs.append(msg('shutdown', None, id=3)) +reqs.append(notif('exit', {})) + +proc = subprocess.Popen([lsp], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) +stdout, stderr = proc.communicate(b''.join(reqs), timeout=5) + +for p in stdout.decode().split('Content-Length:'): + if code in p and 'publishDiagnostics' in p: + sys.exit(0) +sys.exit(1) +" 2>/dev/null + + if [ $? -eq 0 ]; then + echo "PASS" + else + echo "FAIL" + fi + + rm -f "$tmpfile" +} + +echo "=== Testing all diagnostic codes ===" + +test_diag "D001" "D001" "mov \$1, %rax" +test_diag "D012" "D012" "pushb \$42" +test_diag "D020" "D020" "# TODO: fix this" +test_diag "D002" "D002" "mov %eax, %ebx" +test_diag "D003" "D003" "movl %eax, %rax" +test_diag "D004" "D004" "movb \$256, %al" +test_diag "D005" "D005" "mov %ah, %r8" +test_diag "D009" "D009" "mov (%eax), %eax" +test_diag "D010" "D010" "add %eax, %eax" +test_diag "D011" "D011" "div \$4" +test_diag "D013" "D013" "imul %eax" +test_diag "D014" "D014" "mul %eax" +test_diag "D015" "D015" "shl %eax, %ebx" +test_diag "D016" "D016" "syscall" +test_diag "D017" "D017" "int \$0x80" +test_diag "D018" "D018" "mylabel" + +echo "" +echo "=== Tests complete ===" \ No newline at end of file