Skip to content

Instantly share code, notes, and snippets.

@simolus3
simolus3 / info.md
Last active March 31, 2023 05:22
Analyzer plugin - tips and tricks

Analyzer plugins - tips and tricks

Debugging

Analyzer plugins run in a processes started and managed by the analysis server. This is useful when shipping plugins to users, but unfortunate for us as we can't attach a debugger to the plugin process.

Luckily, we can use a little trick to help us here. For debugging purposes, we instead use the following model. The actual plugin will start a websocket server. When the proxy loaded by the analysis server gets started, it will connect to that server and relay all operations. In fact, almost no code changes are necessary to the plugin.

Moor: Sent CREATE TABLE IF NOT EXISTS blood_sugars (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, value INTEGER NOT NULL, date INTEGER NOT NULL, type VARCHAR NOT NULL); with args []
Moor: Sent INSERT INTO blood_sugars (id, value, date, type) VALUES (?, ?, ?, ?) with args [2, 13, 1578779185, some type]
Moor: Sent SELECT * FROM blood_sugars WHERE (CAST(strftime("%Y", date, "unixepoch") AS INTEGER)) = ? AND (CAST(strftime("%m", date, "unixepoch") AS INTEGER)) = ? AND (CAST(strftime("%d", date, "unixepoch") AS INTEGER)) = ?; with args [2020, 1, 11]
[BloodSugar(id: 2, value: 13, date: 2020-01-11 22:46:25.000, type: some type)]
@simolus3
simolus3 / number_length.dart
Last active March 31, 2020 14:51
Benchmark of number length testing
import 'dart:math';
import 'dart:typed_data';
import 'package:benchmark_harness/benchmark_harness.dart';
const length = 1000000;
final inputs = Int64List(length);
class WithLog extends BenchmarkBase {
WithLog() : super('log');
import 'package:moor_ffi/database.dart';
void main() {
final db = Database.memory();
db.execute('''
CREATE TABLE ravs(
id INTEGER NOT NULL PRIMARY KEY,
originalId INTEGER NOT NULL,
sourceId INTEGER NOT NULL,
import 'dart:math';
import 'dart:async';
import 'dart:typed_data';
const _int32Length = 32 ~/ 8;
final _encodeInts = ByteData(_int32Length);
extension ReadLengthPrefixed on Stream<List<int>> {
// Note: Assumes that length bytes aren't splitted across multiple packets
Stream<Uint8List> transformLengthPrefixed() async* {
@simolus3
simolus3 / cipher_db.dart
Last active January 15, 2021 09:08
Template to use moor_ffi with SQLCipher
import 'dart:async';
import 'dart:ffi';
import 'dart:io';
import 'dart:math';
import 'package:moor/backends.dart';
import 'package:moor/moor.dart';
import 'package:moor_ffi/moor_ffi.dart';
import 'package:moor_ffi/open_helper.dart';
@simolus3
simolus3 / _usage.md
Created July 15, 2020 12:00
build.yaml schema

IntelliJ

Open a build.yaml file and click on "No JSON schema" in the bottom toolbar (at the right). Click on "New schema mapping" and fill in the options:

  • Name: build.yaml, or what you prefer
  • Schema file or URL: https://simonbinder.eu/schema.json
  • Schema version: JSON schema version 7
  • The file pattern should be build.yaml and optionally *.build.yaml
@simolus3
simolus3 / gist:e53810ef299584cac799f619066fd6d5
Created August 26, 2020 08:51
JSON schema for dart_test.yaml files
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "http://json.schemastore.org/dart_test",
"title": "dart_test.yaml",
"description": "Configuration for Dart tests",
"definitions": {
"timeout": {
"$comment": "Based on https://github.com/dart-lang/test/blob/3b8d3b90efd24f55f7316cd414716d1cb031761c/pkgs/test_api/lib/src/frontend/timeout.dart#L55-L68",
"oneOf": [
{
@simolus3
simolus3 / why_imported.dart
Last active June 5, 2021 20:42
Analyze where dart:html came from
import 'package:analyzer/dart/analysis/analysis_context_collection.dart';
import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:path/path.dart';
// Usage: dart tool/why_imported.dart path/to/entrypoint.dart
void main(List<String> args) async {
final collection = AnalysisContextCollection(includedPaths: [current]);
final entrypoint = args.single;
@simolus3
simolus3 / chacha20.dart
Created September 24, 2021 21:11
Fast and efficient ChaCha20 implementation in pure Dart
import 'dart:convert';
import 'dart:math';
import 'dart:typed_data';
/// A pure-Dart implementation of the ChaCha20 algorithm as specified by RFC
/// 7539.
///
/// To encrypt or decrypt a full message, call [encrypt] or [decrypt].
/// This codec supports an optimized, memory-efficient conversion of streaming
/// data as well: