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
126 changes: 126 additions & 0 deletions __mocks__/vscode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// Mock the 'vscode' module for Jest testing
const mockedVSCode = {
// Basic types
Position: class {
line: number;
character: number;

constructor(line: number, character: number) {
this.line = line;
this.character = character;
}

isBefore(other: any): boolean { return false; }
isBeforeOrEqual(other: any): boolean { return false; }
isAfter(other: any): boolean { return false; }
isAfterOrEqual(other: any): boolean { return false; }
isEqual(other: any): boolean { return false; }
compareTo(other: any): number { return 0; }
translate(...args: any[]): any { return this; }
with(...args: any[]): any { return this; }
},

Range: class {
start: any;
end: any;

constructor(start: any, end: any) {
this.start = start;
this.end = end;
}

contains(position: any): boolean {
return false;
}
},

MarkdownString: class {
value: string;

constructor(value?: string) {
this.value = value || '';
}

appendCodeblock(code: string): any {
return this;
}
},

Hover: class {
contents: any;
range: any;

constructor(contents: any, range?: any) {
this.contents = contents;
this.range = range;
}
},

CancellationToken: {},

OutputChannel: class {
name: string;

constructor(name: string = 'test-channel') {
this.name = name;
}

appendLine(message: string): void {}
append(message: string): void {}
replace(value: string): void {}
clear(): void {}
show(preserveFocus?: boolean): void {}
hide(): void {}
dispose(): void {}
},

TextDocument: class {},

HoverProvider: class {},

languages: {
registerHoverProvider: jest.fn(),
},

EndOfLine: {
LF: 1, // Line Feed character
CRLF: 2, // Carriage Return Line Feed
},

// Add any other VS Code API elements that might be needed
Uri: class {
constructor(...args: any[]) {}
static file(path: string): any { return { fsPath: path }; }
static parse(value: string): any { return { toString: () => value }; }
},

CompletionItemKind: {
Field: 5, // From VS Code API - Field = 5
Variable: 6, // From VS Code API - Variable = 6
Keyword: 14, // From VS Code API - Keyword = 14
},

window: {
createOutputChannel: (name: string) => new mockedVSCode.OutputChannel(name),
},

CompletionItem: class {
label: string;
kind?: any;
detail?: string;
insertText?: string;
data?: any;

constructor(labelOrConfiguration: string | any, kind?: any) {
if (typeof labelOrConfiguration === 'string') {
this.label = labelOrConfiguration;
this.kind = kind;
} else {
// If passed an object with configuration
Object.assign(this, labelOrConfiguration);
}
}
},
};

export = mockedVSCode;
12 changes: 12 additions & 0 deletions coverage/coverage-summary.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{"total": {"lines":{"total":2176,"covered":1366,"skipped":0,"pct":62.77},"statements":{"total":2204,"covered":1380,"skipped":0,"pct":62.61},"functions":{"total":337,"covered":129,"skipped":0,"pct":38.27},"branches":{"total":524,"covered":217,"skipped":0,"pct":41.41},"branchesTrue":{"total":0,"covered":0,"skipped":0,"pct":100}}
,"/mnt/ext2/code/prompts/github/forks/vscode-cashscript/src/CashscriptCompletionProvider.ts": {"lines":{"total":118,"covered":96,"skipped":0,"pct":81.35},"functions":{"total":19,"covered":15,"skipped":0,"pct":78.94},"statements":{"total":138,"covered":103,"skipped":0,"pct":74.63},"branches":{"total":68,"covered":34,"skipped":0,"pct":50}}
,"/mnt/ext2/code/prompts/github/forks/vscode-cashscript/src/CashscriptSignatureCompleter.ts": {"lines":{"total":11,"covered":11,"skipped":0,"pct":100},"functions":{"total":2,"covered":2,"skipped":0,"pct":100},"statements":{"total":11,"covered":11,"skipped":0,"pct":100},"branches":{"total":3,"covered":2,"skipped":0,"pct":66.66}}
,"/mnt/ext2/code/prompts/github/forks/vscode-cashscript/src/LanguageDesc.ts": {"lines":{"total":14,"covered":14,"skipped":0,"pct":100},"functions":{"total":1,"covered":1,"skipped":0,"pct":100},"statements":{"total":19,"covered":19,"skipped":0,"pct":100},"branches":{"total":9,"covered":7,"skipped":0,"pct":77.77}}
,"/mnt/ext2/code/prompts/github/forks/vscode-cashscript/src/extension.ts": {"lines":{"total":20,"covered":20,"skipped":0,"pct":100},"functions":{"total":2,"covered":2,"skipped":0,"pct":100},"statements":{"total":20,"covered":20,"skipped":0,"pct":100},"branches":{"total":2,"covered":2,"skipped":0,"pct":100}}
,"/mnt/ext2/code/prompts/github/forks/vscode-cashscript/src/server.ts": {"lines":{"total":21,"covered":14,"skipped":0,"pct":66.66},"functions":{"total":4,"covered":1,"skipped":0,"pct":25},"statements":{"total":22,"covered":14,"skipped":0,"pct":63.63},"branches":{"total":2,"covered":0,"skipped":0,"pct":0}}
,"/mnt/ext2/code/prompts/github/forks/vscode-cashscript/src/CashscriptLinter/CashscriptLinter.ts": {"lines":{"total":17,"covered":17,"skipped":0,"pct":100},"functions":{"total":1,"covered":1,"skipped":0,"pct":100},"statements":{"total":17,"covered":17,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
,"/mnt/ext2/code/prompts/github/forks/vscode-cashscript/src/CashscriptLinter/ErrorListeners.ts": {"lines":{"total":12,"covered":12,"skipped":0,"pct":100},"functions":{"total":4,"covered":4,"skipped":0,"pct":100},"statements":{"total":12,"covered":12,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
,"/mnt/ext2/code/prompts/github/forks/vscode-cashscript/src/CashscriptLinter/grammar/CashScriptLexer.ts": {"lines":{"total":103,"covered":96,"skipped":0,"pct":93.2},"functions":{"total":10,"covered":3,"skipped":0,"pct":30},"statements":{"total":104,"covered":97,"skipped":0,"pct":93.26},"branches":{"total":2,"covered":2,"skipped":0,"pct":100}}
,"/mnt/ext2/code/prompts/github/forks/vscode-cashscript/src/CashscriptLinter/grammar/CashScriptParser.ts": {"lines":{"total":1858,"covered":1084,"skipped":0,"pct":58.34},"functions":{"total":294,"covered":100,"skipped":0,"pct":34.01},"statements":{"total":1859,"covered":1085,"skipped":0,"pct":58.36},"branches":{"total":438,"covered":170,"skipped":0,"pct":38.81}}
,"/mnt/ext2/code/prompts/github/forks/vscode-cashscript/src/CashscriptLinter/grammar/CashScriptVisitor.ts": {"lines":{"total":2,"covered":2,"skipped":0,"pct":100},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":2,"covered":2,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
}
28 changes: 28 additions & 0 deletions debug_test_tokens.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

import { CashScriptLexer } from './src/CashscriptLinter/grammar/CashScriptLexer.js';
import { CharStreams } from 'antlr4ts';

const code = `
pragma cashscript ^0.8.0;

contract ComplexContract(int threshold, pubkey owner) {
function spend(sig signature, int amount) {
require(verify(owner, signature));
require(amount > threshold);
}
}
`;

const chars = new CharStreams.fromString(code);
const lexer = new CashScriptLexer(chars);
lexer.removeErrorListeners();

const tokens = [];
let token;
do {
token = lexer.nextToken();
tokens.push({ type: token.type, text: token.text });
} while (token.type !== CashScriptLexer.EOF);

console.log('Tokens:', tokens.map(t => `${t.text}(${t.type})`).join(', '));

27 changes: 27 additions & 0 deletions dist/debug_tokens.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var antlr4_1 = require("antlr4");
var CashScriptLexer_1 = require("./src/CashscriptLinter/grammar/CashScriptLexer");
var debugLexer = function (code) {
console.log("Code: ".concat(code));
console.log('Tokens:');
var inputStream = new antlr4_1.CharStream(code);
var lexer = new CashScriptLexer_1.default(inputStream);
var token;
var i = 0;
do {
token = lexer.nextToken();
console.log(" [".concat(i, "] type=").concat(token.type, ", text='").concat(token.text, "'"));
i++;
} while (token.type !== CashScriptLexer_1.default.EOF);
console.log('');
};
// Debug various test cases
debugLexer('pragma cashscript ^0.8.0;');
debugLexer('contract MyContract(int x) { }');
debugLexer('function spend(int secret) { }');
debugLexer('require(balance > 100);');
debugLexer('a + b - c * d / e % f == g != h < i > j <= k >= l && m || n ! o');
debugLexer('int bool string pubkey sig datasig');
debugLexer('constant');
debugLexer(' int x = 5 ; ');
Loading