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
10 changes: 2 additions & 8 deletions apps/vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
"package": "node scripts/package.js",
"publish": "node scripts/publish.js",
"tsc": "tsc -b tsconfig.json",
"clean": "rm -r dist/",
"vscode:install-extension": "code --install-extension ./dist/regex-radar-*.vsix",
"vscode:uninstall-extension": "code --uninstall-extension regex-radar.regex-radar"
"clean": "rm -r dist/"
},
"devDependencies": {
"@types/node": "^22.18.13",
Expand All @@ -27,11 +25,6 @@
"@regex-radar/client": "*",
"vscode-languageclient": "^9.0.1"
},
"imports": {
"#wasm/tree-sitter.wasm": "./dist/wasm/tree-sitter.wasm",
"#wasm/grammars/*.wasm": "./dist/wasm/*.wasm",
"#workers/recheck/thread.worker": "./dist/workers/recheck/thread.worker.js"
},
"repository": {
"type": "git",
"url": "https://github.com/kevinramharak/regex-radar.git",
Expand All @@ -58,6 +51,7 @@
"dist/server.min.js",
"dist/wasm/*.wasm",
"dist/workers/recheck/*",
"dist/node_modules/**",
"assets/icon.png",
"LICENSE"
],
Expand Down
15 changes: 12 additions & 3 deletions apps/vscode-extension/scripts/package.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-check
import * as path from 'node:path';
import { readFile, writeFile, readdir, copyFile, mkdir } from 'node:fs/promises';
import { readFile, writeFile, readdir, copyFile, mkdir, cp } from 'node:fs/promises';
import { fileURLToPath } from 'node:url';

import { createVSIX } from '@vscode/vsce';
Expand Down Expand Up @@ -56,7 +56,7 @@ async function ensureServerWasmFilesAreCopied() {
]);
}

const workerPath = path.resolve(nodeModulesPath, '@local', 'recheck', 'lib', 'thread.worker.js');
const workerPath = path.resolve(nodeModulesPath, '@regex-radar', 'recheck-esm', 'lib', 'thread.worker.js');
const workerDestinationPath = path.resolve(distDirectoryPath, 'workers', 'recheck');

async function ensureWorkerFilesAreCopied() {
Expand All @@ -66,8 +66,15 @@ async function ensureWorkerFilesAreCopied() {
await copyFile(workerPath, path.join(workerDestinationPath, 'thread.worker.js'));
}

async function ensureDependenciesAreCopied() {
console.log('copying @regex-radar/recheck-scalajs');
const source = path.resolve(nodeModulesPath, '@regex-radar', 'recheck-scalajs')
const dest = path.resolve(distDirectoryPath, 'node_modules', '@regex-radar', 'recheck-scalajs');
await cp(source, dest, { recursive: true });
}

/**
* @param {import('../package.json') & { imports: Record<string, string>}} json
* @param {import('../package.json') & Record<string, unknown>} json
*/
async function patchPackageJson(json) {
console.log('patching package.json');
Expand All @@ -79,6 +86,7 @@ async function patchPackageJson(json) {
json.main = mainMin;
}
// create import mappings for the wasm and worker paths
// TODO: just copy these dependencies to dist/node_modules and drop the import maps
json['imports'] = {
'#wasm/tree-sitter.wasm': './dist/wasm/tree-sitter.wasm',
'#wasm/grammars/*.wasm': './dist/wasm/*.wasm',
Expand Down Expand Up @@ -188,6 +196,7 @@ async function main(...args) {
await ensureServerWasmFilesAreCopied();
await ensureWorkerFilesAreCopied();
await ensureServerModuleIsCopied();
await ensureDependenciesAreCopied();
await patchPackageJson(json);
await packageVSIX(isPreRelease);
} catch (error) {
Expand Down
8 changes: 4 additions & 4 deletions docs/architecture/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ This directory contains documentation for the internal architecture of the Regex
Regex Radar is built on top of the Language Server Protocol (LSP), with a strict separation between:

- The **client extension** (VS Code)
- The **language server** (discovery, analysis, diagnostics)
- The **shared protocol** (custom requests, configuration, capabilities)

Each subsystem has its own document. Only `diagnostics.md` exists today; the others serve asroadmaps for future documentation.
- The **language client** (LSP Client)
- The **language server** (LSP Server)
- The **shared protocol** (custom requests, configuration, capabilities - build on top of LSP)
- The **Regex Radar features** (linter, ReDoS check, analysis, diagnostics)

## Diagram

Expand Down
22 changes: 22 additions & 0 deletions docs/architecture/parsers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Regex Radar - Parsers Architecture

This document describes how Regex Radar parses source files into structured information that other components can use.

Its main features are:

- Provide incremental ASTs for (virtual) source files.
- Cache ASTs with invalidation / (minimal) reparsing on edits.
- Provide tree-sitter queries callers can use to extract information from the ASTs
- Cache & own the tree sitter instances (this requires manual memory management for the instances returned from the WASM binary).
- Be as language-agnostic as possible, implementing new languages should be fairly easy and straightforward.

## Tree Sitter
Regex Radar uses `tree-sitter`(https://tree-sitter.github.io/tree-sitter/) to implement its parsers. This brings the following advantages:

- A WASM binding with [`web-tree-sitter`](https://github.com/tree-sitter/tree-sitter/tree/master/lib/binding_web)
- A lot of grammars for programming languages available at [`tree-sitter-grammars`](https://github.com/tree-sitter-grammars) and [`tree-sitter`](https://github.com/tree-sitter)
- A powerful [query language](https://tree-sitter.github.io/tree-sitter/using-parsers/queries/1-syntax.html) to simplify extracting information from the ASTs.
- Is build with edits in mind, providing an [edit API](https://tree-sitter.github.io/tree-sitter/using-parsers/3-advanced-parsing.html#editing) to effeciently reparse changed documents. This synergizes well with incremental document synchronization that the LSP defines.

### Grammars
Grammars are generated by a build script, and copied to the consuming applications as part of their package scripts.
1 change: 0 additions & 1 deletion esbuild/plugins/alias-esm-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const aliasEsmPlugin = {
'vscode-jsonrpc': '@local/vscode-jsonrpc',
'vscode-languageserver-protocol': '@local/vscode-languageserver-protocol',
'vscode-languageserver': '@local/vscode-languageserver',
recheck: '@local/recheck',
};
}
},
Expand Down
2 changes: 1 addition & 1 deletion fixture/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "The test directory to test the Regex Radar extension",
"private": true,
"scripts": {
"vscode:install-extension": "code --install-extension ../apps/vscode-extension/dist/regex-radar-0.1.0.vsix",
"vscode:install-extension": "code --install-extension ../apps/vscode-extension/dist/regex-radar-*.vsix",
"vscode:uninstall-extension": "code --uninstall-extension regex-radar.regex-radar"
}
}
Loading